ArmNN
 21.05
ClTensorHandle Class Reference

#include <ClTensorHandle.hpp>

Inheritance diagram for ClTensorHandle:
IClTensorHandle IAclTensorHandle ITensorHandle

Public Member Functions

 ClTensorHandle (const TensorInfo &tensorInfo)
 
 ClTensorHandle (const TensorInfo &tensorInfo, DataLayout dataLayout, MemorySourceFlags importFlags=static_cast< MemorySourceFlags >(MemorySource::Undefined))
 
arm_compute::CLTensor & GetTensor () override
 
arm_compute::CLTensor const & GetTensor () const override
 
virtual void Allocate () override
 Indicate to the memory manager that this resource is no longer active. More...
 
virtual void Manage () override
 Indicate to the memory manager that this resource is active. More...
 
virtual const void * Map (bool blocking=true) const override
 Map the tensor data for access. More...
 
virtual void Unmap () const override
 Unmap the tensor data. More...
 
virtual ITensorHandleGetParent () const override
 Get the parent tensor if this is a subtensor. More...
 
virtual arm_compute::DataType GetDataType () const override
 
virtual void SetMemoryGroup (const std::shared_ptr< arm_compute::IMemoryGroup > &memoryGroup) override
 
TensorShape GetStrides () const override
 Get the strides for each dimension ordered from largest to smallest where the smallest value is the same as the size of a single element in the tensor. More...
 
TensorShape GetShape () const override
 Get the number of elements for each dimension ordered from slowest iterating dimension to fastest iterating dimension. More...
 
void SetImportFlags (MemorySourceFlags importFlags)
 
MemorySourceFlags GetImportFlags () const override
 Get flags describing supported import sources. More...
 
void SetImportEnabledFlag (bool importEnabledFlag)
 
virtual bool Import (void *memory, MemorySource source) override
 Import externally allocated memory. More...
 
- Public Member Functions inherited from ITensorHandle
virtual ~ITensorHandle ()
 
void * Map (bool blocking=true)
 Map the tensor data for access. More...
 
void Unmap ()
 Unmap the tensor data that was previously mapped with call to Map(). More...
 

Detailed Description

Definition at line 34 of file ClTensorHandle.hpp.

Constructor & Destructor Documentation

◆ ClTensorHandle() [1/2]

ClTensorHandle ( const TensorInfo tensorInfo)
inline

Definition at line 37 of file ClTensorHandle.hpp.

38  : m_ImportFlags(static_cast<MemorySourceFlags>(MemorySource::Undefined)),
39  m_Imported(false),
40  m_IsImportEnabled(false)
41  {
42  armnn::armcomputetensorutils::BuildArmComputeTensor(m_Tensor, tensorInfo);
43  }

◆ ClTensorHandle() [2/2]

ClTensorHandle ( const TensorInfo tensorInfo,
DataLayout  dataLayout,
MemorySourceFlags  importFlags = static_cast<MemorySourceFlags>(MemorySource::Undefined) 
)
inline

Definition at line 45 of file ClTensorHandle.hpp.

48  : m_ImportFlags(importFlags),
49  m_Imported(false),
50  m_IsImportEnabled(false)
51  {
52  armnn::armcomputetensorutils::BuildArmComputeTensor(m_Tensor, tensorInfo, dataLayout);
53  }

Member Function Documentation

◆ Allocate()

virtual void Allocate ( )
inlineoverridevirtual

Indicate to the memory manager that this resource is no longer active.

This is used to compute overlapping lifetimes of resources.

Implements ITensorHandle.

Definition at line 57 of file ClTensorHandle.hpp.

58  {
59  // If we have enabled Importing, don't allocate the tensor
60  if (m_IsImportEnabled)
61  {
62  throw MemoryImportException("ClTensorHandle::Attempting to allocate memory when importing");
63  }
64  else
65  {
66  armnn::armcomputetensorutils::InitialiseArmComputeTensorEmpty(m_Tensor);
67  }
68 
69  }

◆ GetDataType()

virtual arm_compute::DataType GetDataType ( ) const
inlineoverridevirtual

Implements IClTensorHandle.

Definition at line 95 of file ClTensorHandle.hpp.

96  {
97  return m_Tensor.info()->data_type();
98  }

◆ GetImportFlags()

MemorySourceFlags GetImportFlags ( ) const
inlineoverridevirtual

Get flags describing supported import sources.

Reimplemented from ITensorHandle.

Definition at line 120 of file ClTensorHandle.hpp.

121  {
122  return m_ImportFlags;
123  }

◆ GetParent()

virtual ITensorHandle* GetParent ( ) const
inlineoverridevirtual

Get the parent tensor if this is a subtensor.

Returns
a pointer to the parent tensor. Otherwise nullptr if not a subtensor.

Implements ITensorHandle.

Definition at line 93 of file ClTensorHandle.hpp.

93 { return nullptr; }

◆ GetShape()

TensorShape GetShape ( ) const
inlineoverridevirtual

Get the number of elements for each dimension ordered from slowest iterating dimension to fastest iterating dimension.

Returns
a TensorShape filled with the number of elements for each dimension.

Implements ITensorHandle.

Definition at line 110 of file ClTensorHandle.hpp.

Referenced by ClRankWorkload::Execute().

111  {
112  return armcomputetensorutils::GetShape(m_Tensor.info()->tensor_shape());
113  }

◆ GetStrides()

TensorShape GetStrides ( ) const
inlineoverridevirtual

Get the strides for each dimension ordered from largest to smallest where the smallest value is the same as the size of a single element in the tensor.

Returns
a TensorShape filled with the strides for each dimension

Implements ITensorHandle.

Definition at line 105 of file ClTensorHandle.hpp.

106  {
107  return armcomputetensorutils::GetStrides(m_Tensor.info()->strides_in_bytes());
108  }

◆ GetTensor() [1/2]

arm_compute::CLTensor& GetTensor ( )
inlineoverridevirtual

Implements IClTensorHandle.

Definition at line 55 of file ClTensorHandle.hpp.

55 { return m_Tensor; }

◆ GetTensor() [2/2]

arm_compute::CLTensor const& GetTensor ( ) const
inlineoverridevirtual

Implements IClTensorHandle.

Definition at line 56 of file ClTensorHandle.hpp.

56 { return m_Tensor; }

◆ Import()

virtual bool Import ( void *  memory,
MemorySource  source 
)
inlineoverridevirtual

Import externally allocated memory.

Parameters
memorybase address of the memory being imported.
sourcesource of the allocation for the memory being imported.
Returns
true on success or false on failure

Reimplemented from ITensorHandle.

Definition at line 130 of file ClTensorHandle.hpp.

References ITensorHandle::CopyOutTo(), IClTensorHandle::GetDataType(), armnn::IgnoreUnused(), and ITensorHandle::Map().

131  {
132  armnn::IgnoreUnused(memory);
133  if (m_ImportFlags & static_cast<MemorySourceFlags>(source))
134  {
135  throw MemoryImportException("ClTensorHandle::Incorrect import flag");
136  }
137  m_Imported = false;
138  return false;
139  }
void IgnoreUnused(Ts &&...)

◆ Manage()

virtual void Manage ( )
inlineoverridevirtual

Indicate to the memory manager that this resource is active.

This is used to compute overlapping lifetimes of resources.

Implements ITensorHandle.

Definition at line 71 of file ClTensorHandle.hpp.

72  {
73  // If we have enabled Importing, don't manage the tensor
74  if (m_IsImportEnabled)
75  {
76  throw MemoryImportException("ClTensorHandle::Attempting to manage memory when importing");
77  }
78  else
79  {
80  assert(m_MemoryGroup != nullptr);
81  m_MemoryGroup->manage(&m_Tensor);
82  }
83  }

◆ Map()

virtual const void* Map ( bool  blocking = true) const
inlineoverridevirtual

Map the tensor data for access.

Parameters
blockinghint to block the calling thread until all other accesses are complete. (backend dependent)
Returns
pointer to the first element of the mapped data.

Implements ITensorHandle.

Definition at line 85 of file ClTensorHandle.hpp.

86  {
87  const_cast<arm_compute::CLTensor*>(&m_Tensor)->map(blocking);
88  return static_cast<const void*>(m_Tensor.buffer() + m_Tensor.info()->offset_first_element_in_bytes());
89  }

◆ SetImportEnabledFlag()

void SetImportEnabledFlag ( bool  importEnabledFlag)
inline

Definition at line 125 of file ClTensorHandle.hpp.

126  {
127  m_IsImportEnabled = importEnabledFlag;
128  }

◆ SetImportFlags()

void SetImportFlags ( MemorySourceFlags  importFlags)
inline

Definition at line 115 of file ClTensorHandle.hpp.

116  {
117  m_ImportFlags = importFlags;
118  }

◆ SetMemoryGroup()

virtual void SetMemoryGroup ( const std::shared_ptr< arm_compute::IMemoryGroup > &  memoryGroup)
inlineoverridevirtual

Implements IClTensorHandle.

Definition at line 100 of file ClTensorHandle.hpp.

101  {
102  m_MemoryGroup = PolymorphicPointerDowncast<arm_compute::MemoryGroup>(memoryGroup);
103  }

◆ Unmap()

virtual void Unmap ( ) const
inlineoverridevirtual

Unmap the tensor data.

Implements ITensorHandle.

Definition at line 91 of file ClTensorHandle.hpp.

91 { const_cast<arm_compute::CLTensor*>(&m_Tensor)->unmap(); }

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