HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CE_MemoryPool Class Reference

#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 &not_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
 

Detailed Description

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.

Constructor & Destructor Documentation

CE_MemoryPool::CE_MemoryPool ( int64  size)

Initialize the pool with specified maximum size.

virtual CE_MemoryPool::~CE_MemoryPool ( )
virtual

Member Function Documentation

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.

exint CE_MemoryPool::freeMemory ( exint  amount)

Attempts to release the requested amount of memory back to the system. Returns the amount actually freed.

int64 CE_MemoryPool::getMaxSize ( ) const
inline

Returns the maximum size of the pool.

Definition at line 49 of file CE_MemoryPool.h.

void CE_MemoryPool::getUsage ( exint total,
exint not_in_use 
) const
inline

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.

void CE_MemoryPool::registerClient ( UT_MemoryResource resource)
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().

void CE_MemoryPool::setMaxSize ( int64  size)
inline

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).

void CE_MemoryPool::unregisterClient ( UT_MemoryResource resource)
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.

Friends And Related Function Documentation

friend class CE_Context
friend

Definition at line 161 of file CE_MemoryPool.h.

friend class ut_clBuffer
friend

Definition at line 160 of file CE_MemoryPool.h.


The documentation for this class was generated from the following file: