blob: 9fcc0447a3eb2b5e4d7205ce22f639ee34c585d6 [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 "WorkloadDataFwd.hpp"
8
David Beck0dbe0ee2018-09-24 15:59:27 +01009#include <armnn/Types.hpp>
10#include <armnn/Tensor.hpp>
11#include <armnn/Descriptors.hpp>
12#include <armnn/Exceptions.hpp>
13
14#include <InternalTypes.hpp>
15#include <backends/OutputHandler.hpp>
16
telsoa014fcda012018-03-09 14:13:49 +000017#include "CpuTensorHandleFwd.hpp"
18
19namespace armnn
20{
21
telsoa01c577f2c2018-08-31 09:22:23 +010022//A helper function that returns the bias data type required for given input data type.
telsoa014fcda012018-03-09 14:13:49 +000023DataType GetBiasDataType(DataType inputDataType);
24
25struct WorkloadInfo;
26
27struct QueueDescriptor
28{
29 std::vector<ITensorHandle*> m_Inputs;
30 std::vector<ITensorHandle*> m_Outputs;
31
32 void ValidateInputsOutputs(const std::string& descName,
33 unsigned int numExpectedIn, unsigned int numExpectedOut) const;
34
35
36protected:
37 ~QueueDescriptor() = default;
38 QueueDescriptor() = default;
39 QueueDescriptor(QueueDescriptor const&) = default;
40 QueueDescriptor& operator=(QueueDescriptor const&) = default;
41};
42
telsoa01c577f2c2018-08-31 09:22:23 +010043// Base class for queue descriptors which contain parameters.
telsoa014fcda012018-03-09 14:13:49 +000044template <typename LayerDescriptor>
45struct QueueDescriptorWithParameters : public QueueDescriptor
46{
47 LayerDescriptor m_Parameters;
48
49protected:
50 ~QueueDescriptorWithParameters() = default;
51 QueueDescriptorWithParameters() = default;
52 QueueDescriptorWithParameters(QueueDescriptorWithParameters const&) = default;
53 QueueDescriptorWithParameters& operator=(QueueDescriptorWithParameters const&) = default;
54};
55
56struct MemCopyQueueDescriptor : QueueDescriptor
57{
58 void Validate(const WorkloadInfo& workloadInfo) const;
59};
60
61using InputQueueDescriptor = MemCopyQueueDescriptor;
62using OutputQueueDescriptor = MemCopyQueueDescriptor;
63
telsoa01c577f2c2018-08-31 09:22:23 +010064// Softmax layer workload data.
telsoa014fcda012018-03-09 14:13:49 +000065struct SoftmaxQueueDescriptor : QueueDescriptorWithParameters<SoftmaxDescriptor>
66{
67 void Validate(const WorkloadInfo& workloadInfo) const;
68};
69
telsoa01c577f2c2018-08-31 09:22:23 +010070// Splitter layer workload data.
telsoa014fcda012018-03-09 14:13:49 +000071struct SplitterQueueDescriptor : QueueDescriptorWithParameters<ViewsDescriptor>
72{
73 struct ViewOrigin
74 {
75 ViewOrigin() {}
76 ViewOrigin(std::vector<unsigned int> const& origin) : m_Origin(origin) {}
77
telsoa01c577f2c2018-08-31 09:22:23 +010078 //View origin (size of the vector is the same as number of dimensions of the view).
telsoa014fcda012018-03-09 14:13:49 +000079 std::vector<unsigned int> m_Origin;
80 };
81
telsoa01c577f2c2018-08-31 09:22:23 +010082 //View defines a tensor that will be carved from the input tensor.
83 //View origins are stored here, the extents are defined by sizes of the output tensors.
telsoa014fcda012018-03-09 14:13:49 +000084 std::vector<ViewOrigin> m_ViewOrigins;
85
86 void Validate(const WorkloadInfo& workloadInfo) const;
87};
88
telsoa01c577f2c2018-08-31 09:22:23 +010089// Merger layer workload data.
telsoa014fcda012018-03-09 14:13:49 +000090struct MergerQueueDescriptor : QueueDescriptorWithParameters<OriginsDescriptor>
91{
92 struct ViewOrigin
93 {
94 ViewOrigin() {}
95 ViewOrigin(const std::vector<unsigned int>& origin) : m_Origin(origin) {}
96
telsoa01c577f2c2018-08-31 09:22:23 +010097 //View origin (size of the vector is the same as number of dimensions of the view).
telsoa014fcda012018-03-09 14:13:49 +000098 std::vector<unsigned int> m_Origin;
99 };
100
telsoa01c577f2c2018-08-31 09:22:23 +0100101 //View defines a sub-area of the output tensor that will be filled with the corresponding input tensor.
102 //View origins are stored here, the extents are defined by sizes of the input tensors.
telsoa014fcda012018-03-09 14:13:49 +0000103 std::vector<ViewOrigin> m_ViewOrigins;
104
105 void Validate(const WorkloadInfo& workloadInfo) const;
106};
107
telsoa01c577f2c2018-08-31 09:22:23 +0100108// Activation layer workload data.
telsoa014fcda012018-03-09 14:13:49 +0000109struct ActivationQueueDescriptor : QueueDescriptorWithParameters<ActivationDescriptor>
110{
111 void Validate(const WorkloadInfo& workloadInfo) const;
112};
113
telsoa01c577f2c2018-08-31 09:22:23 +0100114// Fully connected layer workload data.
telsoa014fcda012018-03-09 14:13:49 +0000115struct FullyConnectedQueueDescriptor : QueueDescriptorWithParameters<FullyConnectedDescriptor>
116{
117 FullyConnectedQueueDescriptor()
118 : m_Weight(nullptr)
119 , m_Bias(nullptr)
120 {
121 }
122
123 const ConstCpuTensorHandle* m_Weight;
124 const ConstCpuTensorHandle* m_Bias;
125
126 void Validate(const WorkloadInfo& workloadInfo) const;
127};
128
telsoa01c577f2c2018-08-31 09:22:23 +0100129// Permute layer workload data.
telsoa014fcda012018-03-09 14:13:49 +0000130struct PermuteQueueDescriptor : QueueDescriptorWithParameters<PermuteDescriptor>
131{
132 void Validate(const WorkloadInfo& workloadInfo) const;
133};
134
telsoa01c577f2c2018-08-31 09:22:23 +0100135// Pooling 2D layer workload data.
telsoa014fcda012018-03-09 14:13:49 +0000136struct Pooling2dQueueDescriptor : QueueDescriptorWithParameters<Pooling2dDescriptor>
137{
138 void Validate(const WorkloadInfo& workloadInfo) const;
139};
140
telsoa01c577f2c2018-08-31 09:22:23 +0100141// Convolution 2D layer workload data.
telsoa014fcda012018-03-09 14:13:49 +0000142struct Convolution2dQueueDescriptor : QueueDescriptorWithParameters<Convolution2dDescriptor>
143{
144 Convolution2dQueueDescriptor()
145 : m_Weight(nullptr)
146 , m_Bias(nullptr)
Francis Murtagh351d13d2018-09-24 15:01:18 +0100147 , m_DataLayout(DataLayout::NCHW)
telsoa014fcda012018-03-09 14:13:49 +0000148 {
149 }
150
151 const ConstCpuTensorHandle* m_Weight;
152 const ConstCpuTensorHandle* m_Bias;
Francis Murtagh351d13d2018-09-24 15:01:18 +0100153 DataLayout m_DataLayout;
telsoa014fcda012018-03-09 14:13:49 +0000154
155 void Validate(const WorkloadInfo& workloadInfo) const;
156};
157
telsoa01c577f2c2018-08-31 09:22:23 +0100158// Depthwise Convolution 2D layer workload data.
telsoa014fcda012018-03-09 14:13:49 +0000159struct DepthwiseConvolution2dQueueDescriptor : QueueDescriptorWithParameters<DepthwiseConvolution2dDescriptor>
160{
161 DepthwiseConvolution2dQueueDescriptor()
162 : m_Weight(nullptr)
163 , m_Bias(nullptr)
Nikhil Raja05c2102018-09-25 16:16:13 +0100164 , m_DataLayout(DataLayout::NCHW)
telsoa014fcda012018-03-09 14:13:49 +0000165 {
166 }
167
168 const ConstCpuTensorHandle* m_Weight;
169 const ConstCpuTensorHandle* m_Bias;
Nikhil Raja05c2102018-09-25 16:16:13 +0100170 DataLayout m_DataLayout;
telsoa014fcda012018-03-09 14:13:49 +0000171
172 void Validate(const WorkloadInfo& workloadInfo) const;
173};
174
telsoa01c577f2c2018-08-31 09:22:23 +0100175// Normalization layer workload data.
telsoa014fcda012018-03-09 14:13:49 +0000176struct NormalizationQueueDescriptor : QueueDescriptorWithParameters<NormalizationDescriptor>
177{
178 void Validate(const WorkloadInfo& workloadInfo) const;
179};
180
telsoa01c577f2c2018-08-31 09:22:23 +0100181// Add layer workload data.
telsoa014fcda012018-03-09 14:13:49 +0000182struct AdditionQueueDescriptor : QueueDescriptor
183{
184 void Validate(const WorkloadInfo& workloadInfo) const;
185};
186
telsoa01c577f2c2018-08-31 09:22:23 +0100187// Multiplication layer workload data.
telsoa014fcda012018-03-09 14:13:49 +0000188struct MultiplicationQueueDescriptor : QueueDescriptor
189{
190 void Validate(const WorkloadInfo& workloadInfo) const;
191};
192
Francis Murtaghe7a86a42018-08-29 12:42:10 +0100193// Division layer workload data.
194struct DivisionQueueDescriptor : QueueDescriptor
195{
196 void Validate(const WorkloadInfo& workloadInfo) const;
197};
198
David Beckc2044fe2018-09-05 15:00:38 +0100199// Subtraction layer workload data.
200struct SubtractionQueueDescriptor : QueueDescriptor
201{
202 void Validate(const WorkloadInfo& workloadInfo) const;
203};
204
narpra01a6bf9122018-09-10 09:50:09 +0100205// Mean layer workload data.
narpra0132b90462018-09-13 11:07:48 +0100206struct MeanQueueDescriptor : QueueDescriptorWithParameters<MeanDescriptor>
narpra01a6bf9122018-09-10 09:50:09 +0100207{
208 void Validate(const WorkloadInfo& workloadInfo) const;
209};
210
jimfly012c9322a2018-09-19 10:59:49 +0100211// Pad layer workload data
212struct PadQueueDescriptor : QueueDescriptorWithParameters<PadDescriptor>
213{
214 void Validate(const WorkloadInfo& workloadInfo) const;
215};
216
telsoa01c577f2c2018-08-31 09:22:23 +0100217// Batch norm layer workload data.
telsoa014fcda012018-03-09 14:13:49 +0000218struct BatchNormalizationQueueDescriptor : QueueDescriptorWithParameters<BatchNormalizationDescriptor>
219{
220 BatchNormalizationQueueDescriptor()
221 : m_Mean(nullptr)
222 , m_Variance(nullptr)
223 , m_Beta(nullptr)
224 , m_Gamma(nullptr)
225 {
226 }
227
228 const ConstCpuTensorHandle* m_Mean;
229 const ConstCpuTensorHandle* m_Variance;
230 const ConstCpuTensorHandle* m_Beta;
231 const ConstCpuTensorHandle* m_Gamma;
232
233 void Validate(const WorkloadInfo& workloadInfo) const;
234};
235
236struct ResizeBilinearQueueDescriptor : QueueDescriptorWithParameters<ResizeBilinearDescriptor>
237{
238 void Validate(const WorkloadInfo& workloadInfo) const;
239};
240
241struct FakeQuantizationQueueDescriptor : QueueDescriptorWithParameters<FakeQuantizationDescriptor>
242{
243 FakeQuantizationQueueDescriptor()
244 : m_Min(nullptr)
245 , m_Max(nullptr)
246 {
247 }
248
249 const ConstCpuTensorHandle* m_Min;
250 const ConstCpuTensorHandle* m_Max;
251
252 void Validate(const WorkloadInfo& workloadInfo) const;
253};
254
Matteo Martincighbcd3c852018-09-28 14:14:12 +0100255struct L2NormalizationQueueDescriptor : QueueDescriptorWithParameters<L2NormalizationDescriptor>
telsoa014fcda012018-03-09 14:13:49 +0000256{
257 void Validate(const WorkloadInfo& workloadInfo) const;
258};
259
260struct ConstantQueueDescriptor : QueueDescriptor
261{
262 ConstantQueueDescriptor()
263 : m_LayerOutput(nullptr)
264 {
265 }
266
267 const ConstCpuTensorHandle* m_LayerOutput;
268
269 void Validate(const WorkloadInfo& workloadInfo) const;
270};
271
272struct ReshapeQueueDescriptor : QueueDescriptorWithParameters<ReshapeDescriptor>
273{
274 void Validate(const WorkloadInfo& workloadInfo) const;
275};
276
277struct FloorQueueDescriptor : QueueDescriptor
278{
279 void Validate(const WorkloadInfo& workloadInfo) const;
280};
281
telsoa01c577f2c2018-08-31 09:22:23 +0100282struct LstmQueueDescriptor : QueueDescriptorWithParameters<LstmDescriptor>
283{
284 LstmQueueDescriptor()
285 : m_InputToInputWeights(nullptr)
286 , m_InputToForgetWeights(nullptr)
287 , m_InputToCellWeights(nullptr)
288 , m_InputToOutputWeights(nullptr)
289 , m_RecurrentToInputWeights(nullptr)
290 , m_RecurrentToForgetWeights(nullptr)
291 , m_RecurrentToCellWeights(nullptr)
292 , m_RecurrentToOutputWeights(nullptr)
293 , m_CellToInputWeights(nullptr)
294 , m_CellToForgetWeights(nullptr)
295 , m_CellToOutputWeights(nullptr)
296 , m_InputGateBias(nullptr)
297 , m_ForgetGateBias(nullptr)
298 , m_CellBias(nullptr)
299 , m_OutputGateBias(nullptr)
300 , m_ProjectionWeights(nullptr)
301 , m_ProjectionBias(nullptr)
302 {
303 }
304
305 const ConstCpuTensorHandle* m_InputToInputWeights;
306 const ConstCpuTensorHandle* m_InputToForgetWeights;
307 const ConstCpuTensorHandle* m_InputToCellWeights;
308 const ConstCpuTensorHandle* m_InputToOutputWeights;
309 const ConstCpuTensorHandle* m_RecurrentToInputWeights;
310 const ConstCpuTensorHandle* m_RecurrentToForgetWeights;
311 const ConstCpuTensorHandle* m_RecurrentToCellWeights;
312 const ConstCpuTensorHandle* m_RecurrentToOutputWeights;
313 const ConstCpuTensorHandle* m_CellToInputWeights;
314 const ConstCpuTensorHandle* m_CellToForgetWeights;
315 const ConstCpuTensorHandle* m_CellToOutputWeights;
316 const ConstCpuTensorHandle* m_InputGateBias;
317 const ConstCpuTensorHandle* m_ForgetGateBias;
318 const ConstCpuTensorHandle* m_CellBias;
319 const ConstCpuTensorHandle* m_OutputGateBias;
320 const ConstCpuTensorHandle* m_ProjectionWeights;
321 const ConstCpuTensorHandle* m_ProjectionBias;
322
323 void Validate(const WorkloadInfo& workloadInfo) const;
324};
325
326struct ConvertFp16ToFp32QueueDescriptor : QueueDescriptor
327{
328 void Validate(const WorkloadInfo& workloadInfo) const;
329};
330
331struct ConvertFp32ToFp16QueueDescriptor : QueueDescriptor
332{
333 void Validate(const WorkloadInfo& workloadInfo) const;
334};
335
telsoa014fcda012018-03-09 14:13:49 +0000336} //namespace armnn