blob: 28d7753973b73d996f88b5b588a3e6ec9f83181d [file] [log] [blame]
Francis Murtagh9270d9e2022-08-12 13:54:17 +01001//
Tracy Narine10403ec2023-11-28 11:55:08 +00002// Copyright © 2022-2024 Arm Ltd and Contributors. All rights reserved.
Francis Murtagh9270d9e2022-08-12 13:54:17 +01003// SPDX-License-Identifier: MIT
4//
5
6
7#include <armnn/Optional.hpp>
8#include <armnn/Types.hpp>
9#include <tosaReference/TosaRefLayerSupport.hpp>
10
11#include <doctest/doctest.h>
12
13#include <string>
14
Cathal Corbettb30e6552022-12-07 11:50:50 +000015using namespace armnn;
16
Francis Murtagh9270d9e2022-08-12 13:54:17 +010017TEST_SUITE("TosaRefLayerSupported")
18{
19
20TEST_CASE("IsLayerSupportedTosaReferenceAddition")
21{
Cathal Corbettb30e6552022-12-07 11:50:50 +000022 TensorShape shape0 = {1,1,3,4};
Matthew Sloyan67fd5262022-12-07 19:28:18 +000023 TensorShape shape1 = {1,1,3,4};
Cathal Corbettb30e6552022-12-07 11:50:50 +000024 TensorShape outShape = {1,1,3,4};
25 TensorInfo in0(shape0, DataType::Float32);
26 TensorInfo in1(shape1, DataType::Float32);
27 TensorInfo out(outShape, DataType::Float32);
Francis Murtagh9270d9e2022-08-12 13:54:17 +010028
Cathal Corbettb30e6552022-12-07 11:50:50 +000029 BaseDescriptor desc;
30 TosaRefLayerSupport supportChecker;
Francis Murtagh9270d9e2022-08-12 13:54:17 +010031 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +000032 auto supported = supportChecker.IsLayerSupported(LayerType::Addition,
Francis Murtagh9270d9e2022-08-12 13:54:17 +010033 {in0, in1, out},
34 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +000035 EmptyOptional(),
36 EmptyOptional(),
Francis Murtagh9270d9e2022-08-12 13:54:17 +010037 reasonIfNotSupported);
38
39 CHECK(supported);
40}
41
42TEST_CASE("IsLayerSupportedTosaReferenceAdditionUnsupported")
43{
Cathal Corbettb30e6552022-12-07 11:50:50 +000044 TensorShape shape0 = {1,1,3,4};
45 TensorShape shape1 = {4};
46 TensorShape outShape = {1,1,3,4};
47 TensorInfo in0(shape0, DataType::Signed64);
48 TensorInfo in1(shape1, DataType::Signed64);
49 TensorInfo out(outShape, DataType::Signed64);
Francis Murtagh9270d9e2022-08-12 13:54:17 +010050
Cathal Corbettb30e6552022-12-07 11:50:50 +000051 BaseDescriptor desc;
52 TosaRefLayerSupport supportChecker;
Francis Murtagh9270d9e2022-08-12 13:54:17 +010053 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +000054 auto supported = supportChecker.IsLayerSupported(LayerType::Addition,
Francis Murtagh9270d9e2022-08-12 13:54:17 +010055 {in0, in1, out},
56 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +000057 EmptyOptional(),
58 EmptyOptional(),
Francis Murtagh9270d9e2022-08-12 13:54:17 +010059 reasonIfNotSupported);
60
61 CHECK(!supported);
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000062}
63
Kevin May5b58e312022-12-15 10:15:21 +000064TEST_CASE("IsLayerSupportedTosaReferenceConcat")
65{
66 TensorShape input0Shape = { 2, 3, 2, 2 };
67 TensorShape input1Shape = { 2, 3, 2, 2 };
68 TensorShape outputShape = { 2, 6, 2, 2 };
69 TensorInfo input0Info(input0Shape, DataType::Float32);
70 TensorInfo input1Info(input1Shape, DataType::Float32);
71 TensorInfo outputInfo(outputShape, DataType::Float32);
72
73 OriginsDescriptor descriptor;
74 std::vector<TensorShape> shapes = {input0Shape, input1Shape} ;
75 unsigned int concatAxis = 1;
76 descriptor = CreateDescriptorForConcatenation(shapes.begin(), shapes.end(), concatAxis);
77
78 TosaRefLayerSupport supportChecker;
79 std::string reasonIfNotSupported;
80 auto supported = supportChecker.IsLayerSupported(LayerType::Concat,
81 {input0Info, input1Info, outputInfo},
82 descriptor,
83 EmptyOptional(),
84 EmptyOptional(),
85 reasonIfNotSupported);
86
87 CHECK(supported);
88}
89
90TEST_CASE("IsLayerSupportedTosaReferenceConcatUnsupported")
91{
92 TensorShape input0Shape = { 2, 3, 2, 2 };
93 TensorShape input1Shape = { 2, 3, 2, 2 };
94 TensorShape outputShape = { 2, 6, 2, 2 };
95 TensorInfo input0Info(input0Shape, armnn::DataType::QAsymmU8);
96 TensorInfo input1Info(input1Shape, armnn::DataType::QAsymmU8);
97 TensorInfo outputInfo(outputShape, armnn::DataType::QAsymmU8);
98
99 OriginsDescriptor descriptor;
100 std::vector<armnn::TensorShape> shapes = {input0Shape, input1Shape} ;
101 unsigned int concatAxis = 1;
102 descriptor = armnn::CreateDescriptorForConcatenation(shapes.begin(), shapes.end(), concatAxis);
103
104 TosaRefLayerSupport supportChecker;
105 std::string reasonIfNotSupported;
106 auto supported = supportChecker.IsLayerSupported(LayerType::Concat,
107 {input0Info, input1Info, outputInfo},
108 descriptor,
109 EmptyOptional(),
110 EmptyOptional(),
111 reasonIfNotSupported);
112
113 CHECK(!supported);
114}
115
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000116TEST_CASE("IsLayerSupportedTosaReferenceConstant")
117{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000118 TensorInfo outputInfo({1,1,3,4}, DataType::Float32);
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000119
Cathal Corbettb30e6552022-12-07 11:50:50 +0000120 TosaRefLayerSupport supportChecker;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000121 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000122 auto supported = supportChecker.IsLayerSupported(LayerType::Constant,
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000123 {outputInfo},
Cathal Corbettb30e6552022-12-07 11:50:50 +0000124 BaseDescriptor(),
125 EmptyOptional(),
126 EmptyOptional(),
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000127 reasonIfNotSupported);
128
129 CHECK(supported);
130}
131
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000132TEST_CASE("IsLayerSupportedTosaReferenceConv2d")
133{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000134 TensorInfo inputInfo ({ 1, 5, 5, 1 }, DataType::Float32);
135 TensorInfo outputInfo({ 1, 3, 3, 1 }, DataType::Float32);
136 TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32);
137 TensorInfo biasesInfo ({ 1 }, DataType::Float32);
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000138
Cathal Corbettb30e6552022-12-07 11:50:50 +0000139 Convolution2dDescriptor desc;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000140 desc.m_BiasEnabled = true;
141
Cathal Corbettb30e6552022-12-07 11:50:50 +0000142 TosaRefLayerSupport supportChecker;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000143 std::string reasonIfNotSupported;
Matthew Sloyanfc9d5e72022-12-08 13:38:23 +0000144 auto supported = supportChecker.IsLayerSupported(LayerType::Convolution2d,
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000145 {inputInfo, outputInfo, weightsInfo, biasesInfo},
146 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000147 EmptyOptional(),
148 EmptyOptional(),
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000149 reasonIfNotSupported);
150
151 CHECK(supported);
152}
153
154TEST_CASE("IsLayerSupportedTosaReferenceConv2dUnsupported")
155{
156 // If inputs and weights are Fp32, output must match.
Cathal Corbettb30e6552022-12-07 11:50:50 +0000157 TensorInfo inputInfo ({ 1, 5, 5, 1 }, DataType::Float32);
158 TensorInfo outputInfo({ 1, 3, 3, 1 }, DataType::Signed64);
159 TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32, 0.0f, 0, true);
160 TensorInfo biasesInfo ({ 1 }, DataType::Float32, 0.0f, 0, true);
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000161
Cathal Corbettb30e6552022-12-07 11:50:50 +0000162 Convolution2dDescriptor desc;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000163 desc.m_BiasEnabled = true;
164
Cathal Corbettb30e6552022-12-07 11:50:50 +0000165 TosaRefLayerSupport supportChecker;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000166 std::string reasonIfNotSupported;
Matthew Sloyanfc9d5e72022-12-08 13:38:23 +0000167 auto supported = supportChecker.IsLayerSupported(LayerType::Convolution2d,
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000168 {inputInfo, outputInfo, weightsInfo, biasesInfo},
169 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000170 EmptyOptional(),
171 EmptyOptional(),
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000172 reasonIfNotSupported);
173
174 CHECK(!supported);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000175}
176
Nikhil Raj9a339462022-12-05 11:24:35 +0000177TEST_CASE("IsLayerSupportedTosaReferenceMultiplication")
178{
179 TensorShape shape0 = {1,1,3,4};
180 TensorShape shape1 = {1,1,3,4};
181 TensorShape outShape = {1,1,3,4};
182 TensorInfo in0(shape0, armnn::DataType::Float32);
183 TensorInfo in1(shape1, armnn::DataType::Float32);
184 TensorInfo out(outShape, armnn::DataType::Float32);
185
186 BaseDescriptor desc;
187 TosaRefLayerSupport supportChecker;
188 std::string reasonIfNotSupported;
189 auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Multiplication,
190 {in0, in1, out},
191 desc,
192 armnn::EmptyOptional(),
193 armnn::EmptyOptional(),
194 reasonIfNotSupported);
195
196 CHECK(supported);
197}
198
199TEST_CASE("IsLayerSupportedTosaReferenceMultiplicationUnsupported")
200{
201 TensorShape shape0 = {1,1,3,4};
202 TensorShape shape1 = {1,2,3,4};
203 TensorShape outShape = {1,1,3,4};
204 TensorInfo in0(shape0, armnn::DataType::Signed64);
205 TensorInfo in1(shape1, armnn::DataType::Signed64);
206 TensorInfo out(outShape, armnn::DataType::Signed64);
207
208 BaseDescriptor desc;
209 TosaRefLayerSupport supportChecker;
210 std::string reasonIfNotSupported;
211 auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Multiplication,
212 {in0, in1, out},
213 desc,
214 armnn::EmptyOptional(),
215 armnn::EmptyOptional(),
216 reasonIfNotSupported);
217
218 CHECK(!supported);
219}
220
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000221TEST_CASE("IsLayerSupportedTosaReferenceMaxPooling2d")
222{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000223 TensorShape inShape = {1,1,3,4};
224 TensorShape outShape = {1,1,3,4};
225 TensorInfo in(inShape, DataType::Float32);
226 TensorInfo out(outShape, DataType::Float32);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000227
Cathal Corbettb30e6552022-12-07 11:50:50 +0000228 Pooling2dDescriptor desc;
Matthew Sloyan67fd5262022-12-07 19:28:18 +0000229 desc.m_PoolHeight = 1;
230 desc.m_PoolWidth = 1;
231 desc.m_StrideX = 1;
232 desc.m_StrideY = 1;
Matthew Sloyanfc9d5e72022-12-08 13:38:23 +0000233 desc.m_PoolType = PoolingAlgorithm::Max;
Matthew Sloyan67fd5262022-12-07 19:28:18 +0000234
Cathal Corbettb30e6552022-12-07 11:50:50 +0000235 TosaRefLayerSupport supportChecker;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000236 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000237 auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d,
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000238 {in, out},
239 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000240 EmptyOptional(),
241 EmptyOptional(),
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000242 reasonIfNotSupported);
243
244 CHECK(supported);
245}
246
247TEST_CASE("IsLayerSupportedTosaReferenceAvgPooling2d_IgnoreValue")
248{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000249 TensorShape inShape = {1,1,3,4};
250 TensorShape outShape = {1,1,3,4};
251 TensorInfo in(inShape, DataType::Float32);
252 TensorInfo out(outShape, DataType::Float32);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000253
Cathal Corbettb30e6552022-12-07 11:50:50 +0000254 Pooling2dDescriptor desc;
Matthew Sloyan67fd5262022-12-07 19:28:18 +0000255 desc.m_PoolHeight = 1;
256 desc.m_PoolWidth = 1;
257 desc.m_StrideX = 1;
258 desc.m_StrideY = 1;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000259 desc.m_PaddingMethod = PaddingMethod::IgnoreValue;
260 desc.m_PoolType = PoolingAlgorithm::Average;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000261
Cathal Corbettb30e6552022-12-07 11:50:50 +0000262 TosaRefLayerSupport supportChecker;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000263 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000264 auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d,
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000265 {in, out},
266 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000267 EmptyOptional(),
268 EmptyOptional(),
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000269 reasonIfNotSupported);
270
271 CHECK(supported);
272}
273
Tracy Narine10403ec2023-11-28 11:55:08 +0000274TEST_CASE("IsLayerSupportedTosaReferenceLeakyReLuActivation")
275{
276 TensorInfo inputInfo1({1,1,3,4}, DataType::Float32);
277 TensorInfo inputInfo2({1,1,3,4}, DataType::Float32);
278 TensorInfo outputInfo({1,1,3,4}, DataType::Float32);
279
280 TosaRefLayerSupport supportChecker;
281 std::string reasonIfNotSupported;
282 ActivationDescriptor descriptor;
283 descriptor.m_Function = ActivationFunction::LeakyReLu;
284 auto supported = supportChecker.IsLayerSupported(LayerType::Activation,
285 {inputInfo1, inputInfo2, outputInfo},
286 descriptor,
287 EmptyOptional(),
288 EmptyOptional(),
289 reasonIfNotSupported);
290
291 CHECK(supported);
292}
293
294TEST_CASE("IsLayerSupportedTosaReferenceActivationUnsupported")
295{
296 TensorInfo inputInfo1({1,1,3,4}, DataType::Float32);
297 TensorInfo inputInfo2({1,1,3,4}, DataType::Float32);
298 TensorInfo outputInfo({1,1,3,4}, DataType::Float32);
299
300 TosaRefLayerSupport supportChecker;
301 std::string reasonIfNotSupported;
302 ActivationDescriptor descriptor;
303 descriptor.m_Function = ActivationFunction::HardSwish;
304 auto supported = supportChecker.IsLayerSupported(LayerType::Activation,
305 {inputInfo1, inputInfo2, outputInfo},
306 descriptor,
307 EmptyOptional(),
308 EmptyOptional(),
309 reasonIfNotSupported);
310
311 CHECK(!supported);
312}
313
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000314TEST_CASE("IsLayerSupportedTosaReferenceMaxPooling2dUnsupported")
315{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000316 TensorShape inShape = {1,1,3,4};
317 TensorShape outShape = {1,1,3,4};
318 TensorInfo in(inShape, DataType::Signed64);
319 TensorInfo out(outShape, DataType::Signed64);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000320
Cathal Corbettb30e6552022-12-07 11:50:50 +0000321 Pooling2dDescriptor desc;
322 TosaRefLayerSupport supportChecker;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000323 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000324 auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d,
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000325 {in, out},
326 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000327 EmptyOptional(),
328 EmptyOptional(),
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000329 reasonIfNotSupported);
330
331 CHECK(!supported);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000332}
333
334TEST_CASE("IsLayerSupportedTosaReferenceAvgPooling2dUnsupported_InputOutputDatatypeDifferent")
335{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000336 TensorShape inShape = {1,1,3,4};
337 TensorShape outShape = {1,1,3,4};
338 TensorInfo in(inShape, DataType::Float32);
339 TensorInfo out(outShape, DataType::Float16);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000340
Cathal Corbettb30e6552022-12-07 11:50:50 +0000341 Pooling2dDescriptor desc;
342 desc.m_PaddingMethod = PaddingMethod::IgnoreValue;
343 desc.m_PoolType = PoolingAlgorithm::Average;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000344
Cathal Corbettb30e6552022-12-07 11:50:50 +0000345 TosaRefLayerSupport supportChecker;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000346 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000347 auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d,
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000348 {in, out},
349 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000350 EmptyOptional(),
351 EmptyOptional(),
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000352 reasonIfNotSupported);
353
354 CHECK(!supported);
Cathal Corbettb30e6552022-12-07 11:50:50 +0000355}
356
357TEST_CASE("IsLayerSupportedTosaReferenceReshape")
358{
359 TensorShape inShape = {3,4};
360 TensorShape outShape = {12};
361 TensorInfo in(inShape, DataType::Float32);
362 TensorInfo out(outShape, DataType::Float32);
363
364 ReshapeDescriptor desc;
365 desc.m_TargetShape = {12};
366
367 TosaRefLayerSupport supportChecker;
368 std::string reasonIfNotSupported;
369 auto supported = supportChecker.IsLayerSupported(LayerType::Reshape,
370 {in, out},
371 desc,
372 EmptyOptional(),
373 EmptyOptional(),
374 reasonIfNotSupported);
375
376 CHECK(supported);
377}
378
Teresa Charlince655882023-11-21 15:44:13 +0000379TEST_CASE("IsLayerSupportedTosaReferenceResize")
380{
381 TensorShape inShape = { 1, 720, 1280, 3 };
382 TensorShape outShape = { 1, 1080, 1920, 3 };
383 TensorInfo in(inShape, DataType::Float32);
384 TensorInfo out(outShape, DataType::Float32);
385
386 ResizeDescriptor descriptor;
387 descriptor.m_DataLayout = armnn::DataLayout::NHWC;
388 descriptor.m_TargetHeight = 1080;
389 descriptor.m_TargetWidth = 1920;
390
391 TosaRefLayerSupport supportChecker;
392 std::string reasonIfNotSupported;
393 auto supported = supportChecker.IsLayerSupported(LayerType::Resize,
394 {in, out},
395 descriptor,
396 EmptyOptional(),
397 EmptyOptional(),
398 reasonIfNotSupported);
399
400 CHECK(supported);
401}
402
Cathal Corbettb30e6552022-12-07 11:50:50 +0000403TEST_CASE("IsLayerSupportedTosaReferenceReshapeUnsupported")
404{
405 TensorShape inShape = {3,4};
406 TensorShape outShape = {12};
407 TensorInfo in(inShape, DataType::Signed64);
408 TensorInfo out(outShape, DataType::Signed64);
409
410 ReshapeDescriptor desc;
411 desc.m_TargetShape = {12};
412
413 TosaRefLayerSupport supportChecker;
414 std::string reasonIfNotSupported;
415 auto supported = supportChecker.IsLayerSupported(LayerType::Reshape,
416 {in, out},
417 desc,
418 EmptyOptional(),
419 EmptyOptional(),
420 reasonIfNotSupported);
421
422 CHECK(!supported);
Francis Murtagh9270d9e2022-08-12 13:54:17 +0100423}
424
David Monahand7fca092023-01-12 14:53:34 +0000425TEST_CASE("IsLayerSupportedTosaReferenceRsqrt")
426{
427 TensorShape shape0 = {2,2};
428 TensorShape outShape = {2,2};
429 TensorInfo in0(shape0, DataType::Float32);
430 TensorInfo out(outShape, DataType::Float32);
431
432 ElementwiseUnaryDescriptor desc(UnaryOperation::Rsqrt);
433 TosaRefLayerSupport supportChecker;
434 std::string reasonIfNotSupported;
435 auto supported = supportChecker.IsLayerSupported(LayerType::ElementwiseUnary,
436 {in0, out},
437 desc,
438 EmptyOptional(),
439 EmptyOptional(),
440 reasonIfNotSupported);
441
442 CHECK(supported);
443}
444
445TEST_CASE("IsLayerSupportedTosaReferenceRsqrtUnsupported")
446{
447 TensorShape shape0 = {1,1,3,4};
448 TensorShape outShape = {1,3,1,4};
449 TensorInfo in0(shape0, DataType::Signed64);
450 TensorInfo out(outShape, DataType::Signed64);
451
452 ElementwiseUnaryDescriptor desc(UnaryOperation::Rsqrt);
453 TosaRefLayerSupport supportChecker;
454 std::string reasonIfNotSupported;
455 auto supported = supportChecker.IsLayerSupported(LayerType::ElementwiseUnary,
456 {in0, out},
457 desc,
458 EmptyOptional(),
459 EmptyOptional(),
460 reasonIfNotSupported);
461
462 CHECK(!supported);
463}
464
Cathal Corbett3b9acd52022-12-09 12:17:27 +0000465TEST_CASE("IsLayerSupportedTosaReferenceSlice")
466{
467 TensorShape inShape = {3,2,3};
468 TensorShape outShape = {2,1,3};
469 TensorInfo in(inShape, DataType::Float32);
470 TensorInfo out(outShape, DataType::Float32);
471
472 SliceDescriptor descriptor;
473 descriptor.m_Begin = {1,0,0 };
474 descriptor.m_Size = {2,1,3 };
475
476 TosaRefLayerSupport supportChecker;
477 std::string reasonIfNotSupported;
478 auto supported = supportChecker.IsLayerSupported(LayerType::Slice,
479 {in, out},
480 descriptor,
481 EmptyOptional(),
482 EmptyOptional(),
483 reasonIfNotSupported);
484
485 CHECK(supported);
486}
487
488TEST_CASE("IsLayerSupportedTosaReferenceSliceUnsupported")
489{
490 TensorShape inShape = {3,2,3};
491 TensorShape outShape = {2,1,3};
492 TensorInfo in(inShape, DataType::Signed64);
493 TensorInfo out(outShape, DataType::Signed64);
494
495 SliceDescriptor descriptor;
496 descriptor.m_Begin = {1,0,0};
497 descriptor.m_Size = {2,1,3};
498
499 TosaRefLayerSupport supportChecker;
500 std::string reasonIfNotSupported;
501 auto supported = supportChecker.IsLayerSupported(LayerType::Slice,
502 {in, out},
503 descriptor,
504 EmptyOptional(),
505 EmptyOptional(),
506 reasonIfNotSupported);
507
508 CHECK(!supported);
Cathal Corbett3b9acd52022-12-09 12:17:27 +0000509}
510
Kevin May1bea6be2023-12-12 11:18:46 +0000511TEST_CASE("IsLayerSupportedTosaReferenceSplit")
512{
513 TensorShape inShape = {1, 18, 4, 4};
514 TensorShape outShape = {1, 6, 4, 4};
515 TensorInfo in(inShape, DataType::Float32);
516 TensorInfo out(outShape, DataType::Float32);
517
518 const unsigned int numViews = 3;
519 const unsigned int numDimensions = 4;
520 armnn::SplitterDescriptor descriptor(numViews, numDimensions);
521 descriptor.SetAxis(static_cast<int32_t>(1));
522
523 TosaRefLayerSupport supportChecker;
524 std::string reasonIfNotSupported;
525 auto supported = supportChecker.IsLayerSupported(LayerType::Splitter,
Teresa Charlin7db70892024-04-23 13:43:03 +0100526 {in, out, out, out},
Kevin May1bea6be2023-12-12 11:18:46 +0000527 descriptor,
528 EmptyOptional(),
529 EmptyOptional(),
530 reasonIfNotSupported);
531
532 CHECK(supported);
533}
534
535TEST_CASE("IsLayerSupportedTosaReferenceSplitUnsupported")
536{
537 TensorShape inShape = {1, 18, 4, 4};
538 TensorShape outShape = {1, 6, 4, 4};
539 TensorInfo in(inShape, DataType::Signed64);
540 TensorInfo out(outShape, DataType::Signed64);
541
542 const unsigned int numViews = 3;
543 const unsigned int numDimensions = 4;
544 armnn::SplitterDescriptor descriptor(numViews, numDimensions);
545 descriptor.SetAxis(static_cast<int32_t>(1));
546
547 TosaRefLayerSupport supportChecker;
548 std::string reasonIfNotSupported;
549 auto supported = supportChecker.IsLayerSupported(LayerType::Splitter,
Teresa Charlin7db70892024-04-23 13:43:03 +0100550 {in, out, out, out},
Kevin May1bea6be2023-12-12 11:18:46 +0000551 descriptor,
552 EmptyOptional(),
553 EmptyOptional(),
554 reasonIfNotSupported);
555
556 CHECK(!supported);
557}
558
Nikhil Raj9a339462022-12-05 11:24:35 +0000559TEST_CASE("IsLayerSupportedTosaReferenceSubtraction")
560{
561 TensorShape shape0 = {1,1,3,4};
562 TensorShape shape1 = {1,1,3,4};
563 TensorShape outShape = {1,1,3,4};
564 TensorInfo in0(shape0, armnn::DataType::Float32);
565 TensorInfo in1(shape1, armnn::DataType::Float32);
566 TensorInfo out(outShape, armnn::DataType::Float32);
567
568 BaseDescriptor desc;
569 TosaRefLayerSupport supportChecker;
570 std::string reasonIfNotSupported;
571 auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Subtraction,
572 {in0, in1, out},
573 desc,
574 armnn::EmptyOptional(),
575 armnn::EmptyOptional(),
576 reasonIfNotSupported);
577
578 CHECK(supported);
579}
580
581TEST_CASE("IsLayerSupportedTosaReferenceSubtractionUnsupported")
582{
583 TensorShape shape0 = {1,1,3,4};
584 TensorShape shape1 = {4};
585 TensorShape outShape = {1,1,3,4};
586 TensorInfo in0(shape0, armnn::DataType::Signed64);
587 TensorInfo in1(shape1, armnn::DataType::Signed64);
588 TensorInfo out(outShape, armnn::DataType::Signed64);
589
590 BaseDescriptor desc;
591 TosaRefLayerSupport supportChecker;
592 std::string reasonIfNotSupported;
593 auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Subtraction,
594 {in0, in1, out},
595 desc,
596 armnn::EmptyOptional(),
597 armnn::EmptyOptional(),
598 reasonIfNotSupported);
599
600 CHECK(!supported);
601}
602
Matthew Sloyanfc9d5e72022-12-08 13:38:23 +0000603TEST_CASE("IsLayerSupportedTosaReferenceTransposeConv2d")
604{
605 TensorInfo inputInfo ({ 1, 3, 3, 1 }, DataType::Float32);
606 TensorInfo outputInfo({ 1, 5, 5, 1 }, DataType::Float32);
607 TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32);
608 TensorInfo biasesInfo ({ 1 }, DataType::Float32);
609
610 TransposeConvolution2dDescriptor desc;
611 desc.m_StrideX = 1;
612 desc.m_StrideY = 1;
613 desc.m_BiasEnabled = true;
614
615 TosaRefLayerSupport supportChecker;
616 std::string reasonIfNotSupported;
617 auto supported = supportChecker.IsLayerSupported(LayerType::TransposeConvolution2d,
618 {inputInfo, outputInfo, weightsInfo, biasesInfo},
619 desc,
620 EmptyOptional(),
621 EmptyOptional(),
622 reasonIfNotSupported);
623 CHECK(supported);
624}
625
626TEST_CASE("IsLayerSupportedTosaReferenceTransposeConv2dUnsupported")
627{
628 // If inputs and weights are Fp32, output must match.
629 TensorInfo inputInfo ({ 1, 3, 3, 1 }, DataType::Float32);
630 TensorInfo outputInfo({ 1, 5, 5, 1 }, DataType::Float32);
631 TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32, 0.0f, 0, true);
632 TensorInfo biasesInfo ({ 1 }, DataType::Float32, 0.0f, 0, true);
633
634 TransposeConvolution2dDescriptor desc;
635 desc.m_BiasEnabled = true;
636
637 TosaRefLayerSupport supportChecker;
638 std::string reasonIfNotSupported;
639 auto supported = supportChecker.IsLayerSupported(LayerType::TransposeConvolution2d,
640 {inputInfo, outputInfo, weightsInfo, biasesInfo},
641 desc,
642 EmptyOptional(),
643 EmptyOptional(),
644 reasonIfNotSupported);
645 CHECK(!supported);
646}
647
Cathal Corbett0bb096d2022-12-22 13:09:38 +0000648TEST_CASE("IsLayerSupportedTosaReferenceTranspose")
649{
650 TensorShape inShape = { 1, 1, 5, 3 };
651 TensorShape outShape = { 1, 5, 1, 3 };
652 TensorInfo in(inShape, DataType::Float32);
653 TensorInfo out(outShape, DataType::Float32);
654
655 TransposeDescriptor transposeDescriptor = TransposeDescriptor({ 0, 2, 1 ,3 });
656
657 TosaRefLayerSupport supportChecker;
658 std::string reasonIfNotSupported;
659 auto supported = supportChecker.IsLayerSupported(LayerType::Transpose,
660 {in, out},
661 transposeDescriptor,
662 EmptyOptional(),
663 EmptyOptional(),
664 reasonIfNotSupported);
665
666 CHECK(supported);
667}
668
669TEST_CASE("IsLayerSupportedTosaReferenceTransposeUnsupported")
670{
671 TensorShape inShape = { 1, 1, 5, 3 };
672 TensorShape outShape = { 1, 5, 1, 3 };
673 TensorInfo in(inShape, DataType::Signed64);
674 TensorInfo out(outShape, DataType::Signed64);
675
676 TransposeDescriptor transposeDescriptor = TransposeDescriptor({ 0, 2, 1 ,3 });
677
678 TosaRefLayerSupport supportChecker;
679 std::string reasonIfNotSupported;
680 auto supported = supportChecker.IsLayerSupported(LayerType::Transpose,
681 {in, out},
682 transposeDescriptor,
683 EmptyOptional(),
684 EmptyOptional(),
685 reasonIfNotSupported);
686
687 CHECK(!supported);
688}
689
Francis Murtagh9270d9e2022-08-12 13:54:17 +0100690}