blob: ff02e06859be4c0140d329315800b07776822684 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
Mike Kelly3ec30772023-03-08 13:47:17 +00002// Copyright © 2017-2023 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
Mike Kelly2c14db62023-03-15 15:06:23 +0000625ARMNN_NO_DEPRECATE_WARN_BEGIN
telsoa014fcda012018-03-09 14:13:49 +0000626DECLARE_LAYER_POLICY_1_PARAM(Addition)
Mike Kelly2c14db62023-03-15 15:06:23 +0000627ARMNN_NO_DEPRECATE_WARN_END
telsoa014fcda012018-03-09 14:13:49 +0000628
Nikhil Rajee391d52019-09-05 17:50:44 +0100629DECLARE_LAYER_POLICY_2_PARAM(ArgMinMax)
630
Samuel Yap6b478092022-07-06 15:36:03 +0100631DECLARE_LAYER_POLICY_2_PARAM(BatchMatMul)
632
telsoa014fcda012018-03-09 14:13:49 +0000633DECLARE_LAYER_POLICY_2_PARAM(BatchNormalization)
634
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000635DECLARE_LAYER_POLICY_2_PARAM(BatchToSpaceNd)
636
mathad01b392e982021-04-07 12:07:30 +0100637DECLARE_LAYER_POLICY_1_PARAM(Cast)
638
Simon Obute51f67772021-09-03 15:50:13 +0100639DECLARE_LAYER_POLICY_2_PARAM(ChannelShuffle)
640
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100641DECLARE_LAYER_POLICY_2_PARAM(Comparison)
642
Jim Flynne242f2d2019-05-22 14:24:13 +0100643DECLARE_LAYER_POLICY_2_PARAM(Concat)
644
telsoa014fcda012018-03-09 14:13:49 +0000645DECLARE_LAYER_POLICY_1_PARAM(Constant)
646
telsoa01c577f2c2018-08-31 09:22:23 +0100647DECLARE_LAYER_POLICY_1_PARAM(ConvertFp16ToFp32)
648
649DECLARE_LAYER_POLICY_1_PARAM(ConvertFp32ToFp16)
650
telsoa014fcda012018-03-09 14:13:49 +0000651DECLARE_LAYER_POLICY_2_PARAM(Convolution2d)
652
Matthew Sloyanb63a3112021-09-08 13:05:51 +0100653DECLARE_LAYER_POLICY_2_PARAM(Convolution3d)
654
telsoa014fcda012018-03-09 14:13:49 +0000655DECLARE_LAYER_POLICY_1_PARAM(MemCopy)
656
Derek Lambertif674aa02019-08-01 15:56:25 +0100657DECLARE_LAYER_POLICY_1_PARAM(MemImport)
658
Nattapat Chaimanowong964e9552019-03-26 11:03:26 +0000659DECLARE_LAYER_POLICY_1_PARAM(Debug)
Nattapat Chaimanowonga9a1cf12018-12-03 16:06:49 +0000660
Aron Virginas-Tardd6247f2019-09-19 14:31:17 +0100661DECLARE_LAYER_POLICY_2_PARAM(DepthToSpace)
662
telsoa014fcda012018-03-09 14:13:49 +0000663DECLARE_LAYER_POLICY_2_PARAM(DepthwiseConvolution2d)
664
Nattapat Chaimanowonge4294fd2019-03-28 09:56:53 +0000665DECLARE_LAYER_POLICY_1_PARAM(Dequantize)
666
Narumol Prangnawarat94dd5d82019-01-23 18:06:26 +0000667DECLARE_LAYER_POLICY_2_PARAM(DetectionPostProcess)
668
Mike Kelly3ec30772023-03-08 13:47:17 +0000669DECLARE_LAYER_POLICY_2_PARAM(ElementwiseBinary)
670
josh minor4a3c6102020-01-06 16:40:46 -0600671DECLARE_LAYER_POLICY_2_PARAM(ElementwiseUnary)
672
telsoa014fcda012018-03-09 14:13:49 +0000673DECLARE_LAYER_POLICY_2_PARAM(FakeQuantization)
674
Ryan OSheaec6c6802020-06-05 17:17:06 +0100675DECLARE_LAYER_POLICY_2_PARAM(Fill)
676
telsoa014fcda012018-03-09 14:13:49 +0000677DECLARE_LAYER_POLICY_1_PARAM(Floor)
678
679DECLARE_LAYER_POLICY_2_PARAM(FullyConnected)
680
Teresa Charlin52664732020-06-29 16:27:03 +0100681DECLARE_LAYER_POLICY_2_PARAM(Gather)
narpra01b89b05f2019-01-16 09:53:09 +0000682
Teresa Charlinb2d3ec52022-04-12 22:07:09 +0100683DECLARE_LAYER_POLICY_1_PARAM(GatherNd)
684
telsoa014fcda012018-03-09 14:13:49 +0000685DECLARE_LAYER_POLICY_CUSTOM_PARAM(Input, armnn::LayerBindingId)
686
Kevin Mayce5045a2019-10-02 14:07:47 +0100687DECLARE_LAYER_POLICY_2_PARAM(InstanceNormalization)
688
Matteo Martincighbcd3c852018-09-28 14:14:12 +0100689DECLARE_LAYER_POLICY_2_PARAM(L2Normalization)
telsoa014fcda012018-03-09 14:13:49 +0000690
James Conroyaba90cd2020-11-06 16:28:18 +0000691DECLARE_LAYER_POLICY_2_PARAM(LogicalBinary)
692
Aron Virginas-Tarf982dea2019-10-11 14:07:53 +0100693DECLARE_LAYER_POLICY_2_PARAM(LogSoftmax)
694
telsoa01c577f2c2018-08-31 09:22:23 +0100695DECLARE_LAYER_POLICY_2_PARAM(Lstm)
696
Jim Flynn68db06f2020-10-06 10:14:50 +0100697DECLARE_LAYER_POLICY_MAP_PARAM(Map, void)
698
Mike Kelly2c14db62023-03-15 15:06:23 +0000699ARMNN_NO_DEPRECATE_WARN_BEGIN
Nattapat Chaimanowong5a4304a2018-11-28 10:44:37 +0000700DECLARE_LAYER_POLICY_1_PARAM(Maximum)
Mike Kelly2c14db62023-03-15 15:06:23 +0000701ARMNN_NO_DEPRECATE_WARN_END
Nattapat Chaimanowong5a4304a2018-11-28 10:44:37 +0000702
narpra0132b90462018-09-13 11:07:48 +0100703DECLARE_LAYER_POLICY_2_PARAM(Mean)
704
Nattapat Chaimanowong1f886302019-04-05 13:37:19 +0100705DECLARE_LAYER_POLICY_1_PARAM(Merge)
706
Mike Kelly2c14db62023-03-15 15:06:23 +0000707ARMNN_NO_DEPRECATE_WARN_BEGIN
kevmay0190539692018-11-29 08:40:19 +0000708DECLARE_LAYER_POLICY_1_PARAM(Minimum)
Mike Kelly2c14db62023-03-15 15:06:23 +0000709ARMNN_NO_DEPRECATE_WARN_END
kevmay0190539692018-11-29 08:40:19 +0000710
Mike Kelly2c14db62023-03-15 15:06:23 +0000711ARMNN_NO_DEPRECATE_WARN_BEGIN
telsoa014fcda012018-03-09 14:13:49 +0000712DECLARE_LAYER_POLICY_1_PARAM(Multiplication)
Mike Kelly2c14db62023-03-15 15:06:23 +0000713ARMNN_NO_DEPRECATE_WARN_END
telsoa014fcda012018-03-09 14:13:49 +0000714
715DECLARE_LAYER_POLICY_2_PARAM(Normalization)
716
717DECLARE_LAYER_POLICY_CUSTOM_PARAM(Output, armnn::LayerBindingId)
718
Mohamed Nour Abouelseoud5662c202018-09-24 13:30:09 +0100719DECLARE_LAYER_POLICY_2_PARAM(Pad)
720
Derek Lambertia9cca6a2019-03-25 15:41:58 +0000721DECLARE_LAYER_POLICY_1_PARAM(Quantize)
722
telsoa014fcda012018-03-09 14:13:49 +0000723DECLARE_LAYER_POLICY_2_PARAM(Permute)
724
725DECLARE_LAYER_POLICY_2_PARAM(Pooling2d)
726
Tamás Nyíri7b885b32021-10-26 14:47:57 +0100727DECLARE_LAYER_POLICY_2_PARAM(Pooling3d)
728
Matteo Martincigh49124022019-01-11 13:25:59 +0000729DECLARE_LAYER_POLICY_2_PARAM(PreCompiled)
730
Matteo Martincigh0e406ee2019-06-12 15:42:18 +0100731DECLARE_LAYER_POLICY_1_PARAM(Prelu)
Narumol Prangnawarat8ed39ae2021-07-15 16:16:25 +0100732
James Conroy586a9aa2020-03-20 08:49:33 +0000733DECLARE_LAYER_POLICY_2_PARAM(QLstm)
734
James Conroyee18dc82019-07-17 11:27:46 +0100735DECLARE_LAYER_POLICY_1_PARAM(QuantizedLstm)
736
Mike Kelly2c14db62023-03-15 15:06:23 +0000737ARMNN_NO_DEPRECATE_WARN_BEGIN
Francis Murtaghe7a86a42018-08-29 12:42:10 +0100738DECLARE_LAYER_POLICY_1_PARAM(Division)
Mike Kelly2c14db62023-03-15 15:06:23 +0000739ARMNN_NO_DEPRECATE_WARN_END
Francis Murtaghe7a86a42018-08-29 12:42:10 +0100740
Finn Williams2605b232020-06-10 15:53:46 +0100741DECLARE_LAYER_POLICY_1_PARAM(Rank)
742
Teresa Charlin79a06a52023-07-13 17:16:45 +0100743DECLARE_LAYER_POLICY_2_PARAM(Reduce)
744
Teresa Charlina9075df2019-06-27 15:41:57 +0100745DECLARE_LAYER_POLICY_2_PARAM(Resize)
746
telsoa01c577f2c2018-08-31 09:22:23 +0100747DECLARE_LAYER_POLICY_2_PARAM(Reshape)
748
Teresa Charlin79a06a52023-07-13 17:16:45 +0100749DECLARE_LAYER_POLICY_1_PARAM(ReverseV2)
750
Keith Davis3ae3f972021-05-21 16:33:48 +0100751DECLARE_LAYER_POLICY_1_PARAM(Shape)
752
Aron Virginas-Tar636ab402019-09-16 14:27:45 +0100753DECLARE_LAYER_POLICY_2_PARAM(Slice)
754
telsoa014fcda012018-03-09 14:13:49 +0000755DECLARE_LAYER_POLICY_2_PARAM(Softmax)
756
Nattapat Chaimanowong207ef9a2018-11-02 10:57:25 +0000757DECLARE_LAYER_POLICY_2_PARAM(SpaceToBatchNd)
758
Aron Virginas-Tar972af152019-06-11 14:14:03 +0100759DECLARE_LAYER_POLICY_2_PARAM(SpaceToDepth)
760
telsoa014fcda012018-03-09 14:13:49 +0000761DECLARE_LAYER_POLICY_2_PARAM(Splitter)
762
Matthew Jackson2b8c1da2019-07-04 14:59:16 +0100763DECLARE_LAYER_POLICY_2_PARAM(Stack)
764
Derek Lamberti013c3902019-10-21 10:46:16 +0100765DECLARE_LAYER_POLICY_EXCEPTION_2_PARAM(StandIn)
766
Conor Kennedy430b5d82018-11-14 15:28:28 +0000767DECLARE_LAYER_POLICY_2_PARAM(StridedSlice)
768
Mike Kelly2c14db62023-03-15 15:06:23 +0000769ARMNN_NO_DEPRECATE_WARN_BEGIN
David Beckc2044fe2018-09-05 15:00:38 +0100770DECLARE_LAYER_POLICY_1_PARAM(Subtraction)
Mike Kelly2c14db62023-03-15 15:06:23 +0000771ARMNN_NO_DEPRECATE_WARN_END
telsoa014fcda012018-03-09 14:13:49 +0000772
Sadik Armaganeff363d2019-04-05 15:25:46 +0100773DECLARE_LAYER_POLICY_1_PARAM(Switch)
774
Teresa Charlin79a06a52023-07-13 17:16:45 +0100775DECLARE_LAYER_POLICY_2_PARAM(Tile)
776
Mike Kellyc9ea45a2020-02-28 18:11:58 +0000777DECLARE_LAYER_POLICY_2_PARAM(Transpose)
778
Aron Virginas-Tar639fb042019-06-20 14:28:19 +0100779DECLARE_LAYER_POLICY_2_PARAM(TransposeConvolution2d)
780
Narumol Prangnawarat8ed39ae2021-07-15 16:16:25 +0100781DECLARE_LAYER_POLICY_2_PARAM(UnidirectionalSequenceLstm)
782
Jim Flynn3a40ea52020-10-08 11:42:30 +0100783DECLARE_LAYER_POLICY_MAP_PARAM(Unmap, void)
784
telsoa014fcda012018-03-09 14:13:49 +0000785
786// Generic implementation to get the number of input slots for a given layer type;
787template<armnn::LayerType Type>
788unsigned int GetNumInputs(const armnn::Layer& layer)
789{
790 return layer.GetNumInputSlots();
791}
792
793// Generic implementation to get the number of output slots for a given layer type;
794template<armnn::LayerType Type>
795unsigned int GetNumOutputs(const armnn::Layer& layer)
796{
797 return layer.GetNumOutputSlots();
798}
799
telsoa014fcda012018-03-09 14:13:49 +0000800
telsoa01c577f2c2018-08-31 09:22:23 +0100801// Tests that the IsLayerSupported() function returns the correct value.
802// 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 +0000803// Returns true if expectations are met, otherwise returns false.
804template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type>
805bool IsLayerSupportedTest(FactoryType *factory, Tag<Type>)
806{
807 using LayerPolicy = LayerTypePolicy<Type, DataType>;
808 using LayerType = typename LayerPolicy::Type;
809 using LayerDesc = typename LayerPolicy::Desc;
810 DummyLayer<LayerType, LayerDesc> layer;
811
Derek Lambertib99ef392019-10-21 14:10:38 +0100812 if (LayerPolicy::IsException) //Don't test exceptions to the rule.
813 {
814 return true;
815 }
816
telsoa014fcda012018-03-09 14:13:49 +0000817 unsigned int numIn = GetNumInputs<Type>(*layer.m_Layer);
818 unsigned int numOut = GetNumOutputs<Type>(*layer.m_Layer);
819
telsoa01c577f2c2018-08-31 09:22:23 +0100820 // Make another dummy layer just to make IsLayerSupported have valid inputs.
telsoa014fcda012018-03-09 14:13:49 +0000821 DummyLayer<armnn::ConstantLayer, void> previousLayer;
telsoa01c577f2c2018-08-31 09:22:23 +0100822 // Set output of the previous layer to a dummy tensor.
telsoa014fcda012018-03-09 14:13:49 +0000823 armnn::TensorInfo output = MakeDummyTensorInfo<DataType>();
824 previousLayer.m_Layer->GetOutputSlot(0).SetTensorInfo(output);
telsoa01c577f2c2018-08-31 09:22:23 +0100825 // Connect all outputs of the previous layer to inputs of tested layer.
Narumol Prangnawarat270641b2023-05-22 10:57:47 +0100826 for (unsigned int i = 0; i < numIn; ++i)
telsoa014fcda012018-03-09 14:13:49 +0000827 {
828 armnn::IOutputSlot& previousLayerOutputSlot = previousLayer.m_Layer->GetOutputSlot(0);
829 armnn::IInputSlot& layerInputSlot = layer.m_Layer->GetInputSlot(i);
830 previousLayerOutputSlot.Connect(layerInputSlot);
831 }
telsoa01c577f2c2018-08-31 09:22:23 +0100832 // Set outputs of tested layer to a dummy tensor.
Narumol Prangnawarat270641b2023-05-22 10:57:47 +0100833 for (unsigned int i = 0; i < numOut; ++i)
telsoa014fcda012018-03-09 14:13:49 +0000834 {
Narumol Prangnawarat270641b2023-05-22 10:57:47 +0100835 layer.m_Layer->GetOutputSlot(i).SetTensorInfo(output);
telsoa014fcda012018-03-09 14:13:49 +0000836 }
837
838 std::string layerName = LayerPolicy::NameStr;
839 std::string reasonIfUnsupported;
840 if (FactoryType::IsLayerSupported(*layer.m_Layer, DataType, reasonIfUnsupported))
841 {
842 std::string errorMsg = " layer expected support but found none.";
843 try
844 {
845 bool retVal = LayerPolicy::MakeDummyWorkload(factory, numIn, numOut).get() != nullptr;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100846 CHECK_MESSAGE(retVal, layerName << errorMsg);
telsoa014fcda012018-03-09 14:13:49 +0000847 return retVal;
848 }
telsoa01c577f2c2018-08-31 09:22:23 +0100849 catch(const armnn::InvalidArgumentException& e)
telsoa014fcda012018-03-09 14:13:49 +0000850 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000851 IgnoreUnused(e);
telsoa014fcda012018-03-09 14:13:49 +0000852 // This is ok since we throw InvalidArgumentException when creating the dummy workload.
853 return true;
854 }
855 catch(const std::exception& e)
856 {
857 errorMsg = e.what();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100858 FAIL(layerName << ": " << errorMsg);
telsoa014fcda012018-03-09 14:13:49 +0000859 return false;
860 }
telsoa01c577f2c2018-08-31 09:22:23 +0100861 catch(...)
telsoa014fcda012018-03-09 14:13:49 +0000862 {
863 errorMsg = "Unexpected error while testing support for ";
Sadik Armagan1625efc2021-06-10 18:24:34 +0100864 FAIL(errorMsg << layerName);
telsoa014fcda012018-03-09 14:13:49 +0000865 return false;
866 }
867 }
868 else
869 {
870 std::string errorMsg = "layer expected no support (giving reason: " + reasonIfUnsupported + ") but found some.";
871 try
872 {
873 bool retVal = LayerPolicy::MakeDummyWorkload(factory, numIn, numOut).get() == nullptr;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100874 CHECK_MESSAGE(retVal, layerName << errorMsg);
telsoa014fcda012018-03-09 14:13:49 +0000875 return retVal;
876 }
877 // These two exceptions are ok: For workloads that are partially supported, attempting to instantiate them
878 // using parameters that make IsLayerSupported() return false should throw an
telsoa01c577f2c2018-08-31 09:22:23 +0100879 // InvalidArgumentException or UnimplementedException.
telsoa014fcda012018-03-09 14:13:49 +0000880 catch(const armnn::InvalidArgumentException& e)
881 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000882 IgnoreUnused(e);
telsoa014fcda012018-03-09 14:13:49 +0000883 return true;
884 }
telsoa01c577f2c2018-08-31 09:22:23 +0100885 catch(const armnn::UnimplementedException& e)
telsoa014fcda012018-03-09 14:13:49 +0000886 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000887 IgnoreUnused(e);
telsoa014fcda012018-03-09 14:13:49 +0000888 return true;
889 }
890 catch(const std::exception& e)
891 {
892 errorMsg = e.what();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100893 FAIL(layerName << ": " << errorMsg);
telsoa014fcda012018-03-09 14:13:49 +0000894 return false;
895 }
telsoa01c577f2c2018-08-31 09:22:23 +0100896 catch(...)
telsoa014fcda012018-03-09 14:13:49 +0000897 {
898 errorMsg = "Unexpected error while testing support for ";
Sadik Armagan1625efc2021-06-10 18:24:34 +0100899 FAIL(errorMsg << layerName);
telsoa014fcda012018-03-09 14:13:49 +0000900 return false;
901 }
902 }
903}
904
Jim Flynn68db06f2020-10-06 10:14:50 +0100905template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type>
906bool IsLayerSupportedTest(FactoryType *factory, Tag<armnn::LayerType::Map>)
907{
908 IgnoreUnused(factory);
909 return true;
910}
911
Jim Flynn3a40ea52020-10-08 11:42:30 +0100912template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type>
913bool IsLayerSupportedTest(FactoryType *factory, Tag<armnn::LayerType::Unmap>)
914{
915 IgnoreUnused(factory);
916 return true;
917}
918
telsoa01c577f2c2018-08-31 09:22:23 +0100919// Helper function to compute the next type in the LayerType enum.
telsoa014fcda012018-03-09 14:13:49 +0000920constexpr armnn::LayerType NextType(armnn::LayerType type)
921{
922 return static_cast<armnn::LayerType>(static_cast<int>(type)+1);
923}
924
telsoa01c577f2c2018-08-31 09:22:23 +0100925// Termination function for determining the end of the LayerType enumeration.
telsoa014fcda012018-03-09 14:13:49 +0000926template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type>
927bool IsLayerSupportedTestsImpl(FactoryType *factory, Tag<armnn::LayerType::LastLayer>)
928{
929 return IsLayerSupportedTest<FactoryType, DataType, Type>(factory, Tag<Type>());
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000930}
telsoa014fcda012018-03-09 14:13:49 +0000931
telsoa01c577f2c2018-08-31 09:22:23 +0100932// Recursive function to test and enter in the LayerType enum and then iterate on the next entry.
telsoa014fcda012018-03-09 14:13:49 +0000933template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type>
934bool IsLayerSupportedTestsImpl(FactoryType *factory, Tag<Type>)
935{
936 bool v = IsLayerSupportedTest<FactoryType, DataType, Type>(factory, Tag<Type>());
937
938 return v &&
939 IsLayerSupportedTestsImpl<FactoryType, DataType, NextType(Type)>
940 (factory, Tag<NextType(Type)>());
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000941}
telsoa014fcda012018-03-09 14:13:49 +0000942
943// Helper function to pass through to the test framework.
944template<typename FactoryType, armnn::DataType DataType>
945bool IsLayerSupportedTests(FactoryType *factory)
946{
947 return IsLayerSupportedTestsImpl<FactoryType, DataType>(factory, Tag<armnn::LayerType::FirstLayer>());
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000948}
telsoa014fcda012018-03-09 14:13:49 +0000949
950template<armnn::LayerType Type>
951bool TestLayerTypeMatches()
952{
953 using LayerPolicy = LayerTypePolicy<Type, armnn::DataType::Float32>;
954 using LayerType = typename LayerPolicy::Type;
955 using LayerDesc = typename LayerPolicy::Desc;
956 DummyLayer<LayerType, LayerDesc> layer;
957
958 std::stringstream ss;
959 ss << LayerPolicy::NameStr << " layer type mismatches expected layer type value.";
960 bool v = Type == layer.m_Layer->GetType();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100961 CHECK_MESSAGE(v, ss.str());
telsoa014fcda012018-03-09 14:13:49 +0000962 return v;
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000963}
telsoa014fcda012018-03-09 14:13:49 +0000964
965template<armnn::LayerType Type>
966bool LayerTypeMatchesTestImpl(Tag<armnn::LayerType::LastLayer>)
967{
968 return TestLayerTypeMatches<Type>();
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000969}
telsoa014fcda012018-03-09 14:13:49 +0000970
971template<armnn::LayerType Type>
972bool LayerTypeMatchesTestImpl(Tag<Type>)
973{
974 return TestLayerTypeMatches<Type>() &&
975 LayerTypeMatchesTestImpl<NextType(Type)>(Tag<NextType(Type)>());
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000976}
telsoa014fcda012018-03-09 14:13:49 +0000977
telsoa01c577f2c2018-08-31 09:22:23 +0100978template<typename FactoryType, typename LayerType, armnn::DataType InputDataType , armnn::DataType OutputDataType>
979bool IsConvertLayerSupportedTests(std::string& reasonIfUnsupported)
980{
981 armnn::Graph graph;
982 LayerType* const layer = graph.AddLayer<LayerType>("LayerName");
983
984 armnn::Layer* const input = graph.AddLayer<armnn::InputLayer>(0, "input");
985 armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output");
986
987 armnn::TensorInfo inputTensorInfo({1, 3, 2, 3}, InputDataType);
988 armnn::TensorInfo outputTensorInfo({1, 3, 2, 3}, OutputDataType);
989
990 input->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
991 input->GetOutputHandler(0).SetTensorInfo(inputTensorInfo);
992 layer->GetOutputSlot(0).Connect(output->GetInputSlot(0));
993 layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo);
994
995 bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported);
996
997 return result;
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000998}
telsoa01c577f2c2018-08-31 09:22:23 +0100999
Matthew Bentham1f0ff352019-01-02 13:26:31 +00001000template<typename FactoryType, armnn::DataType InputDataType , armnn::DataType OutputDataType>
James Conroy177df1e2020-11-13 10:18:51 +00001001bool IsLogicalBinaryLayerSupportedTests(std::string& reasonIfUnsupported)
1002{
1003 armnn::Graph graph;
1004 armnn::LogicalBinaryDescriptor desc(armnn::LogicalBinaryOperation::LogicalOr);
1005
1006 armnn::Layer* const input0 = graph.AddLayer<armnn::InputLayer>(0, "input0");
1007 armnn::Layer* const input1 = graph.AddLayer<armnn::InputLayer>(1, "input1");
1008
1009 armnn::Layer* const layer = graph.AddLayer<armnn::LogicalBinaryLayer>(desc, "logicalOrLayer");
1010
1011 armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output1");
1012
1013 armnn::TensorInfo inputTensorInfo0({1, 1, 1, 4}, InputDataType);
1014 armnn::TensorInfo inputTensorInfo1({1, 1, 1, 4}, InputDataType);
1015
1016 armnn::TensorInfo outputTensorInfo({1, 1, 1, 4}, OutputDataType);
1017
1018 input0->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
1019 input1->GetOutputSlot(0).Connect(layer->GetInputSlot(1));
1020
1021 input0->GetOutputHandler(0).SetTensorInfo(inputTensorInfo0);
1022 input1->GetOutputHandler(0).SetTensorInfo(inputTensorInfo1);
1023
1024 layer->GetOutputSlot(0).Connect(output->GetInputSlot(0));
1025 layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo);
1026
1027 bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported);
1028
1029 return result;
1030}
1031
1032template<typename FactoryType, armnn::DataType InputDataType , armnn::DataType OutputDataType>
1033bool IsLogicalBinaryLayerBroadcastSupportedTests(std::string& reasonIfUnsupported)
1034{
1035 armnn::Graph graph;
1036 armnn::LogicalBinaryDescriptor desc(armnn::LogicalBinaryOperation::LogicalAnd);
1037
1038 armnn::Layer* const input0 = graph.AddLayer<armnn::InputLayer>(0, "input0");
1039 armnn::Layer* const input1 = graph.AddLayer<armnn::InputLayer>(1, "input1");
1040
1041 armnn::Layer* const layer = graph.AddLayer<armnn::LogicalBinaryLayer>(desc, "logicalAndLayer");
1042
1043 armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output2");
1044
1045 armnn::TensorInfo inputTensorInfo0({1, 1, 1, 4}, InputDataType);
1046 armnn::TensorInfo inputTensorInfo1({1, 1, 1, 1}, InputDataType);
1047
1048 armnn::TensorInfo outputTensorInfo({1, 1, 1, 4}, OutputDataType);
1049
1050 input0->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
1051 input1->GetOutputSlot(0).Connect(layer->GetInputSlot(1));
1052
1053 input0->GetOutputHandler(0).SetTensorInfo(inputTensorInfo0);
1054 input1->GetOutputHandler(0).SetTensorInfo(inputTensorInfo1);
1055
1056 layer->GetOutputSlot(0).Connect(output->GetInputSlot(0));
1057 layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo);
1058
1059 bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported);
1060
1061 return result;
1062}
1063
1064template<typename FactoryType, armnn::DataType InputDataType , armnn::DataType OutputDataType>
Matthew Bentham1f0ff352019-01-02 13:26:31 +00001065bool IsMeanLayerSupportedTests(std::string& reasonIfUnsupported)
1066{
1067 armnn::Graph graph;
1068 static const std::vector<unsigned> axes = {1, 0};
1069 armnn::MeanDescriptor desc(axes, false);
1070
1071 armnn::Layer* const layer = graph.AddLayer<armnn::MeanLayer>(desc, "LayerName");
1072
1073 armnn::Layer* const input = graph.AddLayer<armnn::InputLayer>(0, "input");
1074 armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output");
1075
1076 armnn::TensorInfo inputTensorInfo({4, 3, 2}, InputDataType);
1077 armnn::TensorInfo outputTensorInfo({2}, OutputDataType);
1078
1079 input->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
1080 input->GetOutputHandler(0).SetTensorInfo(inputTensorInfo);
1081 layer->GetOutputSlot(0).Connect(output->GetInputSlot(0));
1082 layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo);
1083
1084 bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported);
1085
1086 return result;
1087}
1088
James Conroy4d1ff582019-06-10 17:06:39 +01001089// Tests that IsMeanSupported fails when input tensor dimensions
1090// do not match output tensor dimensions when keepDims == true
1091template<typename FactoryType, armnn::DataType InputDataType , armnn::DataType OutputDataType>
1092bool IsMeanLayerNotSupportedTests(std::string& reasonIfUnsupported)
1093{
1094 armnn::Graph graph;
1095 static const std::vector<unsigned> axes = {};
1096 // Set keepDims == true
1097 armnn::MeanDescriptor desc(axes, true);
1098
1099 armnn::Layer* const layer = graph.AddLayer<armnn::MeanLayer>(desc, "LayerName");
1100
1101 armnn::Layer* const input = graph.AddLayer<armnn::InputLayer>(0, "input");
1102 armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output");
1103
1104 // Mismatching number of tensor dimensions
1105 armnn::TensorInfo inputTensorInfo({1, 1, 1, 1}, InputDataType);
1106 armnn::TensorInfo outputTensorInfo({1, 1}, OutputDataType);
1107
1108 input->GetOutputSlot(0).Connect(layer->GetInputSlot(0));
1109 input->GetOutputHandler(0).SetTensorInfo(inputTensorInfo);
1110 layer->GetOutputSlot(0).Connect(output->GetInputSlot(0));
1111 layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo);
1112
1113 bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported);
1114
1115 return result;
1116}
1117
Mike Kelly0886ac42020-04-27 09:55:40 +01001118template<typename FactoryType, armnn::DataType OutputDataType>
1119bool IsConstantLayerSupportedTests(std::string& reasonIfUnsupported)
1120{
1121 armnn::Graph graph;
1122
1123 armnn::Layer* const layer = graph.AddLayer<armnn::ConstantLayer>("ConstantLayerName");
1124 armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "OutputLayerName");
1125
1126 armnn::TensorInfo outputTensorInfo({1, 1}, OutputDataType);
1127
1128 layer->GetOutputSlot(0).Connect(output->GetInputSlot(0));
1129 layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo);
1130
1131 bool result = FactoryType::IsLayerSupported(*layer, OutputDataType, reasonIfUnsupported);
1132
1133 return result;
1134}
Matthew Bentham1f0ff352019-01-02 13:26:31 +00001135
telsoa014fcda012018-03-09 14:13:49 +00001136} //namespace