From 8d2ca734165a068478df7cffa46185680b05cd20 Mon Sep 17 00:00:00 2001 From: Nikhil Raj Date: Fri, 24 Feb 2023 10:28:19 +0000 Subject: Update Doxygen docu for 23.02 Signed-off-by: Nikhil Raj Change-Id: Ie6c19a27d50fefab2796b2b5875374e81f5bf971 --- 23.02/namespacearmnn_utils.xhtml | 2262 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 2262 insertions(+) create mode 100644 23.02/namespacearmnn_utils.xhtml (limited to '23.02/namespacearmnn_utils.xhtml') diff --git a/23.02/namespacearmnn_utils.xhtml b/23.02/namespacearmnn_utils.xhtml new file mode 100644 index 0000000000..25844d14c7 --- /dev/null +++ b/23.02/namespacearmnn_utils.xhtml @@ -0,0 +1,2262 @@ + + + + + + + + + + + + + +ArmNN: armnnUtils Namespace Reference + + + + + + + + + + + + + + + + +
+
+ + + + ArmNN + + + +
+
+  23.02 +
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+ +
+ +
+ +
+
armnnUtils Namespace Reference
+
+
+ + + + +

+Namespaces

 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 = mapbox::util::variant< std::vector< float >, std::vector< int >, std::vector< unsigned char >, std::vector< int8_t > >
 
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. More...
 
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. More...
 
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)
 
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<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. More...
 
std::string Strip (const std::string &originalString, const std::string &characterSet=" ")
 Remove any preceding and trailing character specified in the characterSet. More...
 
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. More...
 
void CalculateStridedSliceOutputTensorInfo (const armnn::TensorInfo &inputTensorInfo, const armnn::StridedSliceDescriptor &desc, armnn::TensorInfo &outputTensorInfo)
 Create output tensor info for a StridedSlice operator. More...
 
std::string ConvertInt32ToOctalString (int value)
 Converts an int value into the Prototxt octal representation. More...
 
std::string ConvertTensorShapeToString (const armnn::TensorShape &shape)
 Converts an TensorShape into Prototxt representation. More...
 
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 = mapbox::util::variant<std::vector<float>, std::vector<int>, std::vector<unsigned char>, std::vector<int8_t> >
+
+ +

Definition at line 18 of file TContainer.hpp.

+ +
+
+

Function Documentation

+ +

◆ CalculateReducedOutputTensoInfo()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void CalculateReducedOutputTensoInfo (const armnn::TensorInfoinputTensorInfo,
const std::set< unsigned int > & axisSet,
bool keepDims,
armnn::TensorInfooutputTensorInfo 
)
+
+ +

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

+ +

Definition at line 52 of file ParserHelper.cpp.

+ +

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

+
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:191
+ + +
DataType GetDataType() const
Definition: Tensor.hpp:198
+
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:195
+
+
+
+ +

◆ CalculateStridedSliceOutputTensorInfo()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
void CalculateStridedSliceOutputTensorInfo (const armnn::TensorInfoinputTensorInfo,
const armnn::StridedSliceDescriptordesc,
armnn::TensorInfooutputTensorInfo 
)
+
+ +

Create output tensor info for a StridedSlice operator.

+ +

Definition at line 103 of file ParserHelper.cpp.

+ +

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

+
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 }
const TensorShape & GetShape() const
Definition: Tensor.hpp:191
+
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
+ + +
DataType GetDataType() const
Definition: Tensor.hpp:198
+
std::vector< int > m_Stride
Stride values for the input that will be sliced.
+
int GetStopForAxis(const TensorShape &inputShape, unsigned int axis, int startForAxis) const
+
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:195
+
+
+
+ +

◆ CheckSizes()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
void armnnUtils::CheckSizes (const std::vector< PrimitiveType > & data,
const armnn::TensorInfotensorInfo,
unsigned int size = 1 
)
+
+ +

Definition at line 237 of file TensorUtils.cpp.

+ +

References CHECK_LOCATION, and TensorInfo::GetNumElements().

+ +

Referenced by ToFloatArray().

+
238 {
239  if (data.size() / size != tensorInfo.GetNumElements())
240  {
242  fmt::format("The data does not contain the expected number of elements {} != {}. {}",
243  data.size(), tensorInfo.GetNumElements(), CHECK_LOCATION().AsString()));
244  }
245 }
+
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
+
unsigned int GetNumElements() const
Definition: Tensor.hpp:196
+
+
+
+ +

◆ CheckValidSize()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void CheckValidSize (std::initializer_list< size_t > validInputCounts,
size_t actualValue,
const char * validExpr,
const char * actualExpr,
const CheckLocationlocation 
)
+
+ +

Definition at line 16 of file VerificationHelpers.cpp.

+ +

References CheckLocation::AsString().

+
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
Definition: Exceptions.hpp:29
+ +
+
+
+ +

◆ CompatibleTypes()

+ +
+
+ + + + + + + + +
bool CompatibleTypes (armnn::DataType )
+
+ +

Definition at line 17 of file CompatibleTypes.cpp.

+
18 {
19  return false;
20 }
+
+
+ +

◆ CompatibleTypes< BFloat16 >()

+ +
+
+ + + + + + + + +
bool armnnUtils::CompatibleTypes< BFloat16 > (DataType dataType)
+
+ +

Definition at line 35 of file CompatibleTypes.cpp.

+ +

References armnn::BFloat16.

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

◆ CompatibleTypes< float >()

+ +
+
+ + + + + + + + +
bool armnnUtils::CompatibleTypes< float > (DataType dataType)
+
+ +

Definition at line 23 of file CompatibleTypes.cpp.

+ +

References armnn::Float32.

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

◆ CompatibleTypes< Half >()

+ +
+
+ + + + + + + + +
bool armnnUtils::CompatibleTypes< Half > (DataType dataType)
+
+ +

Definition at line 29 of file CompatibleTypes.cpp.

+ +

References armnn::Float16.

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

◆ CompatibleTypes< int16_t >()

+ +
+
+ + + + + + + + +
bool armnnUtils::CompatibleTypes< int16_t > (DataType dataType)
+
+ +

Definition at line 54 of file CompatibleTypes.cpp.

+ +

References armnn::QSymmS16.

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

◆ CompatibleTypes< int32_t >()

+ +
+
+ + + + + + + + +
bool armnnUtils::CompatibleTypes< int32_t > (DataType dataType)
+
+ +

Definition at line 60 of file CompatibleTypes.cpp.

+ +

References armnn::Signed32.

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

◆ CompatibleTypes< int8_t >()

+ +
+
+ + + + + + + + +
bool armnnUtils::CompatibleTypes< int8_t > (DataType dataType)
+
+ +

Definition at line 47 of file CompatibleTypes.cpp.

+ +

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

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

◆ CompatibleTypes< uint8_t >()

+ +
+
+ + + + + + + + +
bool armnnUtils::CompatibleTypes< uint8_t > (DataType dataType)
+
+ +

Definition at line 41 of file CompatibleTypes.cpp.

+ +

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

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

◆ 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::TensorShapeshape)
+
+ +

Converts an TensorShape into Prototxt representation.

+ +

Definition at line 32 of file PrototxtConversions.cpp.

+ +

References TensorShape::GetNumDimensions().

+
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
+
+
+
+ +

◆ ExpandDims()

+ +
+
+ + + + + + + + + + + + + + + + + + +
TensorShape ExpandDims (const armnn::TensorShapetensorShape,
int axis 
)
+
+ +

Definition at line 140 of file TensorUtils.cpp.

+ +

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

+ +

Referenced by Converter::ConvertOperation().

+
141 {
142  unsigned int outputDim = tensorShape.GetNumDimensions() + 1;
143 
144  if (axis < -armnn::numeric_cast<int>(outputDim) || axis > armnn::numeric_cast<int>(tensorShape.GetNumDimensions()))
145  {
146  throw InvalidArgumentException(fmt::format("Invalid expansion axis {} for {}D input tensor. {}",
147  axis,
148  tensorShape.GetNumDimensions(),
149  CHECK_LOCATION().AsString()));
150  }
151 
152  if (axis < 0)
153  {
154  axis = armnn::numeric_cast<int>(outputDim) + axis;
155  }
156 
157  std::vector<unsigned int> outputShape;
158  outputShape.reserve(tensorShape.GetNumDimensions());
159  for (unsigned int i = 0; i < tensorShape.GetNumDimensions(); ++i)
160  {
161  outputShape.push_back(tensorShape[i]);
162  }
163  outputShape.insert(outputShape.begin() + axis, 1);
164 
165  return { outputDim, outputShape.data() };
166 }
+
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
+
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
Definition: Tensor.cpp:174
+
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35
+
+
+
+ +

◆ FindMinMax()

+ +
+
+ + + + + + + + +
std::pair< float, float > FindMinMax (armnn::ITensorHandletensorHandle)
+
+ +

Definition at line 79 of file TensorUtils.cpp.

+ +

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

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

◆ GetNumElementsAfter()

+ +
+
+ + + + + + + + + + + + + + + + + + +
unsigned int GetNumElementsAfter (const armnn::TensorShapeshape,
unsigned int axis 
)
+
+ +

Definition at line 209 of file TensorUtils.cpp.

+ +

References ARMNN_ASSERT, and TensorShape::GetNumDimensions().

+ +

Referenced by GetPerAxisParams(), PerAxisIterator< const int8_t, Decoder< float > >::PerAxisIterator(), and ToFloatArray().

+
210 {
211  unsigned int numDim = shape.GetNumDimensions();
212  ARMNN_ASSERT(axis <= numDim - 1);
213  unsigned int count = 1;
214  for (unsigned int i = axis+1; i < numDim; i++)
215  {
216  count *= shape[i];
217  }
218  return count;
219 }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
+
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
Definition: Tensor.cpp:174
+
+
+
+ +

◆ GetNumElementsBetween()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
unsigned int GetNumElementsBetween (const armnn::TensorShapeshape,
unsigned int firstAxisInclusive,
unsigned int lastAxisExclusive 
)
+
+ +

Definition at line 182 of file TensorUtils.cpp.

+ +

References ARMNN_ASSERT, and TensorShape::GetNumDimensions().

+ +

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

+
185 {
186  ARMNN_ASSERT(firstAxisInclusive <= lastAxisExclusive);
187  ARMNN_ASSERT(lastAxisExclusive <= shape.GetNumDimensions());
188  unsigned int count = 1;
189  for (unsigned int i = firstAxisInclusive; i < lastAxisExclusive; i++)
190  {
191  count *= shape[i];
192  }
193  return count;
194 }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
+
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
Definition: Tensor.cpp:174
+
+
+
+ +

◆ GetPerAxisParams()

+ +
+
+ + + + + + + + +
std::pair< unsigned int, std::vector< float > > GetPerAxisParams (const armnn::TensorInfoinfo)
+
+ +

Definition at line 221 of file TensorUtils.cpp.

+ +

References CHECK_LOCATION, TensorInfo::GetDataType(), armnn::GetDataTypeName(), GetNumElementsAfter(), TensorInfo::GetQuantizationDim(), TensorInfo::GetQuantizationScales(), TensorInfo::GetShape(), TensorInfo::HasPerAxisQuantization(), and OptionalReferenceSwitch< IsReference, T >::value().

+ +

Referenced by armnn::MakeDecoder(), and armnn::MakeEncoder().

+
222 {
223  const std::vector<float>& scales = info.GetQuantizationScales();
224  armnn::Optional<unsigned int> quantizationDim = info.GetQuantizationDim();
225  if (!info.HasPerAxisQuantization())
226  {
228  std::string("Per-axis quantization params not set for tensor of type ") +
230  }
231  unsigned int axisFactor = GetNumElementsAfter(info.GetShape(), quantizationDim.value()) ;
232 
233  return { axisFactor, scales };
234 }
const TensorShape & GetShape() const
Definition: Tensor.hpp:191
+ +
bool HasPerAxisQuantization() const
Definition: Tensor.cpp:446
+
Optional< unsigned int > GetQuantizationDim() const
Definition: Tensor.cpp:494
+ +
std::vector< float > GetQuantizationScales() const
Definition: Tensor.cpp:451
+
constexpr const char * GetDataTypeName(DataType dataType)
Definition: TypesUtils.hpp:206
+
DataType GetDataType() const
Definition: Tensor.hpp:198
+ +
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
+
unsigned int GetNumElementsAfter(const armnn::TensorShape &shape, unsigned int axis)
+
+
+
+ +

◆ GetTensorInfo() [1/2]

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

Definition at line 38 of file TensorUtils.cpp.

+ +

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

+
44 {
45  switch (dataLayout)
46  {
47  case DataLayout::NCHW:
48  return TensorInfo({numberOfBatches, numberOfChannels, height, width}, dataType);
49  case DataLayout::NHWC:
50  return TensorInfo({numberOfBatches, height, width, numberOfChannels}, dataType);
51  default:
52  throw InvalidArgumentException("Unknown data layout ["
53  + std::to_string(static_cast<int>(dataLayout)) +
54  "]", CHECK_LOCATION());
55  }
56 }
+ +
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
+
+
+
+ +

◆ GetTensorInfo() [2/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 58 of file TensorUtils.cpp.

+ +

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

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

◆ GetTensorShape()

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

Definition at line 19 of file TensorUtils.cpp.

+ +

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

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

◆ GetUnsignedAxis()

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

Definition at line 196 of file TensorUtils.cpp.

+ +

References ARMNN_ASSERT_MSG, and armnn::numeric_cast().

+ +

Referenced by armnn::ArgMinMax(), ClArgMinMaxWorkload::ClArgMinMaxWorkload(), ArgMinMaxLayer::InferOutputShapes(), NeonArgMinMaxWorkload::NeonArgMinMaxWorkload(), TfLiteParserImpl::OutputShapeOfReshape(), and ArgMinMaxQueueDescriptor::Validate().

+
197 {
198  ARMNN_ASSERT_MSG(axis < armnn::numeric_cast<int>(inputDimension),
199  "Required axis index greater than number of dimensions.");
200  ARMNN_ASSERT_MSG(axis >= -armnn::numeric_cast<int>(inputDimension),
201  "Required axis index lower than negative of the number of dimensions");
202 
203  unsigned int uAxis = axis < 0 ?
204  inputDimension - armnn::numeric_cast<unsigned int>(abs(axis))
205  : armnn::numeric_cast<unsigned int>(axis);
206  return uAxis;
207 }
+
#define ARMNN_ASSERT_MSG(COND, MSG)
Definition: Assert.hpp:15
+
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35
+
+
+
+ +

◆ GraphTopologicalSort()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
bool armnnUtils::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()

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

Definition at line 17 of file TensorIOUtils.hpp.

+ +

References TensorInfo::SetConstant().

+
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 }
+
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
Definition: Tensor.hpp:392
+
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Definition: Tensor.hpp:327
+
std::pair< armnn::LayerBindingId, armnn::TensorInfo > BindingPointInfo
Definition: Tensor.hpp:274
+
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
+
mapbox::util::variant< std::vector< float >, std::vector< int >, std::vector< unsigned char >, std::vector< int8_t > > TContainer
Definition: TContainer.hpp:18
+
void SetConstant(const bool IsConstant=true)
Marks the data corresponding to this tensor info as constant.
Definition: Tensor.cpp:514
+
+
+
+ +

◆ MakeOutputTensors()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + +
armnn::OutputTensors armnnUtils::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:319
+
std::vector< std::pair< LayerBindingId, class Tensor > > OutputTensors
Definition: Tensor.hpp:393
+
std::pair< armnn::LayerBindingId, armnn::TensorInfo > BindingPointInfo
Definition: Tensor.hpp:274
+
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
+
mapbox::util::variant< std::vector< float >, std::vector< int >, std::vector< unsigned char >, std::vector< int8_t > > TContainer
Definition: TContainer.hpp:18
+
+
+
+ +

◆ NonNegative()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
uint32_t NonNegative (const char * expr,
int32_t value,
const CheckLocationlocation 
)
+
+ +

Definition at line 35 of file VerificationHelpers.cpp.

+ +

References CheckLocation::AsString().

+
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 }
std::string AsString() const
Definition: Exceptions.hpp:29
+ +
+
+
+ +

◆ operator==() [1/2]

+ +
+
+ + + + + + + + + + + + + + + + + + +
bool operator== (const armnn::DataLayoutdataLayout,
const DataLayoutIndexedindexed 
)
+
+ +

Equality methods.

+ +

Definition at line 46 of file DataLayoutIndexed.cpp.

+ +

References DataLayoutIndexed::GetDataLayout().

+ +

Referenced by OutputSlot::Disconnect(), and DataLayoutIndexed::GetIndex().

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

◆ operator==() [2/2]

+ +
+
+ + + + + + + + + + + + + + + + + + +
bool operator== (const DataLayoutIndexedindexed,
const armnn::DataLayoutdataLayout 
)
+
+ +

Definition at line 51 of file DataLayoutIndexed.cpp.

+ +

References DataLayoutIndexed::GetDataLayout().

+
52 {
53  return indexed.GetDataLayout() == dataLayout;
54 }
armnn::DataLayout GetDataLayout() const
+
+
+
+ +

◆ Permute()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void Permute (const armnn::TensorShapedstShape,
const armnn::PermutationVectormappings,
const void * src,
void * dst,
size_t dataTypeSize 
)
+
+ +

Definition at line 131 of file Permute.cpp.

+ +

Referenced by armnnOnnxParser::CreateConstTensorImpl(), armnn::DepthToSpace(), IDeserializer::DeserializerImpl::GetNetworkOutputBindingInfo(), and PermuteLayer::PermuteLayer().

+
133 {
134  PermuteLoop(dstShape, mappings).Unroll(src, dst, dataTypeSize);
135 }
+
+
+ +

◆ Permuted() [1/2]

+ +
+
+ + + + + + + + + + + + + + + + + + +
armnn::TensorShape Permuted (const armnn::TensorShapesrcShape,
const armnn::PermutationVectormappings 
)
+
+ +

Definition at line 98 of file Permute.cpp.

+ +

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

+ +

Referenced by BatchMatMul::BatchMatMul(), armnn::Convert1HWOTensorInfoToAcl(), armnn::ConvertWeightTensorInfoFromArmnnToAcl(), armnnOnnxParser::CreateConstTensorImpl(), OnnxParserImpl::CreateNetworkFromString(), RefUnidirectionalSequenceLstmWorkload::ExecuteAsync(), IDeserializer::DeserializerImpl::GetNetworkOutputBindingInfo(), BatchMatMulLayer::InferOutputShapes(), PermuteLayer::InferOutputShapes(), Permuted(), armnn::PermuteTensor(), PermuteDepthwiseConv2dWeightsImpl::Run(), MovePermuteUpImpl::Run(), armnn_driver::SwizzleAndroidNn4dTensorToArmNn(), and BatchMatMulQueueDescriptor::Validate().

+
100 {
101  assert(srcShape.GetNumDimensions() == mappings.GetSize());
102 
103  const unsigned int numDims = mappings.GetSize();
104  unsigned int outDims[armnn::MaxNumOfTensorDimensions];
105 
106  for (unsigned int i = 0U; i < numDims; ++i)
107  {
108  outDims[mappings[i]] = srcShape[i];
109  }
110 
111  armnn::TensorShape permutedShape(numDims, outDims);
112  return permutedShape;
113 }
+
SizeType GetSize() const
Definition: Types.hpp:338
+
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
Definition: Tensor.cpp:174
+
constexpr unsigned int MaxNumOfTensorDimensions
Definition: Types.hpp:31
+
+
+
+ +

◆ Permuted() [2/2]

+ +
+
+ + + + + + + + + + + + + + + + + + +
armnn::TensorInfo Permuted (const armnn::TensorInfoinfo,
const armnn::PermutationVectormappings 
)
+
+ +

Definition at line 115 of file Permute.cpp.

+ +

References TensorInfo::GetQuantizationDim(), TensorInfo::GetShape(), OptionalBase::has_value(), Permuted(), TensorInfo::SetQuantizationDim(), TensorInfo::SetShape(), and OptionalReferenceSwitch< IsReference, T >::value().

+
117 {
118  armnn::TensorInfo outInfo(info);
119  outInfo.SetShape(Permuted(info.GetShape(), mappings));
120 
121  // If TensorInfo has Per-Axis Quantization then it also has a QuantizationDim which needs to
122  // be permuted according to the mapping
123  if (info.GetQuantizationDim().has_value())
124  {
125  outInfo.SetQuantizationDim(mappings[info.GetQuantizationDim().value()]);
126  }
127 
128  return outInfo;
129 }
const TensorShape & GetShape() const
Definition: Tensor.hpp:191
+ +
Optional< unsigned int > GetQuantizationDim() const
Definition: Tensor.cpp:494
+ +
bool has_value() const noexcept
Definition: Optional.hpp:53
+
armnn::TensorShape Permuted(const armnn::TensorShape &srcShape, const armnn::PermutationVector &mappings)
Definition: Permute.cpp:98
+
+
+
+ +

◆ ProcessConcatInputTensorInfo()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void ProcessConcatInputTensorInfo (armnn::TensorInfoinputTensorInfo,
armnn::OriginsDescriptorconcatDescriptor,
const unsigned int & concatAxis,
unsigned int inputIndex,
unsigned int & mergeDimOrigin 
)
+
+ +

Definition at line 19 of file ParserHelper.cpp.

+ +

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

+ +

Referenced by OnnxParserImpl::CreateNetworkFromString(), and TfLiteParserImpl::OutputShapeOfReshape().

+
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 }
const TensorShape & GetShape() const
Definition: Tensor.hpp:191
+
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
+ +
uint32_t GetNumDimensions() const
Get the number of dimensions.
+
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:195
+
Status SetViewOriginCoord(uint32_t view, uint32_t coord, uint32_t value)
Set the view origin coordinates.
+
+
+
+ +

◆ QuantizedVector() [1/3]

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
std::vector<T> armnnUtils::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 }
+
+
+ +

◆ QuantizedVector() [2/3]

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
std::vector<T> armnnUtils::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 }
+
+
+ +

◆ QuantizedVector() [3/3]

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
std::vector<T> armnnUtils::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 }
+
+
+ +

◆ ReduceDims() [1/2]

+ +
+
+ + + + + + + + + + + + + + + + + + +
TensorShape ReduceDims (const armnn::TensorShapetensorInfo,
unsigned int dimensions 
)
+
+ +

Definition at line 106 of file TensorUtils.cpp.

+ +

References TensorShape::GetNumDimensions().

+ +

Referenced by ReduceDims().

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

◆ ReduceDims() [2/2]

+ +
+
+ + + + + + + + + + + + + + + + + + +
TensorInfo ReduceDims (const armnn::TensorInfotensorInfo,
unsigned int dimensions 
)
+
+ +

Definition at line 132 of file TensorUtils.cpp.

+ +

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

+
133 {
134  TensorInfo strippedTensor(tensorInfo);
135  TensorShape strippedShape = ReduceDims(tensorInfo.GetShape(), dimensions);
136  strippedTensor.SetShape(strippedShape);
137  return strippedTensor;
138 }
const TensorShape & GetShape() const
Definition: Tensor.hpp:191
+ +
armnn::TensorShape ReduceDims(const armnn::TensorShape &tensorInfo, unsigned int dimensions)
+ +
+
+
+ +

◆ SelectiveDequantize()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
float armnnUtils::SelectiveDequantize (value,
float scale,
int32_t offset 
)
+
+ +

Definition at line 91 of file QuantizeHelper.hpp.

+ +

References SelectiveQuantizer< T, DoQuantize >::Dequantize().

+
92 {
93  return SelectiveQuantizer<T, armnn::IsQuantizedType<T>()>::Dequantize(value, scale, offset);
94 };
float Dequantize(QuantizedType value, float scale, int32_t offset)
Dequantize an 8-bit data type into a floating point data type.
Definition: TypesUtils.cpp:46
+
+
+
+ +

◆ SelectiveQuantize()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
T armnnUtils::SelectiveQuantize (float value,
float scale,
int32_t offset 
)
+
+ +

Definition at line 85 of file QuantizeHelper.hpp.

+ +

References SelectiveQuantizer< T, DoQuantize >::Quantize().

+
86 {
87  return SelectiveQuantizer<T, armnn::IsQuantizedType<T>()>::Quantize(value, scale, offset);
88 };
QuantizedType Quantize(float value, float scale, int32_t offset)
Quantize a floating point data type into an 8-bit data type.
Definition: TypesUtils.cpp:30
+
+
+
+ +

◆ 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
+ +

Definition at line 40 of file ModelAccuracyChecker.cpp.

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

◆ SqueezeDims()

+ +
+
+ + + + + + + + +
std::vector< unsigned int > SqueezeDims (const armnn::TensorShapetensorShape)
+
+ +

Definition at line 168 of file TensorUtils.cpp.

+ +

References TensorShape::GetNumDimensions().

+ +

Referenced by Layer::ValidateAndCopyShape().

+
169 {
170  std::vector<unsigned int> squeezedDims;
171 
172  for (unsigned int i = 0; i < tensorShape.GetNumDimensions(); ++i)
173  {
174  if (tensorShape[i] != 1)
175  {
176  squeezedDims.push_back(tensorShape[i]);
177  }
178  }
179  return squeezedDims;
180 }
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
Definition: Tensor.cpp:174
+
+
+
+ +

◆ 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 64 of file ModelAccuracyChecker.cpp.

+ +

References ARMNN_ASSERT.

+
65 {
66  ARMNN_ASSERT(!characterSet.empty());
67  const std::size_t firstFound = originalString.find_first_not_of(characterSet);
68  const std::size_t lastFound = originalString.find_last_not_of(characterSet);
69  // Return empty if the originalString is empty or the originalString contains only to-be-striped characters
70  if (firstFound == std::string::npos || lastFound == std::string::npos)
71  {
72  return "";
73  }
74  return originalString.substr(firstFound, lastFound + 1 - firstFound);
75 }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
+
+
+
+ +

◆ ToFloatArray() [1/2]

+ +
+
+ + + + + + + + + + + + + + + + + + +
std::unique_ptr< float[]> ToFloatArray (const std::vector< PrimitiveType > & data,
const armnn::TensorInfotensorInfo 
)
+
+ +

Definition at line 248 of file TensorUtils.cpp.

+ +

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

+ +

Referenced by TfLiteParserImpl::GetBuffer().

+
249 {
250  CheckSizes(data, tensorInfo);
251 
252  std::unique_ptr<float[]> returnBuffer(new float[tensorInfo.GetNumElements()]);
253 
254  if (tensorInfo.HasPerAxisQuantization())
255  {
256  unsigned int axis = tensorInfo.GetQuantizationDim().value();
257  auto axisDimensionality = tensorInfo.GetShape()[axis];
258  auto axisFactor = armnnUtils::GetNumElementsAfter(tensorInfo.GetShape(), axis);
259 
260  for (unsigned int i = 0; i < tensorInfo.GetNumElements(); ++i)
261  {
262  unsigned int axisIndex;
263 
264  if (i < axisFactor)
265  {
266  axisIndex = 0;
267  }
268  else
269  {
270  axisIndex = (i / axisFactor) % axisDimensionality;
271  }
272  returnBuffer[i] = Dequantize<PrimitiveType>(data[i],
273  tensorInfo.GetQuantizationScales()[axisIndex],
274  tensorInfo.GetQuantizationOffset());
275  }
276  }
277  else
278  {
279  for (unsigned int i = 0; i < tensorInfo.GetNumElements(); ++i)
280  {
281  returnBuffer[i] = Dequantize<PrimitiveType>(data[i],
282  tensorInfo.GetQuantizationScale(),
283  tensorInfo.GetQuantizationOffset());
284  }
285  }
286  return returnBuffer;
287 }
const TensorShape & GetShape() const
Definition: Tensor.hpp:191
+
bool HasPerAxisQuantization() const
Definition: Tensor.cpp:446
+
Optional< unsigned int > GetQuantizationDim() const
Definition: Tensor.cpp:494
+ +
std::vector< float > GetQuantizationScales() const
Definition: Tensor.cpp:451
+
int32_t GetQuantizationOffset() const
Definition: Tensor.cpp:478
+
float GetQuantizationScale() const
Definition: Tensor.cpp:461
+
void CheckSizes(const std::vector< PrimitiveType > &data, const armnn::TensorInfo &tensorInfo, unsigned int size=1)
+
unsigned int GetNumElementsAfter(const armnn::TensorShape &shape, unsigned int axis)
+
unsigned int GetNumElements() const
Definition: Tensor.hpp:196
+
+
+
+ +

◆ ToFloatArray() [2/2]

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

Definition at line 289 of file TensorUtils.cpp.

+ +

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

+
290 {
291  if (tensorInfo.GetDataType() == DataType::QAsymmS8 || tensorInfo.GetDataType() == DataType::QSymmS8)
292  {
293  CheckSizes(data, tensorInfo);
294  std::vector<int8_t> buffer(tensorInfo.GetNumElements());
295  ::memcpy(buffer.data(), data.data(), data.size());
296  return ToFloatArray<int8_t>(buffer, tensorInfo);
297  }
298  else if (tensorInfo.GetDataType() == DataType::QAsymmU8)
299  {
300  CheckSizes(data, tensorInfo);
301  return ToFloatArray<uint8_t>(data, tensorInfo);
302  }
303  else if (tensorInfo.GetDataType() == DataType::Signed32)
304  {
305  CheckSizes(data, tensorInfo, 4);
306  std::vector<int32_t> buffer(tensorInfo.GetNumElements());
307  ::memcpy(buffer.data(), data.data(), data.size());
308  return ToFloatArray<int32_t>(buffer, tensorInfo);
309  }
310  else if (tensorInfo.GetDataType() == DataType::Signed64)
311  {
312  CheckSizes(data, tensorInfo, 8);
313  std::vector<int64_t> buffer(tensorInfo.GetNumElements());
314  ::memcpy(buffer.data(), data.data(), data.size());
315  return ToFloatArray<int64_t>(buffer, tensorInfo);
316  }
318  fmt::format("Unsupported datatype {}. {}",
319  GetDataTypeName(tensorInfo.GetDataType()),
320  CHECK_LOCATION().AsString()));
321 }
constexpr const char * GetDataTypeName(DataType dataType)
Definition: TypesUtils.hpp:206
+
DataType GetDataType() const
Definition: Tensor.hpp:198
+ +
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
+
void CheckSizes(const std::vector< PrimitiveType > &data, const armnn::TensorInfo &tensorInfo, unsigned int size=1)
+
unsigned int GetNumElements() const
Definition: Tensor.hpp:196
+
+
+
+ +

◆ Transpose()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void Transpose (const armnn::TensorShapedstShape,
const armnn::PermutationVectormappings,
const void * src,
void * dst,
size_t dataTypeSize 
)
+
+ +

Definition at line 120 of file Transpose.cpp.

+ +

Referenced by TransposeLayer::TransposeLayer().

+
122 {
123  TransposeLoop(srcShape, mappings).Unroll(src, dst, dataTypeSize);
124 }
+
+
+ +

◆ TransposeTensorShape() [1/2]

+ +
+
+ + + + + + + + + + + + + + + + + + +
armnn::TensorShape TransposeTensorShape (const armnn::TensorShapesrcShape,
const armnn::PermutationVectormappings 
)
+
+ +

Definition at line 98 of file Transpose.cpp.

+ +

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

+ +

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

+
99 {
100  assert(srcShape.GetNumDimensions() == mappings.GetSize());
101 
102  const unsigned int numDims = mappings.GetSize();
103  unsigned int outDims[armnn::MaxNumOfTensorDimensions];
104 
105  for (unsigned int i = 0U; i < numDims; ++i)
106  {
107  outDims[i] = srcShape[mappings[i]];
108  }
109  armnn::TensorShape permutedShape(numDims, outDims);
110  return permutedShape;
111 }
+
SizeType GetSize() const
Definition: Types.hpp:338
+
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
Definition: Tensor.cpp:174
+
constexpr unsigned int MaxNumOfTensorDimensions
Definition: Types.hpp:31
+
+
+
+ +

◆ TransposeTensorShape() [2/2]

+ +
+
+ + + + + + + + + + + + + + + + + + +
armnn::TensorInfo TransposeTensorShape (const armnn::TensorInfoinfo,
const armnn::PermutationVectormappings 
)
+
+ +

Definition at line 113 of file Transpose.cpp.

+ +

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

+
114 {
115  armnn::TensorInfo outInfo(info);
116  outInfo.SetShape(TransposeTensorShape(info.GetShape(), mappings));
117  return outInfo;
118 }
const TensorShape & GetShape() const
Definition: Tensor.hpp:191
+ +
armnn::TensorShape TransposeTensorShape(const armnn::TensorShape &srcShape, const armnn::PermutationVector &mappings)
Definition: Transpose.cpp:98
+
+
+
+ +

◆ VerifyInt32()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
int32_t VerifyInt32 (const char * expr,
int64_t value,
const armnn::CheckLocationlocation 
)
+
+ +

Definition at line 52 of file VerificationHelpers.cpp.

+ +

References CheckLocation::AsString().

+
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 }
std::string AsString() const
Definition: Exceptions.hpp:29
+ +
+
+
+ +

◆ within_percentage_tolerance()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
bool armnnUtils::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.

+ +
+
+ +

◆ NHWCToArmNN

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

Definition at line 16 of file ParserHelper.cpp.

+ +
+
+
+
+ + + + -- cgit v1.2.1