2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
10 #include "BackendId.hpp"
11 #include "Exceptions.hpp"
16 constexpr unsigned int MaxNumOfTensorDimensions = 5U;
18 /// @enum Status enumeration
19 /// @var Status::Successful
20 /// @var Status::Failure
43 enum class ActivationFunction
49 BoundedReLu = 4, ///< min(a, max(b, input))
57 enum class ArgMinMaxFunction
63 enum class ComparisonOperation
73 enum class PoolingAlgorithm
80 enum class ResizeMethod
87 /// The padding method modifies the output of pooling layers.
88 /// In both supported methods, the values are ignored (they are
89 /// not even zeroes, which would make a difference for max pooling
90 /// a tensor with negative values). The difference between
91 /// IgnoreValue and Exclude is that the former counts the padding
92 /// fields in the divisor of Average and L2 pooling, while
95 enum class PaddingMethod
97 /// The padding fields count, but are ignored
99 /// The padding fields don't count and are ignored
103 enum class NormalizationAlgorithmChannel
109 enum class NormalizationAlgorithmMethod
111 /// Krichevsky 2012: Local Brightness Normalization
113 /// Jarret 2009: Local Contrast Normalization
117 enum class OutputShapeRounding
123 /// Each backend should implement an IBackend.
128 virtual ~IBackend() {}
131 virtual const BackendId& GetId() const = 0;
134 using IBackendSharedPtr = std::shared_ptr<IBackend>;
135 using IBackendUniquePtr = std::unique_ptr<IBackend, void(*)(IBackend* backend)>;
137 /// Device specific knowledge to be passed to the optimizer.
142 virtual ~IDeviceSpec() {}
144 virtual const BackendIdSet& GetSupportedBackends() const = 0;
147 /// Type of identifiers for bindable layers (inputs, outputs).
148 using LayerBindingId = int;
150 class PermutationVector
153 using ValueType = unsigned int;
154 using SizeType = unsigned int;
155 using ArrayType = std::array<ValueType, MaxNumOfTensorDimensions>;
156 using ConstIterator = typename ArrayType::const_iterator;
158 /// @param dimMappings - Indicates how to translate tensor elements from a given source into the target destination,
159 /// when source and target potentially have different memory layouts.
161 /// E.g. For a 4-d tensor laid out in a memory with the format (Batch Element, Height, Width, Channels),
162 /// which is to be passed as an input to ArmNN, each source dimension is mapped to the corresponding
163 /// ArmNN dimension. The Batch dimension remains the same (0 -> 0). The source Height dimension is mapped
164 /// to the location of the ArmNN Height dimension (1 -> 2). Similar arguments are made for the Width and
165 /// Channels (2 -> 3 and 3 -> 1). This will lead to @ref m_DimMappings pointing to the following array:
168 /// Note that the mapping should be reversed if considering the case of ArmNN 4-d outputs (Batch Element,
169 /// Channels, Height, Width) being written to a destination with the format mentioned above. We now have
170 /// 0 -> 0, 2 -> 1, 3 -> 2, 1 -> 3, which, when reordered, lead to the following @ref m_DimMappings contents:
173 PermutationVector(const ValueType *dimMappings, SizeType numDimMappings);
175 PermutationVector(std::initializer_list<ValueType> dimMappings);
177 ValueType operator[](SizeType i) const { return m_DimMappings.at(i); }
179 SizeType GetSize() const { return m_NumDimMappings; }
181 ConstIterator begin() const { return m_DimMappings.begin(); }
182 ConstIterator end() const { return m_DimMappings.end(); }
184 bool IsEqual(const PermutationVector& other) const
186 if (m_NumDimMappings != other.m_NumDimMappings) return false;
187 for (unsigned int i = 0; i < m_NumDimMappings; ++i)
189 if (m_DimMappings[i] != other.m_DimMappings[i]) return false;
194 bool IsInverse(const PermutationVector& other) const
196 bool isInverse = (GetSize() == other.GetSize());
197 for (SizeType i = 0; isInverse && (i < GetSize()); ++i)
199 isInverse = (m_DimMappings[other.m_DimMappings[i]] == i);
205 ArrayType m_DimMappings;
206 /// Number of valid entries in @ref m_DimMappings
207 SizeType m_NumDimMappings;
210 /// Define LayerGuid type.
211 using LayerGuid = unsigned int;
215 /// Define the type of callback for the Debug layer to call
216 /// @param guid - guid of layer connected to the input of the Debug layer
217 /// @param slotIndex - index of the output slot connected to the input of the Debug layer
218 /// @param tensorHandle - TensorHandle for the input tensor to the Debug layer
219 using DebugCallbackFunction = std::function<void(LayerGuid guid, unsigned int slotIndex, ITensorHandle* tensorHandle)>;