Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
342e007d
Commit
342e007d
authored
11 years ago
by
Vladislav Vinogradov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
now Allocator accepts GpuMat* instead of 3 pointers
parent
3b412b51
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
29 deletions
+28
-29
cuda.hpp
modules/core/include/opencv2/core/cuda.hpp
+3
-2
private.cuda.hpp
modules/core/include/opencv2/core/private.cuda.hpp
+2
-2
gpu_mat.cu
modules/core/src/cuda/gpu_mat.cu
+16
-17
cuda_buffer_pool.cpp
modules/core/src/cuda_buffer_pool.cpp
+7
-8
No files found.
modules/core/include/opencv2/core/cuda.hpp
View file @
342e007d
...
@@ -66,8 +66,9 @@ public:
...
@@ -66,8 +66,9 @@ public:
public
:
public
:
virtual
~
Allocator
()
{}
virtual
~
Allocator
()
{}
virtual
bool
allocate
(
uchar
**
devPtr
,
size_t
*
step
,
int
**
refcount
,
int
rows
,
int
cols
,
size_t
elemSize
)
=
0
;
// allocator must fill data, step and refcount fields
virtual
void
free
(
uchar
*
devPtr
,
int
*
refcount
)
=
0
;
virtual
bool
allocate
(
GpuMat
*
mat
,
int
rows
,
int
cols
,
size_t
elemSize
)
=
0
;
virtual
void
free
(
GpuMat
*
mat
)
=
0
;
};
};
//! default allocator
//! default allocator
...
...
This diff is collapsed.
Click to expand it.
modules/core/include/opencv2/core/private.cuda.hpp
View file @
342e007d
...
@@ -98,8 +98,8 @@ namespace cv { namespace cuda
...
@@ -98,8 +98,8 @@ namespace cv { namespace cuda
explicit
StackAllocator
(
cudaStream_t
stream
);
explicit
StackAllocator
(
cudaStream_t
stream
);
~
StackAllocator
();
~
StackAllocator
();
bool
allocate
(
uchar
**
devPtr
,
size_t
*
step
,
int
**
refcoun
t
,
int
rows
,
int
cols
,
size_t
elemSize
);
bool
allocate
(
GpuMat
*
ma
t
,
int
rows
,
int
cols
,
size_t
elemSize
);
void
free
(
uchar
*
devPtr
,
int
*
refcoun
t
);
void
free
(
GpuMat
*
ma
t
);
private
:
private
:
StackAllocator
(
const
StackAllocator
&
);
StackAllocator
(
const
StackAllocator
&
);
...
...
This diff is collapsed.
Click to expand it.
modules/core/src/cuda/gpu_mat.cu
View file @
342e007d
...
@@ -60,32 +60,32 @@ namespace
...
@@ -60,32 +60,32 @@ namespace
class DefaultAllocator : public GpuMat::Allocator
class DefaultAllocator : public GpuMat::Allocator
{
{
public:
public:
bool allocate(
uchar** devPtr, size_t* step, int** refcoun
t, int rows, int cols, size_t elemSize);
bool allocate(
GpuMat* ma
t, int rows, int cols, size_t elemSize);
void free(
uchar* devPtr, int* refcoun
t);
void free(
GpuMat* ma
t);
};
};
bool DefaultAllocator::allocate(
uchar** devPtr, size_t* step, int** refcoun
t, int rows, int cols, size_t elemSize)
bool DefaultAllocator::allocate(
GpuMat* ma
t, int rows, int cols, size_t elemSize)
{
{
if (rows > 1 && cols > 1)
if (rows > 1 && cols > 1)
{
{
CV_CUDEV_SAFE_CALL( cudaMallocPitch(
devPtr,
step, elemSize * cols, rows) );
CV_CUDEV_SAFE_CALL( cudaMallocPitch(
&mat->data, &mat->
step, elemSize * cols, rows) );
}
}
else
else
{
{
// Single row or single column must be continuous
// Single row or single column must be continuous
CV_CUDEV_SAFE_CALL( cudaMalloc(
devPtr
, elemSize * cols * rows) );
CV_CUDEV_SAFE_CALL( cudaMalloc(
&mat->data
, elemSize * cols * rows) );
*
step = elemSize * cols;
mat->
step = elemSize * cols;
}
}
*refcount = static_cast<int*>(fastMalloc(sizeof(int)
));
mat->refcount = (int*) fastMalloc(sizeof(int
));
return true;
return true;
}
}
void DefaultAllocator::free(
uchar* devPtr, int* refcoun
t)
void DefaultAllocator::free(
GpuMat* ma
t)
{
{
cudaFree(
devPtr
);
cudaFree(
mat->datastart
);
fastFree(refcount);
fastFree(
mat->
refcount);
}
}
DefaultAllocator cudaDefaultAllocator;
DefaultAllocator cudaDefaultAllocator;
...
@@ -124,16 +124,15 @@ void cv::cuda::GpuMat::create(int _rows, int _cols, int _type)
...
@@ -124,16 +124,15 @@ void cv::cuda::GpuMat::create(int _rows, int _cols, int _type)
rows = _rows;
rows = _rows;
cols = _cols;
cols = _cols;
uchar* devPtr;
const size_t esz = elemSize();
const size_t esz = elemSize();
bool allocSuccess = allocator->allocate(
&devPtr, &step, &refcount
, rows, cols, esz);
bool allocSuccess = allocator->allocate(
this
, rows, cols, esz);
if (!allocSuccess)
if (!allocSuccess)
{
{
// custom allocator fails, try default allocator
// custom allocator fails, try default allocator
allocator = defaultAllocator();
allocator = defaultAllocator();
allocSuccess = allocator->allocate(
&devPtr, &step, &refcount
, rows, cols, esz);
allocSuccess = allocator->allocate(
this
, rows, cols, esz);
CV_Assert( allocSuccess );
CV_Assert( allocSuccess );
}
}
...
@@ -143,11 +142,11 @@ void cv::cuda::GpuMat::create(int _rows, int _cols, int _type)
...
@@ -143,11 +142,11 @@ void cv::cuda::GpuMat::create(int _rows, int _cols, int _type)
int64 _nettosize = static_cast<int64>(step) * rows;
int64 _nettosize = static_cast<int64>(step) * rows;
size_t nettosize = static_cast<size_t>(_nettosize);
size_t nettosize = static_cast<size_t>(_nettosize);
datastart = data
= static_cast<uchar*>(devPtr)
;
datastart = data;
dataend = data + nettosize;
dataend = data + nettosize;
refcount = static_cast<int*>(fastMalloc(sizeof(*refcount)));
if (refcount)
*refcount = 1;
*refcount = 1;
}
}
}
}
...
@@ -159,7 +158,7 @@ void cv::cuda::GpuMat::release()
...
@@ -159,7 +158,7 @@ void cv::cuda::GpuMat::release()
CV_DbgAssert( allocator != 0 );
CV_DbgAssert( allocator != 0 );
if (refcount && CV_XADD(refcount, -1) == 1)
if (refcount && CV_XADD(refcount, -1) == 1)
allocator->free(
datastart, refcount
);
allocator->free(
this
);
data = datastart = dataend = 0;
data = datastart = dataend = 0;
step = rows = cols = 0;
step = rows = cols = 0;
...
...
This diff is collapsed.
Click to expand it.
modules/core/src/cuda_buffer_pool.cpp
View file @
342e007d
...
@@ -337,7 +337,7 @@ namespace
...
@@ -337,7 +337,7 @@ namespace
}
}
}
}
bool
cv
::
cuda
::
StackAllocator
::
allocate
(
uchar
**
devPtr
,
size_t
*
step
,
int
**
refcoun
t
,
int
rows
,
int
cols
,
size_t
elemSize
)
bool
cv
::
cuda
::
StackAllocator
::
allocate
(
GpuMat
*
ma
t
,
int
rows
,
int
cols
,
size_t
elemSize
)
{
{
if
(
memStack_
==
0
)
if
(
memStack_
==
0
)
return
false
;
return
false
;
...
@@ -361,21 +361,20 @@ bool cv::cuda::StackAllocator::allocate(uchar** devPtr, size_t* step, int** refc
...
@@ -361,21 +361,20 @@ bool cv::cuda::StackAllocator::allocate(uchar** devPtr, size_t* step, int** refc
if
(
ptr
==
0
)
if
(
ptr
==
0
)
return
false
;
return
false
;
*
devPtr
=
ptr
;
mat
->
data
=
ptr
;
*
step
=
pitch
;
mat
->
step
=
pitch
;
mat
->
refcount
=
(
int
*
)
fastMalloc
(
sizeof
(
int
));
*
refcount
=
static_cast
<
int
*>
(
fastMalloc
(
sizeof
(
int
)));
return
true
;
return
true
;
}
}
void
cv
::
cuda
::
StackAllocator
::
free
(
uchar
*
devPtr
,
int
*
refcoun
t
)
void
cv
::
cuda
::
StackAllocator
::
free
(
GpuMat
*
ma
t
)
{
{
if
(
memStack_
==
0
)
if
(
memStack_
==
0
)
return
;
return
;
memStack_
->
returnMemory
(
devPtr
);
memStack_
->
returnMemory
(
mat
->
datastart
);
fastFree
(
refcount
);
fastFree
(
mat
->
refcount
);
}
}
void
cv
::
cuda
::
setBufferPoolUsage
(
bool
on
)
void
cv
::
cuda
::
setBufferPoolUsage
(
bool
on
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment