blob: 051965f541148c33ea3629bf678f2462f939dd5d [file] [log] [blame]
Francis Murtagh9270d9e2022-08-12 13:54:17 +01001//
2// Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
3// 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
193TEST_CASE("IsLayerSupportedTosaReferenceMaxPooling2d")
194{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000195 TensorShape inShape = {1,1,3,4};
196 TensorShape outShape = {1,1,3,4};
197 TensorInfo in(inShape, DataType::Float32);
198 TensorInfo out(outShape, DataType::Float32);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000199
Cathal Corbettb30e6552022-12-07 11:50:50 +0000200 Pooling2dDescriptor desc;
Matthew Sloyan67fd5262022-12-07 19:28:18 +0000201 desc.m_PoolHeight = 1;
202 desc.m_PoolWidth = 1;
203 desc.m_StrideX = 1;
204 desc.m_StrideY = 1;
Matthew Sloyanfc9d5e72022-12-08 13:38:23 +0000205 desc.m_PoolType = PoolingAlgorithm::Max;
Matthew Sloyan67fd5262022-12-07 19:28:18 +0000206
Cathal Corbettb30e6552022-12-07 11:50:50 +0000207 TosaRefLayerSupport supportChecker;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000208 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000209 auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d,
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000210 {in, out},
211 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000212 EmptyOptional(),
213 EmptyOptional(),
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000214 reasonIfNotSupported);
215
216 CHECK(supported);
217}
218
219TEST_CASE("IsLayerSupportedTosaReferenceAvgPooling2d_IgnoreValue")
220{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000221 TensorShape inShape = {1,1,3,4};
222 TensorShape outShape = {1,1,3,4};
223 TensorInfo in(inShape, DataType::Float32);
224 TensorInfo out(outShape, DataType::Float32);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000225
Cathal Corbettb30e6552022-12-07 11:50:50 +0000226 Pooling2dDescriptor desc;
Matthew Sloyan67fd5262022-12-07 19:28:18 +0000227 desc.m_PoolHeight = 1;
228 desc.m_PoolWidth = 1;
229 desc.m_StrideX = 1;
230 desc.m_StrideY = 1;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000231 desc.m_PaddingMethod = PaddingMethod::IgnoreValue;
232 desc.m_PoolType = PoolingAlgorithm::Average;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000233
Cathal Corbettb30e6552022-12-07 11:50:50 +0000234 TosaRefLayerSupport supportChecker;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000235 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000236 auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d,
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000237 {in, out},
238 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000239 EmptyOptional(),
240 EmptyOptional(),
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000241 reasonIfNotSupported);
242
243 CHECK(supported);
244}
245
246TEST_CASE("IsLayerSupportedTosaReferenceMaxPooling2dUnsupported")
247{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000248 TensorShape inShape = {1,1,3,4};
249 TensorShape outShape = {1,1,3,4};
250 TensorInfo in(inShape, DataType::Signed64);
251 TensorInfo out(outShape, DataType::Signed64);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000252
Cathal Corbettb30e6552022-12-07 11:50:50 +0000253 Pooling2dDescriptor desc;
254 TosaRefLayerSupport supportChecker;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000255 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000256 auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d,
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000257 {in, out},
258 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000259 EmptyOptional(),
260 EmptyOptional(),
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000261 reasonIfNotSupported);
262
263 CHECK(!supported);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000264}
265
266TEST_CASE("IsLayerSupportedTosaReferenceAvgPooling2dUnsupported_InputOutputDatatypeDifferent")
267{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000268 TensorShape inShape = {1,1,3,4};
269 TensorShape outShape = {1,1,3,4};
270 TensorInfo in(inShape, DataType::Float32);
271 TensorInfo out(outShape, DataType::Float16);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000272
Cathal Corbettb30e6552022-12-07 11:50:50 +0000273 Pooling2dDescriptor desc;
274 desc.m_PaddingMethod = PaddingMethod::IgnoreValue;
275 desc.m_PoolType = PoolingAlgorithm::Average;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000276
Cathal Corbettb30e6552022-12-07 11:50:50 +0000277 TosaRefLayerSupport supportChecker;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000278 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000279 auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d,
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000280 {in, out},
281 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000282 EmptyOptional(),
283 EmptyOptional(),
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000284 reasonIfNotSupported);
285
286 CHECK(!supported);
Cathal Corbettb30e6552022-12-07 11:50:50 +0000287}
288
289TEST_CASE("IsLayerSupportedTosaReferenceReshape")
290{
291 TensorShape inShape = {3,4};
292 TensorShape outShape = {12};
293 TensorInfo in(inShape, DataType::Float32);
294 TensorInfo out(outShape, DataType::Float32);
295
296 ReshapeDescriptor desc;
297 desc.m_TargetShape = {12};
298
299 TosaRefLayerSupport supportChecker;
300 std::string reasonIfNotSupported;
301 auto supported = supportChecker.IsLayerSupported(LayerType::Reshape,
302 {in, out},
303 desc,
304 EmptyOptional(),
305 EmptyOptional(),
306 reasonIfNotSupported);
307
308 CHECK(supported);
309}
310
311TEST_CASE("IsLayerSupportedTosaReferenceReshapeUnsupported")
312{
313 TensorShape inShape = {3,4};
314 TensorShape outShape = {12};
315 TensorInfo in(inShape, DataType::Signed64);
316 TensorInfo out(outShape, DataType::Signed64);
317
318 ReshapeDescriptor desc;
319 desc.m_TargetShape = {12};
320
321 TosaRefLayerSupport supportChecker;
322 std::string reasonIfNotSupported;
323 auto supported = supportChecker.IsLayerSupported(LayerType::Reshape,
324 {in, out},
325 desc,
326 EmptyOptional(),
327 EmptyOptional(),
328 reasonIfNotSupported);
329
330 CHECK(!supported);
Francis Murtagh9270d9e2022-08-12 13:54:17 +0100331}
332
Cathal Corbett3b9acd52022-12-09 12:17:27 +0000333TEST_CASE("IsLayerSupportedTosaReferenceSlice")
334{
335 TensorShape inShape = {3,2,3};
336 TensorShape outShape = {2,1,3};
337 TensorInfo in(inShape, DataType::Float32);
338 TensorInfo out(outShape, DataType::Float32);
339
340 SliceDescriptor descriptor;
341 descriptor.m_Begin = {1,0,0 };
342 descriptor.m_Size = {2,1,3 };
343
344 TosaRefLayerSupport supportChecker;
345 std::string reasonIfNotSupported;
346 auto supported = supportChecker.IsLayerSupported(LayerType::Slice,
347 {in, out},
348 descriptor,
349 EmptyOptional(),
350 EmptyOptional(),
351 reasonIfNotSupported);
352
353 CHECK(supported);
354}
355
356TEST_CASE("IsLayerSupportedTosaReferenceSliceUnsupported")
357{
358 TensorShape inShape = {3,2,3};
359 TensorShape outShape = {2,1,3};
360 TensorInfo in(inShape, DataType::Signed64);
361 TensorInfo out(outShape, DataType::Signed64);
362
363 SliceDescriptor descriptor;
364 descriptor.m_Begin = {1,0,0};
365 descriptor.m_Size = {2,1,3};
366
367 TosaRefLayerSupport supportChecker;
368 std::string reasonIfNotSupported;
369 auto supported = supportChecker.IsLayerSupported(LayerType::Slice,
370 {in, out},
371 descriptor,
372 EmptyOptional(),
373 EmptyOptional(),
374 reasonIfNotSupported);
375
376 CHECK(!supported);
Cathal Corbett3b9acd52022-12-09 12:17:27 +0000377}
378
Matthew Sloyanfc9d5e72022-12-08 13:38:23 +0000379TEST_CASE("IsLayerSupportedTosaReferenceTransposeConv2d")
380{
381 TensorInfo inputInfo ({ 1, 3, 3, 1 }, DataType::Float32);
382 TensorInfo outputInfo({ 1, 5, 5, 1 }, DataType::Float32);
383 TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32);
384 TensorInfo biasesInfo ({ 1 }, DataType::Float32);
385
386 TransposeConvolution2dDescriptor desc;
387 desc.m_StrideX = 1;
388 desc.m_StrideY = 1;
389 desc.m_BiasEnabled = true;
390
391 TosaRefLayerSupport supportChecker;
392 std::string reasonIfNotSupported;
393 auto supported = supportChecker.IsLayerSupported(LayerType::TransposeConvolution2d,
394 {inputInfo, outputInfo, weightsInfo, biasesInfo},
395 desc,
396 EmptyOptional(),
397 EmptyOptional(),
398 reasonIfNotSupported);
399 CHECK(supported);
400}
401
402TEST_CASE("IsLayerSupportedTosaReferenceTransposeConv2dUnsupported")
403{
404 // If inputs and weights are Fp32, output must match.
405 TensorInfo inputInfo ({ 1, 3, 3, 1 }, DataType::Float32);
406 TensorInfo outputInfo({ 1, 5, 5, 1 }, DataType::Float32);
407 TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32, 0.0f, 0, true);
408 TensorInfo biasesInfo ({ 1 }, DataType::Float32, 0.0f, 0, true);
409
410 TransposeConvolution2dDescriptor desc;
411 desc.m_BiasEnabled = true;
412
413 TosaRefLayerSupport supportChecker;
414 std::string reasonIfNotSupported;
415 auto supported = supportChecker.IsLayerSupported(LayerType::TransposeConvolution2d,
416 {inputInfo, outputInfo, weightsInfo, biasesInfo},
417 desc,
418 EmptyOptional(),
419 EmptyOptional(),
420 reasonIfNotSupported);
421 CHECK(!supported);
422}
423
Francis Murtagh9270d9e2022-08-12 13:54:17 +0100424}