mirror of
https://github.com/opencv/opencv.git
synced 2025-07-25 22:57:53 +08:00
Expose BufferPool class for external use also
This commit is contained in:
parent
c1007c7276
commit
cdcf44b3ef
@ -327,6 +327,34 @@ The function does not reallocate memory if the matrix has proper attributes alre
|
|||||||
*/
|
*/
|
||||||
CV_EXPORTS void ensureSizeIsEnough(int rows, int cols, int type, OutputArray arr);
|
CV_EXPORTS void ensureSizeIsEnough(int rows, int cols, int type, OutputArray arr);
|
||||||
|
|
||||||
|
/** @brief BufferPool for use with CUDA streams
|
||||||
|
|
||||||
|
* BufferPool utilizes cuda::Stream's allocator to create new buffers. It is
|
||||||
|
* particularly useful when BufferPoolUsage is set to true, or a custom
|
||||||
|
* allocator is specified for the cuda::Stream, and you want to implement your
|
||||||
|
* own stream based functions utilizing the same underlying GPU memory
|
||||||
|
* management.
|
||||||
|
*/
|
||||||
|
class CV_EXPORTS BufferPool
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! Gets the BufferPool for the given stream.
|
||||||
|
explicit BufferPool(Stream& stream);
|
||||||
|
|
||||||
|
//! Allocates a new GpuMat of given size and type.
|
||||||
|
GpuMat getBuffer(int rows, int cols, int type);
|
||||||
|
|
||||||
|
//! Allocates a new GpuMat of given size and type.
|
||||||
|
GpuMat getBuffer(Size size, int type) { return getBuffer(size.height, size.width, type); }
|
||||||
|
|
||||||
|
//! Returns the allocator associated with the stream.
|
||||||
|
Ptr<GpuMat::Allocator> getAllocator() const { return allocator_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ptr<GpuMat::Allocator> allocator_;
|
||||||
|
};
|
||||||
|
|
||||||
//! BufferPool management (must be called before Stream creation)
|
//! BufferPool management (must be called before Stream creation)
|
||||||
CV_EXPORTS void setBufferPoolUsage(bool on);
|
CV_EXPORTS void setBufferPoolUsage(bool on);
|
||||||
CV_EXPORTS void setBufferPoolConfig(int deviceId, size_t stackSize, int stackCount);
|
CV_EXPORTS void setBufferPoolConfig(int deviceId, size_t stackSize, int stackCount);
|
||||||
|
@ -102,20 +102,6 @@ static inline void throw_no_cuda() { CV_Error(cv::Error::StsNotImplemented, "The
|
|||||||
|
|
||||||
namespace cv { namespace cuda
|
namespace cv { namespace cuda
|
||||||
{
|
{
|
||||||
class CV_EXPORTS BufferPool
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit BufferPool(Stream& stream);
|
|
||||||
|
|
||||||
GpuMat getBuffer(int rows, int cols, int type);
|
|
||||||
GpuMat getBuffer(Size size, int type) { return getBuffer(size.height, size.width, type); }
|
|
||||||
|
|
||||||
GpuMat::Allocator* getAllocator() const { return allocator_; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
GpuMat::Allocator* allocator_;
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline void checkNppError(int code, const char* file, const int line, const char* func)
|
static inline void checkNppError(int code, const char* file, const int line, const char* func)
|
||||||
{
|
{
|
||||||
if (code < 0)
|
if (code < 0)
|
||||||
|
@ -668,20 +668,33 @@ void cv::cuda::setBufferPoolConfig(int deviceId, size_t stackSize, int stackCoun
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_CUDA
|
#ifndef HAVE_CUDA
|
||||||
|
cv::cuda::BufferPool::BufferPool(Stream& stream)
|
||||||
cv::cuda::BufferPool::BufferPool(Stream& stream) : allocator_(stream.impl_->stackAllocator.get())
|
{
|
||||||
|
(void) stream;
|
||||||
|
throw_no_cuda();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
cv::cuda::BufferPool::BufferPool(Stream& stream) : allocator_(stream.impl_->stackAllocator)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
GpuMat cv::cuda::BufferPool::getBuffer(int rows, int cols, int type)
|
GpuMat cv::cuda::BufferPool::getBuffer(int rows, int cols, int type)
|
||||||
{
|
{
|
||||||
|
#ifndef HAVE_CUDA
|
||||||
|
(void) rows;
|
||||||
|
(void) cols;
|
||||||
|
(void) type;
|
||||||
|
throw_no_cuda();
|
||||||
|
return GpuMat();
|
||||||
|
#else
|
||||||
GpuMat buf(allocator_);
|
GpuMat buf(allocator_);
|
||||||
buf.create(rows, cols, type);
|
buf.create(rows, cols, type);
|
||||||
return buf;
|
return buf;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
// Event
|
// Event
|
||||||
|
Loading…
Reference in New Issue
Block a user