2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
11 #include "BackendId.hpp"
12 #include "Exceptions.hpp"
17 constexpr unsigned int MaxNumOfTensorDimensions = 5U;
19 // The lowest performance data capture interval we support is 10 miliseconds.
20 constexpr unsigned int LOWEST_CAPTURE_PERIOD = 10000u;
22 /// @enum Status enumeration
23 /// @var Status::Successful
24 /// @var Status::Failure
39 QuantizedSymm8PerAxis = 6
48 enum class ActivationFunction
54 BoundedReLu = 4, ///< min(a, max(b, input))
62 enum class ArgMinMaxFunction
68 enum class ComparisonOperation
78 enum class PoolingAlgorithm
85 enum class ResizeMethod
92 /// The padding method modifies the output of pooling layers.
93 /// In both supported methods, the values are ignored (they are
94 /// not even zeroes, which would make a difference for max pooling
95 /// a tensor with negative values). The difference between
96 /// IgnoreValue and Exclude is that the former counts the padding
97 /// fields in the divisor of Average and L2 pooling, while
100 enum class PaddingMethod
102 /// The padding fields count, but are ignored
104 /// The padding fields don't count and are ignored
108 enum class NormalizationAlgorithmChannel
114 enum class NormalizationAlgorithmMethod
116 /// Krichevsky 2012: Local Brightness Normalization
118 /// Jarret 2009: Local Contrast Normalization
122 enum class OutputShapeRounding
128 /// Each backend should implement an IBackend.
133 virtual ~IBackend() {}
136 virtual const BackendId& GetId() const = 0;
139 using IBackendSharedPtr = std::shared_ptr<IBackend>;
140 using IBackendUniquePtr = std::unique_ptr<IBackend, void(*)(IBackend* backend)>;
142 /// Device specific knowledge to be passed to the optimizer.
147 virtual ~IDeviceSpec() {}
149 virtual const BackendIdSet& GetSupportedBackends() const = 0;
152 /// Type of identifiers for bindable layers (inputs, outputs).
153 using LayerBindingId = int;
155 class PermutationVector
158 using ValueType = unsigned int;
159 using SizeType = unsigned int;
160 using ArrayType = std::array<ValueType, MaxNumOfTensorDimensions>;
161 using ConstIterator = typename ArrayType::const_iterator;
163 /// @param dimMappings - Indicates how to translate tensor elements from a given source into the target destination,
164 /// when source and target potentially have different memory layouts.
166 /// E.g. For a 4-d tensor laid out in a memory with the format (Batch Element, Height, Width, Channels),
167 /// which is to be passed as an input to ArmNN, each source dimension is mapped to the corresponding
168 /// ArmNN dimension. The Batch dimension remains the same (0 -> 0). The source Height dimension is mapped
169 /// to the location of the ArmNN Height dimension (1 -> 2). Similar arguments are made for the Width and
170 /// Channels (2 -> 3 and 3 -> 1). This will lead to @ref m_DimMappings pointing to the following array:
173 /// Note that the mapping should be reversed if considering the case of ArmNN 4-d outputs (Batch Element,
174 /// Channels, Height, Width) being written to a destination with the format mentioned above. We now have
175 /// 0 -> 0, 2 -> 1, 3 -> 2, 1 -> 3, which, when reordered, lead to the following @ref m_DimMappings contents:
178 PermutationVector(const ValueType *dimMappings, SizeType numDimMappings);
180 PermutationVector(std::initializer_list<ValueType> dimMappings);
182 ValueType operator[](SizeType i) const { return m_DimMappings.at(i); }
184 SizeType GetSize() const { return m_NumDimMappings; }
186 ConstIterator begin() const { return m_DimMappings.begin(); }
187 ConstIterator end() const { return m_DimMappings.end(); }
189 bool IsEqual(const PermutationVector& other) const
191 if (m_NumDimMappings != other.m_NumDimMappings) return false;
192 for (unsigned int i = 0; i < m_NumDimMappings; ++i)
194 if (m_DimMappings[i] != other.m_DimMappings[i]) return false;
199 bool IsInverse(const PermutationVector& other) const
201 bool isInverse = (GetSize() == other.GetSize());
202 for (SizeType i = 0; isInverse && (i < GetSize()); ++i)
204 isInverse = (m_DimMappings[other.m_DimMappings[i]] == i);
210 ArrayType m_DimMappings;
211 /// Number of valid entries in @ref m_DimMappings
212 SizeType m_NumDimMappings;
215 namespace profiling { class ProfilingGuid; }
217 /// Define LayerGuid type.
218 using LayerGuid = profiling::ProfilingGuid;
222 /// Define the type of callback for the Debug layer to call
223 /// @param guid - guid of layer connected to the input of the Debug layer
224 /// @param slotIndex - index of the output slot connected to the input of the Debug layer
225 /// @param tensorHandle - TensorHandle for the input tensor to the Debug layer
226 using DebugCallbackFunction = std::function<void(LayerGuid guid, unsigned int slotIndex, ITensorHandle* tensorHandle)>;
235 ProfilingGuid(uint64_t guid) : m_Guid(guid) {}
237 operator uint64_t() const { return m_Guid; }
239 bool operator==(const ProfilingGuid& other) const
241 return m_Guid == other.m_Guid;
244 bool operator!=(const ProfilingGuid& other) const
246 return m_Guid != other.m_Guid;
249 bool operator<(const ProfilingGuid& other) const
251 return m_Guid < other.m_Guid;
254 bool operator<=(const ProfilingGuid& other) const
256 return m_Guid <= other.m_Guid;
259 bool operator>(const ProfilingGuid& other) const
261 return m_Guid > other.m_Guid;
264 bool operator>=(const ProfilingGuid& other) const
266 return m_Guid >= other.m_Guid;
273 /// Strongly typed guids to distinguish between those generated at runtime, and those that are statically defined.
274 struct ProfilingDynamicGuid : public ProfilingGuid
276 using ProfilingGuid::ProfilingGuid;
279 struct ProfilingStaticGuid : public ProfilingGuid
281 using ProfilingGuid::ProfilingGuid;
284 } // namespace profiling
291 // make ProfilingGuid hashable
293 struct hash<armnn::profiling::ProfilingGuid>
295 std::size_t operator()(armnn::profiling::ProfilingGuid const& guid) const noexcept
297 return hash<uint64_t>()(uint64_t(guid));
301 // make ProfilingDynamicGuid hashable
303 struct hash<armnn::profiling::ProfilingDynamicGuid>
305 std::size_t operator()(armnn::profiling::ProfilingDynamicGuid const& guid) const noexcept
307 return hash<uint64_t>()(uint64_t(guid));
311 // make ProfilingStaticGuid hashable
313 struct hash<armnn::profiling::ProfilingStaticGuid>
315 std::size_t operator()(armnn::profiling::ProfilingStaticGuid const& guid) const noexcept
317 return hash<uint64_t>()(uint64_t(guid));