ArmNN  NotReleased
Types.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
7 #include <array>
8 #include <functional>
9 #include <memory>
10 #include <stdint.h>
11 #include "BackendId.hpp"
12 #include "Exceptions.hpp"
13 #include "Deprecated.hpp"
14 
15 namespace armnn
16 {
17 
18 constexpr unsigned int MaxNumOfTensorDimensions = 5U;
19 
20 // The lowest performance data capture interval we support is 10 miliseconds.
21 constexpr unsigned int LOWEST_CAPTURE_PERIOD = 10000u;
22 
26 enum class Status
27 {
28  Success = 0,
29  Failure = 1
30 };
31 
32 enum class DataType
33 {
34  Float16 = 0,
35  Float32 = 1,
36  QAsymmU8 = 2,
37  Signed32 = 3,
38  Boolean = 4,
39  QSymmS16 = 5,
40  QuantizedSymm8PerAxis ARMNN_DEPRECATED_ENUM_MSG("Per Axis property inferred by number of scales in TensorInfo") = 6,
41  QSymmS8 = 7,
42  QAsymmS8 = 8,
43 
44  QuantisedAsymm8 ARMNN_DEPRECATED_ENUM_MSG("Use DataType::QAsymmU8 instead.") = QAsymmU8,
45  QuantisedSymm16 ARMNN_DEPRECATED_ENUM_MSG("Use DataType::QSymmS16 instead.") = QSymmS16
46 };
47 
48 enum class DataLayout
49 {
50  NCHW = 1,
51  NHWC = 2
52 };
53 
55 {
56  Sigmoid = 0,
57  TanH = 1,
58  Linear = 2,
59  ReLu = 3,
60  BoundedReLu = 4,
61  SoftReLu = 5,
62  LeakyReLu = 6,
63  Abs = 7,
64  Sqrt = 8,
65  Square = 9
66 };
67 
69 {
70  Min = 0,
71  Max = 1
72 };
73 
75 {
76  Equal = 0,
77  Greater = 1,
78  GreaterOrEqual = 2,
79  Less = 3,
80  LessOrEqual = 4,
81  NotEqual = 5
82 };
83 
84 enum class UnaryOperation
85 {
86  Abs = 0,
87  Exp = 1,
88  Sqrt = 2,
89  Rsqrt = 3,
90  Neg = 4
91 };
92 
93 enum class PoolingAlgorithm
94 {
95  Max = 0,
96  Average = 1,
97  L2 = 2
98 };
99 
100 enum class ResizeMethod
101 {
102  Bilinear = 0,
103  NearestNeighbor = 1
104 };
105 
115 enum class PaddingMethod
116 {
118  IgnoreValue = 0,
120  Exclude = 1
121 };
122 
124 {
125  Across = 0,
126  Within = 1
127 };
128 
130 {
132  LocalBrightness = 0,
134  LocalContrast = 1
135 };
136 
138 {
139  Floor = 0,
140  Ceiling = 1
141 };
142 
144 class IBackend
145 {
146 protected:
147  IBackend() {}
148  virtual ~IBackend() {}
149 
150 public:
151  virtual const BackendId& GetId() const = 0;
152 };
153 
154 using IBackendSharedPtr = std::shared_ptr<IBackend>;
155 using IBackendUniquePtr = std::unique_ptr<IBackend, void(*)(IBackend* backend)>;
156 
159 {
160 protected:
162  virtual ~IDeviceSpec() {}
163 public:
164  virtual const BackendIdSet& GetSupportedBackends() const = 0;
165 };
166 
168 using LayerBindingId = int;
169 
171 {
172 public:
173  using ValueType = unsigned int;
174  using SizeType = unsigned int;
175  using ArrayType = std::array<ValueType, MaxNumOfTensorDimensions>;
176  using ConstIterator = typename ArrayType::const_iterator;
177 
193  PermutationVector(const ValueType *dimMappings, SizeType numDimMappings);
194 
195  PermutationVector(std::initializer_list<ValueType> dimMappings);
196 
197  ValueType operator[](SizeType i) const { return m_DimMappings.at(i); }
198 
199  SizeType GetSize() const { return m_NumDimMappings; }
200 
201  ConstIterator begin() const { return m_DimMappings.begin(); }
202  ConstIterator end() const { return m_DimMappings.end(); }
203 
204  bool IsEqual(const PermutationVector& other) const
205  {
206  if (m_NumDimMappings != other.m_NumDimMappings) return false;
207  for (unsigned int i = 0; i < m_NumDimMappings; ++i)
208  {
209  if (m_DimMappings[i] != other.m_DimMappings[i]) return false;
210  }
211  return true;
212  }
213 
214  bool IsInverse(const PermutationVector& other) const
215  {
216  bool isInverse = (GetSize() == other.GetSize());
217  for (SizeType i = 0; isInverse && (i < GetSize()); ++i)
218  {
219  isInverse = (m_DimMappings[other.m_DimMappings[i]] == i);
220  }
221  return isInverse;
222  }
223 
224 private:
225  ArrayType m_DimMappings;
227  SizeType m_NumDimMappings;
228 };
229 
230 namespace profiling { class ProfilingGuid; }
231 
234 
235 class ITensorHandle;
236 
241 using DebugCallbackFunction = std::function<void(LayerGuid guid, unsigned int slotIndex, ITensorHandle* tensorHandle)>;
242 
243 
244 namespace profiling
245 {
246 
247 static constexpr uint64_t MIN_STATIC_GUID = 1llu << 63;
248 
250 {
251 public:
252  ProfilingGuid(uint64_t guid) : m_Guid(guid) {}
253 
254  operator uint64_t() const { return m_Guid; }
255 
256  bool operator==(const ProfilingGuid& other) const
257  {
258  return m_Guid == other.m_Guid;
259  }
260 
261  bool operator!=(const ProfilingGuid& other) const
262  {
263  return m_Guid != other.m_Guid;
264  }
265 
266  bool operator<(const ProfilingGuid& other) const
267  {
268  return m_Guid < other.m_Guid;
269  }
270 
271  bool operator<=(const ProfilingGuid& other) const
272  {
273  return m_Guid <= other.m_Guid;
274  }
275 
276  bool operator>(const ProfilingGuid& other) const
277  {
278  return m_Guid > other.m_Guid;
279  }
280 
281  bool operator>=(const ProfilingGuid& other) const
282  {
283  return m_Guid >= other.m_Guid;
284  }
285 
286 protected:
287  uint64_t m_Guid;
288 };
289 
292 {
294 };
295 
297 {
299 };
300 
301 } // namespace profiling
302 
303 } // namespace armnn
304 
305 
306 namespace std
307 {
308 // make ProfilingGuid hashable
309 template<>
310 struct hash<armnn::profiling::ProfilingGuid>
311 {
312  std::size_t operator()(armnn::profiling::ProfilingGuid const& guid) const noexcept
313  {
314  return hash<uint64_t>()(uint64_t(guid));
315  }
316 };
317 
318 // make ProfilingDynamicGuid hashable
319 template<>
320 struct hash<armnn::profiling::ProfilingDynamicGuid>
321 {
322  std::size_t operator()(armnn::profiling::ProfilingDynamicGuid const& guid) const noexcept
323  {
324  return hash<uint64_t>()(uint64_t(guid));
325  }
326 };
327 
328 // make ProfilingStaticGuid hashable
329 template<>
330 struct hash<armnn::profiling::ProfilingStaticGuid>
331 {
332  std::size_t operator()(armnn::profiling::ProfilingStaticGuid const& guid) const noexcept
333  {
334  return hash<uint64_t>()(uint64_t(guid));
335  }
336 };
337 } // namespace std
PaddingMethod
Definition: Types.hpp:115
std::array< ValueType, MaxNumOfTensorDimensions > ArrayType
Definition: Types.hpp:175
std::size_t operator()(armnn::profiling::ProfilingStaticGuid const &guid) const noexcept
Definition: Types.hpp:332
bool IsEqual(const PermutationVector &other) const
Definition: Types.hpp:204
Status
Definition: Types.hpp:26
Each backend should implement an IBackend.
Definition: Types.hpp:144
ResizeMethod
Definition: Types.hpp:100
ValueType operator[](SizeType i) const
Definition: Types.hpp:197
bool operator>(const ProfilingGuid &other) const
Definition: Types.hpp:276
bool IsInverse(const PermutationVector &other) const
Definition: Types.hpp:214
ConstIterator begin() const
Definition: Types.hpp:201
ConstIterator end() const
Definition: Types.hpp:202
ActivationFunction
Definition: Types.hpp:54
OutputShapeRounding
Definition: Types.hpp:137
unsigned int SizeType
Definition: Types.hpp:174
#define ARMNN_DEPRECATED_ENUM_MSG(message)
Definition: Deprecated.hpp:50
std::size_t operator()(armnn::profiling::ProfilingDynamicGuid const &guid) const noexcept
Definition: Types.hpp:322
constexpr unsigned int LOWEST_CAPTURE_PERIOD
Definition: Types.hpp:21
Krichevsky 2012: Local Brightness Normalization.
Jarret 2009: Local Contrast Normalization.
std::function< void(LayerGuid guid, unsigned int slotIndex, ITensorHandle *tensorHandle)> DebugCallbackFunction
Definition: Types.hpp:241
std::shared_ptr< IBackend > IBackendSharedPtr
Definition: Types.hpp:154
ComparisonOperation
Definition: Types.hpp:74
PoolingAlgorithm
Definition: Types.hpp:93
The padding fields count, but are ignored.
The padding fields don&#39;t count and are ignored.
std::size_t operator()(armnn::profiling::ProfilingGuid const &guid) const noexcept
Definition: Types.hpp:312
virtual ~IDeviceSpec()
Definition: Types.hpp:162
virtual ~IBackend()
Definition: Types.hpp:148
NormalizationAlgorithmMethod
Definition: Types.hpp:129
typename ArrayType::const_iterator ConstIterator
Definition: Types.hpp:176
SizeType GetSize() const
Definition: Types.hpp:199
ProfilingGuid(uint64_t guid)
Definition: Types.hpp:252
UnaryOperation
Definition: Types.hpp:84
constexpr unsigned int MaxNumOfTensorDimensions
Definition: Types.hpp:18
DataLayout
Definition: Types.hpp:48
ArgMinMaxFunction
Definition: Types.hpp:68
DataType
Definition: Types.hpp:32
bool operator==(const ProfilingGuid &other) const
Definition: Types.hpp:256
std::unordered_set< BackendId > BackendIdSet
Definition: BackendId.hpp:191
NormalizationAlgorithmChannel
Definition: Types.hpp:123
bool operator<=(const ProfilingGuid &other) const
Definition: Types.hpp:271
Strongly typed guids to distinguish between those generated at runtime, and those that are statically...
Definition: Types.hpp:291
bool operator>=(const ProfilingGuid &other) const
Definition: Types.hpp:281
std::unique_ptr< IBackend, void(*)(IBackend *backend)> IBackendUniquePtr
Definition: Types.hpp:155
unsigned int ValueType
Definition: Types.hpp:173
bool operator!=(const ProfilingGuid &other) const
Definition: Types.hpp:261
bool operator<(const ProfilingGuid &other) const
Definition: Types.hpp:266
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
Definition: Types.hpp:168
Device specific knowledge to be passed to the optimizer.
Definition: Types.hpp:158