Compute Library
 23.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...
 
virtual ~CLBufferMemoryRegion () override
 
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 94 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 60 of file CLMemoryRegion.cpp.

62 {
63  if(_size != 0)
64  {
65  _mem = cl::Buffer(CLScheduler::get().context(), flags, _size);
66  }
67 }

References arm_compute::test::validation::context, and CLScheduler::get().

◆ CLBufferMemoryRegion() [2/2]

CLBufferMemoryRegion ( const cl::Buffer &  buffer)

Constructor.

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

Definition at line 69 of file CLMemoryRegion.cpp.

70  : ICLMemoryRegion(buffer.getInfo<CL_MEM_SIZE>())
71 {
72  _mem = buffer;
73 }

References ICLMemoryRegion::buffer().

◆ ~CLBufferMemoryRegion()

~CLBufferMemoryRegion ( )
overridevirtual

Definition at line 75 of file CLMemoryRegion.cpp.

76 {
77  // Flush the command queue to ensure all commands that may use this memory buffer are scheduled to be finished before
78  // this buffer is freed
79  // Do not call finish as it is a blocking call which affects the performance
80  CLScheduler::get().queue().flush();
81 }

References CLScheduler::get(), and CLScheduler::queue().

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 88 of file CLMemoryRegion.cpp.

89 {
90  ARM_COMPUTE_ERROR_ON(_mem.get() == nullptr);
91  _mapping = q.enqueueMapBuffer(_mem, blocking ? CL_TRUE : CL_FALSE, CL_MAP_READ | CL_MAP_WRITE, 0, _size);
92  return _mapping;
93 }

References ARM_COMPUTE_ERROR_ON.

◆ ptr()

void * ptr ( )
finalvirtual

Host/SVM pointer accessor.

Returns
Host/SVM pointer base

Implements ICLMemoryRegion.

Definition at line 83 of file CLMemoryRegion.cpp.

84 {
85  return nullptr;
86 }

◆ 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 95 of file CLMemoryRegion.cpp.

96 {
97  ARM_COMPUTE_ERROR_ON(_mem.get() == nullptr);
98  q.enqueueUnmapMemObject(_mem, _mapping);
99  _mapping = nullptr;
100 }

References ARM_COMPUTE_ERROR_ON.


The documentation for this class was generated from the following files:
arm_compute::IMemoryRegion::size
size_t size() const
Memory region size accessor.
Definition: IMemoryRegion.h:73
ARM_COMPUTE_ERROR_ON
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:467
arm_compute::ICLMemoryRegion::ICLMemoryRegion
ICLMemoryRegion(size_t size)
Constructor.
Definition: CLMemoryRegion.cpp:31
arm_compute::test::validation::context
auto context
Definition: DirectConv2d.cpp:160
arm_compute::CLScheduler::get
static CLScheduler & get()
Access the scheduler singleton.
Definition: CLScheduler.cpp:103
arm_compute::ICLMemoryRegion::buffer
void * buffer() override
Returns the pointer to the allocated data.
Definition: CLMemoryRegion.cpp:44
arm_compute::CLScheduler::queue
cl::CommandQueue & queue()
Accessor for the associated CL command queue.
Definition: CLScheduler.cpp:39