ArmNN
 25.11
Loading...
Searching...
No Matches
armnnUtils Namespace Reference

Namespaces

namespace  Filesystem

Classes

class  DataLayoutIndexed
 Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout. More...
class  FloatingPointConverter
struct  IsFloatingPointIterator
class  ModelAccuracyChecker
struct  ParserPrototxtFixture
struct  SelectiveQuantizer
struct  SelectiveQuantizer< armnn::BFloat16, false >
struct  SelectiveQuantizer< armnn::Half, false >
struct  SelectiveQuantizer< T, false >

Typedefs

using TContainer
using LabelCategoryNames = std::vector<std::string>

Functions

template<typename T>
bool CompatibleTypes (armnn::DataType)
bool operator== (const armnn::DataLayout &dataLayout, const DataLayoutIndexed &indexed)
 Equality methods.
bool operator== (const DataLayoutIndexed &indexed, const armnn::DataLayout &dataLayout)
bool within_percentage_tolerance (float a, float b, float tolerancePercent=1.0f)
 Compare two floats and return true if their values are within a specified tolerance of each other.
armnn::TensorShape Permuted (const armnn::TensorShape &srcShape, const armnn::PermutationVector &mappings)
armnn::TensorInfo Permuted (const armnn::TensorInfo &info, const armnn::PermutationVector &mappings)
void Permute (const armnn::TensorShape &dstShape, const armnn::PermutationVector &mappings, const void *src, void *dst, size_t dataTypeSize)
template<typename T>
SelectiveQuantize (float value, float scale, int32_t offset)
template<typename T>
float SelectiveDequantize (T value, float scale, int32_t offset)
template<typename T, typename FloatIt, typename std::enable_if< IsFloatingPointIterator< FloatIt >::value, int >::type = 0>
std::vector< T > QuantizedVector (FloatIt first, FloatIt last, float qScale, int32_t qOffset)
template<typename T>
std::vector< T > QuantizedVector (const std::vector< float > &array, float qScale=1.f, int32_t qOffset=0)
template<typename T>
std::vector< T > QuantizedVector (std::initializer_list< float > array, float qScale=1.f, int32_t qOffset=0)
armnn::TensorShape GetTensorShape (unsigned int numberOfBatches, unsigned int numberOfChannels, unsigned int height, unsigned int width, const armnn::DataLayout dataLayout)
armnn::TensorInfo GetTensorInfo (unsigned int numberOfBatches, unsigned int numberOfChannels, unsigned int height, unsigned int width, const armnn::DataLayout dataLayout, const armnn::DataType dataType)
armnn::TensorInfo GetTensorInfo (unsigned int numberOfBatches, unsigned int numberOfChannels, unsigned int depth, unsigned int height, unsigned int width, const armnn::DataLayout dataLayout, const armnn::DataType dataType)
std::pair< float, float > FindMinMax (armnn::ITensorHandle *tensorHandle)
armnn::TensorShape ReduceDims (const armnn::TensorShape &tensorInfo, unsigned int dimensions)
armnn::TensorInfo ReduceDims (const armnn::TensorInfo &tensorInfo, unsigned int dimensions)
armnn::TensorShape ExpandDims (const armnn::TensorShape &tensorShape, int axis)
armnn::TensorShape ExpandDimsToRank (const armnn::TensorShape &tensorShape, unsigned int rank)
std::vector< unsigned int > SqueezeDims (const armnn::TensorShape &tensorShape)
unsigned int GetNumElementsBetween (const armnn::TensorShape &shape, unsigned int firstAxisInclusive, unsigned int lastAxisExclusive)
unsigned int GetUnsignedAxis (const unsigned int inputDimension, const int axis)
unsigned int GetNumElementsAfter (const armnn::TensorShape &shape, unsigned int axis)
std::pair< unsigned int, std::vector< float > > GetPerAxisParams (const armnn::TensorInfo &info)
template<typename PrimitiveType>
std::unique_ptr< float[]> ToFloatArray (const std::vector< PrimitiveType > &data, const armnn::TensorInfo &tensorInfo)
std::unique_ptr< float[]> ToFloatArray (const std::vector< uint8_t > &data, const armnn::TensorInfo &tensorInfo)
armnn::TensorShape TransposeTensorShape (const armnn::TensorShape &srcShape, const armnn::PermutationVector &mappings)
armnn::TensorInfo TransposeTensorShape (const armnn::TensorInfo &info, const armnn::PermutationVector &mappings)
void Transpose (const armnn::TensorShape &dstShape, const armnn::PermutationVector &mappings, const void *src, void *dst, size_t dataTypeSize)
template<>
bool CompatibleTypes< float > (DataType dataType)
template<>
bool CompatibleTypes< Half > (DataType dataType)
template<>
bool CompatibleTypes< BFloat16 > (DataType dataType)
template<>
bool CompatibleTypes< uint8_t > (DataType dataType)
template<>
bool CompatibleTypes< int8_t > (DataType dataType)
template<>
bool CompatibleTypes< int16_t > (DataType dataType)
template<>
bool CompatibleTypes< int32_t > (DataType dataType)
template<>
bool CompatibleTypes< int64_t > (DataType dataType)
template<typename TNodeId, typename TTargetNodes>
bool GraphTopologicalSort (const TTargetNodes &targetNodes, std::function< std::vector< TNodeId >(TNodeId)> getIncomingEdges, std::vector< TNodeId > &outSorted)
std::vector< std::string > SplitBy (const std::string &originalString, const std::string &delimiter=" ", bool includeEmptyToken=false)
 Split a string into tokens by a delimiter.
std::string Strip (const std::string &originalString, const std::string &characterSet=" ")
 Remove any preceding and trailing character specified in the characterSet.
void ProcessConcatInputTensorInfo (armnn::TensorInfo &inputTensorInfo, armnn::OriginsDescriptor &concatDescriptor, const unsigned int &concatAxis, unsigned int inputIndex, unsigned int &mergeDimOrigin)
void CalculateReducedOutputTensoInfo (const armnn::TensorInfo &inputTensorInfo, const std::set< unsigned int > &axisSet, bool keepDims, armnn::TensorInfo &outputTensorInfo)
 Creates a tensor info after reducing the dimensions mentioned in axisData.
void CalculateStridedSliceOutputTensorInfo (const armnn::TensorInfo &inputTensorInfo, const armnn::StridedSliceDescriptor &desc, armnn::TensorInfo &outputTensorInfo)
 Create output tensor info for a StridedSlice operator.
std::string ConvertInt32ToOctalString (int value)
 Converts an int value into the Prototxt octal representation.
std::string ConvertTensorShapeToString (const armnn::TensorShape &shape)
 Converts an TensorShape into Prototxt representation.
template<typename TContainer>
armnn::InputTensors MakeInputTensors (const std::vector< armnn::BindingPointInfo > &inputBindings, const std::vector< TContainer > &inputDataContainers)
template<typename TContainer>
armnn::OutputTensors MakeOutputTensors (const std::vector< armnn::BindingPointInfo > &outputBindings, std::vector< TContainer > &outputDataContainers)
template<typename PrimitiveType>
void CheckSizes (const std::vector< PrimitiveType > &data, const armnn::TensorInfo &tensorInfo, unsigned int size=1)
void CheckValidSize (std::initializer_list< size_t > validInputCounts, size_t actualValue, const char *validExpr, const char *actualExpr, const CheckLocation &location)
uint32_t NonNegative (const char *expr, int32_t value, const CheckLocation &location)
int32_t VerifyInt32 (const char *expr, int64_t value, const armnn::CheckLocation &location)

Variables

const armnn::PermutationVector NHWCToArmNN = { 0, 2, 3, 1 }
const armnn::PermutationVector ArmNNToNHWC = { 0, 3, 1, 2 }

Typedef Documentation

◆ LabelCategoryNames

using LabelCategoryNames = std::vector<std::string>

Definition at line 25 of file ModelAccuracyChecker.hpp.

◆ TContainer

using TContainer
Initial value:
mapbox::util::variant<std::vector<float>, std::vector<int>, std::vector<unsigned char>, std::vector<int8_t>>

Definition at line 17 of file TContainer.hpp.

Function Documentation

◆ CalculateReducedOutputTensoInfo()

void CalculateReducedOutputTensoInfo ( const armnn::TensorInfo & inputTensorInfo,
const std::set< unsigned int > & axisSet,
bool keepDims,
armnn::TensorInfo & outputTensorInfo )

Creates a tensor info after reducing the dimensions mentioned in axisData.

Definition at line 52 of file ParserHelper.cpp.

56{
57 std::vector<unsigned int> outputShapeVector;
58 bool dimensionFound = false;
59 unsigned int size = 1;
60
61 for (unsigned int i = 0; i < inputTensorInfo.GetNumDimensions(); ++i)
62 {
63 dimensionFound = false;
64 for (unsigned int axis: axisSet)
65 {
66 if (axis == i)
67 {
68 dimensionFound = true;
69 break;
70 }
71 }
72
73 if (!dimensionFound)
74 {
75 size *= inputTensorInfo.GetShape()[i];
76
77 if (keepDims)
78 {
79 outputShapeVector.push_back(inputTensorInfo.GetShape()[i]);
80 }
81 }
82 else
83 {
84 if (keepDims)
85 {
86 outputShapeVector.push_back(1);
87 }
88 }
89 }
90
91 if (keepDims)
92 {
93 armnn::TensorShape outputTensorShape(inputTensorInfo.GetNumDimensions(), &outputShapeVector[0]);
94 outputTensorInfo = armnn::TensorInfo(outputTensorShape, inputTensorInfo.GetDataType());
95 }
96 else
97 {
98 outputTensorInfo = armnn::TensorInfo({size}, inputTensorInfo.GetDataType());
99 }
100}
const TensorShape & GetShape() const
Definition Tensor.hpp:193
unsigned int GetNumDimensions() const
Definition Tensor.hpp:197
DataType GetDataType() const
Definition Tensor.hpp:200

References TensorInfo::GetDataType(), TensorInfo::GetNumDimensions(), and TensorInfo::GetShape().

◆ CalculateStridedSliceOutputTensorInfo()

void CalculateStridedSliceOutputTensorInfo ( const armnn::TensorInfo & inputTensorInfo,
const armnn::StridedSliceDescriptor & desc,
armnn::TensorInfo & outputTensorInfo )

Create output tensor info for a StridedSlice operator.

Definition at line 103 of file ParserHelper.cpp.

106{
107 const armnn::TensorShape& inputShape = inputTensorInfo.GetShape();
108
109 std::vector<unsigned int> outputShapeVector;
110 for (unsigned int i = 0; i < inputTensorInfo.GetNumDimensions(); i++)
111 {
112 if (desc.m_ShrinkAxisMask & (1 << i))
113 {
114 continue;
115 }
116
117 int stride = desc.m_Stride[i];
118 int start = desc.GetStartForAxis(inputShape, i);
119 int stop = desc.GetStopForAxis(inputShape, i, start);
120
121 int newSize = stride > 0 ? ((stop - start) + stride - 1) / stride :
122 ((start - stop) - stride - 1) / -stride;
123
124 newSize = std::max(0, newSize);
125
126 outputShapeVector.push_back(static_cast<unsigned int>(newSize));
127 }
128
129 armnn::TensorShape outputTensorShape(inputTensorInfo.GetNumDimensions(), &outputShapeVector[0]);
130 outputTensorInfo = armnn::TensorInfo(armnn::TensorShape(outputTensorShape), inputTensorInfo.GetDataType());
131}
std::vector< int > m_Stride
Stride values for the input that will be sliced.
int32_t m_ShrinkAxisMask
Shrink axis mask value. If set, the nth specification shrinks the dimensionality by 1.
int GetStartForAxis(const TensorShape &inputShape, unsigned int axis) const
int GetStopForAxis(const TensorShape &inputShape, unsigned int axis, int startForAxis) const

References TensorInfo::GetDataType(), TensorInfo::GetNumDimensions(), TensorInfo::GetShape(), StridedSliceDescriptor::GetStartForAxis(), StridedSliceDescriptor::GetStopForAxis(), StridedSliceDescriptor::m_ShrinkAxisMask, and StridedSliceDescriptor::m_Stride.

◆ CheckSizes()

template<typename PrimitiveType>
void CheckSizes ( const std::vector< PrimitiveType > & data,
const armnn::TensorInfo & tensorInfo,
unsigned int size = 1 )

Definition at line 296 of file TensorUtils.cpp.

297{
298 if (data.size() / size != tensorInfo.GetNumElements())
299 {
301 fmt::format("The data does not contain the expected number of elements {} != {}. {}",
302 data.size(), tensorInfo.GetNumElements(), CHECK_LOCATION().AsString()));
303 }
304}
#define CHECK_LOCATION()
unsigned int GetNumElements() const
Definition Tensor.hpp:198

References CHECK_LOCATION, and TensorInfo::GetNumElements().

Referenced by ToFloatArray(), and ToFloatArray().

◆ CheckValidSize()

void CheckValidSize ( std::initializer_list< size_t > validInputCounts,
size_t actualValue,
const char * validExpr,
const char * actualExpr,
const CheckLocation & location )

Definition at line 16 of file VerificationHelpers.cpp.

21{
22 bool isValid = std::any_of(validInputCounts.begin(),
23 validInputCounts.end(),
24 [&actualValue](size_t x) { return x == actualValue; } );
25 if (!isValid)
26 {
27 throw ParseException(fmt::format("{} = {} is not valid, not in {{}}. {}",
28 actualExpr,
29 actualValue,
30 validExpr,
31 location.AsString()));
32 }
33}
std::string AsString() const

References CheckLocation::AsString().

◆ CompatibleTypes()

template<typename T>
bool CompatibleTypes ( armnn::DataType )

Definition at line 17 of file CompatibleTypes.cpp.

18{
19 return false;
20}

Referenced by ConstTensorHandle::GetConstTensor(), and TensorHandle::GetTensor().

◆ CompatibleTypes< BFloat16 >()

template<>
bool CompatibleTypes< BFloat16 > ( DataType dataType)

Definition at line 35 of file CompatibleTypes.cpp.

36{
37 return dataType == DataType::BFloat16;
38}

References armnn::BFloat16.

◆ CompatibleTypes< float >()

template<>
bool CompatibleTypes< float > ( DataType dataType)

Definition at line 23 of file CompatibleTypes.cpp.

24{
25 return dataType == DataType::Float32;
26}

References armnn::Float32.

◆ CompatibleTypes< Half >()

template<>
bool CompatibleTypes< Half > ( DataType dataType)

Definition at line 29 of file CompatibleTypes.cpp.

30{
31 return dataType == DataType::Float16;
32}

References armnn::Float16.

◆ CompatibleTypes< int16_t >()

template<>
bool CompatibleTypes< int16_t > ( DataType dataType)

Definition at line 54 of file CompatibleTypes.cpp.

55{
56 return dataType == DataType::QSymmS16;
57}

References armnn::QSymmS16.

◆ CompatibleTypes< int32_t >()

template<>
bool CompatibleTypes< int32_t > ( DataType dataType)

Definition at line 60 of file CompatibleTypes.cpp.

61{
62 return dataType == DataType::Signed32;
63}

References armnn::Signed32.

◆ CompatibleTypes< int64_t >()

template<>
bool CompatibleTypes< int64_t > ( DataType dataType)

Definition at line 66 of file CompatibleTypes.cpp.

67{
68 return dataType == DataType::Signed64;
69}

References armnn::Signed64.

◆ CompatibleTypes< int8_t >()

template<>
bool CompatibleTypes< int8_t > ( DataType dataType)

Definition at line 47 of file CompatibleTypes.cpp.

48{
49 return dataType == DataType::QSymmS8
50 || dataType == DataType::QAsymmS8;
51}

References armnn::QAsymmS8, and armnn::QSymmS8.

◆ CompatibleTypes< uint8_t >()

template<>
bool CompatibleTypes< uint8_t > ( DataType dataType)

Definition at line 41 of file CompatibleTypes.cpp.

42{
43 return dataType == DataType::Boolean || dataType == DataType::QAsymmU8;
44}

References armnn::Boolean, and armnn::QAsymmU8.

◆ ConvertInt32ToOctalString()

std::string ConvertInt32ToOctalString ( int value)

Converts an int value into the Prototxt octal representation.

Definition at line 17 of file PrototxtConversions.cpp.

18{
19 std::stringstream ss;
20 std::string returnString;
21 for (int i = 0; i < 4; ++i)
22 {
23 ss << "\\";
24 ss << std::setw(3) << std::setfill('0') << std::oct << ((value >> (i * 8)) & 0xFF);
25 }
26
27 ss >> returnString;
28 return returnString;
29}

◆ ConvertTensorShapeToString()

std::string ConvertTensorShapeToString ( const armnn::TensorShape & shape)

Converts an TensorShape into Prototxt representation.

Definition at line 32 of file PrototxtConversions.cpp.

33{
34 std::stringstream ss;
35 for (unsigned int i = 0 ; i < shape.GetNumDimensions() ; i++)
36 {
37 ss << "dim {\n";
38 ss << "size: " << std::to_string(shape[i]) << "\n";
39 ss << "}\n";
40 }
41 return ss.str();
42
43}
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
Definition Tensor.cpp:174

References TensorShape::GetNumDimensions().

◆ ExpandDims()

TensorShape ExpandDims ( const armnn::TensorShape & tensorShape,
int axis )

Definition at line 142 of file TensorUtils.cpp.

143{
144 unsigned int outputDim = tensorShape.GetNumDimensions() + 1;
145
146 if (axis < -armnn::numeric_cast<int>(outputDim) || axis > armnn::numeric_cast<int>(tensorShape.GetNumDimensions()))
147 {
148 throw InvalidArgumentException(fmt::format("Invalid expansion axis {} for {}D input tensor. {}",
149 axis,
150 tensorShape.GetNumDimensions(),
151 CHECK_LOCATION().AsString()));
152 }
153
154 if (axis < 0)
155 {
156 axis = armnn::numeric_cast<int>(outputDim) + axis;
157 }
158
159 std::vector<unsigned int> outputShape;
160 outputShape.reserve(tensorShape.GetNumDimensions());
161 for (unsigned int i = 0; i < tensorShape.GetNumDimensions(); ++i)
162 {
163 outputShape.push_back(tensorShape[i]);
164 }
165 outputShape.insert(outputShape.begin() + axis, 1);
166
167 return { outputDim, outputShape.data() };
168}
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)

References CHECK_LOCATION, TensorShape::GetNumDimensions(), and armnn::numeric_cast().

◆ ExpandDimsToRank()

TensorShape ExpandDimsToRank ( const armnn::TensorShape & tensorShape,
unsigned int rank )

Definition at line 170 of file TensorUtils.cpp.

171{
172 // Can't expand if rank is smaller than current shape
173 if (tensorShape.GetNumDimensions() >= rank)
174 {
175 return tensorShape;
176 }
177
178 std::vector<unsigned int> newShape;
179
180 // First add 1s to the beginning of the tensorInfo to fill in the space
181 for (unsigned int i = 0; i < rank - tensorShape.GetNumDimensions(); ++i)
182 {
183 newShape.push_back(1);
184 }
185
186 // Then iterate through the original shape and append it to the new shape with the added 1s
187 for (unsigned int i = 0; i < tensorShape.GetNumDimensions(); ++i)
188 {
189 newShape.push_back(tensorShape[i]);
190 }
191
192 return TensorShape(static_cast<unsigned int>(newShape.size()), newShape.data());
193}

References TensorShape::GetNumDimensions().

◆ FindMinMax()

std::pair< float, float > FindMinMax ( armnn::ITensorHandle * tensorHandle)

Definition at line 81 of file TensorUtils.cpp.

82{
83 auto tensor_data = static_cast<const float *>(tensorHandle->Map(true));
84 auto tensor_size = tensorHandle->GetShape().GetNumElements();
85
86 // Set min/max initially to first value in tensor
87 float min = tensor_data[0];
88 float max = tensor_data[0];
89
90 // Loop over rest of tensor and update min/max if necessary
91 for (unsigned int val = 1; val < tensor_size; val++)
92 {
93 if (tensor_data[val] < min)
94 {
95 min = tensor_data[val];
96 }
97 else if (tensor_data[val] > max)
98 {
99 max = tensor_data[val];
100 }
101 }
102
103 tensorHandle->Unmap();
104
105 return std::make_pair(min, max);
106}
virtual const void * Map(bool blocking=true) const =0
Map the tensor data for access.
virtual void Unmap() const =0
Unmap the tensor data.
virtual TensorShape GetShape() const =0
Get the number of elements for each dimension ordered from slowest iterating dimension to fastest ite...
unsigned int GetNumElements() const
Function that calculates the tensor elements by multiplying all dimension size which are Specified.
Definition Tensor.cpp:181

References TensorShape::GetNumElements(), ITensorHandle::GetShape(), ITensorHandle::Map(), and ITensorHandle::Unmap().

◆ GetNumElementsAfter()

unsigned int GetNumElementsAfter ( const armnn::TensorShape & shape,
unsigned int axis )

Definition at line 261 of file TensorUtils.cpp.

262{
263 unsigned int numDim = shape.GetNumDimensions();
264 if (axis >= numDim)
265 {
266 throw armnn::InvalidArgumentException(fmt::format(
267 "{}: axis index [{}D] indexes beyond the number of dimesions of the tensor shape [{}D]",
268 "GetNumElementsAfter",
269 axis,
270 numDim));
271 }
272 unsigned int count = 1;
273 for (unsigned int i = axis+1; i < numDim; i++)
274 {
275 count *= shape[i];
276 }
277 return count;
278}

References TensorShape::GetNumDimensions().

Referenced by GetPerAxisParams(), PerAxisIterator< T, Base >::PerAxisIterator(), and ToFloatArray().

◆ GetNumElementsBetween()

unsigned int GetNumElementsBetween ( const armnn::TensorShape & shape,
unsigned int firstAxisInclusive,
unsigned int lastAxisExclusive )

Definition at line 209 of file TensorUtils.cpp.

212{
213 if (firstAxisInclusive > lastAxisExclusive)
214 {
215 throw armnn::InvalidArgumentException(fmt::format(
216 "GetNumElementsBetween: firstAxisInclusive [{}D] is greater than lastAxisExclusive [{}D]",
217 firstAxisInclusive,
218 lastAxisExclusive));
219 }
220 if (lastAxisExclusive > shape.GetNumDimensions())
221 {
222 throw armnn::InvalidArgumentException(fmt::format(
223 "{}: lastAxisExclusive [{}D] is greater than the number of dimensions of the tensor shape [{}D]"
224 "GetNumElementsBetween",
225 lastAxisExclusive,
226 shape.GetNumDimensions()));
227 }
228 unsigned int count = 1;
229 for (unsigned int i = firstAxisInclusive; i < lastAxisExclusive; i++)
230 {
231 count *= shape[i];
232 }
233 return count;
234}

References TensorShape::GetNumDimensions().

Referenced by armnn::ArgMinMax(), armnn::LogSoftmax(), and armnn::Softmax().

◆ GetPerAxisParams()

std::pair< unsigned int, std::vector< float > > GetPerAxisParams ( const armnn::TensorInfo & info)

Definition at line 280 of file TensorUtils.cpp.

281{
282 const std::vector<float>& scales = info.GetQuantizationScales();
283 armnn::Optional<unsigned int> quantizationDim = info.GetQuantizationDim();
284 if (!info.HasPerAxisQuantization())
285 {
287 std::string("Per-axis quantization params not set for tensor of type ") +
288 armnn::GetDataTypeName(info.GetDataType()), CHECK_LOCATION());
289 }
290 unsigned int axisFactor = GetNumElementsAfter(info.GetShape(), quantizationDim.value()) ;
291
292 return { axisFactor, scales };
293}
constexpr const char * GetDataTypeName(DataType dataType)
unsigned int GetNumElementsAfter(const armnn::TensorShape &shape, unsigned int axis)

References CHECK_LOCATION, armnn::GetDataTypeName(), GetNumElementsAfter(), armnn::info, and OptionalReferenceSwitch< IsReference, T >::value().

Referenced by armnn::MakeEncoder().

◆ GetTensorInfo() [1/2]

TensorInfo GetTensorInfo ( unsigned int numberOfBatches,
unsigned int numberOfChannels,
unsigned int depth,
unsigned int height,
unsigned int width,
const armnn::DataLayout dataLayout,
const armnn::DataType dataType )

Definition at line 60 of file TensorUtils.cpp.

67{
68 switch (dataLayout)
69 {
70 case DataLayout::NDHWC:
71 return TensorInfo({numberOfBatches, depth, height, width, numberOfChannels}, dataType);
72 case DataLayout::NCDHW:
73 return TensorInfo({numberOfBatches, numberOfChannels, depth, height, width}, dataType);
74 default:
75 throw InvalidArgumentException("Unknown data layout ["
76 + std::to_string(static_cast<int>(dataLayout)) +
77 "]", CHECK_LOCATION());
78 }
79}

References CHECK_LOCATION, armnn::NCDHW, and armnn::NDHWC.

◆ GetTensorInfo() [2/2]

TensorInfo GetTensorInfo ( unsigned int numberOfBatches,
unsigned int numberOfChannels,
unsigned int height,
unsigned int width,
const armnn::DataLayout dataLayout,
const armnn::DataType dataType )

◆ GetTensorShape()

TensorShape GetTensorShape ( unsigned int numberOfBatches,
unsigned int numberOfChannels,
unsigned int height,
unsigned int width,
const armnn::DataLayout dataLayout )

Definition at line 21 of file TensorUtils.cpp.

26{
27 switch (dataLayout)
28 {
29 case DataLayout::NCHW:
30 return TensorShape({numberOfBatches, numberOfChannels, height, width});
31 case DataLayout::NHWC:
32 return TensorShape({numberOfBatches, height, width, numberOfChannels});
33 default:
34 throw InvalidArgumentException("Unknown data layout ["
35 + std::to_string(static_cast<int>(dataLayout)) +
36 "]", CHECK_LOCATION());
37 }
38}

References CHECK_LOCATION, armnn::NCHW, and armnn::NHWC.

Referenced by ClUnidirectionalSequenceLstmFloatWorkload::ClUnidirectionalSequenceLstmFloatWorkload(), armnn::ClUnidirectionalSequenceLstmFloatWorkloadValidate(), NeonUnidirectionalSequenceLstmFloatWorkload::NeonUnidirectionalSequenceLstmFloatWorkload(), armnn::NeonUnidirectionalSequenceLstmFloatWorkloadValidate(), NeonUnidirectionalSequenceLstmWorkload::NeonUnidirectionalSequenceLstmWorkload(), and armnn::NeonUnidirectionalSequenceLstmWorkloadValidate().

◆ GetUnsignedAxis()

unsigned int GetUnsignedAxis ( const unsigned int inputDimension,
const int axis )

Definition at line 236 of file TensorUtils.cpp.

237{
238 if (axis >= armnn::numeric_cast<int>(inputDimension))
239 {
240 throw armnn::InvalidArgumentException(fmt::format(
241 "{}: axis index [{}] is not less than the number of dimensions [{}D]",
242 "GetUnsignedAxis",
243 axis,
244 inputDimension));
245 }
246 if (axis < -armnn::numeric_cast<int>(inputDimension))
247 {
248 throw armnn::InvalidArgumentException(fmt::format(
249 "{}: axis index [{}] lower than the negative of the number of dimensions [{}]",
250 "GetUnsignedAxis",
251 axis,
252 -armnn::numeric_cast<int>(inputDimension)));
253 }
254
255 unsigned int uAxis = axis < 0 ?
256 inputDimension - armnn::numeric_cast<unsigned int>(abs(axis))
257 : armnn::numeric_cast<unsigned int>(axis);
258 return uAxis;
259}

References armnn::numeric_cast().

Referenced by armnn::ArgMinMax(), ClArgMinMaxWorkload::ClArgMinMaxWorkload(), armnn::ClArgMinMaxWorkloadValidate(), armnn::ComputeSplitAxis(), ArgMinMaxLayer::InferOutputShapes(), NeonArgMinMaxWorkload::NeonArgMinMaxWorkload(), armnn::NeonArgMinMaxWorkloadValidate(), and ArgMinMaxQueueDescriptor::Validate().

◆ GraphTopologicalSort()

template<typename TNodeId, typename TTargetNodes>
bool GraphTopologicalSort ( const TTargetNodes & targetNodes,
std::function< std::vector< TNodeId >(TNodeId)> getIncomingEdges,
std::vector< TNodeId > & outSorted )

Definition at line 110 of file GraphTopologicalSort.hpp.

114{
115 outSorted.clear();
116 std::map<TNodeId, NodeState> nodeStates;
117
118 for (TNodeId targetNode : targetNodes)
119 {
120 if (!TopologicallySort(targetNode, getIncomingEdges, outSorted, nodeStates))
121 {
122 return false;
123 }
124 }
125
126 return true;
127}

◆ MakeInputTensors()

template<typename TContainer>
armnn::InputTensors MakeInputTensors ( const std::vector< armnn::BindingPointInfo > & inputBindings,
const std::vector< TContainer > & inputDataContainers )
inline

Definition at line 17 of file TensorIOUtils.hpp.

19{
20 armnn::InputTensors inputTensors;
21
22 const size_t numInputs = inputBindings.size();
23 if (numInputs != inputDataContainers.size())
24 {
25 throw armnn::Exception(fmt::format("The number of inputs does not match number of "
26 "tensor data containers: {0} != {1}",
27 numInputs,
28 inputDataContainers.size()));
29 }
30
31 for (size_t i = 0; i < numInputs; i++)
32 {
33 const armnn::BindingPointInfo& inputBinding = inputBindings[i];
34 const TContainer& inputData = inputDataContainers[i];
35
36 mapbox::util::apply_visitor([&](auto&& value)
37 {
38 if (value.size() != inputBinding.second.GetNumElements())
39 {
40 throw armnn::Exception(fmt::format("The input tensor has incorrect size (expected {0} got {1})",
41 inputBinding.second.GetNumElements(),
42 value.size()));
43 }
44 armnn::TensorInfo inputTensorInfo = inputBinding.second;
45 inputTensorInfo.SetConstant(true);
46 armnn::ConstTensor inputTensor(inputTensorInfo, value.data());
47 inputTensors.push_back(std::make_pair(inputBinding.first, inputTensor));
48 },
49 inputData);
50 }
51
52 return inputTensors;
53}
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Definition Tensor.hpp:330
Base class for all ArmNN exceptions so that users can filter to just those.
void SetConstant(const bool IsConstant=true)
Marks the data corresponding to this tensor info as constant.
Definition Tensor.cpp:518
std::pair< armnn::LayerBindingId, armnn::TensorInfo > BindingPointInfo
Definition Tensor.hpp:276
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
Definition Tensor.hpp:394
mapbox::util::variant< std::vector< float >, std::vector< int >, std::vector< unsigned char >, std::vector< int8_t > > TContainer

References TensorInfo::SetConstant().

◆ MakeOutputTensors()

template<typename TContainer>
armnn::OutputTensors MakeOutputTensors ( const std::vector< armnn::BindingPointInfo > & outputBindings,
std::vector< TContainer > & outputDataContainers )
inline

Definition at line 56 of file TensorIOUtils.hpp.

58{
59 armnn::OutputTensors outputTensors;
60
61 const size_t numOutputs = outputBindings.size();
62 if (numOutputs != outputDataContainers.size())
63 {
64 throw armnn::Exception(fmt::format("Number of outputs does not match number"
65 "of tensor data containers: {0} != {1}",
66 numOutputs,
67 outputDataContainers.size()));
68 }
69
70 for (size_t i = 0; i < numOutputs; i++)
71 {
72 const armnn::BindingPointInfo& outputBinding = outputBindings[i];
73 TContainer& outputData = outputDataContainers[i];
74
75 mapbox::util::apply_visitor([&](auto&& value)
76 {
77 if (value.size() != outputBinding.second.GetNumElements())
78 {
79 throw armnn::Exception("Output tensor has incorrect size");
80 }
81
82 armnn::Tensor outputTensor(outputBinding.second, value.data());
83 outputTensors.push_back(std::make_pair(outputBinding.first, outputTensor));
84 },
85 outputData);
86 }
87
88 return outputTensors;
89}
A tensor defined by a TensorInfo (shape and data type) and a mutable backing store.
Definition Tensor.hpp:322
std::vector< std::pair< LayerBindingId, class Tensor > > OutputTensors
Definition Tensor.hpp:395

◆ NonNegative()

uint32_t NonNegative ( const char * expr,
int32_t value,
const CheckLocation & location )

Definition at line 35 of file VerificationHelpers.cpp.

38{
39 if (value < 0)
40 {
41 throw ParseException(fmt::format("'{}' must be non-negative, received: {} at {}",
42 expr,
43 value,
44 location.AsString()));
45 }
46 else
47 {
48 return static_cast<uint32_t>(value);
49 }
50}

References CheckLocation::AsString().

◆ operator==() [1/2]

bool operator== ( const armnn::DataLayout & dataLayout,
const DataLayoutIndexed & indexed )

Equality methods.

Definition at line 46 of file DataLayoutIndexed.cpp.

47{
48 return dataLayout == indexed.GetDataLayout();
49}
armnn::DataLayout GetDataLayout() const

References DataLayoutIndexed::GetDataLayout().

◆ operator==() [2/2]

bool operator== ( const DataLayoutIndexed & indexed,
const armnn::DataLayout & dataLayout )

Definition at line 51 of file DataLayoutIndexed.cpp.

52{
53 return indexed.GetDataLayout() == dataLayout;
54}

References DataLayoutIndexed::GetDataLayout().

◆ Permute()

void Permute ( const armnn::TensorShape & dstShape,
const armnn::PermutationVector & mappings,
const void * src,
void * dst,
size_t dataTypeSize )

Definition at line 164 of file Permute.cpp.

166{
167 PermuteLoop(dstShape, mappings).Unroll(src, dst, dataTypeSize);
168}

Referenced by PermuteLayer::PermuteLayer().

◆ Permuted() [1/2]

armnn::TensorInfo Permuted ( const armnn::TensorInfo & info,
const armnn::PermutationVector & mappings )

Definition at line 148 of file Permute.cpp.

150{
151 armnn::TensorInfo outInfo(info);
152 outInfo.SetShape(Permuted(info.GetShape(), mappings));
153
154 // If TensorInfo has Per-Axis Quantization then it also has a QuantizationDim which needs to
155 // be permuted according to the mapping
156 if (info.GetQuantizationDim().has_value())
157 {
158 outInfo.SetQuantizationDim(mappings[info.GetQuantizationDim().value()]);
159 }
160
161 return outInfo;
162}
armnn::TensorShape Permuted(const armnn::TensorShape &srcShape, const armnn::PermutationVector &mappings)
Definition Permute.cpp:125

References armnn::info, Permuted(), TensorInfo::SetQuantizationDim(), and TensorInfo::SetShape().

◆ Permuted() [2/2]

armnn::TensorShape Permuted ( const armnn::TensorShape & srcShape,
const armnn::PermutationVector & mappings )

Definition at line 125 of file Permute.cpp.

127{
128 if (srcShape.GetNumDimensions() != mappings.GetSize())
129 {
130 std::stringstream msg;
131 msg << "Permute: Number of shape dimensions (" << srcShape.GetNumDimensions() <<
132 ") does not match the size of the mappings (" << mappings.GetSize() << ")";
133 throw armnn::InvalidArgumentException(msg.str());
134 }
135
136 const unsigned int numDims = mappings.GetSize();
137 unsigned int outDims[armnn::MaxNumOfTensorDimensions];
138
139 for (unsigned int i = 0U; i < numDims; ++i)
140 {
141 outDims[mappings[i]] = srcShape[i];
142 }
143
144 armnn::TensorShape permutedShape(numDims, outDims);
145 return permutedShape;
146}
SizeType GetSize() const
Definition Types.hpp:359
constexpr unsigned int MaxNumOfTensorDimensions
Definition Types.hpp:31

References TensorShape::GetNumDimensions(), PermutationVector::GetSize(), and armnn::MaxNumOfTensorDimensions.

Referenced by armnn::ClUnidirectionalSequenceLstmFloatWorkloadValidate(), armnn::Convert1HWOTensorInfoToAcl(), armnn::ConvertWeightTensorInfoFromArmnnToAcl(), armnnOnnxParser::CreateConstTensorImpl(), BatchMatMulLayer::InferOutputShapes(), PermuteLayer::InferOutputShapes(), armnn::NeonUnidirectionalSequenceLstmFloatWorkloadValidate(), armnn::NeonUnidirectionalSequenceLstmWorkloadValidate(), Permuted(), armnn::PermuteTensor(), MovePermuteUpImpl::Run(), BatchMatMulQueueDescriptor::Validate(), and PermuteDepthwiseConv2dWeightsImpl::~PermuteDepthwiseConv2dWeightsImpl().

◆ ProcessConcatInputTensorInfo()

void ProcessConcatInputTensorInfo ( armnn::TensorInfo & inputTensorInfo,
armnn::OriginsDescriptor & concatDescriptor,
const unsigned int & concatAxis,
unsigned int inputIndex,
unsigned int & mergeDimOrigin )

Definition at line 19 of file ParserHelper.cpp.

24{
25 const uint32_t inputRank = concatDescriptor.GetNumDimensions();
26
27 // double check dimensions of the tensors
28 if (inputTensorInfo.GetNumDimensions() != inputRank)
29 {
30 throw armnn::ParseException(fmt::format(
31 "The number of dimensions: {0} for input tensors of the "
32 "concatenation op should be {1} {2}",
33 inputTensorInfo.GetNumDimensions(),
34 inputRank,
35 CHECK_LOCATION().AsString()));
36 }
37
38 for (unsigned int j = 0; j < concatAxis; ++j)
39 {
40 concatDescriptor.SetViewOriginCoord(inputIndex, j, 0);
41 }
42
43 concatDescriptor.SetViewOriginCoord(inputIndex, concatAxis, mergeDimOrigin);
44 mergeDimOrigin += inputTensorInfo.GetShape()[concatAxis];
45
46 for (unsigned int j = concatAxis + 1; j < inputRank; ++j)
47 {
48 concatDescriptor.SetViewOriginCoord(inputIndex, j, 0);
49 }
50}
Status SetViewOriginCoord(uint32_t view, uint32_t coord, uint32_t value)
@Brief Set the view origin coordinates.
uint32_t GetNumDimensions() const
Get the number of dimensions.

References CHECK_LOCATION, OriginsDescriptor::GetNumDimensions(), TensorInfo::GetNumDimensions(), TensorInfo::GetShape(), and OriginsDescriptor::SetViewOriginCoord().

◆ QuantizedVector() [1/3]

template<typename T>
std::vector< T > QuantizedVector ( const std::vector< float > & array,
float qScale = 1.f,
int32_t qOffset = 0 )

Definition at line 121 of file QuantizeHelper.hpp.

122{
123 return QuantizedVector<T>(array.begin(), array.end(), qScale, qOffset);
124}
std::vector< T > QuantizedVector(FloatIt first, FloatIt last, float qScale, int32_t qOffset)

References QuantizedVector().

◆ QuantizedVector() [2/3]

template<typename T, typename FloatIt, typename std::enable_if< IsFloatingPointIterator< FloatIt >::value, int >::type = 0>
std::vector< T > QuantizedVector ( FloatIt first,
FloatIt last,
float qScale,
int32_t qOffset )

Definition at line 105 of file QuantizeHelper.hpp.

106{
107 std::vector<T> quantized;
108 quantized.reserve(armnn::numeric_cast<size_t>(std::distance(first, last)));
109
110 for (auto it = first; it != last; ++it)
111 {
112 auto f = *it;
113 T q = SelectiveQuantize<T>(f, qScale, qOffset);
114 quantized.push_back(q);
115 }
116
117 return quantized;
118}
T SelectiveQuantize(float value, float scale, int32_t offset)

References armnn::numeric_cast(), and SelectiveQuantize().

Referenced by QuantizedVector(), and QuantizedVector().

◆ QuantizedVector() [3/3]

template<typename T>
std::vector< T > QuantizedVector ( std::initializer_list< float > array,
float qScale = 1.f,
int32_t qOffset = 0 )

Definition at line 127 of file QuantizeHelper.hpp.

128{
129 return QuantizedVector<T>(array.begin(), array.end(), qScale, qOffset);
130}

References QuantizedVector().

◆ ReduceDims() [1/2]

TensorInfo ReduceDims ( const armnn::TensorInfo & tensorInfo,
unsigned int dimensions )

Definition at line 134 of file TensorUtils.cpp.

135{
136 TensorInfo strippedTensor(tensorInfo);
137 TensorShape strippedShape = ReduceDims(tensorInfo.GetShape(), dimensions);
138 strippedTensor.SetShape(strippedShape);
139 return strippedTensor;
140}
armnn::TensorShape ReduceDims(const armnn::TensorShape &tensorInfo, unsigned int dimensions)

References TensorInfo::GetShape(), ReduceDims(), and TensorInfo::SetShape().

◆ ReduceDims() [2/2]

TensorShape ReduceDims ( const armnn::TensorShape & tensorInfo,
unsigned int dimensions )

Definition at line 108 of file TensorUtils.cpp.

109{
110 if (tensorShape.GetNumDimensions() <= dimensions)
111 {
112 return tensorShape;
113 }
114 std::vector<unsigned int> newShape;
115
116 unsigned int dimsToSkip = tensorShape.GetNumDimensions() - dimensions;
117 unsigned int dimsSkipped = 0;
118 bool insertRemainder = false;
119
120 for (unsigned int i = 0; i < tensorShape.GetNumDimensions(); ++i)
121 {
122 if (tensorShape[i] == 1 && dimsSkipped < dimsToSkip && !insertRemainder)
123 {
124 ++dimsSkipped;
125 continue;
126 }
127 newShape.push_back(tensorShape[i]);
128 // Once we insert the first dimension we can't skip any more
129 insertRemainder = true;
130 }
131 return TensorShape(static_cast<unsigned int>(newShape.size()), newShape.data());
132}

References TensorShape::GetNumDimensions().

Referenced by ReduceDims().

◆ SelectiveDequantize()

template<typename T>
float SelectiveDequantize ( T value,
float scale,
int32_t offset )

Definition at line 91 of file QuantizeHelper.hpp.

References armnn::Dequantize.

◆ SelectiveQuantize()

template<typename T>
T SelectiveQuantize ( float value,
float scale,
int32_t offset )

◆ SplitBy()

std::vector< std::string > SplitBy ( const std::string & originalString,
const std::string & delimiter = " ",
bool includeEmptyToken = false )

Split a string into tokens by a delimiter.

Parameters
[in]originalStringOriginal string to be split
[in]delimiterDelimiter used to split originalString
[in]includeEmptyToeknIf true, include empty tokens in the result
Returns
A vector of tokens split from originalString by \delimiter

Definition at line 41 of file ModelAccuracyChecker.cpp.

42{
43 std::vector<std::string> tokens;
44 size_t cur = 0;
45 size_t next = 0;
46 while ((next = originalString.find(delimiter, cur)) != std::string::npos)
47 {
48 // Skip empty tokens, unless explicitly stated to include them.
49 if (next - cur > 0 || includeEmptyToken)
50 {
51 tokens.push_back(originalString.substr(cur, next - cur));
52 }
53 cur = next + delimiter.size();
54 }
55 // Get the remaining token
56 // Skip empty tokens, unless explicitly stated to include them.
57 if (originalString.size() - cur > 0 || includeEmptyToken)
58 {
59 tokens.push_back(originalString.substr(cur, originalString.size() - cur));
60 }
61 return tokens;
62}

◆ SqueezeDims()

std::vector< unsigned int > SqueezeDims ( const armnn::TensorShape & tensorShape)

Definition at line 195 of file TensorUtils.cpp.

196{
197 std::vector<unsigned int> squeezedDims;
198
199 for (unsigned int i = 0; i < tensorShape.GetNumDimensions(); ++i)
200 {
201 if (tensorShape[i] != 1)
202 {
203 squeezedDims.push_back(tensorShape[i]);
204 }
205 }
206 return squeezedDims;
207}

References TensorShape::GetNumDimensions().

Referenced by Layer::ValidateAndCopyShape().

◆ Strip()

std::string Strip ( const std::string & originalString,
const std::string & characterSet = " " )

Remove any preceding and trailing character specified in the characterSet.

Parameters
[in]originalStringOriginal string to be stripped
[in]characterSetSet of characters to be stripped from originalString
Returns
A string stripped of all characters specified in characterSet from originalString

Definition at line 65 of file ModelAccuracyChecker.cpp.

66{
67 if (characterSet.empty())
68 {
69 throw armnn::InvalidArgumentException("Strip: string of characters to strip is empty");
70 }
71 const std::size_t firstFound = originalString.find_first_not_of(characterSet);
72 const std::size_t lastFound = originalString.find_last_not_of(characterSet);
73 // Return empty if the originalString is empty or the originalString contains only to-be-striped characters
74 if (firstFound == std::string::npos || lastFound == std::string::npos)
75 {
76 return "";
77 }
78 return originalString.substr(firstFound, lastFound + 1 - firstFound);
79}

◆ ToFloatArray() [1/2]

template<typename PrimitiveType>
std::unique_ptr< float[]> ToFloatArray ( const std::vector< PrimitiveType > & data,
const armnn::TensorInfo & tensorInfo )

Definition at line 307 of file TensorUtils.cpp.

308{
309 CheckSizes(data, tensorInfo);
310
311 std::unique_ptr<float[]> returnBuffer(new float[tensorInfo.GetNumElements()]);
312
313 if (tensorInfo.HasPerAxisQuantization())
314 {
315 unsigned int axis = tensorInfo.GetQuantizationDim().value();
316 auto axisDimensionality = tensorInfo.GetShape()[axis];
317 auto axisFactor = armnnUtils::GetNumElementsAfter(tensorInfo.GetShape(), axis);
318
319 for (unsigned int i = 0; i < tensorInfo.GetNumElements(); ++i)
320 {
321 unsigned int axisIndex;
322
323 if (i < axisFactor)
324 {
325 axisIndex = 0;
326 }
327 else
328 {
329 axisIndex = (i / axisFactor) % axisDimensionality;
330 }
331 returnBuffer[i] = Dequantize<PrimitiveType>(data[i],
332 tensorInfo.GetQuantizationScales()[axisIndex],
333 tensorInfo.GetQuantizationOffset());
334 }
335 }
336 else
337 {
338 for (unsigned int i = 0; i < tensorInfo.GetNumElements(); ++i)
339 {
340 returnBuffer[i] = Dequantize<PrimitiveType>(data[i],
341 tensorInfo.GetQuantizationScale(),
342 tensorInfo.GetQuantizationOffset());
343 }
344 }
345 return returnBuffer;
346}
float GetQuantizationScale() const
Definition Tensor.cpp:461
int32_t GetQuantizationOffset() const
Definition Tensor.cpp:482
Optional< unsigned int > GetQuantizationDim() const
Definition Tensor.cpp:498
std::vector< float > GetQuantizationScales() const
Definition Tensor.cpp:451
bool HasPerAxisQuantization() const
Definition Tensor.cpp:446
void CheckSizes(const std::vector< PrimitiveType > &data, const armnn::TensorInfo &tensorInfo, unsigned int size=1)

References CheckSizes(), armnn::Dequantize, TensorInfo::GetNumElements(), GetNumElementsAfter(), TensorInfo::GetQuantizationDim(), TensorInfo::GetQuantizationOffset(), TensorInfo::GetQuantizationScale(), TensorInfo::GetQuantizationScales(), TensorInfo::GetShape(), TensorInfo::HasPerAxisQuantization(), and OptionalReferenceSwitch< IsReference, T >::value().

Referenced by ToFloatArray().

◆ ToFloatArray() [2/2]

std::unique_ptr< float[]> ToFloatArray ( const std::vector< uint8_t > & data,
const armnn::TensorInfo & tensorInfo )

Definition at line 348 of file TensorUtils.cpp.

349{
350 if (tensorInfo.GetDataType() == DataType::QAsymmS8 || tensorInfo.GetDataType() == DataType::QSymmS8)
351 {
352 CheckSizes(data, tensorInfo);
353 std::vector<int8_t> buffer(tensorInfo.GetNumElements());
354 ::memcpy(buffer.data(), data.data(), data.size());
355 return ToFloatArray<int8_t>(buffer, tensorInfo);
356 }
357 else if (tensorInfo.GetDataType() == DataType::QAsymmU8)
358 {
359 CheckSizes(data, tensorInfo);
360 return ToFloatArray<uint8_t>(data, tensorInfo);
361 }
362 else if (tensorInfo.GetDataType() == DataType::Signed32)
363 {
364 CheckSizes(data, tensorInfo, 4);
365 std::vector<int32_t> buffer(tensorInfo.GetNumElements());
366 ::memcpy(buffer.data(), data.data(), data.size());
367 return ToFloatArray<int32_t>(buffer, tensorInfo);
368 }
369 else if (tensorInfo.GetDataType() == DataType::Signed64)
370 {
371 CheckSizes(data, tensorInfo, 8);
372 std::vector<int64_t> buffer(tensorInfo.GetNumElements());
373 ::memcpy(buffer.data(), data.data(), data.size());
374 return ToFloatArray<int64_t>(buffer, tensorInfo);
375 }
377 fmt::format("Unsupported datatype {}. {}",
378 GetDataTypeName(tensorInfo.GetDataType()),
379 CHECK_LOCATION().AsString()));
380}
std::unique_ptr< float[]> ToFloatArray(const std::vector< PrimitiveType > &data, const armnn::TensorInfo &tensorInfo)

References CHECK_LOCATION, CheckSizes(), TensorInfo::GetDataType(), armnn::GetDataTypeName(), TensorInfo::GetNumElements(), armnn::QAsymmS8, armnn::QAsymmU8, armnn::QSymmS8, armnn::Signed32, armnn::Signed64, and ToFloatArray().

◆ Transpose()

void Transpose ( const armnn::TensorShape & dstShape,
const armnn::PermutationVector & mappings,
const void * src,
void * dst,
size_t dataTypeSize )

Definition at line 153 of file Transpose.cpp.

155{
156 TransposeLoop(srcShape, mappings).Unroll(src, dst, dataTypeSize);
157}

Referenced by TransposeLayer::TransposeLayer().

◆ TransposeTensorShape() [1/2]

armnn::TensorInfo TransposeTensorShape ( const armnn::TensorInfo & info,
const armnn::PermutationVector & mappings )

Definition at line 146 of file Transpose.cpp.

147{
148 armnn::TensorInfo outInfo(info);
149 outInfo.SetShape(TransposeTensorShape(info.GetShape(), mappings));
150 return outInfo;
151}
armnn::TensorShape TransposeTensorShape(const armnn::TensorShape &srcShape, const armnn::PermutationVector &mappings)

References armnn::info, TensorInfo::SetShape(), and TransposeTensorShape().

◆ TransposeTensorShape() [2/2]

armnn::TensorShape TransposeTensorShape ( const armnn::TensorShape & srcShape,
const armnn::PermutationVector & mappings )

Definition at line 125 of file Transpose.cpp.

126{
127 if (srcShape.GetNumDimensions() != mappings.GetSize())
128 {
129 std::stringstream msg;
130 msg << "Transpose: Number of shape dimensions (" << srcShape.GetNumDimensions() <<
131 ") does not match the size of the mappings (" << mappings.GetSize() << ")";
132 throw armnn::InvalidArgumentException(msg.str());
133 }
134
135 const unsigned int numDims = mappings.GetSize();
136 unsigned int outDims[armnn::MaxNumOfTensorDimensions];
137
138 for (unsigned int i = 0U; i < numDims; ++i)
139 {
140 outDims[i] = srcShape[mappings[i]];
141 }
142 armnn::TensorShape permutedShape(numDims, outDims);
143 return permutedShape;
144}

References TensorShape::GetNumDimensions(), PermutationVector::GetSize(), and armnn::MaxNumOfTensorDimensions.

Referenced by TransposeLayer::InferOutputShapes(), MoveTransposeUpImpl::Run(), and TransposeTensorShape().

◆ VerifyInt32()

int32_t VerifyInt32 ( const char * expr,
int64_t value,
const armnn::CheckLocation & location )

Definition at line 52 of file VerificationHelpers.cpp.

55{
56 if (value < std::numeric_limits<int>::min() || value > std::numeric_limits<int>::max())
57 {
58 throw ParseException(fmt::format("'{}' must should fit into a int32 (ArmNN don't support int64),"
59 " received: {} at {}",
60 expr,
61 value,
62 location.AsString()));
63 }
64 else
65 {
66 return static_cast<int32_t>(value);
67 }
68}

References CheckLocation::AsString().

◆ within_percentage_tolerance()

bool within_percentage_tolerance ( float a,
float b,
float tolerancePercent = 1.0f )
inline

Compare two floats and return true if their values are within a specified tolerance of each other.

Parameters
a
b
tolerancePercentageIf not supplied default will be 1% tolerance (1.0f)
Returns
true if the value of float b is within tolerancePercentage of the value for float a.

Definition at line 20 of file FloatingPointComparison.hpp.

21{
22 float toleranceValue = std::fabs(a * (tolerancePercent / 100));
23 return std::fabs(a - b) <= toleranceValue;
24}

Variable Documentation

◆ ArmNNToNHWC

const armnn::PermutationVector ArmNNToNHWC = { 0, 3, 1, 2 }

Definition at line 17 of file ParserHelper.cpp.

17{ 0, 3, 1, 2 };

◆ NHWCToArmNN

const armnn::PermutationVector NHWCToArmNN = { 0, 2, 3, 1 }

Definition at line 16 of file ParserHelper.cpp.

16{ 0, 2, 3, 1 };