blob: 6f038ab69bdc844bf3a08f25aac252cbb12e9364 [file] [log] [blame]
Francis Murtagh9270d9e2022-08-12 13:54:17 +01001//
David Monahand7fca092023-01-12 14:53:34 +00002// Copyright © 2022-2023 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
132TEST_CASE("IsLayerSupportedTosaReferenceConstantUnsupported")
133{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000134 TensorInfo outputInfo({1,1,3,4}, DataType::Signed64);
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000135
Cathal Corbettb30e6552022-12-07 11:50:50 +0000136 TosaRefLayerSupport supportChecker;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000137 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000138 auto supported = supportChecker.IsLayerSupported(LayerType::Constant,
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000139 {outputInfo},
Cathal Corbettb30e6552022-12-07 11:50:50 +0000140 BaseDescriptor(),
141 EmptyOptional(),
142 EmptyOptional(),
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000143 reasonIfNotSupported);
144
145 CHECK(!supported);
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000146}
147
148TEST_CASE("IsLayerSupportedTosaReferenceConv2d")
149{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000150 TensorInfo inputInfo ({ 1, 5, 5, 1 }, DataType::Float32);
151 TensorInfo outputInfo({ 1, 3, 3, 1 }, DataType::Float32);
152 TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32);
153 TensorInfo biasesInfo ({ 1 }, DataType::Float32);
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000154
Cathal Corbettb30e6552022-12-07 11:50:50 +0000155 Convolution2dDescriptor desc;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000156 desc.m_BiasEnabled = true;
157
Cathal Corbettb30e6552022-12-07 11:50:50 +0000158 TosaRefLayerSupport supportChecker;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000159 std::string reasonIfNotSupported;
Matthew Sloyanfc9d5e72022-12-08 13:38:23 +0000160 auto supported = supportChecker.IsLayerSupported(LayerType::Convolution2d,
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000161 {inputInfo, outputInfo, weightsInfo, biasesInfo},
162 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000163 EmptyOptional(),
164 EmptyOptional(),
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000165 reasonIfNotSupported);
166
167 CHECK(supported);
168}
169
170TEST_CASE("IsLayerSupportedTosaReferenceConv2dUnsupported")
171{
172 // If inputs and weights are Fp32, output must match.
Cathal Corbettb30e6552022-12-07 11:50:50 +0000173 TensorInfo inputInfo ({ 1, 5, 5, 1 }, DataType::Float32);
174 TensorInfo outputInfo({ 1, 3, 3, 1 }, DataType::Signed64);
175 TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32, 0.0f, 0, true);
176 TensorInfo biasesInfo ({ 1 }, DataType::Float32, 0.0f, 0, true);
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000177
Cathal Corbettb30e6552022-12-07 11:50:50 +0000178 Convolution2dDescriptor desc;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000179 desc.m_BiasEnabled = true;
180
Cathal Corbettb30e6552022-12-07 11:50:50 +0000181 TosaRefLayerSupport supportChecker;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000182 std::string reasonIfNotSupported;
Matthew Sloyanfc9d5e72022-12-08 13:38:23 +0000183 auto supported = supportChecker.IsLayerSupported(LayerType::Convolution2d,
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000184 {inputInfo, outputInfo, weightsInfo, biasesInfo},
185 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000186 EmptyOptional(),
187 EmptyOptional(),
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000188 reasonIfNotSupported);
189
190 CHECK(!supported);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000191}
192
Nikhil Raj9a339462022-12-05 11:24:35 +0000193TEST_CASE("IsLayerSupportedTosaReferenceMultiplication")
194{
195 TensorShape shape0 = {1,1,3,4};
196 TensorShape shape1 = {1,1,3,4};
197 TensorShape outShape = {1,1,3,4};
198 TensorInfo in0(shape0, armnn::DataType::Float32);
199 TensorInfo in1(shape1, armnn::DataType::Float32);
200 TensorInfo out(outShape, armnn::DataType::Float32);
201
202 BaseDescriptor desc;
203 TosaRefLayerSupport supportChecker;
204 std::string reasonIfNotSupported;
205 auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Multiplication,
206 {in0, in1, out},
207 desc,
208 armnn::EmptyOptional(),
209 armnn::EmptyOptional(),
210 reasonIfNotSupported);
211
212 CHECK(supported);
213}
214
215TEST_CASE("IsLayerSupportedTosaReferenceMultiplicationUnsupported")
216{
217 TensorShape shape0 = {1,1,3,4};
218 TensorShape shape1 = {1,2,3,4};
219 TensorShape outShape = {1,1,3,4};
220 TensorInfo in0(shape0, armnn::DataType::Signed64);
221 TensorInfo in1(shape1, armnn::DataType::Signed64);
222 TensorInfo out(outShape, armnn::DataType::Signed64);
223
224 BaseDescriptor desc;
225 TosaRefLayerSupport supportChecker;
226 std::string reasonIfNotSupported;
227 auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Multiplication,
228 {in0, in1, out},
229 desc,
230 armnn::EmptyOptional(),
231 armnn::EmptyOptional(),
232 reasonIfNotSupported);
233
234 CHECK(!supported);
235}
236
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000237TEST_CASE("IsLayerSupportedTosaReferenceMaxPooling2d")
238{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000239 TensorShape inShape = {1,1,3,4};
240 TensorShape outShape = {1,1,3,4};
241 TensorInfo in(inShape, DataType::Float32);
242 TensorInfo out(outShape, DataType::Float32);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000243
Cathal Corbettb30e6552022-12-07 11:50:50 +0000244 Pooling2dDescriptor desc;
Matthew Sloyan67fd5262022-12-07 19:28:18 +0000245 desc.m_PoolHeight = 1;
246 desc.m_PoolWidth = 1;
247 desc.m_StrideX = 1;
248 desc.m_StrideY = 1;
Matthew Sloyanfc9d5e72022-12-08 13:38:23 +0000249 desc.m_PoolType = PoolingAlgorithm::Max;
Matthew Sloyan67fd5262022-12-07 19:28:18 +0000250
Cathal Corbettb30e6552022-12-07 11:50:50 +0000251 TosaRefLayerSupport supportChecker;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000252 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000253 auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d,
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000254 {in, out},
255 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000256 EmptyOptional(),
257 EmptyOptional(),
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000258 reasonIfNotSupported);
259
260 CHECK(supported);
261}
262
263TEST_CASE("IsLayerSupportedTosaReferenceAvgPooling2d_IgnoreValue")
264{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000265 TensorShape inShape = {1,1,3,4};
266 TensorShape outShape = {1,1,3,4};
267 TensorInfo in(inShape, DataType::Float32);
268 TensorInfo out(outShape, DataType::Float32);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000269
Cathal Corbettb30e6552022-12-07 11:50:50 +0000270 Pooling2dDescriptor desc;
Matthew Sloyan67fd5262022-12-07 19:28:18 +0000271 desc.m_PoolHeight = 1;
272 desc.m_PoolWidth = 1;
273 desc.m_StrideX = 1;
274 desc.m_StrideY = 1;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000275 desc.m_PaddingMethod = PaddingMethod::IgnoreValue;
276 desc.m_PoolType = PoolingAlgorithm::Average;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000277
Cathal Corbettb30e6552022-12-07 11:50:50 +0000278 TosaRefLayerSupport supportChecker;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000279 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000280 auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d,
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000281 {in, out},
282 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000283 EmptyOptional(),
284 EmptyOptional(),
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000285 reasonIfNotSupported);
286
287 CHECK(supported);
288}
289
290TEST_CASE("IsLayerSupportedTosaReferenceMaxPooling2dUnsupported")
291{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000292 TensorShape inShape = {1,1,3,4};
293 TensorShape outShape = {1,1,3,4};
294 TensorInfo in(inShape, DataType::Signed64);
295 TensorInfo out(outShape, DataType::Signed64);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000296
Cathal Corbettb30e6552022-12-07 11:50:50 +0000297 Pooling2dDescriptor desc;
298 TosaRefLayerSupport supportChecker;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000299 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000300 auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d,
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000301 {in, out},
302 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000303 EmptyOptional(),
304 EmptyOptional(),
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000305 reasonIfNotSupported);
306
307 CHECK(!supported);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000308}
309
310TEST_CASE("IsLayerSupportedTosaReferenceAvgPooling2dUnsupported_InputOutputDatatypeDifferent")
311{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000312 TensorShape inShape = {1,1,3,4};
313 TensorShape outShape = {1,1,3,4};
314 TensorInfo in(inShape, DataType::Float32);
315 TensorInfo out(outShape, DataType::Float16);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000316
Cathal Corbettb30e6552022-12-07 11:50:50 +0000317 Pooling2dDescriptor desc;
318 desc.m_PaddingMethod = PaddingMethod::IgnoreValue;
319 desc.m_PoolType = PoolingAlgorithm::Average;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000320
Cathal Corbettb30e6552022-12-07 11:50:50 +0000321 TosaRefLayerSupport supportChecker;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000322 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000323 auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d,
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000324 {in, out},
325 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000326 EmptyOptional(),
327 EmptyOptional(),
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000328 reasonIfNotSupported);
329
330 CHECK(!supported);
Cathal Corbettb30e6552022-12-07 11:50:50 +0000331}
332
333TEST_CASE("IsLayerSupportedTosaReferenceReshape")
334{
335 TensorShape inShape = {3,4};
336 TensorShape outShape = {12};
337 TensorInfo in(inShape, DataType::Float32);
338 TensorInfo out(outShape, DataType::Float32);
339
340 ReshapeDescriptor desc;
341 desc.m_TargetShape = {12};
342
343 TosaRefLayerSupport supportChecker;
344 std::string reasonIfNotSupported;
345 auto supported = supportChecker.IsLayerSupported(LayerType::Reshape,
346 {in, out},
347 desc,
348 EmptyOptional(),
349 EmptyOptional(),
350 reasonIfNotSupported);
351
352 CHECK(supported);
353}
354
Teresa Charlince655882023-11-21 15:44:13 +0000355TEST_CASE("IsLayerSupportedTosaReferenceResize")
356{
357 TensorShape inShape = { 1, 720, 1280, 3 };
358 TensorShape outShape = { 1, 1080, 1920, 3 };
359 TensorInfo in(inShape, DataType::Float32);
360 TensorInfo out(outShape, DataType::Float32);
361
362 ResizeDescriptor descriptor;
363 descriptor.m_DataLayout = armnn::DataLayout::NHWC;
364 descriptor.m_TargetHeight = 1080;
365 descriptor.m_TargetWidth = 1920;
366
367 TosaRefLayerSupport supportChecker;
368 std::string reasonIfNotSupported;
369 auto supported = supportChecker.IsLayerSupported(LayerType::Resize,
370 {in, out},
371 descriptor,
372 EmptyOptional(),
373 EmptyOptional(),
374 reasonIfNotSupported);
375
376 CHECK(supported);
377}
378
Cathal Corbettb30e6552022-12-07 11:50:50 +0000379TEST_CASE("IsLayerSupportedTosaReferenceReshapeUnsupported")
380{
381 TensorShape inShape = {3,4};
382 TensorShape outShape = {12};
383 TensorInfo in(inShape, DataType::Signed64);
384 TensorInfo out(outShape, DataType::Signed64);
385
386 ReshapeDescriptor desc;
387 desc.m_TargetShape = {12};
388
389 TosaRefLayerSupport supportChecker;
390 std::string reasonIfNotSupported;
391 auto supported = supportChecker.IsLayerSupported(LayerType::Reshape,
392 {in, out},
393 desc,
394 EmptyOptional(),
395 EmptyOptional(),
396 reasonIfNotSupported);
397
398 CHECK(!supported);
Francis Murtagh9270d9e2022-08-12 13:54:17 +0100399}
400
David Monahand7fca092023-01-12 14:53:34 +0000401TEST_CASE("IsLayerSupportedTosaReferenceRsqrt")
402{
403 TensorShape shape0 = {2,2};
404 TensorShape outShape = {2,2};
405 TensorInfo in0(shape0, DataType::Float32);
406 TensorInfo out(outShape, DataType::Float32);
407
408 ElementwiseUnaryDescriptor desc(UnaryOperation::Rsqrt);
409 TosaRefLayerSupport supportChecker;
410 std::string reasonIfNotSupported;
411 auto supported = supportChecker.IsLayerSupported(LayerType::ElementwiseUnary,
412 {in0, out},
413 desc,
414 EmptyOptional(),
415 EmptyOptional(),
416 reasonIfNotSupported);
417
418 CHECK(supported);
419}
420
421TEST_CASE("IsLayerSupportedTosaReferenceRsqrtUnsupported")
422{
423 TensorShape shape0 = {1,1,3,4};
424 TensorShape outShape = {1,3,1,4};
425 TensorInfo in0(shape0, DataType::Signed64);
426 TensorInfo out(outShape, DataType::Signed64);
427
428 ElementwiseUnaryDescriptor desc(UnaryOperation::Rsqrt);
429 TosaRefLayerSupport supportChecker;
430 std::string reasonIfNotSupported;
431 auto supported = supportChecker.IsLayerSupported(LayerType::ElementwiseUnary,
432 {in0, out},
433 desc,
434 EmptyOptional(),
435 EmptyOptional(),
436 reasonIfNotSupported);
437
438 CHECK(!supported);
439}
440
Cathal Corbett3b9acd52022-12-09 12:17:27 +0000441TEST_CASE("IsLayerSupportedTosaReferenceSlice")
442{
443 TensorShape inShape = {3,2,3};
444 TensorShape outShape = {2,1,3};
445 TensorInfo in(inShape, DataType::Float32);
446 TensorInfo out(outShape, DataType::Float32);
447
448 SliceDescriptor descriptor;
449 descriptor.m_Begin = {1,0,0 };
450 descriptor.m_Size = {2,1,3 };
451
452 TosaRefLayerSupport supportChecker;
453 std::string reasonIfNotSupported;
454 auto supported = supportChecker.IsLayerSupported(LayerType::Slice,
455 {in, out},
456 descriptor,
457 EmptyOptional(),
458 EmptyOptional(),
459 reasonIfNotSupported);
460
461 CHECK(supported);
462}
463
464TEST_CASE("IsLayerSupportedTosaReferenceSliceUnsupported")
465{
466 TensorShape inShape = {3,2,3};
467 TensorShape outShape = {2,1,3};
468 TensorInfo in(inShape, DataType::Signed64);
469 TensorInfo out(outShape, DataType::Signed64);
470
471 SliceDescriptor descriptor;
472 descriptor.m_Begin = {1,0,0};
473 descriptor.m_Size = {2,1,3};
474
475 TosaRefLayerSupport supportChecker;
476 std::string reasonIfNotSupported;
477 auto supported = supportChecker.IsLayerSupported(LayerType::Slice,
478 {in, out},
479 descriptor,
480 EmptyOptional(),
481 EmptyOptional(),
482 reasonIfNotSupported);
483
484 CHECK(!supported);
Cathal Corbett3b9acd52022-12-09 12:17:27 +0000485}
486
Kevin May1bea6be2023-12-12 11:18:46 +0000487TEST_CASE("IsLayerSupportedTosaReferenceSplit")
488{
489 TensorShape inShape = {1, 18, 4, 4};
490 TensorShape outShape = {1, 6, 4, 4};
491 TensorInfo in(inShape, DataType::Float32);
492 TensorInfo out(outShape, DataType::Float32);
493
494 const unsigned int numViews = 3;
495 const unsigned int numDimensions = 4;
496 armnn::SplitterDescriptor descriptor(numViews, numDimensions);
497 descriptor.SetAxis(static_cast<int32_t>(1));
498
499 TosaRefLayerSupport supportChecker;
500 std::string reasonIfNotSupported;
501 auto supported = supportChecker.IsLayerSupported(LayerType::Splitter,
502 {in, out},
503 descriptor,
504 EmptyOptional(),
505 EmptyOptional(),
506 reasonIfNotSupported);
507
508 CHECK(supported);
509}
510
511TEST_CASE("IsLayerSupportedTosaReferenceSplitUnsupported")
512{
513 TensorShape inShape = {1, 18, 4, 4};
514 TensorShape outShape = {1, 6, 4, 4};
515 TensorInfo in(inShape, DataType::Signed64);
516 TensorInfo out(outShape, DataType::Signed64);
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,
526 {in, out},
527 descriptor,
528 EmptyOptional(),
529 EmptyOptional(),
530 reasonIfNotSupported);
531
532 CHECK(!supported);
533}
534
Nikhil Raj9a339462022-12-05 11:24:35 +0000535TEST_CASE("IsLayerSupportedTosaReferenceSubtraction")
536{
537 TensorShape shape0 = {1,1,3,4};
538 TensorShape shape1 = {1,1,3,4};
539 TensorShape outShape = {1,1,3,4};
540 TensorInfo in0(shape0, armnn::DataType::Float32);
541 TensorInfo in1(shape1, armnn::DataType::Float32);
542 TensorInfo out(outShape, armnn::DataType::Float32);
543
544 BaseDescriptor desc;
545 TosaRefLayerSupport supportChecker;
546 std::string reasonIfNotSupported;
547 auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Subtraction,
548 {in0, in1, out},
549 desc,
550 armnn::EmptyOptional(),
551 armnn::EmptyOptional(),
552 reasonIfNotSupported);
553
554 CHECK(supported);
555}
556
557TEST_CASE("IsLayerSupportedTosaReferenceSubtractionUnsupported")
558{
559 TensorShape shape0 = {1,1,3,4};
560 TensorShape shape1 = {4};
561 TensorShape outShape = {1,1,3,4};
562 TensorInfo in0(shape0, armnn::DataType::Signed64);
563 TensorInfo in1(shape1, armnn::DataType::Signed64);
564 TensorInfo out(outShape, armnn::DataType::Signed64);
565
566 BaseDescriptor desc;
567 TosaRefLayerSupport supportChecker;
568 std::string reasonIfNotSupported;
569 auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Subtraction,
570 {in0, in1, out},
571 desc,
572 armnn::EmptyOptional(),
573 armnn::EmptyOptional(),
574 reasonIfNotSupported);
575
576 CHECK(!supported);
577}
578
Matthew Sloyanfc9d5e72022-12-08 13:38:23 +0000579TEST_CASE("IsLayerSupportedTosaReferenceTransposeConv2d")
580{
581 TensorInfo inputInfo ({ 1, 3, 3, 1 }, DataType::Float32);
582 TensorInfo outputInfo({ 1, 5, 5, 1 }, DataType::Float32);
583 TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32);
584 TensorInfo biasesInfo ({ 1 }, DataType::Float32);
585
586 TransposeConvolution2dDescriptor desc;
587 desc.m_StrideX = 1;
588 desc.m_StrideY = 1;
589 desc.m_BiasEnabled = true;
590
591 TosaRefLayerSupport supportChecker;
592 std::string reasonIfNotSupported;
593 auto supported = supportChecker.IsLayerSupported(LayerType::TransposeConvolution2d,
594 {inputInfo, outputInfo, weightsInfo, biasesInfo},
595 desc,
596 EmptyOptional(),
597 EmptyOptional(),
598 reasonIfNotSupported);
599 CHECK(supported);
600}
601
602TEST_CASE("IsLayerSupportedTosaReferenceTransposeConv2dUnsupported")
603{
604 // If inputs and weights are Fp32, output must match.
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, 0.0f, 0, true);
608 TensorInfo biasesInfo ({ 1 }, DataType::Float32, 0.0f, 0, true);
609
610 TransposeConvolution2dDescriptor desc;
611 desc.m_BiasEnabled = true;
612
613 TosaRefLayerSupport supportChecker;
614 std::string reasonIfNotSupported;
615 auto supported = supportChecker.IsLayerSupported(LayerType::TransposeConvolution2d,
616 {inputInfo, outputInfo, weightsInfo, biasesInfo},
617 desc,
618 EmptyOptional(),
619 EmptyOptional(),
620 reasonIfNotSupported);
621 CHECK(!supported);
622}
623
Cathal Corbett0bb096d2022-12-22 13:09:38 +0000624TEST_CASE("IsLayerSupportedTosaReferenceTranspose")
625{
626 TensorShape inShape = { 1, 1, 5, 3 };
627 TensorShape outShape = { 1, 5, 1, 3 };
628 TensorInfo in(inShape, DataType::Float32);
629 TensorInfo out(outShape, DataType::Float32);
630
631 TransposeDescriptor transposeDescriptor = TransposeDescriptor({ 0, 2, 1 ,3 });
632
633 TosaRefLayerSupport supportChecker;
634 std::string reasonIfNotSupported;
635 auto supported = supportChecker.IsLayerSupported(LayerType::Transpose,
636 {in, out},
637 transposeDescriptor,
638 EmptyOptional(),
639 EmptyOptional(),
640 reasonIfNotSupported);
641
642 CHECK(supported);
643}
644
645TEST_CASE("IsLayerSupportedTosaReferenceTransposeUnsupported")
646{
647 TensorShape inShape = { 1, 1, 5, 3 };
648 TensorShape outShape = { 1, 5, 1, 3 };
649 TensorInfo in(inShape, DataType::Signed64);
650 TensorInfo out(outShape, DataType::Signed64);
651
652 TransposeDescriptor transposeDescriptor = TransposeDescriptor({ 0, 2, 1 ,3 });
653
654 TosaRefLayerSupport supportChecker;
655 std::string reasonIfNotSupported;
656 auto supported = supportChecker.IsLayerSupported(LayerType::Transpose,
657 {in, out},
658 transposeDescriptor,
659 EmptyOptional(),
660 EmptyOptional(),
661 reasonIfNotSupported);
662
663 CHECK(!supported);
664}
665
Francis Murtagh9270d9e2022-08-12 13:54:17 +0100666}