blob: fb7a0271d47c9d3ea04b32240bf1ffa2866dd8aa [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
Mike Kellyec67a0f2022-11-25 13:55:24 +00002// Copyright © 2017,2022 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, "");
telsoa014fcda012018-03-09 14:13:49 +0000245 }
James Conroyee18dc82019-07-17 11:27:46 +0100246
telsoa014fcda012018-03-09 14:13:49 +0000247 ~DummyConvolutionLayer()
248 {
249 dummyGraph.EraseLayer(m_Layer);
250 }
James Conroyee18dc82019-07-17 11:27:46 +0100251
telsoa014fcda012018-03-09 14:13:49 +0000252 ConvolutionLayerType* m_Layer;
253};
254
255template<>
256struct DummyLayer<armnn::Convolution2dLayer>
257 : public DummyConvolutionLayer<armnn::Convolution2dLayer>
258{
259};
260
261template<>
262struct DummyLayer<armnn::DepthwiseConvolution2dLayer>
263 : public DummyConvolutionLayer<armnn::DepthwiseConvolution2dLayer>
264{
265};
266
Mike Kellyec67a0f2022-11-25 13:55:24 +0000267// Note: When m_Weight and m_Bias are removed from TransposeConvolution, Transpose can use DummyConvolutionLayer
268template <>
Aron Virginas-Tar639fb042019-06-20 14:28:19 +0100269struct DummyLayer<armnn::TransposeConvolution2dLayer>
Aron Virginas-Tar639fb042019-06-20 14:28:19 +0100270{
Mike Kellyec67a0f2022-11-25 13:55:24 +0000271 DummyLayer()
272 {
273 typename armnn::TransposeConvolution2dLayer::DescriptorType desc;
274 desc.m_StrideX = 1;
275 desc.m_StrideY = 1;
276 m_Layer = dummyGraph.AddLayer<armnn::TransposeConvolution2dLayer>(desc, "");
277 m_Layer->m_Weight = std::make_unique<armnn::ScopedTensorHandle>(
278 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
279 m_Layer->m_Bias = std::make_unique<armnn::ScopedTensorHandle>(
280 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
281 }
282
283 ~DummyLayer()
284 {
285 dummyGraph.EraseLayer(m_Layer);
286 }
287
288 armnn::TransposeConvolution2dLayer* m_Layer;
Aron Virginas-Tar639fb042019-06-20 14:28:19 +0100289};
290
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000291template<>
292struct DummyLayer<armnn::DetectionPostProcessLayer>
293{
294 DummyLayer()
295 {
296 m_Layer = dummyGraph.AddLayer<armnn::DetectionPostProcessLayer>(armnn::DetectionPostProcessDescriptor(), "");
James Conroy1f58f032021-04-27 17:13:27 +0100297 m_Layer->m_Anchors = std::make_unique<armnn::ScopedTensorHandle>(
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000298 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
299 }
300
301 ~DummyLayer()
302 {
303 dummyGraph.EraseLayer(m_Layer);
304 }
305
306 armnn::DetectionPostProcessLayer* m_Layer;
307};
308
telsoa01c577f2c2018-08-31 09:22:23 +0100309template <typename LstmLayerType>
310struct DummyLstmLayer
311{
312 DummyLstmLayer()
313 {
314 typename LstmLayerType::DescriptorType desc;
315 desc.m_CifgEnabled = false;
316
Matthew Bentham6f24b1a2021-06-29 15:18:32 +0100317 m_Layer = dummyGraph.AddLayer<LstmLayerType>(desc, "");
James Conroy1f58f032021-04-27 17:13:27 +0100318 m_Layer->m_BasicParameters.m_InputToForgetWeights = 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_InputToCellWeights = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100321 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +0100322 m_Layer->m_BasicParameters.m_InputToOutputWeights = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100323 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +0100324 m_Layer->m_BasicParameters.m_RecurrentToForgetWeights = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100325 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +0100326 m_Layer->m_BasicParameters.m_RecurrentToCellWeights = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100327 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +0100328 m_Layer->m_BasicParameters.m_RecurrentToOutputWeights = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100329 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +0100330 m_Layer->m_BasicParameters.m_ForgetGateBias = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100331 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +0100332 m_Layer->m_BasicParameters.m_CellBias = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100333 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +0100334 m_Layer->m_BasicParameters.m_OutputGateBias = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100335 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
336
James Conroy1f58f032021-04-27 17:13:27 +0100337 m_Layer->m_CifgParameters.m_InputToInputWeights = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100338 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +0100339 m_Layer->m_CifgParameters.m_RecurrentToInputWeights = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100340 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
James Conroy1f58f032021-04-27 17:13:27 +0100341 m_Layer->m_CifgParameters.m_InputGateBias = std::make_unique<armnn::ScopedTensorHandle>(
telsoa01c577f2c2018-08-31 09:22:23 +0100342 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
343 }
James Conroyee18dc82019-07-17 11:27:46 +0100344
telsoa01c577f2c2018-08-31 09:22:23 +0100345 ~DummyLstmLayer()
346 {
347 dummyGraph.EraseLayer(m_Layer);
348 }
James Conroyee18dc82019-07-17 11:27:46 +0100349
telsoa01c577f2c2018-08-31 09:22:23 +0100350 armnn::LstmLayer* m_Layer;
351};
352
353template<>
354struct DummyLayer<armnn::LstmLayer>
355 : public DummyLstmLayer<armnn::LstmLayer>
356{
357};
358
Narumol Prangnawarat8ed39ae2021-07-15 16:16:25 +0100359template <typename UnidirectionalSequenceLstmLayerType>
360struct DummyUnidirectionalSequenceLstmLayer
361{
362 DummyUnidirectionalSequenceLstmLayer()
363 {
364 typename UnidirectionalSequenceLstmLayerType::DescriptorType desc;
365 desc.m_CifgEnabled = false;
366
367 m_Layer = dummyGraph.AddLayer<UnidirectionalSequenceLstmLayerType>(desc, "");
368 m_Layer->m_BasicParameters.m_InputToForgetWeights = std::make_unique<armnn::ScopedTensorHandle>(
369 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
370 m_Layer->m_BasicParameters.m_InputToCellWeights = std::make_unique<armnn::ScopedTensorHandle>(
371 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
372 m_Layer->m_BasicParameters.m_InputToOutputWeights = std::make_unique<armnn::ScopedTensorHandle>(
373 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
374 m_Layer->m_BasicParameters.m_RecurrentToForgetWeights = std::make_unique<armnn::ScopedTensorHandle>(
375 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
376 m_Layer->m_BasicParameters.m_RecurrentToCellWeights = std::make_unique<armnn::ScopedTensorHandle>(
377 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
378 m_Layer->m_BasicParameters.m_RecurrentToOutputWeights = std::make_unique<armnn::ScopedTensorHandle>(
379 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
380 m_Layer->m_BasicParameters.m_ForgetGateBias = std::make_unique<armnn::ScopedTensorHandle>(
381 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
382 m_Layer->m_BasicParameters.m_CellBias = std::make_unique<armnn::ScopedTensorHandle>(
383 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
384 m_Layer->m_BasicParameters.m_OutputGateBias = std::make_unique<armnn::ScopedTensorHandle>(
385 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
386
387 m_Layer->m_CifgParameters.m_InputToInputWeights = std::make_unique<armnn::ScopedTensorHandle>(
388 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
389 m_Layer->m_CifgParameters.m_RecurrentToInputWeights = std::make_unique<armnn::ScopedTensorHandle>(
390 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
391 m_Layer->m_CifgParameters.m_InputGateBias = std::make_unique<armnn::ScopedTensorHandle>(
392 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32));
393 }
394
395 ~DummyUnidirectionalSequenceLstmLayer()
396 {
397 dummyGraph.EraseLayer(m_Layer);
398 }
399
400 armnn::UnidirectionalSequenceLstmLayer* m_Layer;
401};
402
403template<>
404struct DummyLayer<armnn::UnidirectionalSequenceLstmLayer>
405 : public DummyUnidirectionalSequenceLstmLayer<armnn::UnidirectionalSequenceLstmLayer>
406{
407};
408
Matthew Bentham6f24b1a2021-06-29 15:18:32 +0100409template<>
410struct DummyLayer<armnn::QLstmLayer>
James Conroy586a9aa2020-03-20 08:49:33 +0000411{
Matthew Bentham6f24b1a2021-06-29 15:18:32 +0100412 DummyLayer()
James Conroy586a9aa2020-03-20 08:49:33 +0000413 {
Matthew Bentham6f24b1a2021-06-29 15:18:32 +0100414 armnn::QLstmLayer::DescriptorType desc;
James Conroy586a9aa2020-03-20 08:49:33 +0000415 desc.m_CifgEnabled = false;
416 desc.m_PeepholeEnabled = true;
417 desc.m_ProjectionEnabled = true;
418 desc.m_LayerNormEnabled = true;
419
Matthew Bentham6f24b1a2021-06-29 15:18:32 +0100420 m_Layer = dummyGraph.AddLayer<armnn::QLstmLayer>(desc, "qLstm");
James Conroy586a9aa2020-03-20 08:49:33 +0000421
422 // Basic params
James Conroy1f58f032021-04-27 17:13:27 +0100423 m_Layer->m_BasicParameters.m_InputToForgetWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000424 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8));
James Conroy1f58f032021-04-27 17:13:27 +0100425 m_Layer->m_BasicParameters.m_InputToCellWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000426 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8));
James Conroy1f58f032021-04-27 17:13:27 +0100427 m_Layer->m_BasicParameters.m_InputToOutputWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000428 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8));
429
James Conroy1f58f032021-04-27 17:13:27 +0100430 m_Layer->m_BasicParameters.m_RecurrentToForgetWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000431 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8));
James Conroy1f58f032021-04-27 17:13:27 +0100432 m_Layer->m_BasicParameters.m_RecurrentToCellWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000433 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8));
James Conroy1f58f032021-04-27 17:13:27 +0100434 m_Layer->m_BasicParameters.m_RecurrentToOutputWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000435 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8));
436
James Conroy1f58f032021-04-27 17:13:27 +0100437 m_Layer->m_BasicParameters.m_ForgetGateBias = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000438 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32));
James Conroy1f58f032021-04-27 17:13:27 +0100439 m_Layer->m_BasicParameters.m_CellBias = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000440 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32));
James Conroy1f58f032021-04-27 17:13:27 +0100441 m_Layer->m_BasicParameters.m_OutputGateBias = 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 // CIFG optional params
James Conroy1f58f032021-04-27 17:13:27 +0100445 m_Layer->m_CifgParameters.m_InputToInputWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000446 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8));
James Conroy1f58f032021-04-27 17:13:27 +0100447 m_Layer->m_CifgParameters.m_RecurrentToInputWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000448 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8));
James Conroy1f58f032021-04-27 17:13:27 +0100449 m_Layer->m_CifgParameters.m_InputGateBias = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000450 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32));
451
452 // Projection optional params
James Conroy1f58f032021-04-27 17:13:27 +0100453 m_Layer->m_ProjectionParameters.m_ProjectionWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000454 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8));
James Conroy1f58f032021-04-27 17:13:27 +0100455 m_Layer->m_ProjectionParameters.m_ProjectionBias = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000456 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32));
457
458 // Peephole optional params
James Conroy1f58f032021-04-27 17:13:27 +0100459 m_Layer->m_PeepholeParameters.m_CellToInputWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000460 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS16));
James Conroy1f58f032021-04-27 17:13:27 +0100461 m_Layer->m_PeepholeParameters.m_CellToForgetWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000462 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS16));
James Conroy1f58f032021-04-27 17:13:27 +0100463 m_Layer->m_PeepholeParameters.m_CellToOutputWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000464 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS16));
465
466 // Layer normalization optional params
James Conroy1f58f032021-04-27 17:13:27 +0100467 m_Layer->m_LayerNormParameters.m_InputLayerNormWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000468 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS16));
James Conroy1f58f032021-04-27 17:13:27 +0100469 m_Layer->m_LayerNormParameters.m_ForgetLayerNormWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000470 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS16));
James Conroy1f58f032021-04-27 17:13:27 +0100471 m_Layer->m_LayerNormParameters.m_CellLayerNormWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000472 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS16));
James Conroy1f58f032021-04-27 17:13:27 +0100473 m_Layer->m_LayerNormParameters.m_OutputLayerNormWeights = std::make_unique<armnn::ScopedTensorHandle>(
James Conroy586a9aa2020-03-20 08:49:33 +0000474 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS16));
475 }
476
Matthew Bentham6f24b1a2021-06-29 15:18:32 +0100477 ~DummyLayer()
James Conroy586a9aa2020-03-20 08:49:33 +0000478 {
479 dummyGraph.EraseLayer(m_Layer);
480 }
481
482 armnn::QLstmLayer* m_Layer;
483};
484
telsoa01c577f2c2018-08-31 09:22:23 +0100485template<>
James Conroyee18dc82019-07-17 11:27:46 +0100486struct DummyLayer<armnn::QuantizedLstmLayer, void>
487{
488 DummyLayer()
489 {
490 m_Layer = dummyGraph.AddLayer<armnn::QuantizedLstmLayer>("");
491
James Conroy1f58f032021-04-27 17:13:27 +0100492 m_Layer->m_QuantizedLstmParameters.m_InputToInputWeights = std::make_unique<armnn::ScopedTensorHandle>(
Derek Lambertif90c56d2020-01-10 17:14:08 +0000493 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8));
James Conroy1f58f032021-04-27 17:13:27 +0100494 m_Layer->m_QuantizedLstmParameters.m_InputToForgetWeights = std::make_unique<armnn::ScopedTensorHandle>(
Derek Lambertif90c56d2020-01-10 17:14:08 +0000495 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8));
James Conroy1f58f032021-04-27 17:13:27 +0100496 m_Layer->m_QuantizedLstmParameters.m_InputToCellWeights = std::make_unique<armnn::ScopedTensorHandle>(
Derek Lambertif90c56d2020-01-10 17:14:08 +0000497 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8));
James Conroy1f58f032021-04-27 17:13:27 +0100498 m_Layer->m_QuantizedLstmParameters.m_InputToOutputWeights = std::make_unique<armnn::ScopedTensorHandle>(
Derek Lambertif90c56d2020-01-10 17:14:08 +0000499 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8));
James Conroyee18dc82019-07-17 11:27:46 +0100500
James Conroy1f58f032021-04-27 17:13:27 +0100501 m_Layer->m_QuantizedLstmParameters.m_RecurrentToInputWeights = std::make_unique<armnn::ScopedTensorHandle>(
Derek Lambertif90c56d2020-01-10 17:14:08 +0000502 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8));
James Conroy1f58f032021-04-27 17:13:27 +0100503 m_Layer->m_QuantizedLstmParameters.m_RecurrentToForgetWeights = std::make_unique<armnn::ScopedTensorHandle>(
Derek Lambertif90c56d2020-01-10 17:14:08 +0000504 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8));
James Conroy1f58f032021-04-27 17:13:27 +0100505 m_Layer->m_QuantizedLstmParameters.m_RecurrentToCellWeights = std::make_unique<armnn::ScopedTensorHandle>(
Derek Lambertif90c56d2020-01-10 17:14:08 +0000506 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8));
James Conroy1f58f032021-04-27 17:13:27 +0100507 m_Layer->m_QuantizedLstmParameters.m_RecurrentToOutputWeights = std::make_unique<armnn::ScopedTensorHandle>(
Derek Lambertif90c56d2020-01-10 17:14:08 +0000508 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8));
James Conroyee18dc82019-07-17 11:27:46 +0100509
James Conroy1f58f032021-04-27 17:13:27 +0100510 m_Layer->m_QuantizedLstmParameters.m_InputGateBias = std::make_unique<armnn::ScopedTensorHandle>(
James Conroyee18dc82019-07-17 11:27:46 +0100511 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32));
James Conroy1f58f032021-04-27 17:13:27 +0100512 m_Layer->m_QuantizedLstmParameters.m_ForgetGateBias = std::make_unique<armnn::ScopedTensorHandle>(
James Conroyee18dc82019-07-17 11:27:46 +0100513 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32));
James Conroy1f58f032021-04-27 17:13:27 +0100514 m_Layer->m_QuantizedLstmParameters.m_CellBias = std::make_unique<armnn::ScopedTensorHandle>(
James Conroyee18dc82019-07-17 11:27:46 +0100515 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32));
James Conroy1f58f032021-04-27 17:13:27 +0100516 m_Layer->m_QuantizedLstmParameters.m_OutputGateBias = std::make_unique<armnn::ScopedTensorHandle>(
James Conroyee18dc82019-07-17 11:27:46 +0100517 armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32));
518 }
519
520 ~DummyLayer()
521 {
522 dummyGraph.EraseLayer(m_Layer);
523 }
524
525 armnn::QuantizedLstmLayer* m_Layer;
526};
527
528template<>
telsoa01c577f2c2018-08-31 09:22:23 +0100529struct DummyLayer<armnn::FullyConnectedLayer>
530{
531 DummyLayer()
532 {
533 armnn::FullyConnectedLayer::DescriptorType desc;
534 m_Layer = dummyGraph.AddLayer<armnn::FullyConnectedLayer>(desc, "");
telsoa01c577f2c2018-08-31 09:22:23 +0100535 }
James Conroyee18dc82019-07-17 11:27:46 +0100536
telsoa01c577f2c2018-08-31 09:22:23 +0100537 ~DummyLayer()
538 {
539 dummyGraph.EraseLayer(m_Layer);
540 }
James Conroyee18dc82019-07-17 11:27:46 +0100541
telsoa01c577f2c2018-08-31 09:22:23 +0100542 armnn::FullyConnectedLayer* m_Layer;
543};
544
telsoa014fcda012018-03-09 14:13:49 +0000545// Tag for giving LayerType entries a unique strong type each.
546template<armnn::LayerType>
547struct Tag{};
548
549#define DECLARE_LAYER_POLICY_CUSTOM_PARAM(name, descType) \
550template<armnn::DataType DataType> \
551struct LayerTypePolicy<armnn::LayerType::name, DataType> \
552{ \
553 using Type = armnn::name##Layer; \
554 using Desc = descType; \
555 using QueueDesc = armnn::name##QueueDescriptor; \
556 constexpr static const char* NameStr = #name; \
Derek Lambertie606b7c2019-10-21 16:51:11 +0100557 constexpr static const bool IsException = false; \
telsoa014fcda012018-03-09 14:13:49 +0000558 \
559 static std::unique_ptr<armnn::IWorkload> MakeDummyWorkload(armnn::IWorkloadFactory *factory, \
560 unsigned int nIn, unsigned int nOut) \
561 { \
562 QueueDesc desc; \
563 armnn::WorkloadInfo info = MakeDummyWorkloadInfo<DataType>(nIn, nOut); \
Teresa Charlin611c7fb2022-01-07 09:47:29 +0000564 return factory->CreateWorkload(armnn::LayerType::name, desc, info); \
telsoa014fcda012018-03-09 14:13:49 +0000565 } \
566};
567
Jim Flynn68db06f2020-10-06 10:14:50 +0100568#define DECLARE_LAYER_POLICY_MAP_PARAM(name, descType) \
569template<armnn::DataType DataType> \
570struct LayerTypePolicy<armnn::LayerType::name, DataType> \
571{ \
572 using Type = armnn::name##Layer; \
573 using Desc = descType; \
574 using QueueDesc = armnn::name##QueueDescriptor; \
575 using Workload = armnn::name##Workload; \
576 constexpr static const char* NameStr = #name; \
577 constexpr static const bool IsException = false; \
578 \
579 static std::unique_ptr<armnn::IWorkload> MakeDummyWorkload(armnn::IWorkloadFactory* factory, \
580 unsigned int nIn, unsigned int nOut) \
581 { \
582 IgnoreUnused(factory); \
583 QueueDesc desc; \
584 armnn::WorkloadInfo info = MakeDummyWorkloadInfo<DataType>(nIn, nOut); \
585 return std::make_unique<armnn::name##Workload>(desc, info); \
586 } \
587};
588
telsoa01c577f2c2018-08-31 09:22:23 +0100589// Define a layer policy specialization for use with the IsLayerSupported tests.
telsoa014fcda012018-03-09 14:13:49 +0000590// Use this version for layers whose constructor takes 1 parameter(name).
591#define DECLARE_LAYER_POLICY_1_PARAM(name) DECLARE_LAYER_POLICY_CUSTOM_PARAM(name, void)
592
telsoa01c577f2c2018-08-31 09:22:23 +0100593// Define a layer policy specialization for use with the IsLayerSupported tests.
telsoa014fcda012018-03-09 14:13:49 +0000594// Use this version for layers whose constructor takes 2 parameters(descriptor and name).
595#define DECLARE_LAYER_POLICY_2_PARAM(name) DECLARE_LAYER_POLICY_CUSTOM_PARAM(name, armnn::name##Descriptor)
596
Derek Lamberti013c3902019-10-21 10:46:16 +0100597
598#define DECLARE_LAYER_POLICY_EXCEPTION(name, descType) \
599template<armnn::DataType DataType> \
600struct LayerTypePolicy<armnn::LayerType::name, DataType> \
601{ \
602 using Type = armnn::name##Layer; \
603 using Desc = descType; \
604 constexpr static const char* NameStr = #name; \
Derek Lambertib99ef392019-10-21 14:10:38 +0100605 constexpr static const bool IsException = true; \
Derek Lamberti013c3902019-10-21 10:46:16 +0100606 \
607 static std::unique_ptr<armnn::IWorkload> MakeDummyWorkload(armnn::IWorkloadFactory *factory, \
608 unsigned int nIn, unsigned int nOut) \
609 { \
Jan Eilers8eb25602020-03-09 12:13:48 +0000610 IgnoreUnused(factory, nIn, nOut); \
Derek Lamberti013c3902019-10-21 10:46:16 +0100611 return std::unique_ptr<armnn::IWorkload>(); \
612 } \
613};
614
615#define DECLARE_LAYER_POLICY_EXCEPTION_1_PARAM(name) DECLARE_LAYER_POLICY_EXCEPTION(name, void)
616#define DECLARE_LAYER_POLICY_EXCEPTION_2_PARAM(name) DECLARE_LAYER_POLICY_EXCEPTION(name, armnn::name##Descriptor)
617
telsoa01c577f2c2018-08-31 09:22:23 +0100618// Layer policy template.
telsoa014fcda012018-03-09 14:13:49 +0000619template<armnn::LayerType Type, armnn::DataType DataType>
620struct LayerTypePolicy;
621
622// Every entry in the armnn::LayerType enum must be accounted for below.
623DECLARE_LAYER_POLICY_2_PARAM(Activation)
624
625DECLARE_LAYER_POLICY_1_PARAM(Addition)
626
Nikhil Rajee391d52019-09-05 17:50:44 +0100627DECLARE_LAYER_POLICY_2_PARAM(ArgMinMax)
628
Samuel Yap6b478092022-07-06 15:36:03 +0100629DECLARE_LAYER_POLICY_2_PARAM(BatchMatMul)
630
telsoa014fcda012018-03-09 14:13:49 +0000631DECLARE_LAYER_POLICY_2_PARAM(BatchNormalization)
632
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000633DECLARE_LAYER_POLICY_2_PARAM(BatchToSpaceNd)
634
mathad01b392e982021-04-07 12:07:30 +0100635DECLARE_LAYER_POLICY_1_PARAM(Cast)
636
Simon Obute51f67772021-09-03 15:50:13 +0100637DECLARE_LAYER_POLICY_2_PARAM(ChannelShuffle)
638
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100639DECLARE_LAYER_POLICY_2_PARAM(Comparison)
640
Jim Flynne242f2d2019-05-22 14:24:13 +0100641DECLARE_LAYER_POLICY_2_PARAM(Concat)
642
telsoa014fcda012018-03-09 14:13:49 +0000643DECLARE_LAYER_POLICY_1_PARAM(Constant)
644
telsoa01c577f2c2018-08-31 09:22:23 +0100645DECLARE_LAYER_POLICY_1_PARAM(ConvertFp16ToFp32)
646
647DECLARE_LAYER_POLICY_1_PARAM(ConvertFp32ToFp16)
648
telsoa014fcda012018-03-09 14:13:49 +0000649DECLARE_LAYER_POLICY_2_PARAM(Convolution2d)
650
Matthew Sloyanb63a3112021-09-08 13:05:51 +0100651DECLARE_LAYER_POLICY_2_PARAM(Convolution3d)
652
telsoa014fcda012018-03-09 14:13:49 +0000653DECLARE_LAYER_POLICY_1_PARAM(MemCopy)
654
Derek Lambertif674aa02019-08-01 15:56:25 +0100655DECLARE_LAYER_POLICY_1_PARAM(MemImport)
656
Nattapat Chaimanowong964e9552019-03-26 11:03:26 +0000657DECLARE_LAYER_POLICY_1_PARAM(Debug)
Nattapat Chaimanowonga9a1cf12018-12-03 16:06:49 +0000658
Aron Virginas-Tardd6247f2019-09-19 14:31:17 +0100659DECLARE_LAYER_POLICY_2_PARAM(DepthToSpace)
660
telsoa014fcda012018-03-09 14:13:49 +0000661DECLARE_LAYER_POLICY_2_PARAM(DepthwiseConvolution2d)
662
Nattapat Chaimanowonge4294fd2019-03-28 09:56:53 +0000663DECLARE_LAYER_POLICY_1_PARAM(Dequantize)
664
Narumol Prangnawarat94dd5d82019-01-23 18:06:26 +0000665DECLARE_LAYER_POLICY_2_PARAM(DetectionPostProcess)
666
josh minor4a3c6102020-01-06 16:40:46 -0600667DECLARE_LAYER_POLICY_2_PARAM(ElementwiseUnary)
668
telsoa014fcda012018-03-09 14:13:49 +0000669DECLARE_LAYER_POLICY_2_PARAM(FakeQuantization)
670
Ryan OSheaec6c6802020-06-05 17:17:06 +0100671DECLARE_LAYER_POLICY_2_PARAM(Fill)
672
telsoa014fcda012018-03-09 14:13:49 +0000673DECLARE_LAYER_POLICY_1_PARAM(Floor)
674
675DECLARE_LAYER_POLICY_2_PARAM(FullyConnected)
676
Teresa Charlin52664732020-06-29 16:27:03 +0100677DECLARE_LAYER_POLICY_2_PARAM(Gather)
narpra01b89b05f2019-01-16 09:53:09 +0000678
Teresa Charlinb2d3ec52022-04-12 22:07:09 +0100679DECLARE_LAYER_POLICY_1_PARAM(GatherNd)
680
telsoa014fcda012018-03-09 14:13:49 +0000681DECLARE_LAYER_POLICY_CUSTOM_PARAM(Input, armnn::LayerBindingId)
682
Kevin Mayce5045a2019-10-02 14:07:47 +0100683DECLARE_LAYER_POLICY_2_PARAM(InstanceNormalization)
684
Matteo Martincighbcd3c852018-09-28 14:14:12 +0100685DECLARE_LAYER_POLICY_2_PARAM(L2Normalization)
telsoa014fcda012018-03-09 14:13:49 +0000686
James Conroyaba90cd2020-11-06 16:28:18 +0000687DECLARE_LAYER_POLICY_2_PARAM(LogicalBinary)
688
Aron Virginas-Tarf982dea2019-10-11 14:07:53 +0100689DECLARE_LAYER_POLICY_2_PARAM(LogSoftmax)
690
telsoa01c577f2c2018-08-31 09:22:23 +0100691DECLARE_LAYER_POLICY_2_PARAM(Lstm)
692
Jim Flynn68db06f2020-10-06 10:14:50 +0100693DECLARE_LAYER_POLICY_MAP_PARAM(Map, void)
694
Nattapat Chaimanowong5a4304a2018-11-28 10:44:37 +0000695DECLARE_LAYER_POLICY_1_PARAM(Maximum)
696
narpra0132b90462018-09-13 11:07:48 +0100697DECLARE_LAYER_POLICY_2_PARAM(Mean)
698
Nattapat Chaimanowong1f886302019-04-05 13:37:19 +0100699DECLARE_LAYER_POLICY_1_PARAM(Merge)
700
kevmay0190539692018-11-29 08:40:19 +0000701DECLARE_LAYER_POLICY_1_PARAM(Minimum)
702
telsoa014fcda012018-03-09 14:13:49 +0000703DECLARE_LAYER_POLICY_1_PARAM(Multiplication)
704
705DECLARE_LAYER_POLICY_2_PARAM(Normalization)
706
707DECLARE_LAYER_POLICY_CUSTOM_PARAM(Output, armnn::LayerBindingId)
708
Mohamed Nour Abouelseoud5662c202018-09-24 13:30:09 +0100709DECLARE_LAYER_POLICY_2_PARAM(Pad)
710
Derek Lambertia9cca6a2019-03-25 15:41:58 +0000711DECLARE_LAYER_POLICY_1_PARAM(Quantize)
712
telsoa014fcda012018-03-09 14:13:49 +0000713DECLARE_LAYER_POLICY_2_PARAM(Permute)
714
715DECLARE_LAYER_POLICY_2_PARAM(Pooling2d)
716
Tamás Nyíri7b885b32021-10-26 14:47:57 +0100717DECLARE_LAYER_POLICY_2_PARAM(Pooling3d)
718
Matteo Martincigh49124022019-01-11 13:25:59 +0000719DECLARE_LAYER_POLICY_2_PARAM(PreCompiled)
720
Matteo Martincigh0e406ee2019-06-12 15:42:18 +0100721DECLARE_LAYER_POLICY_1_PARAM(Prelu)
Narumol Prangnawarat8ed39ae2021-07-15 16:16:25 +0100722
James Conroy586a9aa2020-03-20 08:49:33 +0000723DECLARE_LAYER_POLICY_2_PARAM(QLstm)
724
James Conroyee18dc82019-07-17 11:27:46 +0100725DECLARE_LAYER_POLICY_1_PARAM(QuantizedLstm)
726
Francis Murtaghe7a86a42018-08-29 12:42:10 +0100727DECLARE_LAYER_POLICY_1_PARAM(Division)
728
Finn Williams2605b232020-06-10 15:53:46 +0100729DECLARE_LAYER_POLICY_1_PARAM(Rank)
730
Teresa Charlina9075df2019-06-27 15:41:57 +0100731DECLARE_LAYER_POLICY_2_PARAM(Resize)
732
telsoa01c577f2c2018-08-31 09:22:23 +0100733DECLARE_LAYER_POLICY_2_PARAM(Reshape)
734
Keith Davis3ae3f972021-05-21 16:33:48 +0100735DECLARE_LAYER_POLICY_1_PARAM(Shape)
736
Aron Virginas-Tar636ab402019-09-16 14:27:45 +0100737DECLARE_LAYER_POLICY_2_PARAM(Slice)
738
telsoa014fcda012018-03-09 14:13:49 +0000739DECLARE_LAYER_POLICY_2_PARAM(Softmax)
740
Nattapat Chaimanowong207ef9a2018-11-02 10:57:25 +0000741DECLARE_LAYER_POLICY_2_PARAM(SpaceToBatchNd)
742
Aron Virginas-Tar972af152019-06-11 14:14:03 +0100743DECLARE_LAYER_POLICY_2_PARAM(SpaceToDepth)
744
telsoa014fcda012018-03-09 14:13:49 +0000745DECLARE_LAYER_POLICY_2_PARAM(Splitter)
746
Matthew Jackson2b8c1da2019-07-04 14:59:16 +0100747DECLARE_LAYER_POLICY_2_PARAM(Stack)
748
Derek Lamberti013c3902019-10-21 10:46:16 +0100749DECLARE_LAYER_POLICY_EXCEPTION_2_PARAM(StandIn)
750
Conor Kennedy430b5d82018-11-14 15:28:28 +0000751DECLARE_LAYER_POLICY_2_PARAM(StridedSlice)
752
David Beckc2044fe2018-09-05 15:00:38 +0100753DECLARE_LAYER_POLICY_1_PARAM(Subtraction)
telsoa014fcda012018-03-09 14:13:49 +0000754
Sadik Armagan0c3ea5b2021-02-03 09:29:30 +0000755DECLARE_LAYER_POLICY_2_PARAM(Reduce)
756
Sadik Armaganeff363d2019-04-05 15:25:46 +0100757DECLARE_LAYER_POLICY_1_PARAM(Switch)
758
Mike Kellyc9ea45a2020-02-28 18:11:58 +0000759DECLARE_LAYER_POLICY_2_PARAM(Transpose)
760
Aron Virginas-Tar639fb042019-06-20 14:28:19 +0100761DECLARE_LAYER_POLICY_2_PARAM(TransposeConvolution2d)
762
Narumol Prangnawarat8ed39ae2021-07-15 16:16:25 +0100763DECLARE_LAYER_POLICY_2_PARAM(UnidirectionalSequenceLstm)
764
Jim Flynn3a40ea52020-10-08 11:42:30 +0100765DECLARE_LAYER_POLICY_MAP_PARAM(Unmap, void)
766
telsoa014fcda012018-03-09 14:13:49 +0000767
768// Generic implementation to get the number of input slots for a given layer type;
769template<armnn::LayerType Type>
770unsigned int GetNumInputs(const armnn::Layer& layer)
771{
772 return layer.GetNumInputSlots();
773}
774
775// Generic implementation to get the number of output slots for a given layer type;
776template<armnn::LayerType Type>
777unsigned int GetNumOutputs(const armnn::Layer& layer)
778{
779 return layer.GetNumOutputSlots();
780}
781
telsoa014fcda012018-03-09 14:13:49 +0000782
telsoa01c577f2c2018-08-31 09:22:23 +0100783// Tests that the IsLayerSupported() function returns the correct value.
784// 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 +0000785// Returns true if expectations are met, otherwise returns false.
786template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type>
787bool IsLayerSupportedTest(FactoryType *factory, Tag<Type>)
788{
789 using LayerPolicy = LayerTypePolicy<Type, DataType>;
790 using LayerType = typename LayerPolicy::Type;
791 using LayerDesc = typename LayerPolicy::Desc;
792 DummyLayer<LayerType, LayerDesc> layer;
793
Derek Lambertib99ef392019-10-21 14:10:38 +0100794 if (LayerPolicy::IsException) //Don't test exceptions to the rule.
795 {
796 return true;
797 }
798
telsoa014fcda012018-03-09 14:13:49 +0000799 unsigned int numIn = GetNumInputs<Type>(*layer.m_Layer);
800 unsigned int numOut = GetNumOutputs<Type>(*layer.m_Layer);
801
telsoa01c577f2c2018-08-31 09:22:23 +0100802 // Make another dummy layer just to make IsLayerSupported have valid inputs.
telsoa014fcda012018-03-09 14:13:49 +0000803 DummyLayer<armnn::ConstantLayer, void> previousLayer;
telsoa01c577f2c2018-08-31 09:22:23 +0100804 // Set output of the previous layer to a dummy tensor.
telsoa014fcda012018-03-09 14:13:49 +0000805 armnn::TensorInfo output = MakeDummyTensorInfo<DataType>();
806 previousLayer.m_Layer->GetOutputSlot(0).SetTensorInfo(output);
telsoa01c577f2c2018-08-31 09:22:23 +0100807 // Connect all outputs of the previous layer to inputs of tested layer.
telsoa014fcda012018-03-09 14:13:49 +0000808 for (unsigned int i = 0; i < numIn; i++)
809 {
810 armnn::IOutputSlot& previousLayerOutputSlot = previousLayer.m_Layer->GetOutputSlot(0);
811 armnn::IInputSlot& layerInputSlot = layer.m_Layer->GetInputSlot(i);
812 previousLayerOutputSlot.Connect(layerInputSlot);
813 }
telsoa01c577f2c2018-08-31 09:22:23 +0100814 // Set outputs of tested layer to a dummy tensor.
telsoa014fcda012018-03-09 14:13:49 +0000815 for (unsigned int i = 0; i < numOut; i++)
816 {
817 layer.m_Layer->GetOutputSlot(0).SetTensorInfo(output);
818 }
819
820 std::string layerName = LayerPolicy::NameStr;
821 std::string reasonIfUnsupported;
822 if (FactoryType::IsLayerSupported(*layer.m_Layer, DataType, reasonIfUnsupported))
823 {
824 std::string errorMsg = " layer expected support but found none.";
825 try
826 {
827 bool retVal = LayerPolicy::MakeDummyWorkload(factory, numIn, numOut).get() != nullptr;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100828 CHECK_MESSAGE(retVal, layerName << errorMsg);
telsoa014fcda012018-03-09 14:13:49 +0000829 return retVal;
830 }
telsoa01c577f2c2018-08-31 09:22:23 +0100831 catch(const armnn::InvalidArgumentException& e)
telsoa014fcda012018-03-09 14:13:49 +0000832 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000833 IgnoreUnused(e);
telsoa014fcda012018-03-09 14:13:49 +0000834 // This is ok since we throw InvalidArgumentException when creating the dummy workload.
835 return true;
836 }
837 catch(const std::exception& e)
838 {
839 errorMsg = e.what();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100840 FAIL(layerName << ": " << errorMsg);
telsoa014fcda012018-03-09 14:13:49 +0000841 return false;
842 }
telsoa01c577f2c2018-08-31 09:22:23 +0100843 catch(...)
telsoa014fcda012018-03-09 14:13:49 +0000844 {
845 errorMsg = "Unexpected error while testing support for ";
Sadik Armagan1625efc2021-06-10 18:24:34 +0100846 FAIL(errorMsg << layerName);
telsoa014fcda012018-03-09 14:13:49 +0000847 return false;
848 }
849 }
850 else
851 {
852 std::string errorMsg = "layer expected no support (giving reason: " + reasonIfUnsupported + ") but found some.";
853 try
854 {
855 bool retVal = LayerPolicy::MakeDummyWorkload(factory, numIn, numOut).get() == nullptr;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100856 CHECK_MESSAGE(retVal, layerName << errorMsg);
telsoa014fcda012018-03-09 14:13:49 +0000857 return retVal;
858 }
859 // These two exceptions are ok: For workloads that are partially supported, attempting to instantiate them
860 // using parameters that make IsLayerSupported() return false should throw an
telsoa01c577f2c2018-08-31 09:22:23 +0100861 // InvalidArgumentException or UnimplementedException.
telsoa014fcda012018-03-09 14:13:49 +0000862 catch(const armnn::InvalidArgumentException& e)
863 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000864 IgnoreUnused(e);
telsoa014fcda012018-03-09 14:13:49 +0000865 return true;
866 }
telsoa01c577f2c2018-08-31 09:22:23 +0100867 catch(const armnn::UnimplementedException& e)
telsoa014fcda012018-03-09 14:13:49 +0000868 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000869 IgnoreUnused(e);
telsoa014fcda012018-03-09 14:13:49 +0000870 return true;
871 }
872 catch(const std::exception& e)
873 {
874 errorMsg = e.what();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100875 FAIL(layerName << ": " << errorMsg);
telsoa014fcda012018-03-09 14:13:49 +0000876 return false;
877 }
telsoa01c577f2c2018-08-31 09:22:23 +0100878 catch(...)
telsoa014fcda012018-03-09 14:13:49 +0000879 {
880 errorMsg = "Unexpected error while testing support for ";
Sadik Armagan1625efc2021-06-10 18:24:34 +0100881 FAIL(errorMsg << layerName);
telsoa014fcda012018-03-09 14:13:49 +0000882 return false;
883 }
884 }
885}
886
Jim Flynn68db06f2020-10-06 10:14:50 +0100887template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type>
888bool IsLayerSupportedTest(FactoryType *factory, Tag<armnn::LayerType::Map>)
889{
890 IgnoreUnused(factory);
891 return true;
892}
893
Jim Flynn3a40ea52020-10-08 11:42:30 +0100894template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type>
895bool IsLayerSupportedTest(FactoryType *factory, Tag<armnn::LayerType::Unmap>)
896{
897 IgnoreUnused(factory);
898 return true;
899}
900
telsoa01c577f2c2018-08-31 09:22:23 +0100901// Helper function to compute the next type in the LayerType enum.
telsoa014fcda012018-03-09 14:13:49 +0000902constexpr armnn::LayerType NextType(armnn::LayerType type)
903{
904 return static_cast<armnn::LayerType>(static_cast<int>(type)+1);
905}
906
telsoa01c577f2c2018-08-31 09:22:23 +0100907// Termination function for determining the end of the LayerType enumeration.
telsoa014fcda012018-03-09 14:13:49 +0000908template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type>
909bool IsLayerSupportedTestsImpl(FactoryType *factory, Tag<armnn::LayerType::LastLayer>)
910{
911 return IsLayerSupportedTest<FactoryType, DataType, Type>(factory, Tag<Type>());
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000912}
telsoa014fcda012018-03-09 14:13:49 +0000913
telsoa01c577f2c2018-08-31 09:22:23 +0100914// Recursive function to test and enter in the LayerType enum and then iterate on the next entry.
telsoa014fcda012018-03-09 14:13:49 +0000915template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type>
916bool IsLayerSupportedTestsImpl(FactoryType *factory, Tag<Type>)
917{
918 bool v = IsLayerSupportedTest<FactoryType, DataType, Type>(factory, Tag<Type>());
919
920 return v &&
921 IsLayerSupportedTestsImpl<FactoryType, DataType, NextType(Type)>
922 (factory, Tag<NextType(Type)>());
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000923}
telsoa014fcda012018-03-09 14:13:49 +0000924
925// Helper function to pass through to the test framework.
926template<typename FactoryType, armnn::DataType DataType>
927bool IsLayerSupportedTests(FactoryType *factory)
928{
929 return IsLayerSupportedTestsImpl<FactoryType, DataType>(factory, Tag<armnn::LayerType::FirstLayer>());
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000930}
telsoa014fcda012018-03-09 14:13:49 +0000931
932template<armnn::LayerType Type>
933bool TestLayerTypeMatches()
934{
935 using LayerPolicy = LayerTypePolicy<Type, armnn::DataType::Float32>;
936 using LayerType = typename LayerPolicy::Type;
937 using LayerDesc = typename LayerPolicy::Desc;
938 DummyLayer<LayerType, LayerDesc> layer;
939
940 std::stringstream ss;
941 ss << LayerPolicy::NameStr << " layer type mismatches expected layer type value.";
942 bool v = Type == layer.m_Layer->GetType();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100943 CHECK_MESSAGE(v, ss.str());
telsoa014fcda012018-03-09 14:13:49 +0000944 return v;
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000945}
telsoa014fcda012018-03-09 14:13:49 +0000946
947template<armnn::LayerType Type>
948bool LayerTypeMatchesTestImpl(Tag<armnn::LayerType::LastLayer>)
949{
950 return TestLayerTypeMatches<Type>();
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000951}
telsoa014fcda012018-03-09 14:13:49 +0000952
953template<armnn::LayerType Type>
954bool LayerTypeMatchesTestImpl(Tag<Type>)
955{
956 return TestLayerTypeMatches<Type>() &&
957 LayerTypeMatchesTestImpl<NextType(Type)>(Tag<NextType(Type)>());
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000958}
telsoa014fcda012018-03-09 14:13:49 +0000959
telsoa01c577f2c2018-08-31 09:22:23 +0100960template<typename FactoryType, typename LayerType, armnn::DataType InputDataType , armnn::DataType OutputDataType>
961bool IsConvertLayerSupportedTests(std::string& reasonIfUnsupported)
962{
963 armnn::Graph graph;
964 LayerType* const layer = graph.AddLayer<LayerType>("LayerName");
965
966 armnn::Layer* const input = graph.AddLayer<armnn::InputLayer>(0, "input");
967 armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output");
968
969 armnn::TensorInfo inputTensorInfo({1, 3, 2, 3}, InputDataType);
970 armnn::TensorInfo outputTensorInfo({1, 3, 2, 3}, OutputDataType);
971
972 input->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
973 input->GetOutputHandler(0).SetTensorInfo(inputTensorInfo);
974 layer->GetOutputSlot(0).Connect(output->GetInputSlot(0));
975 layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo);
976
977 bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported);
978
979 return result;
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000980}
telsoa01c577f2c2018-08-31 09:22:23 +0100981
Matthew Bentham1f0ff352019-01-02 13:26:31 +0000982template<typename FactoryType, armnn::DataType InputDataType , armnn::DataType OutputDataType>
James Conroy177df1e2020-11-13 10:18:51 +0000983bool IsLogicalBinaryLayerSupportedTests(std::string& reasonIfUnsupported)
984{
985 armnn::Graph graph;
986 armnn::LogicalBinaryDescriptor desc(armnn::LogicalBinaryOperation::LogicalOr);
987
988 armnn::Layer* const input0 = graph.AddLayer<armnn::InputLayer>(0, "input0");
989 armnn::Layer* const input1 = graph.AddLayer<armnn::InputLayer>(1, "input1");
990
991 armnn::Layer* const layer = graph.AddLayer<armnn::LogicalBinaryLayer>(desc, "logicalOrLayer");
992
993 armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output1");
994
995 armnn::TensorInfo inputTensorInfo0({1, 1, 1, 4}, InputDataType);
996 armnn::TensorInfo inputTensorInfo1({1, 1, 1, 4}, InputDataType);
997
998 armnn::TensorInfo outputTensorInfo({1, 1, 1, 4}, OutputDataType);
999
1000 input0->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
1001 input1->GetOutputSlot(0).Connect(layer->GetInputSlot(1));
1002
1003 input0->GetOutputHandler(0).SetTensorInfo(inputTensorInfo0);
1004 input1->GetOutputHandler(0).SetTensorInfo(inputTensorInfo1);
1005
1006 layer->GetOutputSlot(0).Connect(output->GetInputSlot(0));
1007 layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo);
1008
1009 bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported);
1010
1011 return result;
1012}
1013
1014template<typename FactoryType, armnn::DataType InputDataType , armnn::DataType OutputDataType>
1015bool IsLogicalBinaryLayerBroadcastSupportedTests(std::string& reasonIfUnsupported)
1016{
1017 armnn::Graph graph;
1018 armnn::LogicalBinaryDescriptor desc(armnn::LogicalBinaryOperation::LogicalAnd);
1019
1020 armnn::Layer* const input0 = graph.AddLayer<armnn::InputLayer>(0, "input0");
1021 armnn::Layer* const input1 = graph.AddLayer<armnn::InputLayer>(1, "input1");
1022
1023 armnn::Layer* const layer = graph.AddLayer<armnn::LogicalBinaryLayer>(desc, "logicalAndLayer");
1024
1025 armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output2");
1026
1027 armnn::TensorInfo inputTensorInfo0({1, 1, 1, 4}, InputDataType);
1028 armnn::TensorInfo inputTensorInfo1({1, 1, 1, 1}, InputDataType);
1029
1030 armnn::TensorInfo outputTensorInfo({1, 1, 1, 4}, OutputDataType);
1031
1032 input0->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
1033 input1->GetOutputSlot(0).Connect(layer->GetInputSlot(1));
1034
1035 input0->GetOutputHandler(0).SetTensorInfo(inputTensorInfo0);
1036 input1->GetOutputHandler(0).SetTensorInfo(inputTensorInfo1);
1037
1038 layer->GetOutputSlot(0).Connect(output->GetInputSlot(0));
1039 layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo);
1040
1041 bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported);
1042
1043 return result;
1044}
1045
1046template<typename FactoryType, armnn::DataType InputDataType , armnn::DataType OutputDataType>
Matthew Bentham1f0ff352019-01-02 13:26:31 +00001047bool IsMeanLayerSupportedTests(std::string& reasonIfUnsupported)
1048{
1049 armnn::Graph graph;
1050 static const std::vector<unsigned> axes = {1, 0};
1051 armnn::MeanDescriptor desc(axes, false);
1052
1053 armnn::Layer* const layer = graph.AddLayer<armnn::MeanLayer>(desc, "LayerName");
1054
1055 armnn::Layer* const input = graph.AddLayer<armnn::InputLayer>(0, "input");
1056 armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output");
1057
1058 armnn::TensorInfo inputTensorInfo({4, 3, 2}, InputDataType);
1059 armnn::TensorInfo outputTensorInfo({2}, OutputDataType);
1060
1061 input->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
1062 input->GetOutputHandler(0).SetTensorInfo(inputTensorInfo);
1063 layer->GetOutputSlot(0).Connect(output->GetInputSlot(0));
1064 layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo);
1065
1066 bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported);
1067
1068 return result;
1069}
1070
James Conroy4d1ff582019-06-10 17:06:39 +01001071// Tests that IsMeanSupported fails when input tensor dimensions
1072// do not match output tensor dimensions when keepDims == true
1073template<typename FactoryType, armnn::DataType InputDataType , armnn::DataType OutputDataType>
1074bool IsMeanLayerNotSupportedTests(std::string& reasonIfUnsupported)
1075{
1076 armnn::Graph graph;
1077 static const std::vector<unsigned> axes = {};
1078 // Set keepDims == true
1079 armnn::MeanDescriptor desc(axes, true);
1080
1081 armnn::Layer* const layer = graph.AddLayer<armnn::MeanLayer>(desc, "LayerName");
1082
1083 armnn::Layer* const input = graph.AddLayer<armnn::InputLayer>(0, "input");
1084 armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output");
1085
1086 // Mismatching number of tensor dimensions
1087 armnn::TensorInfo inputTensorInfo({1, 1, 1, 1}, InputDataType);
1088 armnn::TensorInfo outputTensorInfo({1, 1}, OutputDataType);
1089
1090 input->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
1091 input->GetOutputHandler(0).SetTensorInfo(inputTensorInfo);
1092 layer->GetOutputSlot(0).Connect(output->GetInputSlot(0));
1093 layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo);
1094
1095 bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported);
1096
1097 return result;
1098}
1099
Mike Kelly0886ac42020-04-27 09:55:40 +01001100template<typename FactoryType, armnn::DataType OutputDataType>
1101bool IsConstantLayerSupportedTests(std::string& reasonIfUnsupported)
1102{
1103 armnn::Graph graph;
1104
1105 armnn::Layer* const layer = graph.AddLayer<armnn::ConstantLayer>("ConstantLayerName");
1106 armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "OutputLayerName");
1107
1108 armnn::TensorInfo outputTensorInfo({1, 1}, OutputDataType);
1109
1110 layer->GetOutputSlot(0).Connect(output->GetInputSlot(0));
1111 layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo);
1112
1113 bool result = FactoryType::IsLayerSupported(*layer, OutputDataType, reasonIfUnsupported);
1114
1115 return result;
1116}
Matthew Bentham1f0ff352019-01-02 13:26:31 +00001117
telsoa014fcda012018-03-09 14:13:49 +00001118} //namespace