blob: d0a0174ecd82c68c9173522e95a0554f977e20e8 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5#pragma once
6
7#include <array>
David Beckdcb751f2018-10-03 11:42:42 +01008#include <memory>
telsoa014fcda012018-03-09 14:13:49 +00009
10namespace armnn
11{
12
13constexpr unsigned int MaxNumOfTensorDimensions = 4U;
14
15/// @enum Status enumeration
16/// @var Status::Successful
17/// @var Status::Failure
18enum class Status
19{
20 Success = 0,
21 Failure = 1
22};
23
24enum class DataType
25{
telsoa01c577f2c2018-08-31 09:22:23 +010026 Float16 = 0,
27 Float32 = 1,
28 QuantisedAsymm8 = 2,
29 Signed32 = 3
telsoa014fcda012018-03-09 14:13:49 +000030};
31
Derek Lamberti0cff1632018-09-18 16:02:25 +010032enum class DataLayout
33{
34 NCHW = 1,
35 NHWC = 2
36};
37
telsoa014fcda012018-03-09 14:13:49 +000038enum class ActivationFunction
39{
40 Sigmoid = 0,
41 TanH = 1,
42 Linear = 2,
43 ReLu = 3,
telsoa01c577f2c2018-08-31 09:22:23 +010044 BoundedReLu = 4, ///< min(a, max(b, input))
telsoa014fcda012018-03-09 14:13:49 +000045 SoftReLu = 5,
46 LeakyReLu = 6,
47 Abs = 7,
48 Sqrt = 8,
49 Square = 9
50};
51
52enum class PoolingAlgorithm
53{
54 Max = 0,
55 Average = 1,
56 L2 = 2
57};
58
59///
60/// The padding method modifies the output of pooling layers.
61/// In both supported methods, the values are ignored (they are
telsoa01c577f2c2018-08-31 09:22:23 +010062/// not even zeroes, which would make a difference for max pooling
telsoa014fcda012018-03-09 14:13:49 +000063/// a tensor with negative values). The difference between
telsoa01c577f2c2018-08-31 09:22:23 +010064/// IgnoreValue and Exclude is that the former counts the padding
telsoa014fcda012018-03-09 14:13:49 +000065/// fields in the divisor of Average and L2 pooling, while
66/// Exclude does not.
67///
68enum class PaddingMethod
69{
telsoa01c577f2c2018-08-31 09:22:23 +010070 /// The padding fields count, but are ignored
David Beckdcb751f2018-10-03 11:42:42 +010071 IgnoreValue = 0,
telsoa01c577f2c2018-08-31 09:22:23 +010072 /// The padding fields don't count and are ignored
David Beckdcb751f2018-10-03 11:42:42 +010073 Exclude = 1
telsoa014fcda012018-03-09 14:13:49 +000074};
75
76enum class NormalizationAlgorithmChannel
77{
78 Across = 0,
79 Within = 1
80};
81
82enum class NormalizationAlgorithmMethod
83{
David Beckdcb751f2018-10-03 11:42:42 +010084 /// Krichevsky 2012: Local Brightness Normalization
85 LocalBrightness = 0,
86 /// Jarret 2009: Local Contrast Normalization
telsoa01c577f2c2018-08-31 09:22:23 +010087 LocalContrast = 1
telsoa014fcda012018-03-09 14:13:49 +000088};
89
90enum class OutputShapeRounding
91{
92 Floor = 0,
93 Ceiling = 1
94};
95
96enum class Compute
97{
telsoa01c577f2c2018-08-31 09:22:23 +010098 /// CPU Execution: Reference C++ kernels
David Beckdcb751f2018-10-03 11:42:42 +010099 CpuRef = 0,
telsoa01c577f2c2018-08-31 09:22:23 +0100100 /// CPU Execution: NEON: ArmCompute
David Beckdcb751f2018-10-03 11:42:42 +0100101 CpuAcc = 1,
telsoa01c577f2c2018-08-31 09:22:23 +0100102 /// GPU Execution: OpenCL: ArmCompute
David Beckdcb751f2018-10-03 11:42:42 +0100103 GpuAcc = 2,
telsoa014fcda012018-03-09 14:13:49 +0000104 Undefined = 5
105};
106
David Beckdcb751f2018-10-03 11:42:42 +0100107/// Each backend should implement an IBackend.
108class IBackend
109{
110protected:
111 IBackend() {}
112 virtual ~IBackend() {}
113
114public:
115 virtual const std::string& GetId() const = 0;
116};
117
118using IBackendPtr = std::shared_ptr<IBackend>;
119
120/// Device specific knowledge to be passed to the optimizer.
telsoa01c577f2c2018-08-31 09:22:23 +0100121class IDeviceSpec
telsoa014fcda012018-03-09 14:13:49 +0000122{
telsoa01c577f2c2018-08-31 09:22:23 +0100123protected:
124 IDeviceSpec() {};
125 virtual ~IDeviceSpec() {};
telsoa014fcda012018-03-09 14:13:49 +0000126};
127
128/// Type of identifiers for bindable layers (inputs, outputs).
129using LayerBindingId = int;
130
131class PermutationVector
132{
133public:
134 using ValueType = unsigned int;
135 using SizeType = unsigned int;
136 using ArrayType = std::array<ValueType, MaxNumOfTensorDimensions>;
137 using ConstIterator = typename ArrayType::const_iterator;
138
telsoa01c577f2c2018-08-31 09:22:23 +0100139 /// @param dimMappings - Indicates how to translate tensor elements from a given source into the target destination,
telsoa014fcda012018-03-09 14:13:49 +0000140 /// when source and target potentially have different memory layouts.
141 ///
telsoa01c577f2c2018-08-31 09:22:23 +0100142 /// E.g. For a 4-d tensor laid out in a memory with the format (Batch Element, Height, Width, Channels),
telsoa014fcda012018-03-09 14:13:49 +0000143 /// which is to be passed as an input to ArmNN, each source dimension is mapped to the corresponding
144 /// ArmNN dimension. The Batch dimension remains the same (0 -> 0). The source Height dimension is mapped
145 /// to the location of the ArmNN Height dimension (1 -> 2). Similar arguments are made for the Width and
146 /// Channels (2 -> 3 and 3 -> 1). This will lead to @ref m_DimMappings pointing to the following array:
147 /// [ 0, 2, 3, 1 ].
148 ///
149 /// Note that the mapping should be reversed if considering the case of ArmNN 4-d outputs (Batch Element,
150 /// Channels, Height, Width) being written to a destination with the format mentioned above. We now have
151 /// 0 -> 0, 2 -> 1, 3 -> 2, 1 -> 3, which, when reordered, lead to the following @ref m_DimMappings contents:
152 /// [ 0, 3, 1, 2 ].
153 ///
154 PermutationVector(const ValueType *dimMappings, SizeType numDimMappings);
155
156 PermutationVector(std::initializer_list<ValueType> dimMappings);
157
158 ValueType operator[](SizeType i) const { return m_DimMappings.at(i); }
159
160 SizeType GetSize() const { return m_NumDimMappings; }
161
162 ConstIterator begin() const { return m_DimMappings.begin(); }
163 ConstIterator end() const { return m_DimMappings.end(); }
164
165 bool IsEqual(const PermutationVector& other) const
166 {
167 return std::equal(begin(), end(), other.begin(), other.end());
168 }
169
170 bool IsInverse(const PermutationVector& other) const
171 {
172 bool isInverse = (GetSize() == other.GetSize());
173 for (SizeType i = 0; isInverse && (i < GetSize()); ++i)
174 {
175 isInverse = (m_DimMappings[other.m_DimMappings[i]] == i);
176 }
177 return isInverse;
178 }
179
180private:
181 ArrayType m_DimMappings;
182 /// Number of valid entries in @ref m_DimMappings
183 SizeType m_NumDimMappings;
184};
185
telsoa01c577f2c2018-08-31 09:22:23 +0100186/// Define LayerGuid type.
surmeh01bceff2f2018-03-29 16:29:27 +0100187using LayerGuid = unsigned int;
188
telsoa014fcda012018-03-09 14:13:49 +0000189}