12 #include <arm_compute/core/ITensor.h> 13 #include <arm_compute/core/TensorInfo.h> 14 #include <arm_compute/core/Types.h> 22 namespace armcomputetensorutils
33 unsigned int originalInputRank,
34 const std::vector<unsigned int>& armnnAxes);
37 arm_compute::TensorShape BuildArmComputeTensorShape(
const armnn::TensorShape& tensorShape);
41 arm_compute::TensorInfo BuildArmComputeTensorInfo(
const armnn::TensorInfo& tensorInfo);
46 arm_compute::TensorInfo BuildArmComputeTensorInfo(
const armnn::TensorInfo& tensorInfo,
56 arm_compute::PoolingLayerInfo BuildArmComputePoolingLayerInfo(
const Pooling2dDescriptor& descriptor,
57 bool fpMixedPrecision =
false);
62 arm_compute::Pooling3dLayerInfo BuildArmComputePooling3dLayerInfo(
const Pooling3dDescriptor& descriptor,
63 bool fpMixedPrecision =
false);
66 arm_compute::NormalizationLayerInfo BuildArmComputeNormalizationLayerInfo(
const NormalizationDescriptor& desc);
75 arm_compute::Size2D BuildArmComputeSize2D(
const unsigned int width,
const unsigned int height);
78 arm_compute::PixelValue GetPixelValue(
const arm_compute::ITensorInfo* tensorInfo,
float pixelValue);
82 const arm_compute::TensorShape& weightsShape,
83 const arm_compute::TensorShape& inputShape);
86 template <
typename Descriptor>
87 arm_compute::PadStrideInfo BuildArmComputePadStrideInfo(
const Descriptor &descriptor)
89 return arm_compute::PadStrideInfo(descriptor.m_StrideX,
92 descriptor.m_PadRight,
94 descriptor.m_PadBottom,
95 arm_compute::DimensionRoundingType::FLOOR);
99 template <
typename Tensor>
102 tensor.allocator()->init(BuildArmComputeTensorInfo(tensorInfo));
106 template <
typename Tensor>
109 tensor.allocator()->init(BuildArmComputeTensorInfo(tensorInfo, dataLayout));
112 template <
typename Tensor>
113 void InitialiseArmComputeTensorEmpty(Tensor& tensor)
115 tensor.allocator()->allocate();
119 template <
typename Tensor>
120 void FreeTensorIfUnused(std::unique_ptr<Tensor>& tensor)
122 if (tensor && !tensor->is_used())
124 tensor.reset(
nullptr);
129 inline size_t GetTensorOffset(
const arm_compute::ITensorInfo&
info,
132 uint32_t channelIndex,
137 coords.set(4, static_cast<int>(depthIndex));
138 coords.set(3, static_cast<int>(batchIndex));
139 coords.set(2, static_cast<int>(channelIndex));
140 coords.set(1, static_cast<int>(y));
141 coords.set(0, static_cast<int>(x));
146 inline size_t GetLinearBufferOffset(
const arm_compute::ITensorInfo& info,
149 uint32_t channelIndex,
153 const arm_compute::TensorShape& shape = info.tensor_shape();
154 uint32_t width =
static_cast<uint32_t
>(shape[0]);
155 uint32_t height =
static_cast<uint32_t
>(shape[1]);
156 uint32_t numChannels =
static_cast<uint32_t
>(shape[2]);
157 uint32_t numBatches =
static_cast<uint32_t
>(shape[3]);
158 return (((depthIndex * numBatches + batchIndex) * numChannels + channelIndex) * height + y) * width + x;
161 template <
typename T>
162 void CopyArmComputeITensorData(
const arm_compute::ITensor& srcTensor, T* dstData)
167 const arm_compute::ITensorInfo& info = *srcTensor.info();
168 const arm_compute::TensorShape& shape = info.tensor_shape();
169 const uint8_t*
const bufferPtr = srcTensor.buffer();
170 uint32_t width =
static_cast<uint32_t
>(shape[0]);
171 uint32_t height =
static_cast<uint32_t
>(shape[1]);
172 uint32_t numChannels =
static_cast<uint32_t
>(shape[2]);
173 uint32_t numBatches =
static_cast<uint32_t
>(shape[3]);
174 uint32_t depth =
static_cast<uint32_t
>(shape[4]);
176 for (
unsigned int depthIndex = 0; depthIndex < depth; ++depthIndex)
178 for (
unsigned int batchIndex = 0; batchIndex < numBatches; ++batchIndex)
180 for (
unsigned int channelIndex = 0; channelIndex < numChannels; ++channelIndex)
182 for (
unsigned int y = 0; y < height; ++y)
187 dstData + GetLinearBufferOffset(info, depthIndex, batchIndex, channelIndex, y, 0),
188 bufferPtr + GetTensorOffset(info, depthIndex, batchIndex, channelIndex, y, 0),
197 template <
typename T>
198 void CopyArmComputeITensorData(
const T* srcData, arm_compute::ITensor& dstTensor)
203 const arm_compute::ITensorInfo& info = *dstTensor.info();
204 const arm_compute::TensorShape& shape = info.tensor_shape();
205 uint8_t*
const bufferPtr = dstTensor.buffer();
206 uint32_t width =
static_cast<uint32_t
>(shape[0]);
207 uint32_t height =
static_cast<uint32_t
>(shape[1]);
208 uint32_t numChannels =
static_cast<uint32_t
>(shape[2]);
209 uint32_t numBatches =
static_cast<uint32_t
>(shape[3]);
210 uint32_t depth =
static_cast<uint32_t
>(shape[4]);
212 for (
unsigned int depthIndex = 0; depthIndex < depth; ++depthIndex)
214 for (
unsigned int batchIndex = 0; batchIndex < numBatches; ++batchIndex)
216 for (
unsigned int channelIndex = 0; channelIndex < numChannels; ++channelIndex)
218 for (
unsigned int y = 0; y < height; ++y)
223 bufferPtr + GetTensorOffset(info, depthIndex, batchIndex, channelIndex, y, 0),
224 srcData + GetLinearBufferOffset(info, depthIndex, batchIndex, channelIndex, y, 0),
239 template<
typename ArmComputeType,
typename T>
240 TensorShape
GetTensorShape(
const ArmComputeType& shapelike, T initial)
243 for (
unsigned int i=0; i < shapelike.num_dimensions(); ++i)
245 s[(shapelike.num_dimensions()-1)-i] = armnn::numeric_cast<unsigned int>(shapelike[i]);
247 return TensorShape(armnn::numeric_cast<unsigned int>(shapelike.num_dimensions()), s.data());
251 inline TensorShape GetStrides(
const arm_compute::Strides& strides)
257 inline TensorShape GetShape(
const arm_compute::TensorShape& shape)
std::array< unsigned int, MaxNumOfTensorDimensions > Coordinates
Copyright (c) 2021 ARM Limited and Contributors.
const armnnSerializer::Pooling2dDescriptor * Pooling2dDescriptor
armnn::TensorShape GetTensorShape(unsigned int numberOfBatches, unsigned int numberOfChannels, unsigned int height, unsigned int width, const armnn::DataLayout dataLayout)
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
constexpr unsigned int MaxNumOfTensorDimensions
const armnnSerializer::Pooling3dDescriptor * Pooling3dDescriptor