Compute Library
 19.11
CLSubTensor Class Reference

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

#include <CLSubTensor.h>

Collaboration diagram for CLSubTensor:
[legend]

Public Member Functions

 CLSubTensor ()
 Default Constructor. More...
 
 CLSubTensor (ICLTensor *parent, const TensorShape &tensor_shape, const Coordinates &coords, bool extend_parent=false)
 Constructor. More...
 
 ~CLSubTensor ()=default
 Destructor: free the tensor's memory. More...
 
 CLSubTensor (const CLSubTensor &)=delete
 Restrict instances of this class to be copy constructed. More...
 
CLSubTensoroperator= (const CLSubTensor &)=delete
 Restrict instances of this class to be copied. More...
 
 CLSubTensor (CLSubTensor &&)=default
 Allow instances of this class to be move constructed. More...
 
CLSubTensoroperator= (CLSubTensor &&)=default
 Allow instances of this class to be moved. 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...
 
ICLTensorparent ()
 Return the parent tensor of the subtensor. More...
 
ITensorInfoinfo () const override
 Interface to be implemented by the child class to return the tensor's metadata. More...
 
ITensorInfoinfo () 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 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...
 

Detailed Description

Basic implementation of the OpenCL sub-tensor interface.

Definition at line 37 of file CLSubTensor.h.

Constructor & Destructor Documentation

◆ CLSubTensor() [1/4]

Default Constructor.

Definition at line 32 of file CLSubTensor.cpp.

33  : _parent(nullptr), _info()
34 {
35 }

◆ CLSubTensor() [2/4]

CLSubTensor ( ICLTensor parent,
const TensorShape tensor_shape,
const Coordinates coords,
bool  extend_parent = false 
)

Constructor.

Parameters
[in]parentParent tensor
[in]tensor_shapeShape of the subtensor
[in]coordsCoordinates of the first subtensor element inside the parent tensor.
[in]extend_parent(Optional) Extend parent with subtensor shape if subtensor indexes out of bounds

Definition at line 37 of file CLSubTensor.cpp.

38  : _parent(nullptr), _info()
39 {
40  ARM_COMPUTE_ERROR_ON(parent == nullptr);
41  _info = SubTensorInfo(parent->info(), tensor_shape, coords, extend_parent);
42  _parent = parent;
43 }
#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
Store the sub tensor's metadata.
Definition: SubTensorInfo.h:42
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
ICLTensor * parent()
Return the parent tensor of the subtensor.
Definition: CLSubTensor.cpp:66

References ARM_COMPUTE_ERROR_ON, ITensor::info(), and CLSubTensor::parent().

◆ ~CLSubTensor()

~CLSubTensor ( )
default

Destructor: free the tensor's memory.

◆ CLSubTensor() [3/4]

CLSubTensor ( const CLSubTensor )
delete

Restrict instances of this class to be copy constructed.

◆ CLSubTensor() [4/4]

CLSubTensor ( CLSubTensor &&  )
default

Allow instances of this class to be move constructed.

Member Function Documentation

◆ 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 55 of file CLSubTensor.cpp.

56 {
57  ARM_COMPUTE_ERROR_ON(_parent == nullptr);
58  return _parent->cl_buffer();
59 }
#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
virtual const cl::Buffer & cl_buffer() const =0
Interface to be implemented by the child class to return a reference to the OpenCL buffer containing ...

References ARM_COMPUTE_ERROR_ON, and ICLTensor::cl_buffer().

◆ info() [1/2]

ITensorInfo * 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 45 of file CLSubTensor.cpp.

46 {
47  return &_info;
48 }

◆ info() [2/2]

ITensorInfo * 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 50 of file CLSubTensor.cpp.

51 {
52  return &_info;
53 }

◆ map() [1/2]

void map ( bool  blocking = true)

Enqueue a map operation of the allocated buffer.

Note
Mapping a subtensor will lead to the mapping of the whole parent tensor for now.
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 71 of file CLSubTensor.cpp.

72 {
73  ICLTensor::map(CLScheduler::get().queue(), blocking);
74 }
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

References CLScheduler::get(), and ICLTensor::map().

Referenced by CLSubTensorHandle::map().

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

CLSubTensor& operator= ( const CLSubTensor )
delete

Restrict instances of this class to be copied.

◆ operator=() [2/2]

CLSubTensor& operator= ( CLSubTensor &&  )
default

Allow instances of this class to be moved.

◆ parent()

ICLTensor * parent ( )

Return the parent tensor of the subtensor.

Returns
Parent tensor

Definition at line 66 of file CLSubTensor.cpp.

67 {
68  return _parent;
69 }

Referenced by CLSubTensor::CLSubTensor().

◆ 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 61 of file CLSubTensor.cpp.

62 {
63  return _parent->quantization();
64 }
virtual CLQuantization quantization() const =0
Interface to be implemented by the child class to return the wrapped quantization info data.

References ICLTensor::quantization().

◆ unmap() [1/2]

void unmap ( )

Enqueue an unmap operation of the allocated and mapped buffer.

Note
Unmapping a subtensor will lead to the unmapping of the whole parent tensor for now.
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 76 of file CLSubTensor.cpp.

77 {
79 }
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

References CLScheduler::get(), and ICLTensor::unmap().

Referenced by CLSubTensorHandle::unmap().

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