blob: 3c3abc2af3c5c288e70f8b0a1befeaa9fa6b5c1a [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
64TEST_CASE("IsLayerSupportedTosaReferenceConstant")
65{
Cathal Corbettb30e6552022-12-07 11:50:50 +000066 TensorInfo outputInfo({1,1,3,4}, DataType::Float32);
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000067
Cathal Corbettb30e6552022-12-07 11:50:50 +000068 TosaRefLayerSupport supportChecker;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000069 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +000070 auto supported = supportChecker.IsLayerSupported(LayerType::Constant,
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000071 {outputInfo},
Cathal Corbettb30e6552022-12-07 11:50:50 +000072 BaseDescriptor(),
73 EmptyOptional(),
74 EmptyOptional(),
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000075 reasonIfNotSupported);
76
77 CHECK(supported);
78}
79
80TEST_CASE("IsLayerSupportedTosaReferenceConstantUnsupported")
81{
Cathal Corbettb30e6552022-12-07 11:50:50 +000082 TensorInfo outputInfo({1,1,3,4}, DataType::Signed64);
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000083
Cathal Corbettb30e6552022-12-07 11:50:50 +000084 TosaRefLayerSupport supportChecker;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000085 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +000086 auto supported = supportChecker.IsLayerSupported(LayerType::Constant,
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000087 {outputInfo},
Cathal Corbettb30e6552022-12-07 11:50:50 +000088 BaseDescriptor(),
89 EmptyOptional(),
90 EmptyOptional(),
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000091 reasonIfNotSupported);
92
93 CHECK(!supported);
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000094}
95
96TEST_CASE("IsLayerSupportedTosaReferenceConv2d")
97{
Cathal Corbettb30e6552022-12-07 11:50:50 +000098 TensorInfo inputInfo ({ 1, 5, 5, 1 }, DataType::Float32);
99 TensorInfo outputInfo({ 1, 3, 3, 1 }, DataType::Float32);
100 TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32);
101 TensorInfo biasesInfo ({ 1 }, DataType::Float32);
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000102
Cathal Corbettb30e6552022-12-07 11:50:50 +0000103 Convolution2dDescriptor desc;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000104 desc.m_BiasEnabled = true;
105
Cathal Corbettb30e6552022-12-07 11:50:50 +0000106 TosaRefLayerSupport supportChecker;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000107 std::string reasonIfNotSupported;
Matthew Sloyanfc9d5e72022-12-08 13:38:23 +0000108 auto supported = supportChecker.IsLayerSupported(LayerType::Convolution2d,
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000109 {inputInfo, outputInfo, weightsInfo, biasesInfo},
110 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000111 EmptyOptional(),
112 EmptyOptional(),
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000113 reasonIfNotSupported);
114
115 CHECK(supported);
116}
117
118TEST_CASE("IsLayerSupportedTosaReferenceConv2dUnsupported")
119{
120 // If inputs and weights are Fp32, output must match.
Cathal Corbettb30e6552022-12-07 11:50:50 +0000121 TensorInfo inputInfo ({ 1, 5, 5, 1 }, DataType::Float32);
122 TensorInfo outputInfo({ 1, 3, 3, 1 }, DataType::Signed64);
123 TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32, 0.0f, 0, true);
124 TensorInfo biasesInfo ({ 1 }, DataType::Float32, 0.0f, 0, true);
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000125
Cathal Corbettb30e6552022-12-07 11:50:50 +0000126 Convolution2dDescriptor desc;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000127 desc.m_BiasEnabled = true;
128
Cathal Corbettb30e6552022-12-07 11:50:50 +0000129 TosaRefLayerSupport supportChecker;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000130 std::string reasonIfNotSupported;
Matthew Sloyanfc9d5e72022-12-08 13:38:23 +0000131 auto supported = supportChecker.IsLayerSupported(LayerType::Convolution2d,
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000132 {inputInfo, outputInfo, weightsInfo, biasesInfo},
133 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000134 EmptyOptional(),
135 EmptyOptional(),
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000136 reasonIfNotSupported);
137
138 CHECK(!supported);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000139}
140
141TEST_CASE("IsLayerSupportedTosaReferenceMaxPooling2d")
142{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000143 TensorShape inShape = {1,1,3,4};
144 TensorShape outShape = {1,1,3,4};
145 TensorInfo in(inShape, DataType::Float32);
146 TensorInfo out(outShape, DataType::Float32);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000147
Cathal Corbettb30e6552022-12-07 11:50:50 +0000148 Pooling2dDescriptor desc;
Matthew Sloyan67fd5262022-12-07 19:28:18 +0000149 desc.m_PoolHeight = 1;
150 desc.m_PoolWidth = 1;
151 desc.m_StrideX = 1;
152 desc.m_StrideY = 1;
Matthew Sloyanfc9d5e72022-12-08 13:38:23 +0000153 desc.m_PoolType = PoolingAlgorithm::Max;
Matthew Sloyan67fd5262022-12-07 19:28:18 +0000154
Cathal Corbettb30e6552022-12-07 11:50:50 +0000155 TosaRefLayerSupport supportChecker;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000156 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000157 auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d,
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000158 {in, out},
159 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000160 EmptyOptional(),
161 EmptyOptional(),
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000162 reasonIfNotSupported);
163
164 CHECK(supported);
165}
166
167TEST_CASE("IsLayerSupportedTosaReferenceAvgPooling2d_IgnoreValue")
168{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000169 TensorShape inShape = {1,1,3,4};
170 TensorShape outShape = {1,1,3,4};
171 TensorInfo in(inShape, DataType::Float32);
172 TensorInfo out(outShape, DataType::Float32);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000173
Cathal Corbettb30e6552022-12-07 11:50:50 +0000174 Pooling2dDescriptor desc;
Matthew Sloyan67fd5262022-12-07 19:28:18 +0000175 desc.m_PoolHeight = 1;
176 desc.m_PoolWidth = 1;
177 desc.m_StrideX = 1;
178 desc.m_StrideY = 1;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000179 desc.m_PaddingMethod = PaddingMethod::IgnoreValue;
180 desc.m_PoolType = PoolingAlgorithm::Average;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000181
Cathal Corbettb30e6552022-12-07 11:50:50 +0000182 TosaRefLayerSupport supportChecker;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000183 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000184 auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d,
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000185 {in, out},
186 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000187 EmptyOptional(),
188 EmptyOptional(),
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000189 reasonIfNotSupported);
190
191 CHECK(supported);
192}
193
194TEST_CASE("IsLayerSupportedTosaReferenceMaxPooling2dUnsupported")
195{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000196 TensorShape inShape = {1,1,3,4};
197 TensorShape outShape = {1,1,3,4};
198 TensorInfo in(inShape, DataType::Signed64);
199 TensorInfo out(outShape, DataType::Signed64);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000200
Cathal Corbettb30e6552022-12-07 11:50:50 +0000201 Pooling2dDescriptor desc;
202 TosaRefLayerSupport supportChecker;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000203 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000204 auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d,
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000205 {in, out},
206 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000207 EmptyOptional(),
208 EmptyOptional(),
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000209 reasonIfNotSupported);
210
211 CHECK(!supported);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000212}
213
214TEST_CASE("IsLayerSupportedTosaReferenceAvgPooling2dUnsupported_InputOutputDatatypeDifferent")
215{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000216 TensorShape inShape = {1,1,3,4};
217 TensorShape outShape = {1,1,3,4};
218 TensorInfo in(inShape, DataType::Float32);
219 TensorInfo out(outShape, DataType::Float16);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000220
Cathal Corbettb30e6552022-12-07 11:50:50 +0000221 Pooling2dDescriptor desc;
222 desc.m_PaddingMethod = PaddingMethod::IgnoreValue;
223 desc.m_PoolType = PoolingAlgorithm::Average;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000224
Cathal Corbettb30e6552022-12-07 11:50:50 +0000225 TosaRefLayerSupport supportChecker;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000226 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000227 auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d,
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000228 {in, out},
229 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000230 EmptyOptional(),
231 EmptyOptional(),
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000232 reasonIfNotSupported);
233
234 CHECK(!supported);
Cathal Corbettb30e6552022-12-07 11:50:50 +0000235}
236
237TEST_CASE("IsLayerSupportedTosaReferenceReshape")
238{
239 TensorShape inShape = {3,4};
240 TensorShape outShape = {12};
241 TensorInfo in(inShape, DataType::Float32);
242 TensorInfo out(outShape, DataType::Float32);
243
244 ReshapeDescriptor desc;
245 desc.m_TargetShape = {12};
246
247 TosaRefLayerSupport supportChecker;
248 std::string reasonIfNotSupported;
249 auto supported = supportChecker.IsLayerSupported(LayerType::Reshape,
250 {in, out},
251 desc,
252 EmptyOptional(),
253 EmptyOptional(),
254 reasonIfNotSupported);
255
256 CHECK(supported);
257}
258
259TEST_CASE("IsLayerSupportedTosaReferenceReshapeUnsupported")
260{
261 TensorShape inShape = {3,4};
262 TensorShape outShape = {12};
263 TensorInfo in(inShape, DataType::Signed64);
264 TensorInfo out(outShape, DataType::Signed64);
265
266 ReshapeDescriptor desc;
267 desc.m_TargetShape = {12};
268
269 TosaRefLayerSupport supportChecker;
270 std::string reasonIfNotSupported;
271 auto supported = supportChecker.IsLayerSupported(LayerType::Reshape,
272 {in, out},
273 desc,
274 EmptyOptional(),
275 EmptyOptional(),
276 reasonIfNotSupported);
277
278 CHECK(!supported);
Francis Murtagh9270d9e2022-08-12 13:54:17 +0100279}
280
Cathal Corbett3b9acd52022-12-09 12:17:27 +0000281TEST_CASE("IsLayerSupportedTosaReferenceSlice")
282{
283 TensorShape inShape = {3,2,3};
284 TensorShape outShape = {2,1,3};
285 TensorInfo in(inShape, DataType::Float32);
286 TensorInfo out(outShape, DataType::Float32);
287
288 SliceDescriptor descriptor;
289 descriptor.m_Begin = {1,0,0 };
290 descriptor.m_Size = {2,1,3 };
291
292 TosaRefLayerSupport supportChecker;
293 std::string reasonIfNotSupported;
294 auto supported = supportChecker.IsLayerSupported(LayerType::Slice,
295 {in, out},
296 descriptor,
297 EmptyOptional(),
298 EmptyOptional(),
299 reasonIfNotSupported);
300
301 CHECK(supported);
302}
303
304TEST_CASE("IsLayerSupportedTosaReferenceSliceUnsupported")
305{
306 TensorShape inShape = {3,2,3};
307 TensorShape outShape = {2,1,3};
308 TensorInfo in(inShape, DataType::Signed64);
309 TensorInfo out(outShape, DataType::Signed64);
310
311 SliceDescriptor descriptor;
312 descriptor.m_Begin = {1,0,0};
313 descriptor.m_Size = {2,1,3};
314
315 TosaRefLayerSupport supportChecker;
316 std::string reasonIfNotSupported;
317 auto supported = supportChecker.IsLayerSupported(LayerType::Slice,
318 {in, out},
319 descriptor,
320 EmptyOptional(),
321 EmptyOptional(),
322 reasonIfNotSupported);
323
324 CHECK(!supported);
Cathal Corbett3b9acd52022-12-09 12:17:27 +0000325}
326
Matthew Sloyanfc9d5e72022-12-08 13:38:23 +0000327TEST_CASE("IsLayerSupportedTosaReferenceTransposeConv2d")
328{
329 TensorInfo inputInfo ({ 1, 3, 3, 1 }, DataType::Float32);
330 TensorInfo outputInfo({ 1, 5, 5, 1 }, DataType::Float32);
331 TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32);
332 TensorInfo biasesInfo ({ 1 }, DataType::Float32);
333
334 TransposeConvolution2dDescriptor desc;
335 desc.m_StrideX = 1;
336 desc.m_StrideY = 1;
337 desc.m_BiasEnabled = true;
338
339 TosaRefLayerSupport supportChecker;
340 std::string reasonIfNotSupported;
341 auto supported = supportChecker.IsLayerSupported(LayerType::TransposeConvolution2d,
342 {inputInfo, outputInfo, weightsInfo, biasesInfo},
343 desc,
344 EmptyOptional(),
345 EmptyOptional(),
346 reasonIfNotSupported);
347 CHECK(supported);
348}
349
350TEST_CASE("IsLayerSupportedTosaReferenceTransposeConv2dUnsupported")
351{
352 // If inputs and weights are Fp32, output must match.
353 TensorInfo inputInfo ({ 1, 3, 3, 1 }, DataType::Float32);
354 TensorInfo outputInfo({ 1, 5, 5, 1 }, DataType::Float32);
355 TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32, 0.0f, 0, true);
356 TensorInfo biasesInfo ({ 1 }, DataType::Float32, 0.0f, 0, true);
357
358 TransposeConvolution2dDescriptor desc;
359 desc.m_BiasEnabled = true;
360
361 TosaRefLayerSupport supportChecker;
362 std::string reasonIfNotSupported;
363 auto supported = supportChecker.IsLayerSupported(LayerType::TransposeConvolution2d,
364 {inputInfo, outputInfo, weightsInfo, biasesInfo},
365 desc,
366 EmptyOptional(),
367 EmptyOptional(),
368 reasonIfNotSupported);
369 CHECK(!supported);
370}
371
Francis Murtagh9270d9e2022-08-12 13:54:17 +0100372}