BufferPool for use with CUDA streams. More...
#include <opencv2/core/cuda.hpp>
Public Member Functions | |
BufferPool (Stream &stream) | |
Gets the BufferPool for the given stream. | |
Ptr< GpuMat::Allocator > | getAllocator () const |
Returns the allocator associated with the stream. | |
GpuMat | getBuffer (int rows, int cols, int type) |
Allocates a new GpuMat of given size and type. | |
GpuMat | getBuffer (Size size, int type) |
Allocates a new GpuMat of given size and type. | |
Detailed Description
BufferPool for use with CUDA streams.
BufferPool utilizes Stream's allocator to create new buffers for GpuMat's. It is only useful when enabled with setBufferPoolUsage.
- Note
- setBufferPoolUsage must be called before any Stream declaration.
Users may specify custom allocator for Stream and may implement their own stream based functions utilizing the same underlying GPU memory management.
If custom allocator is not specified, BufferPool utilizes StackAllocator by default. StackAllocator allocates a chunk of GPU device memory beforehand, and when GpuMat is declared later on, it is given the pre-allocated memory. This kind of strategy reduces the number of calls for memory allocating APIs such as cudaMalloc or cudaMallocPitch.
Below is an example that utilizes BufferPool with StackAllocator:
If we allocate another GpuMat on pool1 in the above example, it will be carried out by the DefaultAllocator since the stack for pool1 is full.
If a third stream is declared in the above example, allocating with getBuffer within that stream will also be carried out by the DefaultAllocator because we've run out of stacks.
- Warning
- When utilizing StackAllocator, deallocation order is important.
Just like a stack, deallocation must be done in LIFO order. Below is an example of erroneous usage that violates LIFO rule. If OpenCV is compiled in Debug mode, this sample code will emit CV_Assert error.
Since C++ local variables are destroyed in the reverse order of construction, the code sample below satisfies the LIFO rule. Local GpuMat's are deallocated and the corresponding memory is automatically returned to the pool for later usage.
Constructor & Destructor Documentation
◆ BufferPool()
|
explicit |
Gets the BufferPool for the given stream.
Member Function Documentation
◆ getAllocator()
|
inline |
Returns the allocator associated with the stream.
◆ getBuffer() [1/2]
GpuMat cv::cuda::BufferPool::getBuffer | ( | int | rows, |
int | cols, | ||
int | type | ||
) |
Allocates a new GpuMat of given size and type.
◆ getBuffer() [2/2]
Allocates a new GpuMat of given size and type.
The documentation for this class was generated from the following file:
- opencv2/core/cuda.hpp