blob: dbcb91aebeaae60ba8dc8d0b5273032f21f99a5d [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
telsoa014fcda012018-03-09 14:13:49 +000063enum class PoolingAlgorithm
64{
65 Max = 0,
66 Average = 1,
67 L2 = 2
68};
69
Teresa Charlina9075df2019-06-27 15:41:57 +010070enum class ResizeMethod
71{
72 Bilinear = 0,
73 NearestNeighbor = 1
74};
75
telsoa014fcda012018-03-09 14:13:49 +000076///
77/// The padding method modifies the output of pooling layers.
78/// In both supported methods, the values are ignored (they are
telsoa01c577f2c2018-08-31 09:22:23 +010079/// not even zeroes, which would make a difference for max pooling
telsoa014fcda012018-03-09 14:13:49 +000080/// a tensor with negative values). The difference between
telsoa01c577f2c2018-08-31 09:22:23 +010081/// IgnoreValue and Exclude is that the former counts the padding
telsoa014fcda012018-03-09 14:13:49 +000082/// fields in the divisor of Average and L2 pooling, while
83/// Exclude does not.
84///
85enum class PaddingMethod
86{
telsoa01c577f2c2018-08-31 09:22:23 +010087 /// The padding fields count, but are ignored
David Beckdcb751f2018-10-03 11:42:42 +010088 IgnoreValue = 0,
telsoa01c577f2c2018-08-31 09:22:23 +010089 /// The padding fields don't count and are ignored
David Beckdcb751f2018-10-03 11:42:42 +010090 Exclude = 1
telsoa014fcda012018-03-09 14:13:49 +000091};
92
93enum class NormalizationAlgorithmChannel
94{
95 Across = 0,
96 Within = 1
97};
98
99enum class NormalizationAlgorithmMethod
100{
David Beckdcb751f2018-10-03 11:42:42 +0100101 /// Krichevsky 2012: Local Brightness Normalization
102 LocalBrightness = 0,
103 /// Jarret 2009: Local Contrast Normalization
telsoa01c577f2c2018-08-31 09:22:23 +0100104 LocalContrast = 1
telsoa014fcda012018-03-09 14:13:49 +0000105};
106
107enum class OutputShapeRounding
108{
109 Floor = 0,
110 Ceiling = 1
111};
112
David Beck9efb57d2018-11-05 13:40:33 +0000113/// Each backend should implement an IBackend.
114class IBackend
115{
116protected:
117 IBackend() {}
118 virtual ~IBackend() {}
119
120public:
121 virtual const BackendId& GetId() const = 0;
122};
123
124using IBackendSharedPtr = std::shared_ptr<IBackend>;
125using IBackendUniquePtr = std::unique_ptr<IBackend, void(*)(IBackend* backend)>;
126
David Beckdcb751f2018-10-03 11:42:42 +0100127/// Device specific knowledge to be passed to the optimizer.
telsoa01c577f2c2018-08-31 09:22:23 +0100128class IDeviceSpec
telsoa014fcda012018-03-09 14:13:49 +0000129{
telsoa01c577f2c2018-08-31 09:22:23 +0100130protected:
Matteo Martincigh9c5d33a2019-02-07 17:52:41 +0000131 IDeviceSpec() {}
132 virtual ~IDeviceSpec() {}
Narumol Prangnawarat87106762019-05-03 15:54:39 +0100133public:
134 virtual const BackendIdSet& GetSupportedBackends() const = 0;
telsoa014fcda012018-03-09 14:13:49 +0000135};
136
137/// Type of identifiers for bindable layers (inputs, outputs).
138using LayerBindingId = int;
139
140class PermutationVector
141{
142public:
143 using ValueType = unsigned int;
144 using SizeType = unsigned int;
145 using ArrayType = std::array<ValueType, MaxNumOfTensorDimensions>;
146 using ConstIterator = typename ArrayType::const_iterator;
147
telsoa01c577f2c2018-08-31 09:22:23 +0100148 /// @param dimMappings - Indicates how to translate tensor elements from a given source into the target destination,
telsoa014fcda012018-03-09 14:13:49 +0000149 /// when source and target potentially have different memory layouts.
150 ///
telsoa01c577f2c2018-08-31 09:22:23 +0100151 /// 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 +0000152 /// which is to be passed as an input to ArmNN, each source dimension is mapped to the corresponding
153 /// ArmNN dimension. The Batch dimension remains the same (0 -> 0). The source Height dimension is mapped
154 /// to the location of the ArmNN Height dimension (1 -> 2). Similar arguments are made for the Width and
155 /// Channels (2 -> 3 and 3 -> 1). This will lead to @ref m_DimMappings pointing to the following array:
156 /// [ 0, 2, 3, 1 ].
157 ///
158 /// Note that the mapping should be reversed if considering the case of ArmNN 4-d outputs (Batch Element,
159 /// Channels, Height, Width) being written to a destination with the format mentioned above. We now have
160 /// 0 -> 0, 2 -> 1, 3 -> 2, 1 -> 3, which, when reordered, lead to the following @ref m_DimMappings contents:
161 /// [ 0, 3, 1, 2 ].
162 ///
163 PermutationVector(const ValueType *dimMappings, SizeType numDimMappings);
164
165 PermutationVector(std::initializer_list<ValueType> dimMappings);
166
167 ValueType operator[](SizeType i) const { return m_DimMappings.at(i); }
168
169 SizeType GetSize() const { return m_NumDimMappings; }
170
171 ConstIterator begin() const { return m_DimMappings.begin(); }
172 ConstIterator end() const { return m_DimMappings.end(); }
173
174 bool IsEqual(const PermutationVector& other) const
175 {
Matthew Jacksondba634f2019-08-15 15:14:18 +0100176 if (m_NumDimMappings != other.m_NumDimMappings) return false;
177 for (unsigned int i = 0; i < m_NumDimMappings; ++i)
178 {
179 if (m_DimMappings[i] != other.m_DimMappings[i]) return false;
180 }
181 return true;
telsoa014fcda012018-03-09 14:13:49 +0000182 }
183
184 bool IsInverse(const PermutationVector& other) const
185 {
186 bool isInverse = (GetSize() == other.GetSize());
187 for (SizeType i = 0; isInverse && (i < GetSize()); ++i)
188 {
189 isInverse = (m_DimMappings[other.m_DimMappings[i]] == i);
190 }
191 return isInverse;
192 }
193
194private:
195 ArrayType m_DimMappings;
196 /// Number of valid entries in @ref m_DimMappings
197 SizeType m_NumDimMappings;
198};
199
telsoa01c577f2c2018-08-31 09:22:23 +0100200/// Define LayerGuid type.
surmeh01bceff2f2018-03-29 16:29:27 +0100201using LayerGuid = unsigned int;
202
Nattapat Chaimanowong6e948202019-03-22 14:01:46 +0000203class ITensorHandle;
204
Nattapat Chaimanowong317cae52019-03-28 10:29:12 +0000205/// Define the type of callback for the Debug layer to call
206/// @param guid - guid of layer connected to the input of the Debug layer
207/// @param slotIndex - index of the output slot connected to the input of the Debug layer
208/// @param tensorHandle - TensorHandle for the input tensor to the Debug layer
209using DebugCallbackFunction = std::function<void(LayerGuid guid, unsigned int slotIndex, ITensorHandle* tensorHandle)>;
Nattapat Chaimanowong6e948202019-03-22 14:01:46 +0000210
David Beck9df2d952018-10-10 15:11:44 +0100211} // namespace armnn