ArmNN
 25.11
Loading...
Searching...
No Matches
Types.hpp
Go to the documentation of this file.
1//
2// Copyright © 2018-2024 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5#pragma once
6
7#include <array>
8#include <functional>
9#include <stdint.h>
10#include <chrono>
11#include "BackendId.hpp"
12#include "Exceptions.hpp"
13#include "Deprecated.hpp"
14
15namespace arm
16{
17namespace pipe
18{
19
20class ProfilingGuid;
21
22} // namespace arm
23} // namespace pipe
24
25/// Define LayerGuid type.
26using LayerGuid = arm::pipe::ProfilingGuid;
27
28namespace armnn
29{
30
31constexpr unsigned int MaxNumOfTensorDimensions = 5U;
32
33/// The lowest performance data capture interval we support is 10 miliseconds.
34constexpr unsigned int LOWEST_CAPTURE_PERIOD = 10000u;
35
36/// Variable to control expire rate of priority queue
37constexpr unsigned int EXPIRE_RATE = 3U;
38
39/// @enum Status enumeration
40/// @var Status::Successful
41/// @var Status::Failure
42enum class Status
43{
46};
47
48enum class DataType
49{
60};
61
62enum class DataLayout
63{
64 NCHW = 1,
65 NHWC = 2,
66 NDHWC = 3,
68};
69
70/// Define the behaviour of the internal profiler when outputting network details
77
78
80{
81 Low = 0,
82 Medium = 1,
83 High = 2
84};
85
87{
89 TanH = 1,
90 Linear = 2,
91 ReLu = 3,
92 BoundedReLu = 4, ///< min(a, max(b, input)) ReLu1 & ReLu6.
95 Abs = 7,
96 Sqrt = 8,
97 Square = 9,
98 Elu = 10,
100 Gelu = 12
101};
102
104{
105 Min = 0,
106 Max = 1
107};
108
118
124
126{
127 Abs = 0,
128 Exp = 1,
129 Sqrt = 2,
130 Rsqrt = 3,
131 Neg = 4,
133 Log = 6,
134 Sin = 7,
136};
137
139{
140 Add = 0,
141 Div = 1,
144 Mul = 4,
145 Sub = 5,
147 Power = 7,
149};
150
152{
153 Max = 0,
155 L2 = 2
156};
157
159{
160 Sum = 0,
161 Max = 1,
162 Mean = 2,
163 Min = 3,
165};
166
167enum class ResizeMethod
168{
171};
172
174{
178};
179
180///
181/// The padding method modifies the output of pooling layers.
182/// In both supported methods, the values are ignored (they are
183/// not even zeroes, which would make a difference for max pooling
184/// a tensor with negative values). The difference between
185/// IgnoreValue and Exclude is that the former counts the padding
186/// fields in the divisor of Average and L2 pooling, while
187/// Exclude does not.
188///
190{
191 /// The padding fields count, but are ignored
193 /// The padding fields don't count and are ignored
195};
196
197///
198/// The padding mode controls whether the padding should be filled with constant values (Constant), or
199/// reflect the input, either including the border values (Symmetric) or not (Reflect).
200///
201enum class PaddingMode
202{
206};
207
213
215{
216 /// Krichevsky 2012: Local Brightness Normalization
218 /// Jarret 2009: Local Contrast Normalization
220};
221
223{
224 Floor = 0,
226};
227
228///
229/// The ShapeInferenceMethod modify how the output shapes are treated.
230/// When ValidateOnly is selected, the output shapes are inferred from the input parameters of the layer
231/// and any mismatch is reported.
232/// When InferAndValidate is selected 2 actions are performed: (1)infer output shape from inputs and (2)validate the
233/// shapes as in ValidateOnly. This option has been added to work with tensors which rank or dimension sizes are not
234/// specified explicitly, however this information can be calculated from the inputs.
235///
237{
238 /// Validate all output shapes
240 /// Infer missing output shapes and validate all output shapes
242};
243
244/// Define the Memory Source to reduce copies
245enum class MemorySource : uint32_t
246{
252};
253
255{
256 // MemBlocks can be packed on the Y axis only, overlap allowed on X axis.
257 // In other words MemBlocks with overlapping lifetimes cannot use the same MemBin,
258 // equivalent to blob or pooling memory management.
260
261 // MemBlocks can be packed on either Y or X axis but cannot overlap on both.
262 // In other words MemBlocks with overlapping lifetimes can use the same MemBin,
263 // equivalent to offset or slab memory management.
265};
266
268{
270};
271
272/// Each backend should implement an IBackend.
274{
275protected:
277 virtual ~IBackend() {}
278
279public:
280 virtual const BackendId& GetId() const = 0;
281};
282
283using IBackendSharedPtr = std::shared_ptr<IBackend>;
284using IBackendUniquePtr = std::unique_ptr<IBackend, void(*)(IBackend* backend)>;
285
286/// BackendCapability class
287enum class BackendCapability : uint32_t
288{
289 /// Constant weights can be accessed through the descriptors,
290 /// On the other hand, non-const weights can be accessed through inputs.
292
293 /// False: Backends that can only be used if all layers in the graph are supported on that backend.
294 /// True: Backends that can be combined with other backends to run a graph.
296
297 // add new enum values here
298};
299
300/// Device specific knowledge to be passed to the optimizer.
302{
303protected:
305 virtual ~IDeviceSpec() {}
306public:
307 virtual const BackendIdSet& GetSupportedBackends() const = 0;
308};
309
310/// Type of identifiers for bindable layers (inputs, outputs).
311using LayerBindingId = int;
312using ImportedInputId = unsigned int;
313using ImportedOutputId = unsigned int;
314
315
317{
318public:
319 using ValueType = unsigned int;
320 using SizeType = unsigned int;
321 using ArrayType = std::array<ValueType, MaxNumOfTensorDimensions>;
322 using ConstIterator = typename ArrayType::const_iterator;
323
324 /// @param dimMappings - Indicates how to translate tensor elements from a given source into the target destination,
325 /// when source and target potentially have different memory layouts.
326 ///
327 /// E.g. For a 4-d tensor laid out in a memory with the format (Batch Element, Height, Width, Channels),
328 /// which is to be passed as an input to ArmNN, each source dimension is mapped to the corresponding
329 /// ArmNN dimension. The Batch dimension remains the same (0 -> 0). The source Height dimension is mapped
330 /// to the location of the ArmNN Height dimension (1 -> 2). Similar arguments are made for the Width and
331 /// Channels (2 -> 3 and 3 -> 1). This will lead to @ref m_DimMappings pointing to the following array:
332 /// [ 0, 2, 3, 1 ].
333 ///
334 /// Note that the mapping should be reversed if considering the case of ArmNN 4-d outputs (Batch Element,
335 /// Channels, Height, Width) being written to a destination with the format mentioned above. We now have
336 /// 0 -> 0, 2 -> 1, 3 -> 2, 1 -> 3, which, when reordered, lead to the following @ref m_DimMappings contents:
337 /// [ 0, 3, 1, 2 ].
338 ///
339 PermutationVector(const ValueType *dimMappings, SizeType numDimMappings);
340
341 PermutationVector(std::initializer_list<ValueType> dimMappings);
342
343 ///
344 /// Indexing method with out-of-bounds error checking for the m_DimMappings array.
345 /// @param i - integer value corresponding to index of m_DimMappings array to retrieve element from.
346 /// @return element at index i of m_DimMappings array.
347 /// @throws InvalidArgumentException when indexing out-of-bounds index of m_DimMappings array.
348 ///
350 {
351 if (i >= GetSize())
352 {
353 throw InvalidArgumentException("Invalid indexing of PermutationVector of size " + std::to_string(GetSize())
354 + " at location [" + std::to_string(i) + "].");
355 }
356 return m_DimMappings.at(i);
357 }
358
359 SizeType GetSize() const { return m_NumDimMappings; }
360
361 ConstIterator begin() const { return m_DimMappings.begin(); }
362 /**
363 *
364 * @return pointer one past the end of the number of mapping not the length of m_DimMappings.
365 */
366 ConstIterator end() const { return m_DimMappings.begin() + m_NumDimMappings; }
367
368 bool IsEqual(const PermutationVector& other) const
369 {
370 if (m_NumDimMappings != other.m_NumDimMappings) return false;
371 for (unsigned int i = 0; i < m_NumDimMappings; ++i)
372 {
373 if (m_DimMappings[i] != other.m_DimMappings[i]) return false;
374 }
375 return true;
376 }
377
378 bool IsInverse(const PermutationVector& other) const
379 {
380 bool isInverse = (GetSize() == other.GetSize());
381 for (SizeType i = 0; isInverse && (i < GetSize()); ++i)
382 {
383 isInverse = (m_DimMappings[other.m_DimMappings[i]] == i);
384 }
385 return isInverse;
386 }
387
388private:
389 ArrayType m_DimMappings;
390 /// Number of valid entries in @ref m_DimMappings
391 SizeType m_NumDimMappings;
392};
393
394class ITensorHandle;
395
396/// Define the type of callback for the Debug layer to call
397/// @param guid - guid of layer connected to the input of the Debug layer
398/// @param slotIndex - index of the output slot connected to the input of the Debug layer
399/// @param tensorHandle - TensorHandle for the input tensor to the Debug layer
400using DebugCallbackFunction = std::function<void(LayerGuid guid, unsigned int slotIndex, ITensorHandle* tensorHandle)>;
401
402/// Define a timer and associated inference ID for recording execution times
403using HighResolutionClock = std::chrono::high_resolution_clock::time_point;
404using InferenceTimingPair = std::pair<HighResolutionClock, HighResolutionClock>;
405
406
407/// This list uses X macro technique.
408/// See https://en.wikipedia.org/wiki/X_Macro for more info
409// New layers should be added at last position to minimize instability.
410#define LIST_OF_LAYER_TYPE \
411 X(Activation) \
412 X(Addition) \
413 X(ArgMinMax) \
414 X(BatchNormalization) \
415 X(BatchToSpaceNd) \
416 X(Comparison) \
417 X(Concat) \
418 X(Constant) \
419 X(ConvertFp16ToFp32) \
420 X(ConvertFp32ToFp16) \
421 X(Convolution2d) \
422 X(Debug) \
423 X(DepthToSpace) \
424 X(DepthwiseConvolution2d) \
425 X(Dequantize) \
426 X(DetectionPostProcess) \
427 X(Division) \
428 X(ElementwiseUnary) \
429 X(FakeQuantization) \
430 X(Fill) \
431 X(Floor) \
432 X(FullyConnected) \
433 X(Gather) \
434 X(Input) \
435 X(InstanceNormalization) \
436 X(L2Normalization) \
437 X(LogicalBinary) \
438 X(LogSoftmax) \
439 X(Lstm) \
440 X(QLstm) \
441 X(Map) \
442 X(Maximum) \
443 X(Mean) \
444 X(MemCopy) \
445 X(MemImport) \
446 X(Merge) \
447 X(Minimum) \
448 X(Multiplication) \
449 X(Normalization) \
450 X(Output) \
451 X(Pad) \
452 X(Permute) \
453 X(Pooling2d) \
454 X(PreCompiled) \
455 X(Prelu) \
456 X(Quantize) \
457 X(QuantizedLstm) \
458 X(Reshape) \
459 X(Rank) \
460 X(Resize) \
461 X(Reduce) \
462 X(Slice) \
463 X(Softmax) \
464 X(SpaceToBatchNd) \
465 X(SpaceToDepth) \
466 X(Splitter) \
467 X(Stack) \
468 X(StandIn) \
469 X(StridedSlice) \
470 X(Subtraction) \
471 X(Switch) \
472 X(Transpose) \
473 X(TransposeConvolution2d) \
474 X(Unmap) \
475 X(Cast) \
476 X(Shape) \
477 X(UnidirectionalSequenceLstm) \
478 X(ChannelShuffle) \
479 X(Convolution3d) \
480 X(Pooling3d) \
481 X(GatherNd) \
482 X(BatchMatMul) \
483 X(ElementwiseBinary) \
484 X(ReverseV2) \
485 X(Tile) \
486 X(Fused) \
487 X(BroadcastTo) \
488 X(ScatterNd) \
489// New layers should be added at last position to minimize instability.
490
491/// When adding a new layer, adapt also the LastLayer enum value in the
492/// enum class LayerType below
493enum class LayerType
494{
495#define X(name) name,
497#undef X
500};
501
503{
505 Add = 1,
506 Sub = 2,
507 Max = 3,
508 Min = 4,
509 Mul = 5
510};
511
512const char* GetLayerTypeAsCString(LayerType type);
513
514} // namespace armnn
#define LIST_OF_LAYER_TYPE
This list uses X macro technique.
Definition Types.hpp:410
arm::pipe::ProfilingGuid LayerGuid
Define LayerGuid type.
Definition Types.hpp:26
Each backend should implement an IBackend.
Definition Types.hpp:274
virtual const BackendId & GetId() const =0
virtual ~IBackend()
Definition Types.hpp:277
virtual const BackendIdSet & GetSupportedBackends() const =0
virtual ~IDeviceSpec()
Definition Types.hpp:305
typename ArrayType::const_iterator ConstIterator
Definition Types.hpp:322
unsigned int SizeType
Definition Types.hpp:320
PermutationVector(const ValueType *dimMappings, SizeType numDimMappings)
SizeType GetSize() const
Definition Types.hpp:359
ConstIterator end() const
Definition Types.hpp:366
ValueType operator[](SizeType i) const
Indexing method with out-of-bounds error checking for the m_DimMappings array.
Definition Types.hpp:349
unsigned int ValueType
Definition Types.hpp:319
bool IsEqual(const PermutationVector &other) const
Definition Types.hpp:368
bool IsInverse(const PermutationVector &other) const
Definition Types.hpp:378
std::array< ValueType, MaxNumOfTensorDimensions > ArrayType
Definition Types.hpp:321
ConstIterator begin() const
Definition Types.hpp:361
Copyright (c) 2021 ARM Limited and Contributors.
PaddingMode
The padding mode controls whether the padding should be filled with constant values (Constant),...
Definition Types.hpp:202
MemorySource
Define the Memory Source to reduce copies.
Definition Types.hpp:246
std::function< void(LayerGuid guid, unsigned int slotIndex, ITensorHandle *tensorHandle)> DebugCallbackFunction
Define the type of callback for the Debug layer to call.
Definition Types.hpp:400
std::unordered_set< BackendId > BackendIdSet
unsigned int ImportedInputId
Definition Types.hpp:312
UnaryOperation
Definition Types.hpp:126
void ScatterNd(const TensorInfo &inputInfo, const TensorInfo &indicesInfo, const TensorInfo &updatesInfo, Decoder< float > &input, Decoder< int > &indices, Decoder< float > &updates, Encoder< float > &output, ScatterNdDescriptor descriptor)
Definition ScatterNd.cpp:41
ComparisonOperation
Definition Types.hpp:110
LogicalBinaryOperation
Definition Types.hpp:120
PaddingMethod
The padding method modifies the output of pooling layers.
Definition Types.hpp:190
@ Exclude
The padding fields don't count and are ignored.
Definition Types.hpp:194
@ IgnoreValue
The padding fields count, but are ignored.
Definition Types.hpp:192
std::chrono::high_resolution_clock::time_point HighResolutionClock
Define a timer and associated inference ID for recording execution times.
Definition Types.hpp:403
std::pair< HighResolutionClock, HighResolutionClock > InferenceTimingPair
Definition Types.hpp:404
FusedKernelType
Definition Types.hpp:268
ActivationFunction
Definition Types.hpp:87
@ BoundedReLu
min(a, max(b, input)) ReLu1 & ReLu6.
Definition Types.hpp:92
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below.
Definition Types.hpp:494
std::unique_ptr< IBackend, void(*)(IBackend *backend)> IBackendUniquePtr
Definition Types.hpp:284
constexpr unsigned int LOWEST_CAPTURE_PERIOD
The lowest performance data capture interval we support is 10 miliseconds.
Definition Types.hpp:34
constexpr unsigned int EXPIRE_RATE
Variable to control expire rate of priority queue.
Definition Types.hpp:37
Status
enumeration
Definition Types.hpp:43
MemBlockStrategyType
Definition Types.hpp:255
ScatterNdFunction
Definition Types.hpp:503
float Activation(float in, ActivationFunction function, float a, float b)
Dimensionality
Definition Types.hpp:174
QosExecPriority
Definition Types.hpp:80
PoolingAlgorithm
Definition Types.hpp:152
ResizeMethod
Definition Types.hpp:168
BackendCapability
BackendCapability class.
Definition Types.hpp:288
@ NonConstWeights
Constant weights can be accessed through the descriptors, On the other hand, non-const weights can be...
Definition Types.hpp:291
@ AllOrNothing
False: Backends that can only be used if all layers in the graph are supported on that backend.
Definition Types.hpp:295
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
Definition Types.hpp:311
ReduceOperation
Definition Types.hpp:159
constexpr unsigned int MaxNumOfTensorDimensions
Definition Types.hpp:31
NormalizationAlgorithmChannel
Definition Types.hpp:209
BinaryOperation
Definition Types.hpp:139
unsigned int ImportedOutputId
Definition Types.hpp:313
DataLayout
Definition Types.hpp:63
NormalizationAlgorithmMethod
Definition Types.hpp:215
@ LocalContrast
Jarret 2009: Local Contrast Normalization.
Definition Types.hpp:219
@ LocalBrightness
Krichevsky 2012: Local Brightness Normalization.
Definition Types.hpp:217
DataType
Definition Types.hpp:49
const char * GetLayerTypeAsCString(LayerType type)
OutputShapeRounding
Definition Types.hpp:223
ShapeInferenceMethod
The ShapeInferenceMethod modify how the output shapes are treated.
Definition Types.hpp:237
@ InferAndValidate
Infer missing output shapes and validate all output shapes.
Definition Types.hpp:241
@ ValidateOnly
Validate all output shapes.
Definition Types.hpp:239
ProfilingDetailsMethod
Define the behaviour of the internal profiler when outputting network details.
Definition Types.hpp:72
std::shared_ptr< IBackend > IBackendSharedPtr
Definition Types.hpp:283
ArgMinMaxFunction
Definition Types.hpp:104