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... | |
void | getUsage (exint &total, exint ¬_in_use) const |
cl::Buffer | allocBuffer (CE_Context *, int64 size) |
void | returnBuffer (cl::Buffer &&buf, bool use_pool) |
exint | sweepInUse () |
exint | freeMemory (exint amount) |
void | registerClient (UT_MemoryResource *resource) |
void | unregisterClient (UT_MemoryResource *resource) |
Friends | |
class | ut_clBuffer |
class | CE_Context |
This class implements a memory pool for OpenCL buffer objects, using an LRUCache to limit the size of the pool.
Definition at line 34 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.
Attempts to release the requested amount of memory back to the system. Returns the amount actually freed.
|
inline |
Returns the maximum size of the pool.
Definition at line 49 of file CE_MemoryPool.h.
Query the current usage; total is the total amount of memory held by the pool, not_in_use is the amount that can be freed immediately on demand.
Definition at line 59 of file CE_MemoryPool.h.
|
inline |
Registers this memory pool as a client for the given resource. This must be called with the appropriate memory resource to ensure that the memory pool can be asked to unload when device memory is tight.
Definition at line 90 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, |
bool | use_pool | ||
) |
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 46 of file CE_MemoryPool.h.
exint 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. Returns the amount of released memory (i.e. memory that's returned back to the system).
|
inline |
Unregisters this memory pool as a client for the given resource. This must be called on destruction with the same resource used with registerClient().
Definition at line 97 of file CE_MemoryPool.h.
|
friend |
Definition at line 161 of file CE_MemoryPool.h.
|
friend |
Definition at line 160 of file CE_MemoryPool.h.