Accelerated Computation Engine
Public Member Functions | List of all members
OpenCL::Buffer< T > Class Template Reference

#include <opencl_buffer.h>

Public Member Functions

void operator= (Buffer< T > &&other)
 
T & operator[] (int index)
 
 Buffer ()=default
 
 Buffer (Context *context, int size)
 
 Buffer (Buffer< T > &&other)
 
 ~Buffer ()
 
const T & at (int index) const
 
bool isNull () const
 
cl_mem id () const
 
int size () const
 
Event mapRead (CommandQueue *queue)
 
Event mapWrite (CommandQueue *queue)
 
Event unmap (CommandQueue *queue)
 
T * data ()
 

Detailed Description

template<class T>
class OpenCL::Buffer< T >

This can contain an OpenCL buffer object or be set to null. The buffer this class contains can be moved to another instance but not copied. This is a template class to enforce strong type checking of the underlying buffer data. This class provides methods for mapping the OpenCL buffer memory to a temporary host pointer and can be accessed through other helper methods that provides range checking or through a raw memory pointer. Other methods are provided for getting the size of the buffer and the underlying OpenCL memory ID used by other OpenCL classes.

Template Parameters
TThe type used to create the buffer data of this object.

Constructor & Destructor Documentation

◆ Buffer() [1/3]

template<class T>
OpenCL::Buffer< T >::Buffer ( )
default

Constructs a new buffer object that is set to null.

◆ Buffer() [2/3]

template<class T >
OpenCL::Buffer< T >::Buffer ( Context context,
int  size 
)

Constructs a new buffer object set to a new OpenCL buffer with the given context and size.

Parameters
contextPointer to context that this buffer object is created from.
sizeThe size of the buffer created as the number of elements of the template type defined.

◆ Buffer() [3/3]

template<class T >
OpenCL::Buffer< T >::Buffer ( Buffer< T > &&  other)

Constructs a new buffer object taking the state of the other given buffer object.

Parameters
otherThe other buffer object whose state, null or set to an OpenCL buffer, is taken by this new buffer object.

◆ ~Buffer()

template<class T >
OpenCL::Buffer< T >::~Buffer ( )

Clears all resources this buffer object may contain.

Member Function Documentation

◆ at()

template<class T >
const T & OpenCL::Buffer< T >::at ( int  index) const

Returns a read only reference to the element with the given index in this buffer object's mapped data for reading. If this buffer object is not mapped, the mapping is not for reading, or the index is out of range then an exception is thrown.

Parameters
index
Returns
Read only reference to element of mapped buffer with the given index.

◆ data()

template<class T >
T * OpenCL::Buffer< T >::data ( )

Returns the host memory pointer of this object's mapped OpenCL buffer data. If this object's buffer is not mapped then an exception is thrown. Care must be taken to only read or write to this pointer depending on what type of mapping it is. Reading from a write mapping or writing to a read mapping is undefined.

Returns
Pointer to host memory mapping of this object's OpenCL buffer.

◆ id()

template<class T >
cl_mem OpenCL::Buffer< T >::id ( ) const

Returns the OpenCL buffer ID of this object. If this object is null then an exception is thrown.

Returns
OpenCL buffer ID of this object.

◆ isNull()

template<class T >
bool OpenCL::Buffer< T >::isNull ( ) const

Tests if this buffer object is null or contains an OpenCL buffer.

Returns
True if this buffer object is null or false otherwise.

◆ mapRead()

template<class T >
Event OpenCL::Buffer< T >::mapRead ( CommandQueue queue)

Maps this object's OpenCL buffer data to a host memory pointer for reading that can be accessed through other methods of this class. The command to map memory is sent to the given command queue and is not complete until the returned event is complete. If this object is null or is already mapped then an exception is thrown.

Parameters
queuePointer to the command queue used to add the OpenCL command for mapping the memory.
Returns
The event for the mapping command sent to the given command queue.

◆ mapWrite()

template<class T >
Event OpenCL::Buffer< T >::mapWrite ( CommandQueue queue)

Maps this object's OpenCL buffer data to a host memory pointer for writing that can be accessed through other methods of this class. The command to map memory is sent to the given command queue and is not complete until the returned event is complete. If this object is null or is already mapped then an exception is thrown.

Parameters
queuePointer to the command queue used to add the OpenCL command for mapping the memory.
Returns
The event for the mapping command sent to the given command queue.

◆ operator=()

template<class T >
void OpenCL::Buffer< T >::operator= ( Buffer< T > &&  other)

Takes the state of the given buffer object , null or set to an OpenCL buffer, overwriting and clearing any OpenCL buffer this object may already contain.

Parameters
otherThe other buffer object whose state, null or set to an OpenCL buffer, is taken by this buffer object.

◆ operator[]()

template<class T >
T & OpenCL::Buffer< T >::operator[] ( int  index)

Returns a reference to the element with the given index in this buffer object's mapped data for writing. If this buffer object is not mapped, the mapping is not for writing, or the index is out of range then an exception is thrown.

Parameters
indexThe index of the element whose reference is returned.
Returns
Reference to element of mapped buffer with the given index.

◆ size()

template<class T >
int OpenCL::Buffer< T >::size ( ) const

Returns the size of this object's OpenCL buffer as the number of elements of the template type defined. If this object is null then -1 is returned.

Returns
The number of elements this buffer object contains or -1 if this object is null.

◆ unmap()

template<class T >
Event OpenCL::Buffer< T >::unmap ( CommandQueue queue)

Unmaps this object's OpenCL buffer data from host memory. The command to unmap memory is sent to the given command queue and is not complete until the returned event is complete. If the object is null or is not mapped then an exception is thrown.

Parameters
queuePointer to the command queue used to add the OpenCL command for unmapping the memory.
Returns
The event for the unmapping command sent to the given command queue.

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