Compute Library
 22.08
CLBufferMemoryRegion Class Referencefinal

OpenCL buffer memory region implementation. More...

#include <CLMemoryRegion.h>

Collaboration diagram for CLBufferMemoryRegion:
[legend]

Public Member Functions

 CLBufferMemoryRegion (cl_mem_flags flags, size_t size)
 Constructor. More...
 
 CLBufferMemoryRegion (const cl::Buffer &buffer)
 Constructor. More...
 
void * ptr () final
 Host/SVM pointer accessor. More...
 
void * map (cl::CommandQueue &q, bool blocking) final
 Enqueue a map operation of the allocated buffer on the given queue. More...
 
void unmap (cl::CommandQueue &q) final
 Enqueue an unmap operation of the allocated buffer on the given queue. More...
 
- Public Member Functions inherited from ICLMemoryRegion
 ICLMemoryRegion (size_t size)
 Constructor. More...
 
virtual ~ICLMemoryRegion ()=default
 Default Destructor. More...
 
 ICLMemoryRegion (const ICLMemoryRegion &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 ICLMemoryRegion (ICLMemoryRegion &&)=default
 Default move constructor. More...
 
ICLMemoryRegionoperator= (const ICLMemoryRegion &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
ICLMemoryRegionoperator= (ICLMemoryRegion &&)=default
 Default move assignment operator. More...
 
const cl::Buffer & cl_data () const
 Returns the underlying CL buffer. More...
 
void * buffer () override
 Returns the pointer to the allocated data. More...
 
const void * buffer () const override
 Returns the pointer to the allocated data. More...
 
std::unique_ptr< IMemoryRegionextract_subregion (size_t offset, size_t size) override
 Extract a sub-region from the memory. More...
 
- Public Member Functions inherited from IMemoryRegion
 IMemoryRegion (size_t size)
 Default constructor. More...
 
virtual ~IMemoryRegion ()=default
 Virtual Destructor. More...
 
size_t size () const
 Memory region size accessor. More...
 
void set_size (size_t size)
 Sets size of region. More...
 

Detailed Description

OpenCL buffer memory region implementation.

Definition at line 95 of file CLMemoryRegion.h.

Constructor & Destructor Documentation

◆ CLBufferMemoryRegion() [1/2]

CLBufferMemoryRegion ( cl_mem_flags  flags,
size_t  size 
)

Constructor.

Parameters
[in]flagsMemory flags
[in]sizeRegion size

Definition at line 61 of file CLMemoryRegion.cpp.

References CLScheduler::get().

63 {
64  if(_size != 0)
65  {
66  _mem = cl::Buffer(CLScheduler::get().context(), flags, _size);
67  }
68 }
static CLScheduler & get()
Access the scheduler singleton.
ICLMemoryRegion(size_t size)
Constructor.
size_t size() const
Memory region size accessor.
Definition: IMemoryRegion.h:73

◆ CLBufferMemoryRegion() [2/2]

CLBufferMemoryRegion ( const cl::Buffer &  buffer)

Constructor.

Parameters
[in]bufferBuffer to be used as a memory region

Definition at line 70 of file CLMemoryRegion.cpp.

References ICLMemoryRegion::buffer().

71  : ICLMemoryRegion(buffer.getInfo<CL_MEM_SIZE>())
72 {
73  _mem = buffer;
74 }
ICLMemoryRegion(size_t size)
Constructor.
void * buffer() override
Returns the pointer to the allocated data.

Member Function Documentation

◆ map()

void * map ( cl::CommandQueue &  q,
bool  blocking 
)
finalvirtual

Enqueue a map operation of the allocated buffer on the given queue.

Parameters
[in,out]qThe CL command queue to use for the mapping operation.
[in]blockingIf true, then the mapping will be ready to use by the time this method returns, else it is the caller's responsibility to flush the queue and wait for the mapping operation to have completed before using the returned mapping pointer.
Returns
The mapping address.

Implements ICLMemoryRegion.

Definition at line 81 of file CLMemoryRegion.cpp.

References ARM_COMPUTE_ERROR_ON.

82 {
83  ARM_COMPUTE_ERROR_ON(_mem.get() == nullptr);
84  _mapping = q.enqueueMapBuffer(_mem, blocking ? CL_TRUE : CL_FALSE, CL_MAP_READ | CL_MAP_WRITE, 0, _size);
85  return _mapping;
86 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466

◆ ptr()

void * ptr ( )
finalvirtual

Host/SVM pointer accessor.

Returns
Host/SVM pointer base

Implements ICLMemoryRegion.

Definition at line 76 of file CLMemoryRegion.cpp.

77 {
78  return nullptr;
79 }

◆ unmap()

void unmap ( cl::CommandQueue &  q)
finalvirtual

Enqueue an unmap operation of the allocated buffer on the given queue.

Note
This method simply enqueue the unmap operation, it is the caller's responsibility to flush the queue and make sure the unmap is finished before the memory is accessed by the device.
Parameters
[in,out]qThe CL command queue to use for the mapping operation.

Implements ICLMemoryRegion.

Definition at line 88 of file CLMemoryRegion.cpp.

References ARM_COMPUTE_ERROR_ON, clFinish(), clSVMAlloc(), clSVMFree(), CLScheduler::get(), ICLMemoryRegion::ICLMemoryRegion(), and IMemoryRegion::size().

89 {
90  ARM_COMPUTE_ERROR_ON(_mem.get() == nullptr);
91  q.enqueueUnmapMemObject(_mem, _mapping);
92  _mapping = nullptr;
93 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466

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