blob: 86b01d8d0ce171d1771b499f518375d92af9111a [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};
23 TensorShape shape1 = {4};
24 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);
Cathal Corbettbd18eab2022-11-15 12:56:16 +000062 REQUIRE(reasonIfNotSupported.find(
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000063 "TOSA Reference Operator: Op_ADD for input: input0_") != std::string::npos);
Cathal Corbettbd18eab2022-11-15 12:56:16 +000064 REQUIRE(reasonIfNotSupported.find(
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000065 "TOSA Reference Operator: Op_ADD for input: input1_") != std::string::npos);
Cathal Corbettbd18eab2022-11-15 12:56:16 +000066 REQUIRE(reasonIfNotSupported.find(
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000067 "TOSA Reference Operator: Op_ADD for output: output0_") != std::string::npos);
Cathal Corbettb30e6552022-12-07 11:50:50 +000068 REQUIRE(reasonIfNotSupported.find(
69 "has an unsupported data type: DType_UNKNOWN") != std::string::npos);
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000070}
71
72TEST_CASE("IsLayerSupportedTosaReferenceConstant")
73{
Cathal Corbettb30e6552022-12-07 11:50:50 +000074 TensorInfo outputInfo({1,1,3,4}, DataType::Float32);
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000075
Cathal Corbettb30e6552022-12-07 11:50:50 +000076 TosaRefLayerSupport supportChecker;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000077 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +000078 auto supported = supportChecker.IsLayerSupported(LayerType::Constant,
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000079 {outputInfo},
Cathal Corbettb30e6552022-12-07 11:50:50 +000080 BaseDescriptor(),
81 EmptyOptional(),
82 EmptyOptional(),
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000083 reasonIfNotSupported);
84
85 CHECK(supported);
86}
87
88TEST_CASE("IsLayerSupportedTosaReferenceConstantUnsupported")
89{
Cathal Corbettb30e6552022-12-07 11:50:50 +000090 TensorInfo outputInfo({1,1,3,4}, DataType::Signed64);
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000091
Cathal Corbettb30e6552022-12-07 11:50:50 +000092 TosaRefLayerSupport supportChecker;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000093 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +000094 auto supported = supportChecker.IsLayerSupported(LayerType::Constant,
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000095 {outputInfo},
Cathal Corbettb30e6552022-12-07 11:50:50 +000096 BaseDescriptor(),
97 EmptyOptional(),
98 EmptyOptional(),
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +000099 reasonIfNotSupported);
100
101 CHECK(!supported);
102 REQUIRE(reasonIfNotSupported.find(
103 "TOSA Reference Operator: Op_CONST for output: constant_") != std::string::npos);
Cathal Corbettb30e6552022-12-07 11:50:50 +0000104 REQUIRE(reasonIfNotSupported.find(
105 "has an unsupported data type: DType_UNKNOWN") != std::string::npos);
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000106}
107
108TEST_CASE("IsLayerSupportedTosaReferenceConv2d")
109{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000110 TensorInfo inputInfo ({ 1, 5, 5, 1 }, DataType::Float32);
111 TensorInfo outputInfo({ 1, 3, 3, 1 }, DataType::Float32);
112 TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32);
113 TensorInfo biasesInfo ({ 1 }, DataType::Float32);
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000114
Cathal Corbettb30e6552022-12-07 11:50:50 +0000115 Convolution2dDescriptor desc;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000116 desc.m_BiasEnabled = true;
117
Cathal Corbettb30e6552022-12-07 11:50:50 +0000118 TosaRefLayerSupport supportChecker;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000119 std::string reasonIfNotSupported;
120 auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Convolution2d,
121 {inputInfo, outputInfo, weightsInfo, biasesInfo},
122 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000123 EmptyOptional(),
124 EmptyOptional(),
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000125 reasonIfNotSupported);
126
127 CHECK(supported);
128}
129
130TEST_CASE("IsLayerSupportedTosaReferenceConv2dUnsupported")
131{
132 // If inputs and weights are Fp32, output must match.
Cathal Corbettb30e6552022-12-07 11:50:50 +0000133 TensorInfo inputInfo ({ 1, 5, 5, 1 }, DataType::Float32);
134 TensorInfo outputInfo({ 1, 3, 3, 1 }, DataType::Signed64);
135 TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32, 0.0f, 0, true);
136 TensorInfo biasesInfo ({ 1 }, DataType::Float32, 0.0f, 0, true);
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000137
Cathal Corbettb30e6552022-12-07 11:50:50 +0000138 Convolution2dDescriptor desc;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000139 desc.m_BiasEnabled = true;
140
Cathal Corbettb30e6552022-12-07 11:50:50 +0000141 TosaRefLayerSupport supportChecker;
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000142 std::string reasonIfNotSupported;
143 auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Convolution2d,
144 {inputInfo, outputInfo, weightsInfo, biasesInfo},
145 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000146 EmptyOptional(),
147 EmptyOptional(),
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000148 reasonIfNotSupported);
149
150 CHECK(!supported);
151 REQUIRE(reasonIfNotSupported.find(
152 "TOSA Reference Operator: Op_CONV2D for input 0: input0_") != std::string::npos);
153 REQUIRE(reasonIfNotSupported.find(
154 "input 1: input1_") != std::string::npos);
155 REQUIRE(reasonIfNotSupported.find(
156 "and output: output0_") != std::string::npos);
157 REQUIRE(reasonIfNotSupported.find(
158 "has an unsupported input data type combination.") != std::string::npos);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000159}
160
161TEST_CASE("IsLayerSupportedTosaReferenceMaxPooling2d")
162{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000163 TensorShape inShape = {1,1,3,4};
164 TensorShape outShape = {1,1,3,4};
165 TensorInfo in(inShape, DataType::Float32);
166 TensorInfo out(outShape, DataType::Float32);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000167
Cathal Corbettb30e6552022-12-07 11:50:50 +0000168 Pooling2dDescriptor desc;
169 TosaRefLayerSupport supportChecker;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000170 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000171 auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d,
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000172 {in, out},
173 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000174 EmptyOptional(),
175 EmptyOptional(),
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000176 reasonIfNotSupported);
177
178 CHECK(supported);
179}
180
181TEST_CASE("IsLayerSupportedTosaReferenceAvgPooling2d_IgnoreValue")
182{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000183 TensorShape inShape = {1,1,3,4};
184 TensorShape outShape = {1,1,3,4};
185 TensorInfo in(inShape, DataType::Float32);
186 TensorInfo out(outShape, DataType::Float32);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000187
Cathal Corbettb30e6552022-12-07 11:50:50 +0000188 Pooling2dDescriptor desc;
189 desc.m_PaddingMethod = PaddingMethod::IgnoreValue;
190 desc.m_PoolType = PoolingAlgorithm::Average;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000191
Cathal Corbettb30e6552022-12-07 11:50:50 +0000192 TosaRefLayerSupport supportChecker;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000193 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000194 auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d,
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000195 {in, out},
196 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000197 EmptyOptional(),
198 EmptyOptional(),
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000199 reasonIfNotSupported);
200
201 CHECK(supported);
202}
203
204TEST_CASE("IsLayerSupportedTosaReferenceAvgPooling2d_InputOutputDatatypeDifferent")
205{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000206 TensorShape inShape = {1,1,3,4};
207 TensorShape outShape = {1,1,3,4};
208 TensorInfo in(inShape, DataType::QAsymmS8);
209 TensorInfo out(outShape, DataType::Signed32);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000210
Cathal Corbettb30e6552022-12-07 11:50:50 +0000211 Pooling2dDescriptor desc;
212 desc.m_PaddingMethod = PaddingMethod::IgnoreValue;
213 desc.m_PoolType = PoolingAlgorithm::Average;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000214
Cathal Corbettb30e6552022-12-07 11:50:50 +0000215 TosaRefLayerSupport supportChecker;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000216 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000217 auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d,
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000218 {in, out},
219 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000220 EmptyOptional(),
221 EmptyOptional(),
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000222 reasonIfNotSupported);
223
224 CHECK(supported);
225}
226
227TEST_CASE("IsLayerSupportedTosaReferenceMaxPooling2dUnsupported")
228{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000229 TensorShape inShape = {1,1,3,4};
230 TensorShape outShape = {1,1,3,4};
231 TensorInfo in(inShape, DataType::Signed64);
232 TensorInfo out(outShape, DataType::Signed64);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000233
Cathal Corbettb30e6552022-12-07 11:50:50 +0000234 Pooling2dDescriptor desc;
235 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 REQUIRE(reasonIfNotSupported.find(
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000246 "TOSA Reference Operator: Op_MAX_POOL2D for input: input0_") != std::string::npos);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000247 REQUIRE(reasonIfNotSupported.find(
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000248 "TOSA Reference Operator: Op_MAX_POOL2D for output: output0_") != std::string::npos);
Cathal Corbettb30e6552022-12-07 11:50:50 +0000249 REQUIRE(reasonIfNotSupported.find(
250 "has an unsupported data type: DType_UNKNOWN") != std::string::npos);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000251}
252
253TEST_CASE("IsLayerSupportedTosaReferenceAvgPooling2dUnsupported_InputOutputDatatypeDifferent")
254{
Cathal Corbettb30e6552022-12-07 11:50:50 +0000255 TensorShape inShape = {1,1,3,4};
256 TensorShape outShape = {1,1,3,4};
257 TensorInfo in(inShape, DataType::Float32);
258 TensorInfo out(outShape, DataType::Float16);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000259
Cathal Corbettb30e6552022-12-07 11:50:50 +0000260 Pooling2dDescriptor desc;
261 desc.m_PaddingMethod = PaddingMethod::IgnoreValue;
262 desc.m_PoolType = PoolingAlgorithm::Average;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000263
Cathal Corbettb30e6552022-12-07 11:50:50 +0000264 TosaRefLayerSupport supportChecker;
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000265 std::string reasonIfNotSupported;
Cathal Corbettb30e6552022-12-07 11:50:50 +0000266 auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d,
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000267 {in, out},
268 desc,
Cathal Corbettb30e6552022-12-07 11:50:50 +0000269 EmptyOptional(),
270 EmptyOptional(),
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000271 reasonIfNotSupported);
272
273 CHECK(!supported);
274 REQUIRE(reasonIfNotSupported.find(
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000275 "TOSA Reference Operator: Op_AVG_POOL2D for input: intermediate0_") != std::string::npos);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000276 REQUIRE(reasonIfNotSupported.find(
Matthew Sloyanc5fe6e72022-11-25 16:10:00 +0000277 " and output: output0_") != std::string::npos);
Cathal Corbettbd18eab2022-11-15 12:56:16 +0000278 REQUIRE(reasonIfNotSupported.find(
Cathal Corbettb30e6552022-12-07 11:50:50 +0000279 " has an unsupported input data type: DType_FP32 to output data type: DType_FP16") != std::string::npos);
280}
281
282TEST_CASE("IsLayerSupportedTosaReferenceReshape")
283{
284 TensorShape inShape = {3,4};
285 TensorShape outShape = {12};
286 TensorInfo in(inShape, DataType::Float32);
287 TensorInfo out(outShape, DataType::Float32);
288
289 ReshapeDescriptor desc;
290 desc.m_TargetShape = {12};
291
292 TosaRefLayerSupport supportChecker;
293 std::string reasonIfNotSupported;
294 auto supported = supportChecker.IsLayerSupported(LayerType::Reshape,
295 {in, out},
296 desc,
297 EmptyOptional(),
298 EmptyOptional(),
299 reasonIfNotSupported);
300
301 CHECK(supported);
302}
303
304TEST_CASE("IsLayerSupportedTosaReferenceReshapeUnsupported")
305{
306 TensorShape inShape = {3,4};
307 TensorShape outShape = {12};
308 TensorInfo in(inShape, DataType::Signed64);
309 TensorInfo out(outShape, DataType::Signed64);
310
311 ReshapeDescriptor desc;
312 desc.m_TargetShape = {12};
313
314 TosaRefLayerSupport supportChecker;
315 std::string reasonIfNotSupported;
316 auto supported = supportChecker.IsLayerSupported(LayerType::Reshape,
317 {in, out},
318 desc,
319 EmptyOptional(),
320 EmptyOptional(),
321 reasonIfNotSupported);
322
323 CHECK(!supported);
324 REQUIRE(reasonIfNotSupported.find(
325 "TOSA Reference Operator: Op_RESHAPE for input: input0_") != std::string::npos);
326 REQUIRE(reasonIfNotSupported.find(
327 "TOSA Reference Operator: Op_RESHAPE for output: output0_") != std::string::npos);
328 REQUIRE(reasonIfNotSupported.find(
329 "has an unsupported data type: DType_UNKNOWN") != std::string::npos);
Francis Murtagh9270d9e2022-08-12 13:54:17 +0100330}
331
332}