blob: 16a148c9c27e6afb544133a5c95f325746c06dc4 [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>
Matthew Bentham47bfac42019-03-25 12:30:56 +00008#include <functional>
David Beckdcb751f2018-10-03 11:42:42 +01009#include <memory>
Jim Flynn44db7c32019-03-22 15:58:39 +000010#include "BackendId.hpp"
11#include "Exceptions.hpp"
telsoa014fcda012018-03-09 14:13:49 +000012
13namespace armnn
14{
15
Matthew Jacksondba634f2019-08-15 15:14:18 +010016constexpr unsigned int MaxNumOfTensorDimensions = 5U;
telsoa014fcda012018-03-09 14:13:49 +000017
18/// @enum Status enumeration
19/// @var Status::Successful
20/// @var Status::Failure
21enum class Status
22{
23 Success = 0,
24 Failure = 1
25};
26
27enum class DataType
28{
telsoa01c577f2c2018-08-31 09:22:23 +010029 Float16 = 0,
ruoyan0120e984f2018-12-12 18:11:25 +000030 Float32 = 1,
telsoa01c577f2c2018-08-31 09:22:23 +010031 QuantisedAsymm8 = 2,
ruoyan0120e984f2018-12-12 18:11:25 +000032 Signed32 = 3,
Nattapat Chaimanowongcd5ac232019-03-19 12:26:36 +000033 Boolean = 4,
34 QuantisedSymm16 = 5
telsoa014fcda012018-03-09 14:13:49 +000035};
36
Derek Lamberti0cff1632018-09-18 16:02:25 +010037enum class DataLayout
38{
39 NCHW = 1,
40 NHWC = 2
41};
42
telsoa014fcda012018-03-09 14:13:49 +000043enum class ActivationFunction
44{
45 Sigmoid = 0,
46 TanH = 1,
47 Linear = 2,
48 ReLu = 3,
telsoa01c577f2c2018-08-31 09:22:23 +010049 BoundedReLu = 4, ///< min(a, max(b, input))
telsoa014fcda012018-03-09 14:13:49 +000050 SoftReLu = 5,
51 LeakyReLu = 6,
52 Abs = 7,
53 Sqrt = 8,
54 Square = 9
55};
56
Narumol Prangnawarat8d001d42019-09-09 15:01:18 +010057enum class ArgMinMaxFunction
58{
59 Min = 0,
60 Max = 1
61};
62
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +010063enum class ComparisonOperation
64{
65 Equal = 0,
66 Greater = 1,
67 GreaterOrEqual = 2,
68 Less = 3,
69 LessOrEqual = 4,
70 NotEqual = 5
71};
72
telsoa014fcda012018-03-09 14:13:49 +000073enum class PoolingAlgorithm
74{
75 Max = 0,
76 Average = 1,
77 L2 = 2
78};
79
Teresa Charlina9075df2019-06-27 15:41:57 +010080enum class ResizeMethod
81{
82 Bilinear = 0,
83 NearestNeighbor = 1
84};
85
telsoa014fcda012018-03-09 14:13:49 +000086///
87/// The padding method modifies the output of pooling layers.
88/// In both supported methods, the values are ignored (they are
telsoa01c577f2c2018-08-31 09:22:23 +010089/// not even zeroes, which would make a difference for max pooling
telsoa014fcda012018-03-09 14:13:49 +000090/// a tensor with negative values). The difference between
telsoa01c577f2c2018-08-31 09:22:23 +010091/// IgnoreValue and Exclude is that the former counts the padding
telsoa014fcda012018-03-09 14:13:49 +000092/// fields in the divisor of Average and L2 pooling, while
93/// Exclude does not.
94///
95enum class PaddingMethod
96{
telsoa01c577f2c2018-08-31 09:22:23 +010097 /// The padding fields count, but are ignored
David Beckdcb751f2018-10-03 11:42:42 +010098 IgnoreValue = 0,
telsoa01c577f2c2018-08-31 09:22:23 +010099 /// The padding fields don't count and are ignored
David Beckdcb751f2018-10-03 11:42:42 +0100100 Exclude = 1
telsoa014fcda012018-03-09 14:13:49 +0000101};
102
103enum class NormalizationAlgorithmChannel
104{
105 Across = 0,
106 Within = 1
107};
108
109enum class NormalizationAlgorithmMethod
110{
David Beckdcb751f2018-10-03 11:42:42 +0100111 /// Krichevsky 2012: Local Brightness Normalization
112 LocalBrightness = 0,
113 /// Jarret 2009: Local Contrast Normalization
telsoa01c577f2c2018-08-31 09:22:23 +0100114 LocalContrast = 1
telsoa014fcda012018-03-09 14:13:49 +0000115};
116
117enum class OutputShapeRounding
118{
119 Floor = 0,
120 Ceiling = 1
121};
122
David Beck9efb57d2018-11-05 13:40:33 +0000123/// Each backend should implement an IBackend.
124class IBackend
125{
126protected:
127 IBackend() {}
128 virtual ~IBackend() {}
129
130public:
131 virtual const BackendId& GetId() const = 0;
132};
133
134using IBackendSharedPtr = std::shared_ptr<IBackend>;
135using IBackendUniquePtr = std::unique_ptr<IBackend, void(*)(IBackend* backend)>;
136
David Beckdcb751f2018-10-03 11:42:42 +0100137/// Device specific knowledge to be passed to the optimizer.
telsoa01c577f2c2018-08-31 09:22:23 +0100138class IDeviceSpec
telsoa014fcda012018-03-09 14:13:49 +0000139{
telsoa01c577f2c2018-08-31 09:22:23 +0100140protected:
Matteo Martincigh9c5d33a2019-02-07 17:52:41 +0000141 IDeviceSpec() {}
142 virtual ~IDeviceSpec() {}
Narumol Prangnawarat87106762019-05-03 15:54:39 +0100143public:
144 virtual const BackendIdSet& GetSupportedBackends() const = 0;
telsoa014fcda012018-03-09 14:13:49 +0000145};
146
147/// Type of identifiers for bindable layers (inputs, outputs).
148using LayerBindingId = int;
149
150class PermutationVector
151{
152public:
153 using ValueType = unsigned int;
154 using SizeType = unsigned int;
155 using ArrayType = std::array<ValueType, MaxNumOfTensorDimensions>;
156 using ConstIterator = typename ArrayType::const_iterator;
157
telsoa01c577f2c2018-08-31 09:22:23 +0100158 /// @param dimMappings - Indicates how to translate tensor elements from a given source into the target destination,
telsoa014fcda012018-03-09 14:13:49 +0000159 /// when source and target potentially have different memory layouts.
160 ///
telsoa01c577f2c2018-08-31 09:22:23 +0100161 /// 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 +0000162 /// 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:
166 /// [ 0, 2, 3, 1 ].
167 ///
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:
171 /// [ 0, 3, 1, 2 ].
172 ///
173 PermutationVector(const ValueType *dimMappings, SizeType numDimMappings);
174
175 PermutationVector(std::initializer_list<ValueType> dimMappings);
176
177 ValueType operator[](SizeType i) const { return m_DimMappings.at(i); }
178
179 SizeType GetSize() const { return m_NumDimMappings; }
180
181 ConstIterator begin() const { return m_DimMappings.begin(); }
182 ConstIterator end() const { return m_DimMappings.end(); }
183
184 bool IsEqual(const PermutationVector& other) const
185 {
Matthew Jacksondba634f2019-08-15 15:14:18 +0100186 if (m_NumDimMappings != other.m_NumDimMappings) return false;
187 for (unsigned int i = 0; i < m_NumDimMappings; ++i)
188 {
189 if (m_DimMappings[i] != other.m_DimMappings[i]) return false;
190 }
191 return true;
telsoa014fcda012018-03-09 14:13:49 +0000192 }
193
194 bool IsInverse(const PermutationVector& other) const
195 {
196 bool isInverse = (GetSize() == other.GetSize());
197 for (SizeType i = 0; isInverse && (i < GetSize()); ++i)
198 {
199 isInverse = (m_DimMappings[other.m_DimMappings[i]] == i);
200 }
201 return isInverse;
202 }
203
204private:
205 ArrayType m_DimMappings;
206 /// Number of valid entries in @ref m_DimMappings
207 SizeType m_NumDimMappings;
208};
209
telsoa01c577f2c2018-08-31 09:22:23 +0100210/// Define LayerGuid type.
surmeh01bceff2f2018-03-29 16:29:27 +0100211using LayerGuid = unsigned int;
212
Nattapat Chaimanowong6e948202019-03-22 14:01:46 +0000213class ITensorHandle;
214
Nattapat Chaimanowong317cae52019-03-28 10:29:12 +0000215/// 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
219using DebugCallbackFunction = std::function<void(LayerGuid guid, unsigned int slotIndex, ITensorHandle* tensorHandle)>;
Nattapat Chaimanowong6e948202019-03-22 14:01:46 +0000220
David Beck9df2d952018-10-10 15:11:44 +0100221} // namespace armnn