HDK
|
#include <CE_MemoryPool.h>
Public Member Functions | |
CE_MemoryPool (int64 size) | |
Initialize the pool with specified maximum size. More... | |
virtual | ~CE_MemoryPool () |
void | clear () |
Empty the memory pool of all held buffers. More... | |
void | setMaxSize (int64 size) |
int64 | getMaxSize () const |
Returns the maximum size of the pool. More... | |
void | reportUsage () const |
Dump memory usage statistics to stderr. More... | |
void | reportUsage (std::ostream &os) const |
Dump memory to a stream. More... | |
cl::Buffer | allocBuffer (CE_Context *, int64 size) |
void | returnBuffer (cl::Buffer &&buf) |
void | sweepInUse () |
Friends | |
class | ut_clBuffer |
This class implements a memory pool for OpenCL buffer objects, using an LRUCache to limit the size of the pool.
Definition at line 30 of file CE_MemoryPool.h.
CE_MemoryPool::CE_MemoryPool | ( | int64 | size | ) |
Initialize the pool with specified maximum size.
|
virtual |
cl::Buffer CE_MemoryPool::allocBuffer | ( | CE_Context * | , |
int64 | size | ||
) |
Allocate a buffer for the provided context. If a buffer of the specified size already exists in the pool, it will be returned. Otherwise a new one will be created on the device.
void CE_MemoryPool::clear | ( | ) |
Empty the memory pool of all held buffers.
|
inline |
Returns the maximum size of the pool.
Definition at line 45 of file CE_MemoryPool.h.
void CE_MemoryPool::reportUsage | ( | ) | const |
Dump memory usage statistics to stderr.
void CE_MemoryPool::reportUsage | ( | std::ostream & | os | ) | const |
Dump memory to a stream.
void CE_MemoryPool::returnBuffer | ( | cl::Buffer && | buf | ) |
Check the provided buffer's reference count. If it is about to be released, return it to the pool if it will fit, else release it. If the reference count is higher than 1, meaning it is still active in an asynchronous operation like a kernel, put it on the inUse list to check later in sweepInUse().
Set the maximums size of the pool. This will prune the LRUCache as needed to fit the size.
Definition at line 42 of file CE_MemoryPool.h.
void CE_MemoryPool::sweepInUse | ( | ) |
Sweep the inUse list, looking for buffers that are no longer being used in an asynchronous operation and can be returned to the pool.
|
friend |
Definition at line 94 of file CE_MemoryPool.h.