ArmNN
 24.08
ClTensorHandle Class Reference

#include <ClTensorHandle.hpp>

Inheritance diagram for ClTensorHandle:
[legend]
Collaboration diagram for ClTensorHandle:
[legend]

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...
 
virtual std::shared_ptr< ITensorHandleDecorateTensorHandle (const TensorInfo &tensorInfo) override
 Returns a decorated version of this TensorHandle allowing us to override the TensorInfo for it. 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 28 of file ClTensorHandle.hpp.

Constructor & Destructor Documentation

◆ ClTensorHandle() [1/2]

ClTensorHandle ( const TensorInfo tensorInfo)
inline

Definition at line 31 of file ClTensorHandle.hpp.

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

References armnn::Undefined.

◆ ClTensorHandle() [2/2]

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

Definition at line 39 of file ClTensorHandle.hpp.

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

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

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

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

136  {
137  // This TensorHandle can never import.
138  armnn::IgnoreUnused(memory, source);
139  return false;
140  }

References armnn::IgnoreUnused().

◆ DecorateTensorHandle()

std::shared_ptr< ITensorHandle > DecorateTensorHandle ( const TensorInfo tensorInfo)
overridevirtual

Returns a decorated version of this TensorHandle allowing us to override the TensorInfo for it.

Parameters
tensorInfothe overidden TensorInfo.

Reimplemented from ITensorHandle.

Definition at line 12 of file ClTensorHandle.cpp.

13  {
14  auto* parent = const_cast<ClTensorHandle*>(this);
15  auto decorated = std::make_shared<ClTensorHandleDecorator>(parent, tensorInfo);
16  m_Decorated.emplace_back(decorated);
17  return decorated;
18  }

◆ GetDataType()

virtual arm_compute::DataType GetDataType ( ) const
inlineoverridevirtual

Implements IClTensorHandle.

Definition at line 89 of file ClTensorHandle.hpp.

90  {
91  return m_Tensor.info()->data_type();
92  }

◆ GetImportFlags()

MemorySourceFlags GetImportFlags ( ) const
inlineoverridevirtual

Get flags describing supported import sources.

Reimplemented from ITensorHandle.

Definition at line 114 of file ClTensorHandle.hpp.

115  {
116  return m_ImportFlags;
117  }

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

87 { 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 104 of file ClTensorHandle.hpp.

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

Referenced by ClRankWorkload::Execute().

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

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

◆ GetTensor() [1/2]

arm_compute::CLTensor const& GetTensor ( ) const
inlineoverridevirtual

Implements IClTensorHandle.

Definition at line 50 of file ClTensorHandle.hpp.

50 { return m_Tensor; }

◆ GetTensor() [2/2]

arm_compute::CLTensor& GetTensor ( )
inlineoverridevirtual

Implements IClTensorHandle.

Definition at line 49 of file ClTensorHandle.hpp.

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

125  {
126  armnn::IgnoreUnused(memory);
127  if (m_ImportFlags& static_cast<MemorySourceFlags>(source))
128  {
129  throw MemoryImportException("ClTensorHandle::Incorrect import flag");
130  }
131  m_Imported = false;
132  return false;
133  }

References armnn::IgnoreUnused().

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

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

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

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

◆ SetImportEnabledFlag()

void SetImportEnabledFlag ( bool  importEnabledFlag)
inline

Definition at line 119 of file ClTensorHandle.hpp.

120  {
121  m_IsImportEnabled = importEnabledFlag;
122  }

◆ SetImportFlags()

void SetImportFlags ( MemorySourceFlags  importFlags)
inline

Definition at line 109 of file ClTensorHandle.hpp.

110  {
111  m_ImportFlags = importFlags;
112  }

◆ SetMemoryGroup()

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

Implements IClTensorHandle.

Definition at line 94 of file ClTensorHandle.hpp.

95  {
96  m_MemoryGroup = PolymorphicPointerDowncast<arm_compute::MemoryGroup>(memoryGroup);
97  }

◆ Unmap()

virtual void Unmap ( ) const
inlineoverridevirtual

Unmap the tensor data.

Implements ITensorHandle.

Definition at line 85 of file ClTensorHandle.hpp.

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

The documentation for this class was generated from the following files:
armnn::MemorySourceFlags
unsigned int MemorySourceFlags
Definition: MemorySources.hpp:15
armnn::MemorySource::Undefined
@ Undefined
armnn::IgnoreUnused
void IgnoreUnused(Ts &&...)
Definition: IgnoreUnused.hpp:14
armnn::ClTensorHandle::ClTensorHandle
ClTensorHandle(const TensorInfo &tensorInfo)
Definition: ClTensorHandle.hpp:31