ArmNN
 22.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...
 
virtual bool CanBeImported (void *memory, MemorySource source) override
 Implementations must determine if this memory block can be imported. 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...
 
virtual void Unimport ()
 Unimport externally allocated memory. More...
 

Detailed Description

Definition at line 26 of file ClTensorHandle.hpp.

Constructor & Destructor Documentation

◆ ClTensorHandle() [1/2]

ClTensorHandle ( const TensorInfo tensorInfo)
inline

Definition at line 29 of file ClTensorHandle.hpp.

30  : m_ImportFlags(static_cast<MemorySourceFlags>(MemorySource::Undefined)),
31  m_Imported(false),
32  m_IsImportEnabled(false)
33  {
34  armnn::armcomputetensorutils::BuildArmComputeTensor(m_Tensor, tensorInfo);
35  }

◆ ClTensorHandle() [2/2]

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

Definition at line 37 of file ClTensorHandle.hpp.

40  : m_ImportFlags(importFlags),
41  m_Imported(false),
42  m_IsImportEnabled(false)
43  {
44  armnn::armcomputetensorutils::BuildArmComputeTensor(m_Tensor, tensorInfo, dataLayout);
45  }

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 49 of file ClTensorHandle.hpp.

50  {
51  // If we have enabled Importing, don't allocate the tensor
52  if (m_IsImportEnabled)
53  {
54  throw MemoryImportException("ClTensorHandle::Attempting to allocate memory when importing");
55  }
56  else
57  {
58  armnn::armcomputetensorutils::InitialiseArmComputeTensorEmpty(m_Tensor);
59  }
60 
61  }

◆ CanBeImported()

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

Implementations must determine if this memory block can be imported.

This might be based on alignment or memory source type.

Returns
true if this memory can be imported.
false by default, cannot be imported.

Reimplemented from ITensorHandle.

Definition at line 133 of file ClTensorHandle.hpp.

References ClTensorHandle::GetDataType(), armnn::IgnoreUnused(), and ClTensorHandle::Map().

134  {
135  // This TensorHandle can never import.
136  armnn::IgnoreUnused(memory, source);
137  return false;
138  }
void IgnoreUnused(Ts &&...)

◆ GetDataType()

virtual arm_compute::DataType GetDataType ( ) const
inlineoverridevirtual

Implements IClTensorHandle.

Definition at line 87 of file ClTensorHandle.hpp.

Referenced by ClTensorHandle::CanBeImported().

88  {
89  return m_Tensor.info()->data_type();
90  }

◆ GetImportFlags()

MemorySourceFlags GetImportFlags ( ) const
inlineoverridevirtual

Get flags describing supported import sources.

Reimplemented from ITensorHandle.

Definition at line 112 of file ClTensorHandle.hpp.

113  {
114  return m_ImportFlags;
115  }

◆ 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 85 of file ClTensorHandle.hpp.

85 { 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 102 of file ClTensorHandle.hpp.

Referenced by ClRankWorkload::Execute().

103  {
104  return armcomputetensorutils::GetShape(m_Tensor.info()->tensor_shape());
105  }

◆ 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 97 of file ClTensorHandle.hpp.

98  {
99  return armcomputetensorutils::GetStrides(m_Tensor.info()->strides_in_bytes());
100  }

◆ GetTensor() [1/2]

arm_compute::CLTensor& GetTensor ( )
inlineoverridevirtual

Implements IClTensorHandle.

Definition at line 47 of file ClTensorHandle.hpp.

47 { return m_Tensor; }

◆ GetTensor() [2/2]

arm_compute::CLTensor const& GetTensor ( ) const
inlineoverridevirtual

Implements IClTensorHandle.

Definition at line 48 of file ClTensorHandle.hpp.

48 { 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 122 of file ClTensorHandle.hpp.

References armnn::IgnoreUnused().

123  {
124  armnn::IgnoreUnused(memory);
125  if (m_ImportFlags & static_cast<MemorySourceFlags>(source))
126  {
127  throw MemoryImportException("ClTensorHandle::Incorrect import flag");
128  }
129  m_Imported = false;
130  return false;
131  }
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 63 of file ClTensorHandle.hpp.

64  {
65  // If we have enabled Importing, don't manage the tensor
66  if (m_IsImportEnabled)
67  {
68  throw MemoryImportException("ClTensorHandle::Attempting to manage memory when importing");
69  }
70  else
71  {
72  assert(m_MemoryGroup != nullptr);
73  m_MemoryGroup->manage(&m_Tensor);
74  }
75  }

◆ 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 77 of file ClTensorHandle.hpp.

Referenced by ClTensorHandle::CanBeImported().

78  {
79  const_cast<arm_compute::CLTensor*>(&m_Tensor)->map(blocking);
80  return static_cast<const void*>(m_Tensor.buffer() + m_Tensor.info()->offset_first_element_in_bytes());
81  }

◆ SetImportEnabledFlag()

void SetImportEnabledFlag ( bool  importEnabledFlag)
inline

Definition at line 117 of file ClTensorHandle.hpp.

118  {
119  m_IsImportEnabled = importEnabledFlag;
120  }

◆ SetImportFlags()

void SetImportFlags ( MemorySourceFlags  importFlags)
inline

Definition at line 107 of file ClTensorHandle.hpp.

108  {
109  m_ImportFlags = importFlags;
110  }

◆ SetMemoryGroup()

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

Implements IClTensorHandle.

Definition at line 92 of file ClTensorHandle.hpp.

93  {
94  m_MemoryGroup = PolymorphicPointerDowncast<arm_compute::MemoryGroup>(memoryGroup);
95  }

◆ Unmap()

virtual void Unmap ( ) const
inlineoverridevirtual

Unmap the tensor data.

Implements ITensorHandle.

Definition at line 83 of file ClTensorHandle.hpp.

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

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