ArmNN
 21.08
ClImportTensorHandle Class Reference

#include <ClImportTensorHandle.hpp>

Inheritance diagram for ClImportTensorHandle:
IClImportTensorHandle IAclTensorHandle ITensorHandle

Public Member Functions

 ClImportTensorHandle (const TensorInfo &tensorInfo, MemorySourceFlags importFlags)
 
 ClImportTensorHandle (const TensorInfo &tensorInfo, DataLayout dataLayout, MemorySourceFlags importFlags)
 
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...
 
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 37 of file ClImportTensorHandle.hpp.

Constructor & Destructor Documentation

◆ ClImportTensorHandle() [1/2]

ClImportTensorHandle ( const TensorInfo tensorInfo,
MemorySourceFlags  importFlags 
)
inline

Definition at line 40 of file ClImportTensorHandle.hpp.

41  : m_ImportFlags(importFlags)
42  {
43  armnn::armcomputetensorutils::BuildArmComputeTensor(m_Tensor, tensorInfo);
44  }

◆ ClImportTensorHandle() [2/2]

ClImportTensorHandle ( const TensorInfo tensorInfo,
DataLayout  dataLayout,
MemorySourceFlags  importFlags 
)
inline

Definition at line 46 of file ClImportTensorHandle.hpp.

49  : m_ImportFlags(importFlags)
50  {
51  armnn::armcomputetensorutils::BuildArmComputeTensor(m_Tensor, tensorInfo, dataLayout);
52  }

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 56 of file ClImportTensorHandle.hpp.

56 {}

◆ GetDataType()

virtual arm_compute::DataType GetDataType ( ) const
inlineoverridevirtual

Implements IClImportTensorHandle.

Definition at line 69 of file ClImportTensorHandle.hpp.

70  {
71  return m_Tensor.info()->data_type();
72  }

◆ GetImportFlags()

MemorySourceFlags GetImportFlags ( ) const
inlineoverridevirtual

Get flags describing supported import sources.

Reimplemented from ITensorHandle.

Definition at line 94 of file ClImportTensorHandle.hpp.

95  {
96  return m_ImportFlags;
97  }

◆ 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 67 of file ClImportTensorHandle.hpp.

67 { 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 84 of file ClImportTensorHandle.hpp.

85  {
86  return armcomputetensorutils::GetShape(m_Tensor.info()->tensor_shape());
87  }

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

80  {
81  return armcomputetensorutils::GetStrides(m_Tensor.info()->strides_in_bytes());
82  }

◆ GetTensor() [1/2]

arm_compute::CLTensor& GetTensor ( )
inlineoverridevirtual

Implements IClImportTensorHandle.

Definition at line 54 of file ClImportTensorHandle.hpp.

54 { return m_Tensor; }

◆ GetTensor() [2/2]

arm_compute::CLTensor const& GetTensor ( ) const
inlineoverridevirtual

Implements IClImportTensorHandle.

Definition at line 55 of file ClImportTensorHandle.hpp.

55 { 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 99 of file ClImportTensorHandle.hpp.

References ARMNN_ASSERT, ITensorHandle::CopyOutTo(), armnn::DmaBuf, armnn::DmaBufProtected, armnn::error, IClImportTensorHandle::GetDataType(), armnn::Malloc, and ITensorHandle::Map().

100  {
101  if (m_ImportFlags & static_cast<MemorySourceFlags>(source))
102  {
103  if (source == MemorySource::Malloc)
104  {
105  const cl_import_properties_arm importProperties[] =
106  {
107  CL_IMPORT_TYPE_ARM,
108  CL_IMPORT_TYPE_HOST_ARM,
109  0
110  };
111 
112  return ClImport(importProperties, memory);
113  }
114  if (source == MemorySource::DmaBuf)
115  {
116  const cl_import_properties_arm importProperties[] =
117  {
118  CL_IMPORT_TYPE_ARM,
119  CL_IMPORT_TYPE_DMA_BUF_ARM,
120  CL_IMPORT_DMA_BUF_DATA_CONSISTENCY_WITH_HOST_ARM,
121  CL_TRUE,
122  0
123  };
124 
125  return ClImport(importProperties, memory);
126 
127  }
128  if (source == MemorySource::DmaBufProtected)
129  {
130  const cl_import_properties_arm importProperties[] =
131  {
132  CL_IMPORT_TYPE_ARM,
133  CL_IMPORT_TYPE_DMA_BUF_ARM,
134  CL_IMPORT_TYPE_PROTECTED_ARM,
135  CL_TRUE,
136  0
137  };
138 
139  return ClImport(importProperties, memory, true);
140 
141  }
142  else
143  {
144  throw MemoryImportException("ClImportTensorHandle::Import flag is not supported");
145  }
146  }
147  else
148  {
149  throw MemoryImportException("ClImportTensorHandle::Incorrect import flag");
150  }
151  }

◆ 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 57 of file ClImportTensorHandle.hpp.

57 {}

◆ 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 59 of file ClImportTensorHandle.hpp.

References armnn::IgnoreUnused().

60  {
61  IgnoreUnused(blocking);
62  return static_cast<const void*>(m_Tensor.buffer() + m_Tensor.info()->offset_first_element_in_bytes());
63  }
void IgnoreUnused(Ts &&...)

◆ SetImportFlags()

void SetImportFlags ( MemorySourceFlags  importFlags)
inline

Definition at line 89 of file ClImportTensorHandle.hpp.

90  {
91  m_ImportFlags = importFlags;
92  }

◆ SetMemoryGroup()

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

Implements IClImportTensorHandle.

Definition at line 74 of file ClImportTensorHandle.hpp.

References armnn::IgnoreUnused().

75  {
76  IgnoreUnused(memoryGroup);
77  }
void IgnoreUnused(Ts &&...)

◆ Unmap()

virtual void Unmap ( ) const
inlineoverridevirtual

Unmap the tensor data.

Implements ITensorHandle.

Definition at line 65 of file ClImportTensorHandle.hpp.

65 {}

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