Compute Library
 19.11
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 &)=default
 Default copy constructor. More...
 
 CLTensor (CLTensor &&)=default
 Default move constructor. More...
 
CLTensoroperator= (const CLTensor &)=default
 Default copy 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...
 
- 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.

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 )
default

Default copy constructor.

◆ CLTensor() [3/3]

CLTensor ( CLTensor &&  )
default

Default move constructor.

Member Function Documentation

◆ allocator()

CLTensorAllocator * allocator ( )

Return a pointer to the tensor's allocator.

Returns
A pointer to the tensor's allocator

Definition at line 61 of file CLTensor.cpp.

62 {
63  return &_allocator;
64 }

Referenced by CLTensorHandle::allocate(), CLTensorHandle::CLTensorHandle(), CLRNNLayer::configure(), CLFFT2D::configure(), CLFFT1D::configure(), CLMeanStdDev::configure(), CLHOGDescriptor::configure(), CLL2NormalizeLayer::configure(), CLHOGGradient::configure(), CLGaussian5x5::configure(), CLSobel5x5::configure(), CLSobel7x7::configure(), CLCannyEdge::configure(), CLFastCorners::configure(), CLLocallyConnectedLayer::configure(), CLWinogradConvolutionLayer::configure(), CLHarrisCorners::configure(), CLHOGMultiDetection::configure(), CLFFTConvolutionLayer::configure(), CLGEMMLowpMatrixMultiplyCore::configure(), CLGenerateProposalsLayer::configure(), CLLSTMLayerQuantized::configure(), CLLSTMLayer::configure(), CLDirectDeconvolutionLayer::configure(), CLGEMMDeconvolutionLayer::configure(), CLGEMMConvolutionLayer::configure(), CLTensorHandle::free(), arm_compute::utils::init_sgemm_output(), CLLocallyConnectedLayer::prepare(), CLWinogradConvolutionLayer::prepare(), CLGEMMLowpMatrixMultiplyCore::prepare(), CLFFTConvolutionLayer::prepare(), CLGEMMDeconvolutionLayer::prepare(), CLDirectDeconvolutionLayer::prepare(), CLLSTMLayerQuantized::prepare(), CLGEMM::prepare(), CLFullyConnectedLayer::prepare(), CLGEMMConvolutionLayer::prepare(), CLGEMMReshapeRHSMatrixKernelManaged::release(), CLConvertFullyConnectedWeightsManaged::release(), CLFullyConnectedLayerReshapeWeightsManaged::release(), CLConvolutionLayerReshapeWeightsTransform::release(), CLTensorHandle::release_if_unused(), CLGEMMReshapeRHSMatrixKernelManaged::run(), CLConvertFullyConnectedWeightsManaged::run(), CLFullyConnectedLayerReshapeWeightsManaged::run(), CLConvolutionLayerReshapeWeightsTransform::run(), CLFFTConvolutionLayer::run(), and arm_compute::test::validation::TEST_CASE().

◆ 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 }
void set_associated_memory_group(IMemoryGroup *associated_memory_group)
Associates the tensor with a memory group.

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 }
const cl::Buffer & cl_data() const
Interface to be implemented by the child class to return the pointer to the CL data.

References CLTensorAllocator::cl_data().

Referenced by CLFastCorners::run(), and CLFFTConvolutionLayer::run().

◆ context()

CLRuntimeContext * context ( )

Definition at line 36 of file CLTensor.cpp.

37 {
38  return _ctx;
39 }

◆ info() [1/2]

TensorInfo * info ( ) const
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.

Definition at line 41 of file CLTensor.cpp.

42 {
43  return &_allocator.info();
44 }
TensorInfo & info()
Return a reference to the tensor's metadata.

References ITensorAllocator::info().

Referenced by CLRNNLayer::configure(), CLDeconvolutionLayer::configure(), CLDepthwiseConvolutionLayer3x3NCHWKernel::configure(), CLDepthwiseConvolutionLayer3x3NHWCKernel::configure(), GCDepthwiseConvolutionLayer3x3Kernel::configure(), GCConvolutionLayerReshapeWeights::configure(), GCDirectConvolutionLayerKernel< kernel_size >::configure(), NERNNLayer::configure(), NEDepthwiseConvolutionLayer3x3Kernel::configure(), NEDirectConvolutionLayerOutputStageKernel::configure(), CLWinogradOutputTransformKernel::configure(), CLDepthwiseConvolutionLayerNativeKernel::configure(), CLConvolutionLayerReshapeWeights::configure(), NEDirectConvolutionLayerKernel::configure(), GCDirectConvolutionLayer::configure(), NEDepthwiseConvolutionAssemblyDispatch::configure(), NEDepthwiseConvolutionLayer::configure(), CLDeconvolutionReshapeOutputKernel::configure(), CLDirectConvolutionLayerKernel::configure(), CLGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointKernel::configure(), NEConvolutionLayerReshapeWeights::configure(), CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFloatKernel::configure(), CLDepthwiseConvolutionLayer::configure(), NEDepthwiseConvolutionLayerNativeKernel::configure(), CLGEMMLowpOffsetContributionOutputStageKernel::configure(), CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel::configure(), CLGEMMLowpQuantizeDownInt32ToUint8ScaleKernel::configure(), CLGEMMLowpOffsetContributionKernel::configure(), NEWinogradConvolutionLayer::configure(), NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointKernel::configure(), NELocallyConnectedLayer::configure(), CLLocallyConnectedLayer::configure(), CLWinogradConvolutionLayer::configure(), NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel::configure(), NEGEMMLowpQuantizeDownInt32ToUint8ScaleKernel::configure(), CLLaplacianReconstruct::configure(), NEWeightsReshapeKernel::configure(), GCFullyConnectedLayer::configure(), CLFFTConvolutionLayer::configure(), NEFFTConvolutionLayer::configure(), CLGaussianPyramidHalf::configure(), CLGenerateProposalsLayer::configure(), NEGEMMLowpOffsetContributionOutputStageKernel::configure(), CLLSTMLayerQuantized::configure(), CLConvolutionLayer::configure(), CLLSTMLayer::configure(), CLDirectDeconvolutionLayer::configure(), NEConvolutionLayer::configure(), NEDeconvolutionLayer::configure(), CLGEMMDeconvolutionLayer::configure(), GCConvolutionLayer::configure(), CLGaussianPyramidOrb::configure(), NEFullyConnectedLayer::configure(), CLFullyConnectedLayer::configure(), NEGEMMConvolutionLayer::configure(), CLGEMMConvolutionLayer::configure(), arm_compute::graph::backends::detail::create_convolution_layer(), arm_compute::graph::backends::detail::create_convolution_layer< GCConvolutionLayerFunctions, GCTargetInfo >(), arm_compute::graph::backends::detail::create_convolution_layer< NEConvolutionLayerFunctions, NETargetInfo >(), arm_compute::graph::backends::detail::create_deconvolution_layer(), arm_compute::graph::backends::detail::create_depthwise_convolution_layer(), arm_compute::graph::backends::detail::create_depthwise_convolution_layer< GCDepthwiseConvolutionLayerFunctions, GCTargetInfo >(), arm_compute::graph::backends::detail::create_fully_connected_layer(), arm_compute::graph::backends::detail::create_fused_convolution_batch_normalization_layer(), arm_compute::graph::backends::detail::create_fused_depthwise_convolution_batch_normalization_layer(), CLAccessor::data_layout(), arm_compute::test::validation::DATA_TEST_CASE(), CLAccessor::data_type(), CLAccessor::element_size(), CLAccessor::format(), arm_compute::test::validation::if(), CLAccessor::num_channels(), CLAccessor::num_elements(), CLAccessor::padding(), CLAccessor::quantization_info(), CLFastCorners::run(), CLAccessor::shape(), CLAccessor::size(), and arm_compute::test::validation::TEST_CASE().

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

Definition at line 46 of file CLTensor.cpp.

47 {
48  return &_allocator.info();
49 }
TensorInfo & info()
Return a reference to the tensor's metadata.

References ITensorAllocator::info().

◆ 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 }
void map(cl::CommandQueue &q, bool blocking=true)
Enqueue a map operation of the allocated buffer on the given queue.
Definition: ICLTensor.cpp:35
static CLScheduler & get()
Access the scheduler singleton.
Definition: CLScheduler.cpp:99
cl::CommandQueue & queue()
Accessor for the associated CL command queue.
Definition: CLScheduler.cpp:41

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

Referenced by CLFFT1D::configure(), CLFFTConvolutionLayer::configure(), CLGEMMLowpMatrixMultiplyCore::configure(), CLDirectDeconvolutionLayer::configure(), CLTensorHandle::map(), and CLHarrisCorners::run().

◆ 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.
Returns
The mapping address.

Definition at line 35 of file ICLTensor.cpp.

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

◆ operator=() [1/2]

CLTensor& operator= ( const CLTensor )
default

Default copy assignment.

◆ operator=() [2/2]

CLTensor& operator= ( CLTensor &&  )
default

Default move assignment operator.

◆ 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 }
CLQuantization quantization() const
Wrapped quantization info data accessor.

References CLTensorAllocator::quantization().

Referenced by arm_compute::test::validation::TEST_CASE().

◆ 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 }
static CLScheduler & get()
Access the scheduler singleton.
Definition: CLScheduler.cpp:99
void unmap(cl::CommandQueue &q)
Enqueue an unmap operation of the allocated and mapped buffer on the given queue.
Definition: ICLTensor.cpp:40
cl::CommandQueue & queue()
Accessor for the associated CL command queue.
Definition: CLScheduler.cpp:41

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

Referenced by CLFFT1D::configure(), CLFFTConvolutionLayer::configure(), CLGEMMLowpMatrixMultiplyCore::configure(), CLDirectDeconvolutionLayer::configure(), CLHarrisCorners::run(), 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: