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...
 
cl::Buffer allocBuffer (CE_Context *, int64 size)
 
void returnBuffer (cl::Buffer &&buf)
 
void sweepInUse ()
 

Friends

class ut_clBuffer
 

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

int64 CE_MemoryPool::getMaxSize ( ) const
inline

Returns the maximum size of the pool.

Definition at line 44 of file CE_MemoryPool.h.

void CE_MemoryPool::reportUsage ( ) const

Dump memory usage statistics to stderr.

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

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

Friends And Related Function Documentation

friend class ut_clBuffer
friend

Definition at line 90 of file CE_MemoryPool.h.


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