Compute Library
 21.02
CLAccessor Class Reference

Accessor implementation for CLTensor objects. More...

#include <CLAccessor.h>

Collaboration diagram for CLAccessor:
[legend]

Public Member Functions

 CLAccessor (CLTensor &tensor)
 Create an accessor for the given tensor. More...
 
 CLAccessor (const CLAccessor &)=delete
 Prevent instances of this class from being copy constructed. More...
 
CLAccessoroperator= (const CLAccessor &)=delete
 Prevent instances of this class from being copied. More...
 
 CLAccessor (CLAccessor &&)=default
 Allow instances of this class to be move constructed. More...
 
 ~CLAccessor ()
 Destructor that unmaps the CL memory. More...
 
const void * data () const
 Get the tensor data. More...
 
void * data ()
 Get the tensor data. More...
 
TensorShape shape () const override
 Shape of the tensor. More...
 
size_t element_size () const override
 Size of each element in the tensor in bytes. More...
 
size_t size () const override
 Total size of the tensor in bytes. More...
 
Format format () const override
 Image format of the tensor. More...
 
DataLayout data_layout () const override
 Data layout of the tensor. More...
 
DataType data_type () const override
 Data type of the tensor. More...
 
int num_channels () const override
 Number of channels of the tensor. More...
 
int num_elements () const override
 Number of elements of the tensor. More...
 
PaddingSize padding () const override
 Available padding around the tensor. More...
 
QuantizationInfo quantization_info () const override
 Quantization info in case of asymmetric quantized type. More...
 
const void * operator() (const Coordinates &coord) const override
 Read only access to the specified element. More...
 
void * operator() (const Coordinates &coord) override
 Access to the specified element. More...
 
- Public Member Functions inherited from IAccessor
virtual ~IAccessor ()=default
 Virtual destructor. More...
 

Detailed Description

Accessor implementation for CLTensor objects.

Definition at line 35 of file CLAccessor.h.

Constructor & Destructor Documentation

◆ CLAccessor() [1/3]

CLAccessor ( CLTensor tensor)
inline

Create an accessor for the given tensor.

Parameters
[in,out]tensorTo be accessed tensor.
Note
The CL memory is mapped by the constructor.

Definition at line 86 of file CLAccessor.h.

References CLTensor::map().

87  : _tensor{ tensor }
88 {
89  _tensor.map();
90 }
void map(bool blocking=true)
Enqueue a map operation of the allocated buffer.
Definition: CLTensor.cpp:66

◆ CLAccessor() [2/3]

CLAccessor ( const CLAccessor )
delete

Prevent instances of this class from being copy constructed.

◆ CLAccessor() [3/3]

CLAccessor ( CLAccessor &&  )
default

Allow instances of this class to be move constructed.

◆ ~CLAccessor()

~CLAccessor ( )
inline

Destructor that unmaps the CL memory.

Definition at line 92 of file CLAccessor.h.

References CLTensor::unmap().

93 {
94  _tensor.unmap();
95 }
void unmap()
Enqueue an unmap operation of the allocated and mapped buffer.
Definition: CLTensor.cpp:71

Member Function Documentation

◆ data() [1/2]

const void * data ( ) const
inline

Get the tensor data.

Returns
a constant pointer to the tensor data.

Definition at line 147 of file CLAccessor.h.

References ICLTensor::buffer().

148 {
149  return _tensor.buffer();
150 }
uint8_t * buffer() const override
Interface to be implemented by the child class to return a pointer to CPU memory. ...
Definition: ICLTensor.cpp:53

◆ data() [2/2]

void * data ( )
inline

Get the tensor data.

Returns
a pointer to the tensor data.

Definition at line 152 of file CLAccessor.h.

References ICLTensor::buffer().

153 {
154  return _tensor.buffer();
155 }
uint8_t * buffer() const override
Interface to be implemented by the child class to return a pointer to CPU memory. ...
Definition: ICLTensor.cpp:53

◆ data_layout()

DataLayout data_layout ( ) const
inlineoverridevirtual

Data layout of the tensor.

Returns
the data layout of the tensor.

Implements IAccessor.

Definition at line 117 of file CLAccessor.h.

References TensorInfo::data_layout(), and CLTensor::info().

118 {
119  return _tensor.info()->data_layout();
120 }
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Definition: CLTensor.cpp:41
DataLayout data_layout() const override
Get the data layout of the tensor.
Definition: TensorInfo.h:315

◆ data_type()

DataType data_type ( ) const
inlineoverridevirtual

Data type of the tensor.

Returns
the data type of the tensor.

Implements IAccessor.

Definition at line 122 of file CLAccessor.h.

References TensorInfo::data_type(), and CLTensor::info().

123 {
124  return _tensor.info()->data_type();
125 }
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Definition: CLTensor.cpp:41
DataType data_type() const override
Data type used for each element of the tensor.
Definition: TensorInfo.h:270

◆ element_size()

size_t element_size ( ) const
inlineoverridevirtual

Size of each element in the tensor in bytes.

Returns
the size of each element in the tensor in bytes.

Implements IAccessor.

Definition at line 102 of file CLAccessor.h.

References TensorInfo::element_size(), and CLTensor::info().

103 {
104  return _tensor.info()->element_size();
105 }
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Definition: CLTensor.cpp:41
size_t element_size() const override
Element size in bytes calculated as data_size() * num_channels()
Definition: TensorInfo.h:250

◆ format()

Format format ( ) const
inlineoverridevirtual

Image format of the tensor.

Returns
the format of the tensor.

Implements IAccessor.

Definition at line 112 of file CLAccessor.h.

References TensorInfo::format(), and CLTensor::info().

113 {
114  return _tensor.info()->format();
115 }
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Definition: CLTensor.cpp:41
Format format() const override
Colour format of the image.
Definition: TensorInfo.h:274

◆ num_channels()

int num_channels ( ) const
inlineoverridevirtual

Number of channels of the tensor.

Returns
the number of channels of the tensor.

Implements IAccessor.

Definition at line 127 of file CLAccessor.h.

References CLTensor::info(), and TensorInfo::num_channels().

128 {
129  return _tensor.info()->num_channels();
130 }
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Definition: CLTensor.cpp:41
size_t num_channels() const override
The number of channels for each tensor element.
Definition: TensorInfo.h:258

◆ num_elements()

int num_elements ( ) const
inlineoverridevirtual

Number of elements of the tensor.

Returns
the number of elements of the tensor.

Implements IAccessor.

Definition at line 132 of file CLAccessor.h.

References CLTensor::info(), TensorInfo::tensor_shape(), and TensorShape::total_size().

133 {
134  return _tensor.info()->tensor_shape().total_size();
135 }
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Definition: CLTensor.cpp:41
size_t total_size() const
Collapses all dimensions to a single linear total size.
Definition: TensorShape.h:172
const TensorShape & tensor_shape() const override
Size for each dimension of the tensor.
Definition: TensorInfo.h:262

◆ operator()() [1/2]

const void * operator() ( const Coordinates coord) const
inlineoverridevirtual

Read only access to the specified element.

Parameters
[in]coordCoordinates of the desired element.
Returns
A pointer to the desired element.

Implements IAccessor.

Definition at line 157 of file CLAccessor.h.

References ITensor::ptr_to_element().

158 {
159  return _tensor.ptr_to_element(coord);
160 }
uint8_t * ptr_to_element(const Coordinates &id) const
Return a pointer to the element at the passed coordinates.
Definition: ITensor.h:63

◆ operator()() [2/2]

void * operator() ( const Coordinates coord)
inlineoverridevirtual

Access to the specified element.

Parameters
[in]coordCoordinates of the desired element.
Returns
A pointer to the desired element.

Implements IAccessor.

Definition at line 162 of file CLAccessor.h.

References ITensor::ptr_to_element().

163 {
164  return _tensor.ptr_to_element(coord);
165 }
uint8_t * ptr_to_element(const Coordinates &id) const
Return a pointer to the element at the passed coordinates.
Definition: ITensor.h:63

◆ operator=()

CLAccessor& operator= ( const CLAccessor )
delete

Prevent instances of this class from being copied.

◆ padding()

PaddingSize padding ( ) const
inlineoverridevirtual

Available padding around the tensor.

Returns
the available padding around the tensor.

Implements IAccessor.

Definition at line 137 of file CLAccessor.h.

References CLTensor::info(), and TensorInfo::padding().

138 {
139  return _tensor.info()->padding();
140 }
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Definition: CLTensor.cpp:41
PaddingSize padding() const override
Padding of tensor.
Definition: TensorInfo.h:282

◆ quantization_info()

QuantizationInfo quantization_info ( ) const
inlineoverridevirtual

Quantization info in case of asymmetric quantized type.

Returns

Implements IAccessor.

Definition at line 142 of file CLAccessor.h.

References CLTensor::info(), and TensorInfo::quantization_info().

143 {
144  return _tensor.info()->quantization_info();
145 }
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Definition: CLTensor.cpp:41
QuantizationInfo quantization_info() const override
Get the quantization settings (scale and offset) of the tensor.
Definition: TensorInfo.h:311

◆ shape()

TensorShape shape ( ) const
inlineoverridevirtual

Shape of the tensor.

Returns
the shape of the tensor.

Implements IAccessor.

Definition at line 97 of file CLAccessor.h.

References CLTensor::info(), and TensorInfo::tensor_shape().

98 {
99  return _tensor.info()->tensor_shape();
100 }
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Definition: CLTensor.cpp:41
const TensorShape & tensor_shape() const override
Size for each dimension of the tensor.
Definition: TensorInfo.h:262

◆ size()

size_t size ( ) const
inlineoverridevirtual

Total size of the tensor in bytes.

Returns
the total size of the tensor in bytes.

Implements IAccessor.

Definition at line 107 of file CLAccessor.h.

References CLTensor::info(), and TensorInfo::total_size().

108 {
109  return _tensor.info()->total_size();
110 }
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Definition: CLTensor.cpp:41
size_t total_size() const override
Returns the total size of the tensor in bytes.
Definition: TensorInfo.h:278

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