blob: 5fdcd9c57a0251c43da295bf6b9538ca28c1cb76 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
Teresa Charlin52664732020-06-29 16:27:03 +01002// Copyright © 2017 Arm Ltd and Contributors. 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
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +00007#include <Graph.hpp>
8
Jim Flynn68db06f2020-10-06 10:14:50 +01009#include <backendsCommon/MapWorkload.hpp>
Jim Flynn3a40ea52020-10-08 11:42:30 +010010#include <backendsCommon/UnmapWorkload.hpp>
Colm Donelan0c479742021-12-10 12:43:54 +000011#include <armnn/backends/WorkloadFactory.hpp>
telsoa014fcda012018-03-09 14:13:49 +000012
Jan Eilers8eb25602020-03-09 12:13:48 +000013#include <armnn/utility/IgnoreUnused.hpp>
telsoa014fcda012018-03-09 14:13:49 +000014
Sadik Armagan1625efc2021-06-10 18:24:34 +010015#include <doctest/doctest.h>
16
telsoa014fcda012018-03-09 14:13:49 +000017namespace
18{
19armnn::Graph dummyGraph;
20
telsoa01c577f2c2018-08-31 09:22:23 +010021// Make a dummy TensorInfo object.
telsoa014fcda012018-03-09 14:13:49 +000022template<armnn::DataType DataType>
23armnn::TensorInfo MakeDummyTensorInfo()
24{
Teresa Charlin33d58272020-01-28 12:24:34 +000025 return armnn::TensorInfo({2,2,2,2}, DataType, 1.0, 0);
telsoa014fcda012018-03-09 14:13:49 +000026}
27
28
29// Make a dummy WorkloadInfo using a dummy TensorInfo.
30template<armnn::DataType DataType>
31armnn::WorkloadInfo MakeDummyWorkloadInfo(unsigned int numInputs, unsigned int numOutputs)
32{
33 armnn::WorkloadInfo info;
James Conroyee18dc82019-07-17 11:27:46 +010034
telsoa014fcda012018-03-09 14:13:49 +000035 for (unsigned int i=0; i < numInputs; i++)
36 {
37 info.m_InputTensorInfos.push_back(MakeDummyTensorInfo<DataType>());
38 }
James Conroyee18dc82019-07-17 11:27:46 +010039
telsoa014fcda012018-03-09 14:13:49 +000040 for (unsigned int o=0; o < numOutputs; o++)
41 {
42 info.m_OutputTensorInfos.push_back(MakeDummyTensorInfo<DataType>());
43 }
James Conroyee18dc82019-07-17 11:27:46 +010044
telsoa014fcda012018-03-09 14:13:49 +000045 return info;
46}
47
telsoa01c577f2c2018-08-31 09:22:23 +010048// Template class to create a dummy layer (2 parameters).
telsoa014fcda012018-03-09 14:13:49 +000049template<typename LayerType, typename DescType = typename LayerType::DescriptorType>
50struct DummyLayer
51{
52 DummyLayer()
53 {
54 m_Layer = dummyGraph.AddLayer<LayerType>(DescType(), "");
55 }
James Conroyee18dc82019-07-17 11:27:46 +010056
telsoa014fcda012018-03-09 14:13:49 +000057 ~DummyLayer()
58 {
59 dummyGraph.EraseLayer(m_Layer);
60 }
James Conroyee18dc82019-07-17 11:27:46 +010061
telsoa014fcda012018-03-09 14:13:49 +000062 LayerType* m_Layer;
63};
64
telsoa01c577f2c2018-08-31 09:22:23 +010065// Template class to create a dummy layer (1 parameter).
telsoa014fcda012018-03-09 14:13:49 +000066template<typename LayerType>
67struct DummyLayer<LayerType, void>
68{
69 DummyLayer()
70 {
71 m_Layer = dummyGraph.AddLayer<LayerType>("");
72 }
James Conroyee18dc82019-07-17 11:27:46 +010073
telsoa014fcda012018-03-09 14:13:49 +000074 ~DummyLayer()
75 {
76 dummyGraph.EraseLayer(m_Layer);
77 }
James Conroyee18dc82019-07-17 11:27:46 +010078
telsoa014fcda012018-03-09 14:13:49 +000079 LayerType* m_Layer;
80};
81
82template<>
telsoa01c577f2c2018-08-31 09:22:23 +010083struct DummyLayer<armnn::BatchNormalizationLayer>
84{
85 DummyLayer()
86 {
87 m_Layer = dummyGraph.AddLayer<armnn::BatchNormalizationLayer>(armnn::BatchNormalizationDescriptor(), "");
James Conroy1f58f032021-04-27 17:13:27 +010088 m_Layer->m_Mean = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +010089 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +010090 m_Layer->m_Variance = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +010091 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +010092 m_Layer->m_Beta = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +010093 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +010094 m_Layer->m_Gamma = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +010095 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
96 }
James Conroyee18dc82019-07-17 11:27:46 +010097
telsoa01c577f2c2018-08-31 09:22:23 +010098 ~DummyLayer()
99 {
100 dummyGraph.EraseLayer(m_Layer);
101 }
telsoa01c577f2c2018-08-31 09:22:23 +0100102
James Conroyee18dc82019-07-17 11:27:46 +0100103 armnn::BatchNormalizationLayer* m_Layer;
telsoa01c577f2c2018-08-31 09:22:23 +0100104};
105
106template<>
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000107struct DummyLayer<armnn::BatchToSpaceNdLayer>
108{
109 DummyLayer()
110 {
111 m_Layer = dummyGraph.AddLayer<armnn::BatchToSpaceNdLayer>(armnn::BatchToSpaceNdDescriptor(), "");
112 }
James Conroyee18dc82019-07-17 11:27:46 +0100113
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000114 ~DummyLayer()
115 {
116 dummyGraph.EraseLayer(m_Layer);
117 }
James Conroyee18dc82019-07-17 11:27:46 +0100118
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000119 armnn::BatchToSpaceNdLayer* m_Layer;
120};
121
122template<>
telsoa014fcda012018-03-09 14:13:49 +0000123struct DummyLayer<armnn::ConstantLayer, void>
124{
125 DummyLayer()
126 {
telsoa01c577f2c2018-08-31 09:22:23 +0100127 m_Layer = dummyGraph.AddLayer<armnn::ConstantLayer>("");
telsoa014fcda012018-03-09 14:13:49 +0000128 }
James Conroyee18dc82019-07-17 11:27:46 +0100129
telsoa014fcda012018-03-09 14:13:49 +0000130 ~DummyLayer()
131 {
132 dummyGraph.EraseLayer(m_Layer);
133 }
James Conroyee18dc82019-07-17 11:27:46 +0100134
telsoa014fcda012018-03-09 14:13:49 +0000135 armnn::ConstantLayer* m_Layer;
136};
137
138template<>
139struct DummyLayer<armnn::InputLayer, armnn::LayerBindingId>
140{
141 DummyLayer()
142 {
143 m_Layer = dummyGraph.AddLayer<armnn::InputLayer>(armnn::LayerBindingId(), "");
telsoa014fcda012018-03-09 14:13:49 +0000144 }
James Conroyee18dc82019-07-17 11:27:46 +0100145
telsoa014fcda012018-03-09 14:13:49 +0000146 ~DummyLayer()
147 {
148 dummyGraph.EraseLayer(m_Layer);
149 }
James Conroyee18dc82019-07-17 11:27:46 +0100150
telsoa014fcda012018-03-09 14:13:49 +0000151 armnn::InputLayer* m_Layer;
152};
153
154template<>
Jim Flynne242f2d2019-05-22 14:24:13 +0100155struct DummyLayer<armnn::ConcatLayer>
telsoa014fcda012018-03-09 14:13:49 +0000156{
157 DummyLayer()
158 {
159 armnn::OriginsDescriptor desc(2);
Jim Flynne242f2d2019-05-22 14:24:13 +0100160 m_Layer = dummyGraph.AddLayer<armnn::ConcatLayer>(desc, "");
telsoa014fcda012018-03-09 14:13:49 +0000161 }
James Conroyee18dc82019-07-17 11:27:46 +0100162
telsoa014fcda012018-03-09 14:13:49 +0000163 ~DummyLayer()
164 {
165 dummyGraph.EraseLayer(m_Layer);
166 }
James Conroyee18dc82019-07-17 11:27:46 +0100167
Jim Flynne242f2d2019-05-22 14:24:13 +0100168 armnn::ConcatLayer* m_Layer;
telsoa014fcda012018-03-09 14:13:49 +0000169};
170
171template<>
Jim Flynn68db06f2020-10-06 10:14:50 +0100172struct DummyLayer<armnn::MapLayer, void>
173{
174 DummyLayer()
175 {
176 m_Layer = dummyGraph.AddLayer<armnn::MapLayer>("");
177 }
178
179 ~DummyLayer()
180 {
181 dummyGraph.EraseLayer(m_Layer);
182 }
183
184 armnn::MapLayer* m_Layer;
185};
186
187template<>
telsoa014fcda012018-03-09 14:13:49 +0000188struct DummyLayer<armnn::OutputLayer, armnn::LayerBindingId>
189{
190 DummyLayer()
191 {
192 m_Layer = dummyGraph.AddLayer<armnn::OutputLayer>(armnn::LayerBindingId(), "");
telsoa014fcda012018-03-09 14:13:49 +0000193 }
James Conroyee18dc82019-07-17 11:27:46 +0100194
telsoa014fcda012018-03-09 14:13:49 +0000195 ~DummyLayer()
196 {
197 dummyGraph.EraseLayer(m_Layer);
198 }
James Conroyee18dc82019-07-17 11:27:46 +0100199
telsoa014fcda012018-03-09 14:13:49 +0000200 armnn::OutputLayer* m_Layer;
201};
202
203template<>
204struct DummyLayer<armnn::SplitterLayer>
205{
206 DummyLayer()
207 {
208 armnn::ViewsDescriptor desc(1);
209 m_Layer = dummyGraph.AddLayer<armnn::SplitterLayer>(desc, "");
telsoa014fcda012018-03-09 14:13:49 +0000210 }
James Conroyee18dc82019-07-17 11:27:46 +0100211
telsoa014fcda012018-03-09 14:13:49 +0000212 ~DummyLayer()
213 {
214 dummyGraph.EraseLayer(m_Layer);
215 }
James Conroyee18dc82019-07-17 11:27:46 +0100216
telsoa014fcda012018-03-09 14:13:49 +0000217 armnn::SplitterLayer* m_Layer;
218};
219
Jim Flynn3a40ea52020-10-08 11:42:30 +0100220template<>
221struct DummyLayer<armnn::UnmapLayer, void>
222{
223 DummyLayer()
224 {
225 m_Layer = dummyGraph.AddLayer<armnn::UnmapLayer>("");
226 }
227
228 ~DummyLayer()
229 {
230 dummyGraph.EraseLayer(m_Layer);
231 }
232
233 armnn::UnmapLayer* m_Layer;
234};
235
telsoa014fcda012018-03-09 14:13:49 +0000236template <typename ConvolutionLayerType>
237struct DummyConvolutionLayer
238{
239 DummyConvolutionLayer()
240 {
241 typename ConvolutionLayerType::DescriptorType desc;
James Conroy663c1842019-11-01 15:21:48 +0000242 desc.m_StrideX = 1;
243 desc.m_StrideY = 1;
telsoa014fcda012018-03-09 14:13:49 +0000244 m_Layer = dummyGraph.AddLayer<ConvolutionLayerType>(desc, "");
James Conroy1f58f032021-04-27 17:13:27 +0100245 m_Layer->m_Weight = std::make_unique<armnn::ScopedTensorHandle>(
telsoa014fcda012018-03-09 14:13:49 +0000246 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +0100247 m_Layer->m_Bias = std::make_unique<armnn::ScopedTensorHandle>(
telsoa014fcda012018-03-09 14:13:49 +0000248 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
249 }
James Conroyee18dc82019-07-17 11:27:46 +0100250
telsoa014fcda012018-03-09 14:13:49 +0000251 ~DummyConvolutionLayer()
252 {
253 dummyGraph.EraseLayer(m_Layer);
254 }
James Conroyee18dc82019-07-17 11:27:46 +0100255
telsoa014fcda012018-03-09 14:13:49 +0000256 ConvolutionLayerType* m_Layer;
257};
258
259template<>
260struct DummyLayer<armnn::Convolution2dLayer>
261 : public DummyConvolutionLayer<armnn::Convolution2dLayer>
262{
263};
264
265template<>
266struct DummyLayer<armnn::DepthwiseConvolution2dLayer>
267 : public DummyConvolutionLayer<armnn::DepthwiseConvolution2dLayer>
268{
269};
270
Aron Virginas-Tar639fb042019-06-20 14:28:19 +0100271template<>
272struct DummyLayer<armnn::TransposeConvolution2dLayer>
273 : public DummyConvolutionLayer<armnn::TransposeConvolution2dLayer>
274{
275};
276
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000277template<>
278struct DummyLayer<armnn::DetectionPostProcessLayer>
279{
280 DummyLayer()
281 {
282 m_Layer = dummyGraph.AddLayer<armnn::DetectionPostProcessLayer>(armnn::DetectionPostProcessDescriptor(), "");
James Conroy1f58f032021-04-27 17:13:27 +0100283 m_Layer->m_Anchors = std::make_unique<armnn::ScopedTensorHandle>(
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000284 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
285 }
286
287 ~DummyLayer()
288 {
289 dummyGraph.EraseLayer(m_Layer);
290 }
291
292 armnn::DetectionPostProcessLayer* m_Layer;
293};
294
telsoa01c577f2c2018-08-31 09:22:23 +0100295template <typename LstmLayerType>
296struct DummyLstmLayer
297{
298 DummyLstmLayer()
299 {
300 typename LstmLayerType::DescriptorType desc;
301 desc.m_CifgEnabled = false;
302
Matthew Bentham6f24b1a2021-06-29 15:18:32 +0100303 m_Layer = dummyGraph.AddLayer<LstmLayerType>(desc, "");
James Conroy1f58f032021-04-27 17:13:27 +0100304 m_Layer->m_BasicParameters.m_InputToForgetWeights = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100305 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +0100306 m_Layer->m_BasicParameters.m_InputToCellWeights = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100307 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +0100308 m_Layer->m_BasicParameters.m_InputToOutputWeights = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100309 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +0100310 m_Layer->m_BasicParameters.m_RecurrentToForgetWeights = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100311 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +0100312 m_Layer->m_BasicParameters.m_RecurrentToCellWeights = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100313 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +0100314 m_Layer->m_BasicParameters.m_RecurrentToOutputWeights = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100315 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +0100316 m_Layer->m_BasicParameters.m_ForgetGateBias = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100317 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +0100318 m_Layer->m_BasicParameters.m_CellBias = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100319 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +0100320 m_Layer->m_BasicParameters.m_OutputGateBias = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100321 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
322
James Conroy1f58f032021-04-27 17:13:27 +0100323 m_Layer->m_CifgParameters.m_InputToInputWeights = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100324 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +0100325 m_Layer->m_CifgParameters.m_RecurrentToInputWeights = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100326 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +0100327 m_Layer->m_CifgParameters.m_InputGateBias = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100328 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
329 }
James Conroyee18dc82019-07-17 11:27:46 +0100330
telsoa01c577f2c2018-08-31 09:22:23 +0100331 ~DummyLstmLayer()
332 {
333 dummyGraph.EraseLayer(m_Layer);
334 }
James Conroyee18dc82019-07-17 11:27:46 +0100335
telsoa01c577f2c2018-08-31 09:22:23 +0100336 armnn::LstmLayer* m_Layer;
337};
338
339template<>
340struct DummyLayer<armnn::LstmLayer>
341 : public DummyLstmLayer<armnn::LstmLayer>
342{
343};
344
Narumol Prangnawarat8ed39ae2021-07-15 16:16:25 +0100345template <typename UnidirectionalSequenceLstmLayerType>
346struct DummyUnidirectionalSequenceLstmLayer
347{
348 DummyUnidirectionalSequenceLstmLayer()
349 {
350 typename UnidirectionalSequenceLstmLayerType::DescriptorType desc;
351 desc.m_CifgEnabled = false;
352
353 m_Layer = dummyGraph.AddLayer<UnidirectionalSequenceLstmLayerType>(desc, "");
354 m_Layer->m_BasicParameters.m_InputToForgetWeights = std::make_unique<armnn::ScopedTensorHandle>(
355 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
356 m_Layer->m_BasicParameters.m_InputToCellWeights = std::make_unique<armnn::ScopedTensorHandle>(
357 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
358 m_Layer->m_BasicParameters.m_InputToOutputWeights = std::make_unique<armnn::ScopedTensorHandle>(
359 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
360 m_Layer->m_BasicParameters.m_RecurrentToForgetWeights = std::make_unique<armnn::ScopedTensorHandle>(
361 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
362 m_Layer->m_BasicParameters.m_RecurrentToCellWeights = std::make_unique<armnn::ScopedTensorHandle>(
363 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
364 m_Layer->m_BasicParameters.m_RecurrentToOutputWeights = std::make_unique<armnn::ScopedTensorHandle>(
365 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
366 m_Layer->m_BasicParameters.m_ForgetGateBias = std::make_unique<armnn::ScopedTensorHandle>(
367 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
368 m_Layer->m_BasicParameters.m_CellBias = std::make_unique<armnn::ScopedTensorHandle>(
369 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
370 m_Layer->m_BasicParameters.m_OutputGateBias = std::make_unique<armnn::ScopedTensorHandle>(
371 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
372
373 m_Layer->m_CifgParameters.m_InputToInputWeights = std::make_unique<armnn::ScopedTensorHandle>(
374 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
375 m_Layer->m_CifgParameters.m_RecurrentToInputWeights = std::make_unique<armnn::ScopedTensorHandle>(
376 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
377 m_Layer->m_CifgParameters.m_InputGateBias = std::make_unique<armnn::ScopedTensorHandle>(
378 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
379 }
380
381 ~DummyUnidirectionalSequenceLstmLayer()
382 {
383 dummyGraph.EraseLayer(m_Layer);
384 }
385
386 armnn::UnidirectionalSequenceLstmLayer* m_Layer;
387};
388
389template<>
390struct DummyLayer<armnn::UnidirectionalSequenceLstmLayer>
391 : public DummyUnidirectionalSequenceLstmLayer<armnn::UnidirectionalSequenceLstmLayer>
392{
393};
394
Matthew Bentham6f24b1a2021-06-29 15:18:32 +0100395template<>
396struct DummyLayer<armnn::QLstmLayer>
James Conroy586a9aa2020-03-20 08:49:33 +0000397{
Matthew Bentham6f24b1a2021-06-29 15:18:32 +0100398 DummyLayer()
James Conroy586a9aa2020-03-20 08:49:33 +0000399 {
Matthew Bentham6f24b1a2021-06-29 15:18:32 +0100400 armnn::QLstmLayer::DescriptorType desc;
James Conroy586a9aa2020-03-20 08:49:33 +0000401 desc.m_CifgEnabled = false;
402 desc.m_PeepholeEnabled = true;
403 desc.m_ProjectionEnabled = true;
404 desc.m_LayerNormEnabled = true;
405
Matthew Bentham6f24b1a2021-06-29 15:18:32 +0100406 m_Layer = dummyGraph.AddLayer<armnn::QLstmLayer>(desc, "qLstm");
James Conroy586a9aa2020-03-20 08:49:33 +0000407
408 // Basic params
James Conroy1f58f032021-04-27 17:13:27 +0100409 m_Layer->m_BasicParameters.m_InputToForgetWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000410 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8));
James Conroy1f58f032021-04-27 17:13:27 +0100411 m_Layer->m_BasicParameters.m_InputToCellWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000412 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8));
James Conroy1f58f032021-04-27 17:13:27 +0100413 m_Layer->m_BasicParameters.m_InputToOutputWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000414 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8));
415
James Conroy1f58f032021-04-27 17:13:27 +0100416 m_Layer->m_BasicParameters.m_RecurrentToForgetWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000417 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8));
James Conroy1f58f032021-04-27 17:13:27 +0100418 m_Layer->m_BasicParameters.m_RecurrentToCellWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000419 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8));
James Conroy1f58f032021-04-27 17:13:27 +0100420 m_Layer->m_BasicParameters.m_RecurrentToOutputWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000421 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8));
422
James Conroy1f58f032021-04-27 17:13:27 +0100423 m_Layer->m_BasicParameters.m_ForgetGateBias = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000424 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32));
James Conroy1f58f032021-04-27 17:13:27 +0100425 m_Layer->m_BasicParameters.m_CellBias = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000426 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32));
James Conroy1f58f032021-04-27 17:13:27 +0100427 m_Layer->m_BasicParameters.m_OutputGateBias = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000428 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32));
429
430 // CIFG optional params
James Conroy1f58f032021-04-27 17:13:27 +0100431 m_Layer->m_CifgParameters.m_InputToInputWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000432 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8));
James Conroy1f58f032021-04-27 17:13:27 +0100433 m_Layer->m_CifgParameters.m_RecurrentToInputWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000434 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8));
James Conroy1f58f032021-04-27 17:13:27 +0100435 m_Layer->m_CifgParameters.m_InputGateBias = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000436 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32));
437
438 // Projection optional params
James Conroy1f58f032021-04-27 17:13:27 +0100439 m_Layer->m_ProjectionParameters.m_ProjectionWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000440 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8));
James Conroy1f58f032021-04-27 17:13:27 +0100441 m_Layer->m_ProjectionParameters.m_ProjectionBias = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000442 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32));
443
444 // Peephole optional params
James Conroy1f58f032021-04-27 17:13:27 +0100445 m_Layer->m_PeepholeParameters.m_CellToInputWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000446 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS16));
James Conroy1f58f032021-04-27 17:13:27 +0100447 m_Layer->m_PeepholeParameters.m_CellToForgetWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000448 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS16));
James Conroy1f58f032021-04-27 17:13:27 +0100449 m_Layer->m_PeepholeParameters.m_CellToOutputWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000450 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS16));
451
452 // Layer normalization optional params
James Conroy1f58f032021-04-27 17:13:27 +0100453 m_Layer->m_LayerNormParameters.m_InputLayerNormWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000454 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS16));
James Conroy1f58f032021-04-27 17:13:27 +0100455 m_Layer->m_LayerNormParameters.m_ForgetLayerNormWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000456 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS16));
James Conroy1f58f032021-04-27 17:13:27 +0100457 m_Layer->m_LayerNormParameters.m_CellLayerNormWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000458 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS16));
James Conroy1f58f032021-04-27 17:13:27 +0100459 m_Layer->m_LayerNormParameters.m_OutputLayerNormWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000460 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS16));
461 }
462
Matthew Bentham6f24b1a2021-06-29 15:18:32 +0100463 ~DummyLayer()
James Conroy586a9aa2020-03-20 08:49:33 +0000464 {
465 dummyGraph.EraseLayer(m_Layer);
466 }
467
468 armnn::QLstmLayer* m_Layer;
469};
470
telsoa01c577f2c2018-08-31 09:22:23 +0100471template<>
James Conroyee18dc82019-07-17 11:27:46 +0100472struct DummyLayer<armnn::QuantizedLstmLayer, void>
473{
474 DummyLayer()
475 {
476 m_Layer = dummyGraph.AddLayer<armnn::QuantizedLstmLayer>("");
477
James Conroy1f58f032021-04-27 17:13:27 +0100478 m_Layer->m_QuantizedLstmParameters.m_InputToInputWeights = std::make_unique<armnn::ScopedTensorHandle>(
Derek Lambertif90c56d2020-01-10 17:14:08 +0000479 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8));
James Conroy1f58f032021-04-27 17:13:27 +0100480 m_Layer->m_QuantizedLstmParameters.m_InputToForgetWeights = std::make_unique<armnn::ScopedTensorHandle>(
Derek Lambertif90c56d2020-01-10 17:14:08 +0000481 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8));
James Conroy1f58f032021-04-27 17:13:27 +0100482 m_Layer->m_QuantizedLstmParameters.m_InputToCellWeights = std::make_unique<armnn::ScopedTensorHandle>(
Derek Lambertif90c56d2020-01-10 17:14:08 +0000483 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8));
James Conroy1f58f032021-04-27 17:13:27 +0100484 m_Layer->m_QuantizedLstmParameters.m_InputToOutputWeights = std::make_unique<armnn::ScopedTensorHandle>(
Derek Lambertif90c56d2020-01-10 17:14:08 +0000485 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8));
James Conroyee18dc82019-07-17 11:27:46 +0100486
James Conroy1f58f032021-04-27 17:13:27 +0100487 m_Layer->m_QuantizedLstmParameters.m_RecurrentToInputWeights = std::make_unique<armnn::ScopedTensorHandle>(
Derek Lambertif90c56d2020-01-10 17:14:08 +0000488 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8));
James Conroy1f58f032021-04-27 17:13:27 +0100489 m_Layer->m_QuantizedLstmParameters.m_RecurrentToForgetWeights = std::make_unique<armnn::ScopedTensorHandle>(
Derek Lambertif90c56d2020-01-10 17:14:08 +0000490 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8));
James Conroy1f58f032021-04-27 17:13:27 +0100491 m_Layer->m_QuantizedLstmParameters.m_RecurrentToCellWeights = std::make_unique<armnn::ScopedTensorHandle>(
Derek Lambertif90c56d2020-01-10 17:14:08 +0000492 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8));
James Conroy1f58f032021-04-27 17:13:27 +0100493 m_Layer->m_QuantizedLstmParameters.m_RecurrentToOutputWeights = std::make_unique<armnn::ScopedTensorHandle>(
Derek Lambertif90c56d2020-01-10 17:14:08 +0000494 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8));
James Conroyee18dc82019-07-17 11:27:46 +0100495
James Conroy1f58f032021-04-27 17:13:27 +0100496 m_Layer->m_QuantizedLstmParameters.m_InputGateBias = std::make_unique<armnn::ScopedTensorHandle>(
James Conroyee18dc82019-07-17 11:27:46 +0100497 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32));
James Conroy1f58f032021-04-27 17:13:27 +0100498 m_Layer->m_QuantizedLstmParameters.m_ForgetGateBias = std::make_unique<armnn::ScopedTensorHandle>(
James Conroyee18dc82019-07-17 11:27:46 +0100499 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32));
James Conroy1f58f032021-04-27 17:13:27 +0100500 m_Layer->m_QuantizedLstmParameters.m_CellBias = std::make_unique<armnn::ScopedTensorHandle>(
James Conroyee18dc82019-07-17 11:27:46 +0100501 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32));
James Conroy1f58f032021-04-27 17:13:27 +0100502 m_Layer->m_QuantizedLstmParameters.m_OutputGateBias = std::make_unique<armnn::ScopedTensorHandle>(
James Conroyee18dc82019-07-17 11:27:46 +0100503 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32));
504 }
505
506 ~DummyLayer()
507 {
508 dummyGraph.EraseLayer(m_Layer);
509 }
510
511 armnn::QuantizedLstmLayer* m_Layer;
512};
513
514template<>
telsoa01c577f2c2018-08-31 09:22:23 +0100515struct DummyLayer<armnn::FullyConnectedLayer>
516{
517 DummyLayer()
518 {
519 armnn::FullyConnectedLayer::DescriptorType desc;
520 m_Layer = dummyGraph.AddLayer<armnn::FullyConnectedLayer>(desc, "");
James Conroy1f58f032021-04-27 17:13:27 +0100521 m_Layer->m_Weight = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100522 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
523 }
James Conroyee18dc82019-07-17 11:27:46 +0100524
telsoa01c577f2c2018-08-31 09:22:23 +0100525 ~DummyLayer()
526 {
527 dummyGraph.EraseLayer(m_Layer);
528 }
James Conroyee18dc82019-07-17 11:27:46 +0100529
telsoa01c577f2c2018-08-31 09:22:23 +0100530 armnn::FullyConnectedLayer* m_Layer;
531};
532
telsoa014fcda012018-03-09 14:13:49 +0000533// Tag for giving LayerType entries a unique strong type each.
534template<armnn::LayerType>
535struct Tag{};
536
537#define DECLARE_LAYER_POLICY_CUSTOM_PARAM(name, descType) \
538template<armnn::DataType DataType> \
539struct LayerTypePolicy<armnn::LayerType::name, DataType> \
540{ \
541 using Type = armnn::name##Layer; \
542 using Desc = descType; \
543 using QueueDesc = armnn::name##QueueDescriptor; \
544 constexpr static const char* NameStr = #name; \
Derek Lambertie606b7c2019-10-21 16:51:11 +0100545 constexpr static const bool IsException = false; \
telsoa014fcda012018-03-09 14:13:49 +0000546 \
547 static std::unique_ptr<armnn::IWorkload> MakeDummyWorkload(armnn::IWorkloadFactory *factory, \
548 unsigned int nIn, unsigned int nOut) \
549 { \
550 QueueDesc desc; \
551 armnn::WorkloadInfo info = MakeDummyWorkloadInfo<DataType>(nIn, nOut); \
Teresa Charlin611c7fb2022-01-07 09:47:29 +0000552 return factory->CreateWorkload(armnn::LayerType::name, desc, info); \
telsoa014fcda012018-03-09 14:13:49 +0000553 } \
554};
555
Jim Flynn68db06f2020-10-06 10:14:50 +0100556#define DECLARE_LAYER_POLICY_MAP_PARAM(name, descType) \
557template<armnn::DataType DataType> \
558struct LayerTypePolicy<armnn::LayerType::name, DataType> \
559{ \
560 using Type = armnn::name##Layer; \
561 using Desc = descType; \
562 using QueueDesc = armnn::name##QueueDescriptor; \
563 using Workload = armnn::name##Workload; \
564 constexpr static const char* NameStr = #name; \
565 constexpr static const bool IsException = false; \
566 \
567 static std::unique_ptr<armnn::IWorkload> MakeDummyWorkload(armnn::IWorkloadFactory* factory, \
568 unsigned int nIn, unsigned int nOut) \
569 { \
570 IgnoreUnused(factory); \
571 QueueDesc desc; \
572 armnn::WorkloadInfo info = MakeDummyWorkloadInfo<DataType>(nIn, nOut); \
573 return std::make_unique<armnn::name##Workload>(desc, info); \
574 } \
575};
576
telsoa01c577f2c2018-08-31 09:22:23 +0100577// Define a layer policy specialization for use with the IsLayerSupported tests.
telsoa014fcda012018-03-09 14:13:49 +0000578// Use this version for layers whose constructor takes 1 parameter(name).
579#define DECLARE_LAYER_POLICY_1_PARAM(name) DECLARE_LAYER_POLICY_CUSTOM_PARAM(name, void)
580
telsoa01c577f2c2018-08-31 09:22:23 +0100581// Define a layer policy specialization for use with the IsLayerSupported tests.
telsoa014fcda012018-03-09 14:13:49 +0000582// Use this version for layers whose constructor takes 2 parameters(descriptor and name).
583#define DECLARE_LAYER_POLICY_2_PARAM(name) DECLARE_LAYER_POLICY_CUSTOM_PARAM(name, armnn::name##Descriptor)
584
Derek Lamberti013c3902019-10-21 10:46:16 +0100585
586#define DECLARE_LAYER_POLICY_EXCEPTION(name, descType) \
587template<armnn::DataType DataType> \
588struct LayerTypePolicy<armnn::LayerType::name, DataType> \
589{ \
590 using Type = armnn::name##Layer; \
591 using Desc = descType; \
592 constexpr static const char* NameStr = #name; \
Derek Lambertib99ef392019-10-21 14:10:38 +0100593 constexpr static const bool IsException = true; \
Derek Lamberti013c3902019-10-21 10:46:16 +0100594 \
595 static std::unique_ptr<armnn::IWorkload> MakeDummyWorkload(armnn::IWorkloadFactory *factory, \
596 unsigned int nIn, unsigned int nOut) \
597 { \
Jan Eilers8eb25602020-03-09 12:13:48 +0000598 IgnoreUnused(factory, nIn, nOut); \
Derek Lamberti013c3902019-10-21 10:46:16 +0100599 return std::unique_ptr<armnn::IWorkload>(); \
600 } \
601};
602
603#define DECLARE_LAYER_POLICY_EXCEPTION_1_PARAM(name) DECLARE_LAYER_POLICY_EXCEPTION(name, void)
604#define DECLARE_LAYER_POLICY_EXCEPTION_2_PARAM(name) DECLARE_LAYER_POLICY_EXCEPTION(name, armnn::name##Descriptor)
605
telsoa01c577f2c2018-08-31 09:22:23 +0100606// Layer policy template.
telsoa014fcda012018-03-09 14:13:49 +0000607template<armnn::LayerType Type, armnn::DataType DataType>
608struct LayerTypePolicy;
609
610// Every entry in the armnn::LayerType enum must be accounted for below.
611DECLARE_LAYER_POLICY_2_PARAM(Activation)
612
613DECLARE_LAYER_POLICY_1_PARAM(Addition)
614
Nikhil Rajee391d52019-09-05 17:50:44 +0100615DECLARE_LAYER_POLICY_2_PARAM(ArgMinMax)
616
Samuel Yap4b7a34d2022-07-06 15:36:03 +0100617DECLARE_LAYER_POLICY_2_PARAM(BatchMatMul)
618
telsoa014fcda012018-03-09 14:13:49 +0000619DECLARE_LAYER_POLICY_2_PARAM(BatchNormalization)
620
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000621DECLARE_LAYER_POLICY_2_PARAM(BatchToSpaceNd)
622
mathad01b392e982021-04-07 12:07:30 +0100623DECLARE_LAYER_POLICY_1_PARAM(Cast)
624
Simon Obute51f67772021-09-03 15:50:13 +0100625DECLARE_LAYER_POLICY_2_PARAM(ChannelShuffle)
626
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100627DECLARE_LAYER_POLICY_2_PARAM(Comparison)
628
Jim Flynne242f2d2019-05-22 14:24:13 +0100629DECLARE_LAYER_POLICY_2_PARAM(Concat)
630
telsoa014fcda012018-03-09 14:13:49 +0000631DECLARE_LAYER_POLICY_1_PARAM(Constant)
632
Narumol Prangnawarat7ddbbae2020-03-13 10:26:05 +0000633DECLARE_LAYER_POLICY_1_PARAM(ConvertBf16ToFp32)
634
telsoa01c577f2c2018-08-31 09:22:23 +0100635DECLARE_LAYER_POLICY_1_PARAM(ConvertFp16ToFp32)
636
Narumol Prangnawaratea54a012020-03-16 16:36:10 +0000637DECLARE_LAYER_POLICY_1_PARAM(ConvertFp32ToBf16)
638
telsoa01c577f2c2018-08-31 09:22:23 +0100639DECLARE_LAYER_POLICY_1_PARAM(ConvertFp32ToFp16)
640
telsoa014fcda012018-03-09 14:13:49 +0000641DECLARE_LAYER_POLICY_2_PARAM(Convolution2d)
642
Matthew Sloyanb63a3112021-09-08 13:05:51 +0100643DECLARE_LAYER_POLICY_2_PARAM(Convolution3d)
644
telsoa014fcda012018-03-09 14:13:49 +0000645DECLARE_LAYER_POLICY_1_PARAM(MemCopy)
646
Derek Lambertif674aa02019-08-01 15:56:25 +0100647DECLARE_LAYER_POLICY_1_PARAM(MemImport)
648
Nattapat Chaimanowong964e9552019-03-26 11:03:26 +0000649DECLARE_LAYER_POLICY_1_PARAM(Debug)
Nattapat Chaimanowonga9a1cf12018-12-03 16:06:49 +0000650
Aron Virginas-Tardd6247f2019-09-19 14:31:17 +0100651DECLARE_LAYER_POLICY_2_PARAM(DepthToSpace)
652
telsoa014fcda012018-03-09 14:13:49 +0000653DECLARE_LAYER_POLICY_2_PARAM(DepthwiseConvolution2d)
654
Nattapat Chaimanowonge4294fd2019-03-28 09:56:53 +0000655DECLARE_LAYER_POLICY_1_PARAM(Dequantize)
656
Narumol Prangnawarat94dd5d82019-01-23 18:06:26 +0000657DECLARE_LAYER_POLICY_2_PARAM(DetectionPostProcess)
658
josh minor4a3c6102020-01-06 16:40:46 -0600659DECLARE_LAYER_POLICY_2_PARAM(ElementwiseUnary)
660
telsoa014fcda012018-03-09 14:13:49 +0000661DECLARE_LAYER_POLICY_2_PARAM(FakeQuantization)
662
Ryan OSheaec6c6802020-06-05 17:17:06 +0100663DECLARE_LAYER_POLICY_2_PARAM(Fill)
664
telsoa014fcda012018-03-09 14:13:49 +0000665DECLARE_LAYER_POLICY_1_PARAM(Floor)
666
667DECLARE_LAYER_POLICY_2_PARAM(FullyConnected)
668
Teresa Charlin52664732020-06-29 16:27:03 +0100669DECLARE_LAYER_POLICY_2_PARAM(Gather)
narpra01b89b05f2019-01-16 09:53:09 +0000670
Teresa Charlinb2d3ec52022-04-12 22:07:09 +0100671DECLARE_LAYER_POLICY_1_PARAM(GatherNd)
672
telsoa014fcda012018-03-09 14:13:49 +0000673DECLARE_LAYER_POLICY_CUSTOM_PARAM(Input, armnn::LayerBindingId)
674
Kevin Mayce5045a2019-10-02 14:07:47 +0100675DECLARE_LAYER_POLICY_2_PARAM(InstanceNormalization)
676
Matteo Martincighbcd3c852018-09-28 14:14:12 +0100677DECLARE_LAYER_POLICY_2_PARAM(L2Normalization)
telsoa014fcda012018-03-09 14:13:49 +0000678
James Conroyaba90cd2020-11-06 16:28:18 +0000679DECLARE_LAYER_POLICY_2_PARAM(LogicalBinary)
680
Aron Virginas-Tarf982dea2019-10-11 14:07:53 +0100681DECLARE_LAYER_POLICY_2_PARAM(LogSoftmax)
682
telsoa01c577f2c2018-08-31 09:22:23 +0100683DECLARE_LAYER_POLICY_2_PARAM(Lstm)
684
Jim Flynn68db06f2020-10-06 10:14:50 +0100685DECLARE_LAYER_POLICY_MAP_PARAM(Map, void)
686
Nattapat Chaimanowong5a4304a2018-11-28 10:44:37 +0000687DECLARE_LAYER_POLICY_1_PARAM(Maximum)
688
narpra0132b90462018-09-13 11:07:48 +0100689DECLARE_LAYER_POLICY_2_PARAM(Mean)
690
Nattapat Chaimanowong1f886302019-04-05 13:37:19 +0100691DECLARE_LAYER_POLICY_1_PARAM(Merge)
692
kevmay0190539692018-11-29 08:40:19 +0000693DECLARE_LAYER_POLICY_1_PARAM(Minimum)
694
telsoa014fcda012018-03-09 14:13:49 +0000695DECLARE_LAYER_POLICY_1_PARAM(Multiplication)
696
697DECLARE_LAYER_POLICY_2_PARAM(Normalization)
698
699DECLARE_LAYER_POLICY_CUSTOM_PARAM(Output, armnn::LayerBindingId)
700
Mohamed Nour Abouelseoud5662c202018-09-24 13:30:09 +0100701DECLARE_LAYER_POLICY_2_PARAM(Pad)
702
Derek Lambertia9cca6a2019-03-25 15:41:58 +0000703DECLARE_LAYER_POLICY_1_PARAM(Quantize)
704
telsoa014fcda012018-03-09 14:13:49 +0000705DECLARE_LAYER_POLICY_2_PARAM(Permute)
706
707DECLARE_LAYER_POLICY_2_PARAM(Pooling2d)
708
Tamás Nyíri7b885b32021-10-26 14:47:57 +0100709DECLARE_LAYER_POLICY_2_PARAM(Pooling3d)
710
Matteo Martincigh49124022019-01-11 13:25:59 +0000711DECLARE_LAYER_POLICY_2_PARAM(PreCompiled)
712
Matteo Martincigh0e406ee2019-06-12 15:42:18 +0100713DECLARE_LAYER_POLICY_1_PARAM(Prelu)
Narumol Prangnawarat8ed39ae2021-07-15 16:16:25 +0100714
James Conroy586a9aa2020-03-20 08:49:33 +0000715DECLARE_LAYER_POLICY_2_PARAM(QLstm)
716
James Conroyee18dc82019-07-17 11:27:46 +0100717DECLARE_LAYER_POLICY_1_PARAM(QuantizedLstm)
718
Francis Murtaghe7a86a42018-08-29 12:42:10 +0100719DECLARE_LAYER_POLICY_1_PARAM(Division)
720
Finn Williams2605b232020-06-10 15:53:46 +0100721DECLARE_LAYER_POLICY_1_PARAM(Rank)
722
Teresa Charlina9075df2019-06-27 15:41:57 +0100723DECLARE_LAYER_POLICY_2_PARAM(Resize)
724
telsoa01c577f2c2018-08-31 09:22:23 +0100725DECLARE_LAYER_POLICY_2_PARAM(Reshape)
726
Keith Davis3ae3f972021-05-21 16:33:48 +0100727DECLARE_LAYER_POLICY_1_PARAM(Shape)
728
Aron Virginas-Tar636ab402019-09-16 14:27:45 +0100729DECLARE_LAYER_POLICY_2_PARAM(Slice)
730
telsoa014fcda012018-03-09 14:13:49 +0000731DECLARE_LAYER_POLICY_2_PARAM(Softmax)
732
Nattapat Chaimanowong207ef9a2018-11-02 10:57:25 +0000733DECLARE_LAYER_POLICY_2_PARAM(SpaceToBatchNd)
734
Aron Virginas-Tar972af152019-06-11 14:14:03 +0100735DECLARE_LAYER_POLICY_2_PARAM(SpaceToDepth)
736
telsoa014fcda012018-03-09 14:13:49 +0000737DECLARE_LAYER_POLICY_2_PARAM(Splitter)
738
Matthew Jackson2b8c1da2019-07-04 14:59:16 +0100739DECLARE_LAYER_POLICY_2_PARAM(Stack)
740
Derek Lamberti013c3902019-10-21 10:46:16 +0100741DECLARE_LAYER_POLICY_EXCEPTION_2_PARAM(StandIn)
742
Conor Kennedy430b5d82018-11-14 15:28:28 +0000743DECLARE_LAYER_POLICY_2_PARAM(StridedSlice)
744
David Beckc2044fe2018-09-05 15:00:38 +0100745DECLARE_LAYER_POLICY_1_PARAM(Subtraction)
telsoa014fcda012018-03-09 14:13:49 +0000746
Sadik Armagan0c3ea5b2021-02-03 09:29:30 +0000747DECLARE_LAYER_POLICY_2_PARAM(Reduce)
748
Sadik Armaganeff363d2019-04-05 15:25:46 +0100749DECLARE_LAYER_POLICY_1_PARAM(Switch)
750
Mike Kellyc9ea45a2020-02-28 18:11:58 +0000751DECLARE_LAYER_POLICY_2_PARAM(Transpose)
752
Aron Virginas-Tar639fb042019-06-20 14:28:19 +0100753DECLARE_LAYER_POLICY_2_PARAM(TransposeConvolution2d)
754
Narumol Prangnawarat8ed39ae2021-07-15 16:16:25 +0100755DECLARE_LAYER_POLICY_2_PARAM(UnidirectionalSequenceLstm)
756
Jim Flynn3a40ea52020-10-08 11:42:30 +0100757DECLARE_LAYER_POLICY_MAP_PARAM(Unmap, void)
758
telsoa014fcda012018-03-09 14:13:49 +0000759
760// Generic implementation to get the number of input slots for a given layer type;
761template<armnn::LayerType Type>
762unsigned int GetNumInputs(const armnn::Layer& layer)
763{
764 return layer.GetNumInputSlots();
765}
766
767// Generic implementation to get the number of output slots for a given layer type;
768template<armnn::LayerType Type>
769unsigned int GetNumOutputs(const armnn::Layer& layer)
770{
771 return layer.GetNumOutputSlots();
772}
773
774template<>
Jim Flynne242f2d2019-05-22 14:24:13 +0100775unsigned int GetNumInputs<armnn::LayerType::Concat>(const armnn::Layer& layer)
telsoa014fcda012018-03-09 14:13:49 +0000776{
Jan Eilers8eb25602020-03-09 12:13:48 +0000777 IgnoreUnused(layer);
telsoa014fcda012018-03-09 14:13:49 +0000778 return 2;
779}
780
telsoa01c577f2c2018-08-31 09:22:23 +0100781// Tests that the IsLayerSupported() function returns the correct value.
782// We determined the correct value by *trying* to create the relevant workload and seeing if it matches what we expect.
telsoa014fcda012018-03-09 14:13:49 +0000783// Returns true if expectations are met, otherwise returns false.
784template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type>
785bool IsLayerSupportedTest(FactoryType *factory, Tag<Type>)
786{
787 using LayerPolicy = LayerTypePolicy<Type, DataType>;
788 using LayerType = typename LayerPolicy::Type;
789 using LayerDesc = typename LayerPolicy::Desc;
790 DummyLayer<LayerType, LayerDesc> layer;
791
Derek Lambertib99ef392019-10-21 14:10:38 +0100792 if (LayerPolicy::IsException) //Don't test exceptions to the rule.
793 {
794 return true;
795 }
796
telsoa014fcda012018-03-09 14:13:49 +0000797 unsigned int numIn = GetNumInputs<Type>(*layer.m_Layer);
798 unsigned int numOut = GetNumOutputs<Type>(*layer.m_Layer);
799
telsoa01c577f2c2018-08-31 09:22:23 +0100800 // Make another dummy layer just to make IsLayerSupported have valid inputs.
telsoa014fcda012018-03-09 14:13:49 +0000801 DummyLayer<armnn::ConstantLayer, void> previousLayer;
telsoa01c577f2c2018-08-31 09:22:23 +0100802 // Set output of the previous layer to a dummy tensor.
telsoa014fcda012018-03-09 14:13:49 +0000803 armnn::TensorInfo output = MakeDummyTensorInfo<DataType>();
804 previousLayer.m_Layer->GetOutputSlot(0).SetTensorInfo(output);
telsoa01c577f2c2018-08-31 09:22:23 +0100805 // Connect all outputs of the previous layer to inputs of tested layer.
telsoa014fcda012018-03-09 14:13:49 +0000806 for (unsigned int i = 0; i < numIn; i++)
807 {
808 armnn::IOutputSlot& previousLayerOutputSlot = previousLayer.m_Layer->GetOutputSlot(0);
809 armnn::IInputSlot& layerInputSlot = layer.m_Layer->GetInputSlot(i);
810 previousLayerOutputSlot.Connect(layerInputSlot);
811 }
telsoa01c577f2c2018-08-31 09:22:23 +0100812 // Set outputs of tested layer to a dummy tensor.
telsoa014fcda012018-03-09 14:13:49 +0000813 for (unsigned int i = 0; i < numOut; i++)
814 {
815 layer.m_Layer->GetOutputSlot(0).SetTensorInfo(output);
816 }
817
818 std::string layerName = LayerPolicy::NameStr;
819 std::string reasonIfUnsupported;
820 if (FactoryType::IsLayerSupported(*layer.m_Layer, DataType, reasonIfUnsupported))
821 {
822 std::string errorMsg = " layer expected support but found none.";
823 try
824 {
825 bool retVal = LayerPolicy::MakeDummyWorkload(factory, numIn, numOut).get() != nullptr;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100826 CHECK_MESSAGE(retVal, layerName << errorMsg);
telsoa014fcda012018-03-09 14:13:49 +0000827 return retVal;
828 }
telsoa01c577f2c2018-08-31 09:22:23 +0100829 catch(const armnn::InvalidArgumentException& e)
telsoa014fcda012018-03-09 14:13:49 +0000830 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000831 IgnoreUnused(e);
telsoa014fcda012018-03-09 14:13:49 +0000832 // This is ok since we throw InvalidArgumentException when creating the dummy workload.
833 return true;
834 }
835 catch(const std::exception& e)
836 {
837 errorMsg = e.what();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100838 FAIL(layerName << ": " << errorMsg);
telsoa014fcda012018-03-09 14:13:49 +0000839 return false;
840 }
telsoa01c577f2c2018-08-31 09:22:23 +0100841 catch(...)
telsoa014fcda012018-03-09 14:13:49 +0000842 {
843 errorMsg = "Unexpected error while testing support for ";
Sadik Armagan1625efc2021-06-10 18:24:34 +0100844 FAIL(errorMsg << layerName);
telsoa014fcda012018-03-09 14:13:49 +0000845 return false;
846 }
847 }
848 else
849 {
850 std::string errorMsg = "layer expected no support (giving reason: " + reasonIfUnsupported + ") but found some.";
851 try
852 {
853 bool retVal = LayerPolicy::MakeDummyWorkload(factory, numIn, numOut).get() == nullptr;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100854 CHECK_MESSAGE(retVal, layerName << errorMsg);
telsoa014fcda012018-03-09 14:13:49 +0000855 return retVal;
856 }
857 // These two exceptions are ok: For workloads that are partially supported, attempting to instantiate them
858 // using parameters that make IsLayerSupported() return false should throw an
telsoa01c577f2c2018-08-31 09:22:23 +0100859 // InvalidArgumentException or UnimplementedException.
telsoa014fcda012018-03-09 14:13:49 +0000860 catch(const armnn::InvalidArgumentException& e)
861 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000862 IgnoreUnused(e);
telsoa014fcda012018-03-09 14:13:49 +0000863 return true;
864 }
telsoa01c577f2c2018-08-31 09:22:23 +0100865 catch(const armnn::UnimplementedException& e)
telsoa014fcda012018-03-09 14:13:49 +0000866 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000867 IgnoreUnused(e);
telsoa014fcda012018-03-09 14:13:49 +0000868 return true;
869 }
870 catch(const std::exception& e)
871 {
872 errorMsg = e.what();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100873 FAIL(layerName << ": " << errorMsg);
telsoa014fcda012018-03-09 14:13:49 +0000874 return false;
875 }
telsoa01c577f2c2018-08-31 09:22:23 +0100876 catch(...)
telsoa014fcda012018-03-09 14:13:49 +0000877 {
878 errorMsg = "Unexpected error while testing support for ";
Sadik Armagan1625efc2021-06-10 18:24:34 +0100879 FAIL(errorMsg << layerName);
telsoa014fcda012018-03-09 14:13:49 +0000880 return false;
881 }
882 }
883}
884
Jim Flynn68db06f2020-10-06 10:14:50 +0100885template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type>
886bool IsLayerSupportedTest(FactoryType *factory, Tag<armnn::LayerType::Map>)
887{
888 IgnoreUnused(factory);
889 return true;
890}
891
Jim Flynn3a40ea52020-10-08 11:42:30 +0100892template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type>
893bool IsLayerSupportedTest(FactoryType *factory, Tag<armnn::LayerType::Unmap>)
894{
895 IgnoreUnused(factory);
896 return true;
897}
898
telsoa01c577f2c2018-08-31 09:22:23 +0100899// Helper function to compute the next type in the LayerType enum.
telsoa014fcda012018-03-09 14:13:49 +0000900constexpr armnn::LayerType NextType(armnn::LayerType type)
901{
902 return static_cast<armnn::LayerType>(static_cast<int>(type)+1);
903}
904
telsoa01c577f2c2018-08-31 09:22:23 +0100905// Termination function for determining the end of the LayerType enumeration.
telsoa014fcda012018-03-09 14:13:49 +0000906template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type>
907bool IsLayerSupportedTestsImpl(FactoryType *factory, Tag<armnn::LayerType::LastLayer>)
908{
909 return IsLayerSupportedTest<FactoryType, DataType, Type>(factory, Tag<Type>());
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000910}
telsoa014fcda012018-03-09 14:13:49 +0000911
telsoa01c577f2c2018-08-31 09:22:23 +0100912// Recursive function to test and enter in the LayerType enum and then iterate on the next entry.
telsoa014fcda012018-03-09 14:13:49 +0000913template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type>
914bool IsLayerSupportedTestsImpl(FactoryType *factory, Tag<Type>)
915{
916 bool v = IsLayerSupportedTest<FactoryType, DataType, Type>(factory, Tag<Type>());
917
918 return v &&
919 IsLayerSupportedTestsImpl<FactoryType, DataType, NextType(Type)>
920 (factory, Tag<NextType(Type)>());
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000921}
telsoa014fcda012018-03-09 14:13:49 +0000922
923// Helper function to pass through to the test framework.
924template<typename FactoryType, armnn::DataType DataType>
925bool IsLayerSupportedTests(FactoryType *factory)
926{
927 return IsLayerSupportedTestsImpl<FactoryType, DataType>(factory, Tag<armnn::LayerType::FirstLayer>());
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000928}
telsoa014fcda012018-03-09 14:13:49 +0000929
930template<armnn::LayerType Type>
931bool TestLayerTypeMatches()
932{
933 using LayerPolicy = LayerTypePolicy<Type, armnn::DataType::Float32>;
934 using LayerType = typename LayerPolicy::Type;
935 using LayerDesc = typename LayerPolicy::Desc;
936 DummyLayer<LayerType, LayerDesc> layer;
937
938 std::stringstream ss;
939 ss << LayerPolicy::NameStr << " layer type mismatches expected layer type value.";
940 bool v = Type == layer.m_Layer->GetType();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100941 CHECK_MESSAGE(v, ss.str());
telsoa014fcda012018-03-09 14:13:49 +0000942 return v;
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000943}
telsoa014fcda012018-03-09 14:13:49 +0000944
945template<armnn::LayerType Type>
946bool LayerTypeMatchesTestImpl(Tag<armnn::LayerType::LastLayer>)
947{
948 return TestLayerTypeMatches<Type>();
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000949}
telsoa014fcda012018-03-09 14:13:49 +0000950
951template<armnn::LayerType Type>
952bool LayerTypeMatchesTestImpl(Tag<Type>)
953{
954 return TestLayerTypeMatches<Type>() &&
955 LayerTypeMatchesTestImpl<NextType(Type)>(Tag<NextType(Type)>());
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000956}
telsoa014fcda012018-03-09 14:13:49 +0000957
telsoa01c577f2c2018-08-31 09:22:23 +0100958template<typename FactoryType, typename LayerType, armnn::DataType InputDataType , armnn::DataType OutputDataType>
959bool IsConvertLayerSupportedTests(std::string& reasonIfUnsupported)
960{
961 armnn::Graph graph;
962 LayerType* const layer = graph.AddLayer<LayerType>("LayerName");
963
964 armnn::Layer* const input = graph.AddLayer<armnn::InputLayer>(0, "input");
965 armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output");
966
967 armnn::TensorInfo inputTensorInfo({1, 3, 2, 3}, InputDataType);
968 armnn::TensorInfo outputTensorInfo({1, 3, 2, 3}, OutputDataType);
969
970 input->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
971 input->GetOutputHandler(0).SetTensorInfo(inputTensorInfo);
972 layer->GetOutputSlot(0).Connect(output->GetInputSlot(0));
973 layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo);
974
975 bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported);
976
977 return result;
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000978}
telsoa01c577f2c2018-08-31 09:22:23 +0100979
Matthew Bentham1f0ff352019-01-02 13:26:31 +0000980template<typename FactoryType, armnn::DataType InputDataType , armnn::DataType OutputDataType>
James Conroy177df1e2020-11-13 10:18:51 +0000981bool IsLogicalBinaryLayerSupportedTests(std::string& reasonIfUnsupported)
982{
983 armnn::Graph graph;
984 armnn::LogicalBinaryDescriptor desc(armnn::LogicalBinaryOperation::LogicalOr);
985
986 armnn::Layer* const input0 = graph.AddLayer<armnn::InputLayer>(0, "input0");
987 armnn::Layer* const input1 = graph.AddLayer<armnn::InputLayer>(1, "input1");
988
989 armnn::Layer* const layer = graph.AddLayer<armnn::LogicalBinaryLayer>(desc, "logicalOrLayer");
990
991 armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output1");
992
993 armnn::TensorInfo inputTensorInfo0({1, 1, 1, 4}, InputDataType);
994 armnn::TensorInfo inputTensorInfo1({1, 1, 1, 4}, InputDataType);
995
996 armnn::TensorInfo outputTensorInfo({1, 1, 1, 4}, OutputDataType);
997
998 input0->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
999 input1->GetOutputSlot(0).Connect(layer->GetInputSlot(1));
1000
1001 input0->GetOutputHandler(0).SetTensorInfo(inputTensorInfo0);
1002 input1->GetOutputHandler(0).SetTensorInfo(inputTensorInfo1);
1003
1004 layer->GetOutputSlot(0).Connect(output->GetInputSlot(0));
1005 layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo);
1006
1007 bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported);
1008
1009 return result;
1010}
1011
1012template<typename FactoryType, armnn::DataType InputDataType , armnn::DataType OutputDataType>
1013bool IsLogicalBinaryLayerBroadcastSupportedTests(std::string& reasonIfUnsupported)
1014{
1015 armnn::Graph graph;
1016 armnn::LogicalBinaryDescriptor desc(armnn::LogicalBinaryOperation::LogicalAnd);
1017
1018 armnn::Layer* const input0 = graph.AddLayer<armnn::InputLayer>(0, "input0");
1019 armnn::Layer* const input1 = graph.AddLayer<armnn::InputLayer>(1, "input1");
1020
1021 armnn::Layer* const layer = graph.AddLayer<armnn::LogicalBinaryLayer>(desc, "logicalAndLayer");
1022
1023 armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output2");
1024
1025 armnn::TensorInfo inputTensorInfo0({1, 1, 1, 4}, InputDataType);
1026 armnn::TensorInfo inputTensorInfo1({1, 1, 1, 1}, InputDataType);
1027
1028 armnn::TensorInfo outputTensorInfo({1, 1, 1, 4}, OutputDataType);
1029
1030 input0->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
1031 input1->GetOutputSlot(0).Connect(layer->GetInputSlot(1));
1032
1033 input0->GetOutputHandler(0).SetTensorInfo(inputTensorInfo0);
1034 input1->GetOutputHandler(0).SetTensorInfo(inputTensorInfo1);
1035
1036 layer->GetOutputSlot(0).Connect(output->GetInputSlot(0));
1037 layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo);
1038
1039 bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported);
1040
1041 return result;
1042}
1043
1044template<typename FactoryType, armnn::DataType InputDataType , armnn::DataType OutputDataType>
Matthew Bentham1f0ff352019-01-02 13:26:31 +00001045bool IsMeanLayerSupportedTests(std::string& reasonIfUnsupported)
1046{
1047 armnn::Graph graph;
1048 static const std::vector<unsigned> axes = {1, 0};
1049 armnn::MeanDescriptor desc(axes, false);
1050
1051 armnn::Layer* const layer = graph.AddLayer<armnn::MeanLayer>(desc, "LayerName");
1052
1053 armnn::Layer* const input = graph.AddLayer<armnn::InputLayer>(0, "input");
1054 armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output");
1055
1056 armnn::TensorInfo inputTensorInfo({4, 3, 2}, InputDataType);
1057 armnn::TensorInfo outputTensorInfo({2}, OutputDataType);
1058
1059 input->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
1060 input->GetOutputHandler(0).SetTensorInfo(inputTensorInfo);
1061 layer->GetOutputSlot(0).Connect(output->GetInputSlot(0));
1062 layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo);
1063
1064 bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported);
1065
1066 return result;
1067}
1068
James Conroy4d1ff582019-06-10 17:06:39 +01001069// Tests that IsMeanSupported fails when input tensor dimensions
1070// do not match output tensor dimensions when keepDims == true
1071template<typename FactoryType, armnn::DataType InputDataType , armnn::DataType OutputDataType>
1072bool IsMeanLayerNotSupportedTests(std::string& reasonIfUnsupported)
1073{
1074 armnn::Graph graph;
1075 static const std::vector<unsigned> axes = {};
1076 // Set keepDims == true
1077 armnn::MeanDescriptor desc(axes, true);
1078
1079 armnn::Layer* const layer = graph.AddLayer<armnn::MeanLayer>(desc, "LayerName");
1080
1081 armnn::Layer* const input = graph.AddLayer<armnn::InputLayer>(0, "input");
1082 armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output");
1083
1084 // Mismatching number of tensor dimensions
1085 armnn::TensorInfo inputTensorInfo({1, 1, 1, 1}, InputDataType);
1086 armnn::TensorInfo outputTensorInfo({1, 1}, OutputDataType);
1087
1088 input->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
1089 input->GetOutputHandler(0).SetTensorInfo(inputTensorInfo);
1090 layer->GetOutputSlot(0).Connect(output->GetInputSlot(0));
1091 layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo);
1092
1093 bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported);
1094
1095 return result;
1096}
1097
Mike Kelly0886ac42020-04-27 09:55:40 +01001098template<typename FactoryType, armnn::DataType OutputDataType>
1099bool IsConstantLayerSupportedTests(std::string& reasonIfUnsupported)
1100{
1101 armnn::Graph graph;
1102
1103 armnn::Layer* const layer = graph.AddLayer<armnn::ConstantLayer>("ConstantLayerName");
1104 armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "OutputLayerName");
1105
1106 armnn::TensorInfo outputTensorInfo({1, 1}, OutputDataType);
1107
1108 layer->GetOutputSlot(0).Connect(output->GetInputSlot(0));
1109 layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo);
1110
1111 bool result = FactoryType::IsLayerSupported(*layer, OutputDataType, reasonIfUnsupported);
1112
1113 return result;
1114}
Matthew Bentham1f0ff352019-01-02 13:26:31 +00001115
telsoa014fcda012018-03-09 14:13:49 +00001116} //namespace