Compute Library
 21.05
CLTensorHandle Class Referencefinal

OpenCL Tensor handle interface object. More...

#include <CLTensorHandle.h>

Collaboration diagram for CLTensorHandle:
[legend]

Public Member Functions

 CLTensorHandle (const ITensorInfo &info)
 Default Constructor. More...
 
 ~CLTensorHandle ()=default
 Destructor: free the tensor's memory. More...
 
 CLTensorHandle (CLTensorHandle &&)=default
 Allow instances of this class to be move constructed. More...
 
CLTensorHandleoperator= (CLTensorHandle &&)=default
 Allow instances of this class to be moved. More...
 
void allocate () override
 Allocates backend memory for the handle. More...
 
void free () override
 Allocates backend memory for the handle. More...
 
void manage (IMemoryGroup *mg) override
 Set backend tensor to be managed by a memory group. More...
 
void map (bool blocking) override
 Maps backend tensor object. More...
 
void unmap () override
 Un-maps a backend tensor object. More...
 
void release_if_unused () override
 Releases backend tensor if is marked as unused. More...
 
arm_compute::ITensortensor () override
 Backend tensor object accessor. More...
 
const arm_compute::ITensortensor () const override
 Backend tensor object const accessor. More...
 
ITensorHandleparent_handle () override
 Return the parent tensor handle if is a subtensor else this. More...
 
bool is_subtensor () const override
 Checks if a backing tensor is a sub-tensor object or not. More...
 
Target target () const override
 Returns target type. More...
 
- Public Member Functions inherited from ITensorHandle
virtual ~ITensorHandle ()=default
 Default virtual destructor. More...
 

Detailed Description

OpenCL Tensor handle interface object.

Definition at line 38 of file CLTensorHandle.h.

Constructor & Destructor Documentation

◆ CLTensorHandle() [1/2]

CLTensorHandle ( const ITensorInfo info)

Default Constructor.

Parameters
[in]infoTensor metadata

Definition at line 34 of file CLTensorHandle.cpp.

35  : _tensor()
36 {
37  _tensor.allocator()->init(info);
38 }
CLTensorAllocator * allocator()
Return a pointer to the tensor's allocator.
Definition: CLTensor.cpp:61
void init(const TensorInfo &input, size_t alignment=0)
Initialize a tensor based on the passed TensorInfo.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)

References CLTensor::allocator(), arm_compute::test::validation::info, and ITensorAllocator::init().

◆ ~CLTensorHandle()

~CLTensorHandle ( )
default

Destructor: free the tensor's memory.

◆ CLTensorHandle() [2/2]

CLTensorHandle ( CLTensorHandle &&  )
default

Allow instances of this class to be move constructed.

Member Function Documentation

◆ allocate()

void allocate ( )
overridevirtual

Allocates backend memory for the handle.

Implements ITensorHandle.

Definition at line 40 of file CLTensorHandle.cpp.

41 {
42  _tensor.allocator()->allocate();
43 }
CLTensorAllocator * allocator()
Return a pointer to the tensor's allocator.
Definition: CLTensor.cpp:61
void allocate() override
Allocate size specified by TensorInfo of OpenCL memory.

References CLTensorAllocator::allocate(), and CLTensor::allocator().

◆ free()

void free ( )
overridevirtual

Allocates backend memory for the handle.

Implements ITensorHandle.

Definition at line 45 of file CLTensorHandle.cpp.

46 {
47  _tensor.allocator()->free();
48 }
CLTensorAllocator * allocator()
Return a pointer to the tensor's allocator.
Definition: CLTensor.cpp:61
void free() override
Free allocated OpenCL memory.

References CLTensor::allocator(), and CLTensorAllocator::free().

◆ is_subtensor()

bool is_subtensor ( ) const
overridevirtual

Checks if a backing tensor is a sub-tensor object or not.

Returns
True if the backend tensor is a sub-tensor else false

Implements ITensorHandle.

Definition at line 92 of file CLTensorHandle.cpp.

93 {
94  return false;
95 }

◆ manage()

void manage ( IMemoryGroup mg)
overridevirtual

Set backend tensor to be managed by a memory group.

Parameters
[in]mgMemory group

Implements ITensorHandle.

Definition at line 50 of file CLTensorHandle.cpp.

51 {
52  if(mg != nullptr)
53  {
54  mg->manage(&_tensor);
55  }
56 }

References IMemoryGroup::manage().

◆ map()

void map ( bool  blocking)
overridevirtual

Maps backend tensor object.

Parameters
[in]blockingFlags if the mapping operations should be blocking

Implements ITensorHandle.

Definition at line 58 of file CLTensorHandle.cpp.

59 {
60  _tensor.map(blocking);
61 }
void map(bool blocking=true)
Enqueue a map operation of the allocated buffer.
Definition: CLTensor.cpp:66

References CLTensor::map().

◆ operator=()

CLTensorHandle& operator= ( CLTensorHandle &&  )
default

Allow instances of this class to be moved.

◆ parent_handle()

ITensorHandle * parent_handle ( )
overridevirtual

Return the parent tensor handle if is a subtensor else this.

Returns
Parent tensor handle

Implements ITensorHandle.

Definition at line 87 of file CLTensorHandle.cpp.

88 {
89  return this;
90 }

◆ release_if_unused()

void release_if_unused ( )
overridevirtual

Releases backend tensor if is marked as unused.

Note
This has no effect on sub-tensors
Warning
Parent tensors don't keep track of sub-tensors, thus if a parent is set as unused then all sub-tensors will be invalidated, on the other hand if a sub-tensor is marked as unused then the parent tensor won't be released

Implements ITensorHandle.

Definition at line 68 of file CLTensorHandle.cpp.

69 {
70  // TODO (geopin01): Release tensor only if all sub-tensors are marked as not used
71  if(!_tensor.is_used())
72  {
73  _tensor.allocator()->free();
74  }
75 }
bool is_used() const
Flags if the tensor is used or not.
Definition: ITensor.cpp:163
CLTensorAllocator * allocator()
Return a pointer to the tensor's allocator.
Definition: CLTensor.cpp:61
void free() override
Free allocated OpenCL memory.

References CLTensor::allocator(), CLTensorAllocator::free(), and ITensor::is_used().

◆ target()

Target target ( ) const
overridevirtual

Returns target type.

Returns
Target type

Implements ITensorHandle.

Definition at line 97 of file CLTensorHandle.cpp.

98 {
99  return Target::CL;
100 }
OpenCL capable target device.

References arm_compute::graph::CL.

◆ tensor() [1/2]

arm_compute::ITensor & tensor ( )
overridevirtual

Backend tensor object accessor.

Implements ITensorHandle.

Definition at line 82 of file CLTensorHandle.cpp.

83 {
84  return _tensor;
85 }

◆ tensor() [2/2]

const arm_compute::ITensor & tensor ( ) const
overridevirtual

Backend tensor object const accessor.

Implements ITensorHandle.

Definition at line 77 of file CLTensorHandle.cpp.

78 {
79  return _tensor;
80 }

◆ unmap()

void unmap ( )
overridevirtual

Un-maps a backend tensor object.

Implements ITensorHandle.

Definition at line 63 of file CLTensorHandle.cpp.

64 {
65  _tensor.unmap();
66 }
void unmap()
Enqueue an unmap operation of the allocated and mapped buffer.
Definition: CLTensor.cpp:71

References CLTensor::unmap().


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