Compute Library
 23.08
CLTensor Class Reference

Basic implementation of the OpenCL tensor interface. More...

#include <CLTensor.h>

Collaboration diagram for CLTensor:
[legend]

Public Member Functions

 CLTensor (IRuntimeContext *ctx=nullptr)
 Constructor. More...
 
 ~CLTensor ()=default
 Destructor. More...
 
 CLTensor (const CLTensor &)=delete
 Prevent copying by construction. More...
 
 CLTensor (CLTensor &&)=default
 Default move constructor. More...
 
CLTensoroperator= (const CLTensor &)=delete
 Prevent copaingy by assignment. More...
 
CLTensoroperator= (CLTensor &&)=default
 Default move assignment operator. More...
 
CLTensorAllocatorallocator ()
 Return a pointer to the tensor's allocator. More...
 
void map (bool blocking=true)
 Enqueue a map operation of the allocated buffer. More...
 
void unmap ()
 Enqueue an unmap operation of the allocated and mapped buffer. More...
 
TensorInfoinfo () const override
 Interface to be implemented by the child class to return the tensor's metadata. More...
 
TensorInfoinfo () override
 Interface to be implemented by the child class to return the tensor's metadata. More...
 
const cl::Buffer & cl_buffer () const override
 Interface to be implemented by the child class to return a reference to the OpenCL buffer containing the image's data. More...
 
CLQuantization quantization () const override
 Interface to be implemented by the child class to return the wrapped quantization info data. More...
 
void associate_memory_group (IMemoryGroup *memory_group) override
 Associates a memory managable object with the memory group that manages it. More...
 
CLRuntimeContextcontext ()
 
void map (cl::CommandQueue &q, bool blocking=true)
 Enqueue a map operation of the allocated buffer on the given queue. More...
 
void unmap (cl::CommandQueue &q)
 Enqueue an unmap operation of the allocated and mapped buffer on the given queue. More...
 
- Public Member Functions inherited from ICLTensor
 ICLTensor ()
 Default constructor. More...
 
 ICLTensor (const ICLTensor &)=delete
 Prevent instances of this class from being copy constructed. More...
 
ICLTensoroperator= (const ICLTensor &)=delete
 Prevent instances of this class from being copied. More...
 
 ICLTensor (ICLTensor &&)=default
 Allow instances of this class to be move constructed. More...
 
ICLTensoroperator= (ICLTensor &&)=default
 Allow instances of this class to be copied. More...
 
virtual ~ICLTensor ()=default
 Default virtual destructor. More...
 
void map (cl::CommandQueue &q, bool blocking=true)
 Enqueue a map operation of the allocated buffer on the given queue. More...
 
void unmap (cl::CommandQueue &q)
 Enqueue an unmap operation of the allocated and mapped buffer on the given queue. More...
 
void clear (cl::CommandQueue &q)
 Clear the contents of the tensor synchronously. More...
 
uint8_t * buffer () const override
 Interface to be implemented by the child class to return a pointer to CPU memory. More...
 
- Public Member Functions inherited from ITensor
virtual ~ITensor ()=default
 Default virtual destructor. More...
 
uint8_t * ptr_to_element (const Coordinates &id) const
 Return a pointer to the element at the passed coordinates. More...
 
void copy_from (const ITensor &src)
 Copy the content of another tensor. More...
 
void print (std::ostream &s, IOFormatInfo io_fmt=IOFormatInfo()) const
 Print a tensor to a given stream using user defined formatting information. More...
 
bool is_used () const
 Flags if the tensor is used or not. More...
 
void mark_as_unused () const
 Marks a tensor as unused. More...
 
void mark_as_used () const
 Marks a tensor as used. More...
 
- Public Member Functions inherited from IMemoryManageable
virtual ~IMemoryManageable ()=default
 Default virtual destructor. More...
 

Detailed Description

Basic implementation of the OpenCL tensor interface.

Definition at line 41 of file CLTensor.h.

Constructor & Destructor Documentation

◆ CLTensor() [1/3]

CLTensor ( IRuntimeContext ctx = nullptr)

Constructor.

Parameters
[in]ctx(Optional) Pointer to a CLRuntimeContext. If nullptr is passed in, the legacy api using the singletons will be used. Otherwise the memory for the tensor will allocate on the context passed in. The singletons legacy api has been deprecated and will be removed in future releases.

Definition at line 31 of file CLTensor.cpp.

32  : _allocator(this, static_cast<CLRuntimeContext *>(ctx)), _ctx(static_cast<CLRuntimeContext *>(ctx))
33 {
34 }

◆ ~CLTensor()

~CLTensor ( )
default

Destructor.

◆ CLTensor() [2/3]

CLTensor ( const CLTensor )
delete

Prevent copying by construction.

◆ CLTensor() [3/3]

CLTensor ( CLTensor &&  )
default

Default move constructor.

Member Function Documentation

◆ allocator()

◆ associate_memory_group()

void associate_memory_group ( IMemoryGroup memory_group)
overridevirtual

Associates a memory managable object with the memory group that manages it.

Parameters
[in]memory_groupMemory group that manages the object.

Implements IMemoryManageable.

Definition at line 86 of file CLTensor.cpp.

87 {
88  _allocator.set_associated_memory_group(memory_group);
89 }

References CLTensorAllocator::set_associated_memory_group().

◆ cl_buffer()

const cl::Buffer & cl_buffer ( ) const
overridevirtual

Interface to be implemented by the child class to return a reference to the OpenCL buffer containing the image's data.

Returns
A reference to an OpenCL buffer containing the image's data.

Implements ICLTensor.

Definition at line 51 of file CLTensor.cpp.

52 {
53  return _allocator.cl_data();
54 }

References CLTensorAllocator::cl_data().

Referenced by arm_compute::create_image2d_from_tensor(), CLFFTConvolutionLayer::run(), and arm_compute::test::validation::TEST_CASE().

◆ context()

CLRuntimeContext * context ( )

Definition at line 36 of file CLTensor.cpp.

37 {
38  return _ctx;
39 }

◆ info() [1/2]

◆ info() [2/2]

TensorInfo* info ( )
overridevirtual

Interface to be implemented by the child class to return the tensor's metadata.

Returns
A pointer to the tensor's metadata.

Implements ITensor.

◆ map() [1/2]

void map ( bool  blocking = true)

Enqueue a map operation of the allocated buffer.

Parameters
[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.

Definition at line 66 of file CLTensor.cpp.

67 {
68  ICLTensor::map(_ctx == nullptr ? CLScheduler::get().queue() : _ctx->gpu_scheduler()->queue(), blocking);
69 }

References CLScheduler::get(), CLRuntimeContext::gpu_scheduler(), ICLTensor::map(), and CLScheduler::queue().

Referenced by AclMapTensor(), CLFFT1D::configure(), CLFFTConvolutionLayer::configure(), CLDirectDeconvolutionLayer::configure(), CLTensorHandle::map(), CLDepthwiseConvolutionLayer::prepare(), and CLQLSTMLayer::prepare().

◆ map() [2/2]

void map

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.

Definition at line 35 of file ICLTensor.cpp.

36 {
37  _mapping = do_map(q, blocking);
38 }

◆ operator=() [1/2]

CLTensor& operator= ( CLTensor &&  )
default

Default move assignment operator.

◆ operator=() [2/2]

CLTensor& operator= ( const CLTensor )
delete

Prevent copaingy by assignment.

◆ quantization()

CLQuantization quantization ( ) const
overridevirtual

Interface to be implemented by the child class to return the wrapped quantization info data.

Returns
A wrapped quantization info object.

Implements ICLTensor.

Definition at line 56 of file CLTensor.cpp.

57 {
58  return _allocator.quantization();
59 }

References CLTensorAllocator::quantization().

◆ unmap() [1/2]

void unmap ( )

Enqueue an unmap operation of the allocated and mapped buffer.

Note
This method simply enqueues 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.

Definition at line 71 of file CLTensor.cpp.

72 {
73  ICLTensor::unmap(_ctx == nullptr ? CLScheduler::get().queue() : _ctx->gpu_scheduler()->queue());
74 }

References CLScheduler::get(), CLRuntimeContext::gpu_scheduler(), CLScheduler::queue(), and ICLTensor::unmap().

Referenced by AclUnmapTensor(), CLFFT1D::configure(), CLFFTConvolutionLayer::configure(), CLDirectDeconvolutionLayer::configure(), CLDepthwiseConvolutionLayer::prepare(), CLQLSTMLayer::prepare(), CLTensorHandle::unmap(), and CLAccessor::~CLAccessor().

◆ unmap() [2/2]

void unmap

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

Note
This method simply enqueues 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.

Definition at line 40 of file ICLTensor.cpp.

41 {
42  do_unmap(q);
43  _mapping = nullptr;
44 }

The documentation for this class was generated from the following files:
arm_compute::ICLTensor::map
void map(cl::CommandQueue &q, bool blocking=true)
Enqueue a map operation of the allocated buffer on the given queue.
Definition: ICLTensor.cpp:35
arm_compute::CLRuntimeContext::gpu_scheduler
CLScheduler * gpu_scheduler()
Definition: CLRuntimeContext.cpp:56
arm_compute::CLTensorAllocator::set_associated_memory_group
void set_associated_memory_group(IMemoryGroup *associated_memory_group)
Associates the tensor with a memory group.
Definition: CLTensorAllocator.cpp:180
arm_compute::CLTensorAllocator::quantization
CLQuantization quantization() const
Wrapped quantization info data accessor.
Definition: CLTensorAllocator.cpp:112
arm_compute::CLTensorAllocator::cl_data
const cl::Buffer & cl_data() const
Interface to be implemented by the child class to return the pointer to the CL data.
Definition: CLTensorAllocator.cpp:122
arm_compute::ITensorAllocator::info
TensorInfo & info()
Return a reference to the tensor's metadata.
Definition: ITensorAllocator.cpp:46
arm_compute::ICLTensor::unmap
void unmap(cl::CommandQueue &q)
Enqueue an unmap operation of the allocated and mapped buffer on the given queue.
Definition: ICLTensor.cpp:40
arm_compute::CLScheduler::get
static CLScheduler & get()
Access the scheduler singleton.
Definition: CLScheduler.cpp:103
arm_compute::CLScheduler::queue
cl::CommandQueue & queue()
Accessor for the associated CL command queue.
Definition: CLScheduler.cpp:39