blob: c60348e529823e84d31f4de3d240eb89eec396ca [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5
telsoa014fcda012018-03-09 14:13:49 +00006#include "RefLayerSupport.hpp"
David Beck3e9e1152018-10-17 14:17:50 +01007#include "RefBackendId.hpp"
David Beck3cc9a622018-10-12 10:38:31 +01008
telsoa014fcda012018-03-09 14:13:49 +00009#include <armnn/Types.hpp>
Derek Lamberti50db4e82019-03-13 14:16:15 +000010#include <armnn/Descriptors.hpp>
Matteo Martincighc601aa62019-10-29 15:03:22 +000011#include <armnn/BackendRegistry.hpp>
telsoa014fcda012018-03-09 14:13:49 +000012
Matteo Martincighe011d202019-11-28 11:35:47 +000013#include <armnnUtils/DataLayoutIndexed.hpp>
14
15#include <InternalTypes.hpp>
16#include <LayerSupportCommon.hpp>
17
Derek Lambertif674aa02019-08-01 15:56:25 +010018#include <backendsCommon/LayerSupportRules.hpp>
Matteo Martincighe011d202019-11-28 11:35:47 +000019
Matteo Martincighe011d202019-11-28 11:35:47 +000020#include <boost/cast.hpp>
telsoa014fcda012018-03-09 14:13:49 +000021#include <boost/core/ignore_unused.hpp>
telsoa014fcda012018-03-09 14:13:49 +000022
Derek Lamberti50db4e82019-03-13 14:16:15 +000023#include <vector>
24#include <algorithm>
25#include <array>
26
telsoa014fcda012018-03-09 14:13:49 +000027using namespace boost;
28
29namespace armnn
30{
31
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +010032namespace
33{
34
35template<typename Float32Func, typename Uint8Func, typename ... Params>
36bool IsSupportedForDataTypeRef(Optional<std::string&> reasonIfUnsupported,
37 DataType dataType,
38 Float32Func floatFuncPtr,
39 Uint8Func uint8FuncPtr,
40 Params&&... params)
41{
42 return IsSupportedForDataTypeGeneric(reasonIfUnsupported,
43 dataType,
44 &FalseFunc<Params...>,
45 floatFuncPtr,
46 uint8FuncPtr,
narpra01db2b1602019-01-23 15:23:11 +000047 &FalseFunc<Params...>,
kevmay012b4d88e2019-01-24 14:05:09 +000048 &FalseFunc<Params...>,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +010049 std::forward<Params>(params)...);
50}
51
52} // anonymous namespace
53
James Conroy4d1ff582019-06-10 17:06:39 +010054namespace
55{
56
57std::string CreateIncorrectDimensionsErrorMsg(unsigned int expected,
58 unsigned int actual,
59 std::string& layerStr,
60 std::string& tensorName)
61{
62 std::string errorMsg = "Reference " + layerStr + ": Expected " + std::to_string(expected) + " dimensions but got" +
63 " " + std::to_string(actual) + " dimensions instead, for the '" + tensorName + "' tensor.";
64
65 return errorMsg;
66}
67
68} // anonymous namespace
Derek Lamberti50db4e82019-03-13 14:16:15 +000069
Sadik Armagan9199e582019-09-05 17:35:31 +010070bool RefLayerSupport::IsAbsSupported(const TensorInfo& input, const TensorInfo& output,
71 Optional<std::string&> reasonIfUnsupported) const
72{
josh minor4a3c6102020-01-06 16:40:46 -060073 return IsElementwiseUnarySupported(input,
74 output,
75 ElementwiseUnaryDescriptor(UnaryOperation::Abs),
76 reasonIfUnsupported);
Sadik Armagan9199e582019-09-05 17:35:31 +010077}
78
arovir011c7c81b2018-10-08 11:34:28 +010079bool RefLayerSupport::IsActivationSupported(const TensorInfo& input,
80 const TensorInfo& output,
81 const ActivationDescriptor& descriptor,
82 Optional<std::string&> reasonIfUnsupported) const
83{
Derek Lamberti50db4e82019-03-13 14:16:15 +000084 bool supported = true;
85
86 // Define supported types.
Matthew Jackson252df3a2019-09-11 09:19:18 +010087 std::array<DataType,4> supportedTypes = {
Derek Lamberti50db4e82019-03-13 14:16:15 +000088 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +010089 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +000090 DataType::QAsymmU8,
91 DataType::QSymmS16
Derek Lamberti50db4e82019-03-13 14:16:15 +000092 };
93
94 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
95 "Reference activation: input type not supported.");
96
97 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
98 "Reference activation: output type not supported.");
99
100 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
101 "Reference activation: input and output types mismatched.");
102
103 supported &= CheckSupportRule(ShapesAreSameRank(input, output), reasonIfUnsupported,
104 "Reference activation: input and output shapes are of different rank.");
105
106
107 struct ActivationFunctionSupported : public Rule
108 {
109 ActivationFunctionSupported(const ActivationDescriptor& desc)
110 {
111 switch(desc.m_Function)
112 {
113 case ActivationFunction::Abs:
114 case ActivationFunction::BoundedReLu:
115 case ActivationFunction::LeakyReLu:
116 case ActivationFunction::Linear:
117 case ActivationFunction::ReLu:
118 case ActivationFunction::Sigmoid:
119 case ActivationFunction::SoftReLu:
120 case ActivationFunction::Sqrt:
121 case ActivationFunction::Square:
122 case ActivationFunction::TanH:
123 {
124 m_Res = true;
125 break;
126 }
127 default:
128 {
129 m_Res = false;
130 break;
131 }
132 }
133 }
134 };
135
136 // Function is supported
137 supported &= CheckSupportRule(ActivationFunctionSupported(descriptor), reasonIfUnsupported,
138 "Reference activation: function not supported.");
139
140 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100141}
142
143bool RefLayerSupport::IsAdditionSupported(const TensorInfo& input0,
144 const TensorInfo& input1,
145 const TensorInfo& output,
146 Optional<std::string&> reasonIfUnsupported) const
147{
Derek Lamberti50db4e82019-03-13 14:16:15 +0000148 bool supported = true;
149
Keith Davis5204aa82020-01-27 15:24:59 +0000150 std::array<DataType,5> supportedTypes = {
Derek Lamberti50db4e82019-03-13 14:16:15 +0000151 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100152 DataType::Float16,
Keith Davis5204aa82020-01-27 15:24:59 +0000153 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000154 DataType::QAsymmU8,
155 DataType::QSymmS16
Derek Lamberti50db4e82019-03-13 14:16:15 +0000156 };
157
158 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
159 "Reference addition: input 0 is not a supported type.");
160
161 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
162 "Reference addition: input 1 is not a supported type.");
163
164 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
165 "Reference addition: output is not a supported type.");
166
167 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
168 "Reference addition: input 0 and Input 1 types are mismatched");
169
170 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
171 "Reference addition: input and output types are mismatched");
172
173 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
174 "Reference addition: shapes are not suitable for implicit broadcast.");
175
176 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100177}
178
Nikhil Raj68c2c902019-09-19 11:21:11 +0100179bool RefLayerSupport::IsArgMinMaxSupported(const armnn::TensorInfo &input, const armnn::TensorInfo &output,
180 const armnn::ArgMinMaxDescriptor &descriptor,
181 armnn::Optional<std::string &> reasonIfUnsupported) const
182{
183 ignore_unused(descriptor);
184
Francis Murtagh1939df52019-11-13 15:21:09 +0000185 std::array<DataType, 4> supportedTypes =
Nikhil Raj68c2c902019-09-19 11:21:11 +0100186 {
187 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000188 DataType::QAsymmU8,
189 DataType::QSymmS16,
Francis Murtagh1939df52019-11-13 15:21:09 +0000190 DataType::Signed32
Nikhil Raj68c2c902019-09-19 11:21:11 +0100191 };
192
193 bool supported = true;
194
195 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
196 "Reference ArgMinMax: input is not a supported type.");
197 supported &= CheckSupportRule(TypeIs(output, DataType::Signed32), reasonIfUnsupported,
198 "Reference ArgMinMax: output type not supported");
199
200 return supported;
201}
202
arovir011c7c81b2018-10-08 11:34:28 +0100203bool RefLayerSupport::IsBatchNormalizationSupported(const TensorInfo& input,
204 const TensorInfo& output,
205 const TensorInfo& mean,
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100206 const TensorInfo& variance,
arovir011c7c81b2018-10-08 11:34:28 +0100207 const TensorInfo& beta,
208 const TensorInfo& gamma,
209 const BatchNormalizationDescriptor& descriptor,
210 Optional<std::string&> reasonIfUnsupported) const
211{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100212 ignore_unused(descriptor);
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100213
Matthew Jackson9bff1442019-09-12 09:08:23 +0100214 std::array<DataType, 4> supportedTypes =
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100215 {
216 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100217 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000218 DataType::QAsymmU8,
219 DataType::QSymmS16
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100220 };
221
222 bool supported = true;
223
224 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
225 "Reference batch normalization: input is not a supported type.");
226
227 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
228 "Reference batch normalization: output is not a supported type.");
229
230 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
231 "Reference batch normalization: input and output types are mismatched");
232
233 supported &= CheckSupportRule(TypeAnyOf(mean, supportedTypes), reasonIfUnsupported,
234 "Reference batch normalization: mean is not a supported type.");
235
236 supported &= CheckSupportRule(TypeAnyOf(variance, supportedTypes), reasonIfUnsupported,
237 "Reference batch normalization: variance is not a supported type.");
238
239 supported &= CheckSupportRule(TypeAnyOf(beta, supportedTypes), reasonIfUnsupported,
240 "Reference batch normalization: beta is not a supported type.");
241
242 supported &= CheckSupportRule(TypeAnyOf(gamma, supportedTypes), reasonIfUnsupported,
243 "Reference batch normalization: gamma is not a supported type.");
244
245 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100246}
247
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000248bool RefLayerSupport::IsBatchToSpaceNdSupported(const TensorInfo& input,
249 const TensorInfo& output,
250 const BatchToSpaceNdDescriptor& descriptor,
251 Optional<std::string&> reasonIfUnsupported) const
252{
253 ignore_unused(descriptor);
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100254
255 bool supported = true;
256
257 std::string batchToSpaceNdLayerStr = "batchToSpaceNd";
258 std::string inputTensorStr = "input";
259 std::string outputTensorStr = "output";
260
261 // Define supported types.
Matthew Jackson9bff1442019-09-12 09:08:23 +0100262 std::array<DataType,4> supportedTypes =
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100263 {
264 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100265 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000266 DataType::QAsymmU8,
267 DataType::QSymmS16
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100268 };
269
270 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
271 "Reference BatchToSpaceNd: input type not supported.");
272
273 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
274 "Reference BatchToSpaceNd: output type not supported.");
275
276 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
277 "Reference BatchToSpaceNd: input and output types mismatched.");
278
279 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 4),
280 reasonIfUnsupported,
281 CreateIncorrectDimensionsErrorMsg(4,
282 output.GetNumDimensions(),
283 batchToSpaceNdLayerStr,
284 outputTensorStr).data());
285
286 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(input, 4),
287 reasonIfUnsupported,
288 CreateIncorrectDimensionsErrorMsg(4,
289 input.GetNumDimensions(),
290 batchToSpaceNdLayerStr,
291 inputTensorStr).data());
292
293 return supported;
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000294}
295
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100296bool RefLayerSupport::IsComparisonSupported(const TensorInfo& input0,
297 const TensorInfo& input1,
298 const TensorInfo& output,
299 const ComparisonDescriptor& descriptor,
300 Optional<std::string&> reasonIfUnsupported) const
301{
302 boost::ignore_unused(descriptor);
303
304 std::array<DataType, 4> supportedInputTypes =
305 {
306 DataType::Float32,
307 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000308 DataType::QAsymmU8,
309 DataType::QSymmS16
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100310 };
311
312 bool supported = true;
313 supported &= CheckSupportRule(TypeAnyOf(input0, supportedInputTypes), reasonIfUnsupported,
314 "Reference comparison: input 0 is not a supported type");
315
316 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
317 "Reference comparison: input 0 and Input 1 types are mismatched");
318
319 supported &= CheckSupportRule(TypeIs(output, DataType::Boolean), reasonIfUnsupported,
320 "Reference comparison: output is not of type Boolean");
321
322 return supported;
323}
324
Jim Flynn906f9462019-05-10 13:55:21 +0100325bool RefLayerSupport::IsConcatSupported(const std::vector<const TensorInfo*> inputs,
326 const TensorInfo& output,
Jim Flynne242f2d2019-05-22 14:24:13 +0100327 const ConcatDescriptor& descriptor,
Jim Flynn906f9462019-05-10 13:55:21 +0100328 Optional<std::string&> reasonIfUnsupported) const
329{
Jim Flynne242f2d2019-05-22 14:24:13 +0100330 ignore_unused(descriptor);
331
332 bool supported = true;
Keith Davis5204aa82020-01-27 15:24:59 +0000333 std::array<DataType,5> supportedTypes =
Jim Flynne242f2d2019-05-22 14:24:13 +0100334 {
335 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100336 DataType::Float16,
Keith Davis5204aa82020-01-27 15:24:59 +0000337 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000338 DataType::QAsymmU8,
339 DataType::QSymmS16
Jim Flynne242f2d2019-05-22 14:24:13 +0100340 };
341
342 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
343 "Reference concatenation: output type not supported");
344 for (const TensorInfo* input : inputs)
345 {
Matthew Jackson81e601c2019-07-11 12:07:09 +0100346 BOOST_ASSERT(input != nullptr);
Jim Flynne242f2d2019-05-22 14:24:13 +0100347 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
348 "Reference concatenation: input type not supported");
349
350 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
351 "Reference concatenation: input and output types mismatched.");
352 }
353
354 return supported;
Jim Flynn906f9462019-05-10 13:55:21 +0100355}
356
arovir011c7c81b2018-10-08 11:34:28 +0100357bool RefLayerSupport::IsConstantSupported(const TensorInfo& output,
358 Optional<std::string&> reasonIfUnsupported) const
359{
Keith Davis5204aa82020-01-27 15:24:59 +0000360 std::array<DataType,5> supportedTypes =
Jim Flynne242f2d2019-05-22 14:24:13 +0100361 {
Nina Drozd58ef2c62019-05-16 12:09:18 +0100362 DataType::Float32,
363 DataType::Signed32,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000364 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +0000365 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000366 DataType::QSymmS16
Nina Drozd58ef2c62019-05-16 12:09:18 +0100367 };
368
369 return CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
370 "Reference constant: output is not a supported type.");
arovir011c7c81b2018-10-08 11:34:28 +0100371}
372
373bool RefLayerSupport::IsConvertFp16ToFp32Supported(const TensorInfo& input,
374 const TensorInfo& output,
375 Optional<std::string&> reasonIfUnsupported) const
376{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100377 return (IsSupportedForDataTypeGeneric(reasonIfUnsupported,
378 input.GetDataType(),
379 &TrueFunc<>,
380 &FalseInputFuncF32<>,
narpra01db2b1602019-01-23 15:23:11 +0000381 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000382 &FalseFuncI32<>,
383 &FalseFuncU8<>) &&
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100384 IsSupportedForDataTypeGeneric(reasonIfUnsupported,
385 output.GetDataType(),
386 &FalseOutputFuncF16<>,
387 &TrueFunc<>,
narpra01db2b1602019-01-23 15:23:11 +0000388 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000389 &FalseFuncI32<>,
390 &FalseFuncU8<>));
arovir011c7c81b2018-10-08 11:34:28 +0100391}
392
393bool RefLayerSupport::IsConvertFp32ToFp16Supported(const TensorInfo& input,
394 const TensorInfo& output,
395 Optional<std::string&> reasonIfUnsupported) const
396{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100397 return (IsSupportedForDataTypeGeneric(reasonIfUnsupported,
398 input.GetDataType(),
399 &FalseInputFuncF16<>,
400 &TrueFunc<>,
narpra01db2b1602019-01-23 15:23:11 +0000401 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000402 &FalseFuncI32<>,
403 &FalseFuncU8<>) &&
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100404 IsSupportedForDataTypeGeneric(reasonIfUnsupported,
405 output.GetDataType(),
406 &TrueFunc<>,
407 &FalseOutputFuncF32<>,
narpra01db2b1602019-01-23 15:23:11 +0000408 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000409 &FalseFuncI32<>,
410 &FalseFuncU8<>));
arovir011c7c81b2018-10-08 11:34:28 +0100411}
412
413bool RefLayerSupport::IsConvolution2dSupported(const TensorInfo& input,
414 const TensorInfo& output,
415 const Convolution2dDescriptor& descriptor,
416 const TensorInfo& weights,
417 const Optional<TensorInfo>& biases,
418 Optional<std::string&> reasonIfUnsupported) const
419{
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100420 bool supported = true;
421
422 // Define supported types.
Keith Davis5204aa82020-01-27 15:24:59 +0000423 std::array<DataType,5> supportedTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000424 {
425 DataType::Float32,
426 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000427 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +0000428 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000429 DataType::QSymmS16
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100430 };
431
432 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000433 "Reference Convolution2d: input is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100434
435 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000436 "Reference Convolution2d: output is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100437
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100438 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000439 "Reference Convolution2d: input and output types mismatched.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100440
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000441 const DataType inputType = input.GetDataType();
Derek Lambertif90c56d2020-01-10 17:14:08 +0000442 if (inputType == DataType::QAsymmU8)
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000443 {
Derek Lambertid466a542020-01-22 15:37:29 +0000444 ARMNN_NO_DEPRECATE_WARN_BEGIN
445 std::array<DataType, 3> supportedWeightTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000446 {
Derek Lambertif90c56d2020-01-10 17:14:08 +0000447 DataType::QAsymmU8,
Derek Lambertid466a542020-01-22 15:37:29 +0000448 DataType::QSymmS8,
449 DataType::QuantizedSymm8PerAxis // deprecated
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000450 };
Derek Lambertid466a542020-01-22 15:37:29 +0000451 ARMNN_NO_DEPRECATE_WARN_END
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000452
453 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000454 "Reference Convolution2d: weights type not supported for quantized input.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000455 }
456 else
457 {
458 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000459 "Reference Convolution2d: weights is not a supported type.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000460
461 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000462 "Reference Convolution2d: input and weights types mismatched.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000463 }
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100464
465 if (biases.has_value())
466 {
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000467 std::array<DataType,3> biasesSupportedTypes =
468 {
469 DataType::Float32,
470 DataType::Float16,
471 DataType::Signed32
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100472 };
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000473
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100474 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000475 "Reference Convolution2d: biases is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100476 }
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100477 ignore_unused(descriptor);
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100478
479 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100480}
481
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000482bool RefLayerSupport::IsDebugSupported(const TensorInfo& input,
483 const TensorInfo& output,
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000484 Optional<std::string&> reasonIfUnsupported) const
485{
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100486 bool supported = true;
487
Keith Davis5204aa82020-01-27 15:24:59 +0000488 std::array<DataType, 6> supportedTypes =
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100489 {
Aron Virginas-Tardb1a2832019-11-12 16:15:11 +0000490 DataType::Float16,
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100491 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000492 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +0000493 DataType::QSymmS8,
Narumol Prangnawaratd2d917d2020-01-09 10:16:39 +0000494 DataType::QSymmS16,
495 DataType::Signed32
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100496 };
497
498 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000499 "Reference for Debug layer: input type not supported");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100500
501 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000502 "Reference for Debug layer: output type not supported");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100503
504 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000505 "Reference for Debug layer: input and output types are mismatched");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100506
507 return supported;
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000508}
509
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100510bool RefLayerSupport::IsDepthToSpaceSupported(const TensorInfo& input,
511 const TensorInfo& output,
512 const DepthToSpaceDescriptor& descriptor,
513 Optional<std::string&> reasonIfUnsupported) const
514{
515 ignore_unused(descriptor);
516 bool supported = true;
517
518 std::array<DataType,4> supportedTypes =
519 {
520 DataType::Float32,
521 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000522 DataType::QAsymmU8,
523 DataType::QSymmS16
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100524 };
525
526 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
527 "Reference DepthToSpace: input type not supported");
528
529 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
530 "Reference DepthToSpace: output type not supported");
531
532 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
533 "Reference DepthToSpace: input and output types are mismatched");
534
535 return supported;
536}
537
arovir011c7c81b2018-10-08 11:34:28 +0100538bool RefLayerSupport::IsDepthwiseConvolutionSupported(const TensorInfo& input,
539 const TensorInfo& output,
540 const DepthwiseConvolution2dDescriptor& descriptor,
541 const TensorInfo& weights,
542 const Optional<TensorInfo>& biases,
543 Optional<std::string&> reasonIfUnsupported) const
544{
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100545 bool supported = true;
546
547 // Define supported types.
Matthew Jackson252df3a2019-09-11 09:19:18 +0100548 std::array<DataType,4> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100549 {
550 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100551 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000552 DataType::QAsymmU8,
553 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100554 };
555
556 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
557 "Reference DepthwiseConvolution2d: input is not a supported type.");
558
559 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
560 "Reference DepthwiseConvolution2d: output is not a supported type.");
561
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100562 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
563 "Reference DepthwiseConvolution2d: input and output types mismatched.");
564
Derek Lambertid466a542020-01-22 15:37:29 +0000565 ARMNN_NO_DEPRECATE_WARN_BEGIN
566 std::array<DataType, 3> supportedWeightTypes =
567 {
568 DataType::QAsymmU8,
569 DataType::QSymmS8,
570 DataType::QuantizedSymm8PerAxis // deprecated
571 };
572 ARMNN_NO_DEPRECATE_WARN_END
573
Teresa Charlind8df0262019-11-11 12:28:15 +0000574 const DataType inputType = input.GetDataType();
Derek Lambertif90c56d2020-01-10 17:14:08 +0000575 if (inputType == DataType::QAsymmU8)
Teresa Charlind8df0262019-11-11 12:28:15 +0000576 {
Teresa Charlind8df0262019-11-11 12:28:15 +0000577
578 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
579 "Reference convolution2d: weights type not supported for quantized input.");
580 }
581 else
582 {
583 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
584 "Reference DepthwiseConvolution2d: weights is not a supported type.");
585
586 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
587 "Reference DepthwiseConvolution2d: input and weights types mismatched.");
588 }
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100589
590 if (biases.has_value())
591 {
Matthew Jackson252df3a2019-09-11 09:19:18 +0100592 std::array<DataType,3> biasesSupportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100593 {
594 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100595 DataType::Float16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100596 DataType::Signed32
597 };
598 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
599 "Reference DepthwiseConvolution2d: biases is not a supported type.");
600 }
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100601 ignore_unused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100602
603 return supported;
604
arovir011c7c81b2018-10-08 11:34:28 +0100605}
606
Nattapat Chaimanowong8a54ac02019-03-29 15:25:04 +0000607bool RefLayerSupport::IsDequantizeSupported(const TensorInfo& input,
608 const TensorInfo& output,
609 Optional<std::string&> reasonIfUnsupported) const
610{
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100611 bool supported = true;
612
Ryan OShea9add1202020-02-07 10:06:33 +0000613 std::array<DataType,4> supportedInputTypes = {
614 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000615 DataType::QAsymmU8,
Finn Williamsfd271062019-12-04 14:27:27 +0000616 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000617 DataType::QSymmS16
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100618 };
619
620 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000621 "Reference for Dequantize layer: input type not supported.");
622
623 supported &= CheckSupportRule( TypeNotPerAxisQuantized(input), reasonIfUnsupported,
624 "Reference for Dequantize layer: per-axis quantized input not support .");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100625
Derek Lambertid466a542020-01-22 15:37:29 +0000626 supported &= CheckSupportRule(TypeNotPerAxisQuantized(input), reasonIfUnsupported,
627 "Reference dequantize: per-axis quantized input not support .");
628
Jan Eilersf7107932019-11-01 11:09:36 +0000629 std::array<DataType,2> supportedOutputTypes = {
630 DataType::Float32,
631 DataType::Float16
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100632 };
633
634 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000635 "Reference for Dequantize layer: output type not supported.");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100636
637 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000638 "Reference for Dequantize layer: input/output shapes have different num total "
639 "elements.");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100640
641 return supported;
Nattapat Chaimanowong8a54ac02019-03-29 15:25:04 +0000642}
643
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000644bool RefLayerSupport::IsDetectionPostProcessSupported(const TensorInfo& boxEncodings,
645 const TensorInfo& scores,
646 const TensorInfo& anchors,
647 const TensorInfo& detectionBoxes,
648 const TensorInfo& detectionClasses,
649 const TensorInfo& detectionScores,
650 const TensorInfo& numDetections,
651 const DetectionPostProcessDescriptor& descriptor,
652 Optional<std::string&> reasonIfUnsupported) const
Narumol Prangnawaratbc67cef2019-01-31 15:31:54 +0000653{
Derek Lamberti901ea112019-12-10 22:07:09 +0000654 boost::ignore_unused(anchors, detectionBoxes, detectionClasses, detectionScores, numDetections, descriptor);
655
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100656 bool supported = true;
657
Mike Kelly4992c342019-08-14 11:33:11 +0100658 std::array<DataType,3> supportedInputTypes =
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100659 {
660 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000661 DataType::QAsymmU8,
662 DataType::QSymmS16
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100663 };
664
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000665 supported &= CheckSupportRule(TypeAnyOf(boxEncodings, supportedInputTypes), reasonIfUnsupported,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100666 "Reference DetectionPostProcess: input 0 is not a supported type.");
667
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000668 supported &= CheckSupportRule(TypeAnyOf(scores, supportedInputTypes), reasonIfUnsupported,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100669 "Reference DetectionPostProcess: input 1 is not a supported type.");
670
671 return supported;
Narumol Prangnawaratbc67cef2019-01-31 15:31:54 +0000672}
673
Pablo Tellof0bd6832019-04-26 17:58:13 +0100674bool RefLayerSupport::IsDilatedDepthwiseConvolutionSupported(const TensorInfo& input,
675 const TensorInfo& output,
676 const DepthwiseConvolution2dDescriptor& descriptor,
677 const TensorInfo& weights,
678 const Optional<TensorInfo>& biases,
679 Optional<std::string&> reasonIfUnsupported) const
680{
Aron Virginas-Taraece4ed2019-06-14 17:00:09 +0100681 return IsDepthwiseConvolutionSupported(input, output, descriptor, weights, biases, reasonIfUnsupported);
Pablo Tellof0bd6832019-04-26 17:58:13 +0100682}
683
Aron Virginas-Taraece4ed2019-06-14 17:00:09 +0100684bool RefLayerSupport::IsDivisionSupported(const TensorInfo& input0,
arovir011c7c81b2018-10-08 11:34:28 +0100685 const TensorInfo& input1,
686 const TensorInfo& output,
687 Optional<std::string&> reasonIfUnsupported) const
688{
Sadik Armagan2999a022019-04-09 14:20:12 +0100689 bool supported = true;
690
Matthew Jackson9bff1442019-09-12 09:08:23 +0100691 std::array<DataType,4> supportedTypes = {
Sadik Armagan2999a022019-04-09 14:20:12 +0100692 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100693 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000694 DataType::QAsymmU8,
695 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +0100696 };
697
698 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
699 "Reference division: input 0 is not a supported type.");
700
701 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
702 "Reference division: input 1 is not a supported type.");
703
704 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
705 "Reference division: output is not a supported type.");
706
707 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
708 "Reference division: input 0 and Input 1 types are mismatched");
709
710 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
711 "Reference division: input and output types are mismatched");
712
713 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
714 "Reference division: shapes are not suitable for implicit broadcast.");
715
716 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100717}
718
josh minor4a3c6102020-01-06 16:40:46 -0600719bool RefLayerSupport::IsElementwiseUnarySupported(const TensorInfo& input,
720 const TensorInfo& output,
721 const ElementwiseUnaryDescriptor& descriptor,
722 Optional<std::string&> reasonIfUnsupported) const
723{
724 boost::ignore_unused(descriptor);
725
726 std::array<DataType, 4> supportedTypes =
727 {
728 DataType::Float32,
729 DataType::Float16,
730 DataType::QAsymmU8,
731 DataType::QSymmS16
732 };
733
734 bool supported = true;
735
736 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
737 "Reference elementwise unary: input type not supported");
738
739 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
740 "Reference elementwise unary: output type not supported");
741
742 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
743 "Reference elementwise unary: input and output types not matching");
744
745 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
746 "Reference elementwise unary: input and output shapes"
747 "have different number of total elements");
748
749 return supported;
750}
751
FrancisMurtagh30cdfca2018-12-18 12:57:35 +0000752bool RefLayerSupport::IsEqualSupported(const TensorInfo& input0,
753 const TensorInfo& input1,
754 const TensorInfo& output,
755 Optional<std::string&> reasonIfUnsupported) const
756{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100757 return IsComparisonSupported(input0,
758 input1,
759 output,
760 ComparisonDescriptor(ComparisonOperation::Equal),
761 reasonIfUnsupported);
FrancisMurtagh30cdfca2018-12-18 12:57:35 +0000762}
763
arovir011c7c81b2018-10-08 11:34:28 +0100764bool RefLayerSupport::IsFakeQuantizationSupported(const TensorInfo& input,
765 const FakeQuantizationDescriptor& descriptor,
766 Optional<std::string&> reasonIfUnsupported) const
767{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100768 ignore_unused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100769 bool supported = true;
770
771 std::array<DataType,1> supportedTypes =
772 {
773 DataType::Float32
774 };
775
776 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
777 "Reference fake quantization: input type not supported.");
778
779 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100780}
781
782bool RefLayerSupport::IsFloorSupported(const TensorInfo& input,
783 const TensorInfo& output,
784 Optional<std::string&> reasonIfUnsupported) const
785{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100786 ignore_unused(output);
James Conroy83735b12019-05-30 16:36:59 +0100787 bool supported = true;
788
Matthew Jackson9bff1442019-09-12 09:08:23 +0100789 std::array<DataType,3> supportedTypes =
James Conroy83735b12019-05-30 16:36:59 +0100790 {
James Conroyb40d7102019-06-04 12:32:09 +0100791 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100792 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000793 DataType::QSymmS16
James Conroy83735b12019-05-30 16:36:59 +0100794 };
795
796 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
797 "Reference Floor: input type not supported.");
798
799 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
800 "Reference Floor: output type not supported.");
801
802 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100803}
804
805bool RefLayerSupport::IsFullyConnectedSupported(const TensorInfo& input,
806 const TensorInfo& output,
807 const TensorInfo& weights,
808 const TensorInfo& biases,
809 const FullyConnectedDescriptor& descriptor,
810 Optional<std::string&> reasonIfUnsupported) const
811{
Francis Murtagh46c09d02019-05-28 08:15:28 +0100812 bool supported = true;
813
814 // Define supported types.
Matthew Jackson252df3a2019-09-11 09:19:18 +0100815 std::array<DataType,4> supportedTypes =
Francis Murtagh46c09d02019-05-28 08:15:28 +0100816 {
817 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100818 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000819 DataType::QAsymmU8,
820 DataType::QSymmS16
Francis Murtagh46c09d02019-05-28 08:15:28 +0100821 };
822
823 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
824 "Reference Fully Connected: input type not supported.");
825
826 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
827 "Reference Fully Connected: output type not supported.");
828
829 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
830 "Reference Fully Connected: input and output types mismatched.");
831
832 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
833 "Reference Fully Connected: weights type not supported.");
834
835 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
836 "Reference Fully Connected: input and weight types mismatched.");
837
838 if (descriptor.m_BiasEnabled)
839 {
840 // Defined supported types for bias
Matthew Jackson252df3a2019-09-11 09:19:18 +0100841 std::array<DataType, 3>
Francis Murtagh46c09d02019-05-28 08:15:28 +0100842 supportedBiasTypes =
843 {
844 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100845 DataType::Float16,
Francis Murtagh46c09d02019-05-28 08:15:28 +0100846 DataType::Signed32
847 };
848
849 supported &= CheckSupportRule(TypeAnyOf(biases, supportedBiasTypes), reasonIfUnsupported,
850 "Reference Fully Connected: bias type not supported.");
851
852 supported &= CheckSupportRule(BiasAndWeightsTypesMatch(biases, weights), reasonIfUnsupported,
853 "Reference Fully Connected: bias and weight types mismatch.");
854
855 supported &= CheckSupportRule(BiasAndWeightsTypesCompatible(weights, supportedBiasTypes), reasonIfUnsupported,
856 "Reference Fully Connected: bias type inferred from weights is incompatible.");
857
858 }
859
860 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100861}
862
narpra014951d842019-01-18 16:53:53 +0000863bool RefLayerSupport::IsGatherSupported(const armnn::TensorInfo& input0,
864 const armnn::TensorInfo& input1,
865 const armnn::TensorInfo& output,
866 armnn::Optional<std::string&> reasonIfUnsupported) const
867{
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100868 bool supported = true;
Matthew Jackson9bff1442019-09-12 09:08:23 +0100869 std::array<DataType,4> supportedTypes =
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100870 {
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100871 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100872 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000873 DataType::QAsymmU8,
874 DataType::QSymmS16
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100875 };
876
877 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
878 "Reference Gather: input type not supported");
879
880 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
881 "Reference Gather: output type not supported");
882
883 supported &= CheckSupportRule(TypeIs(input1, DataType::Signed32), reasonIfUnsupported,
884 "Reference Gather: indices (input1) type not supported");
885
886 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
887 "Reference Gather: input and output types not matching");
888
889 return supported;
narpra014951d842019-01-18 16:53:53 +0000890}
891
FrancisMurtagh878f0232018-12-19 10:56:15 +0000892bool RefLayerSupport::IsGreaterSupported(const TensorInfo& input0,
893 const TensorInfo& input1,
894 const TensorInfo& output,
895 Optional<std::string&> reasonIfUnsupported) const
896{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100897 return IsComparisonSupported(input0,
898 input1,
899 output,
900 ComparisonDescriptor(ComparisonOperation::Greater),
901 reasonIfUnsupported);
FrancisMurtagh878f0232018-12-19 10:56:15 +0000902}
903
Derek Lamberti901ea112019-12-10 22:07:09 +0000904bool RefLayerSupport::IsInputSupported(const TensorInfo& /*input*/,
905 Optional<std::string&> /*reasonIfUnsupported*/) const
arovir011c7c81b2018-10-08 11:34:28 +0100906{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +0100907 return true;
arovir011c7c81b2018-10-08 11:34:28 +0100908}
909
Kevin May09ca49c2019-10-09 12:37:34 +0100910bool RefLayerSupport::IsInstanceNormalizationSupported(const TensorInfo& input,
911 const TensorInfo& output,
912 const InstanceNormalizationDescriptor& descriptor,
913 Optional<std::string&> reasonIfUnsupported) const
914{
915 ignore_unused(descriptor);
916 // Define supported types
917 std::array<DataType, 4> supportedTypes =
918 {
919 DataType::Float32,
920 DataType::Float16
921 };
922
923 bool supported = true;
924
925 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
926 "Reference Instance Normalization: input type not supported.");
927
928 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
929 "Reference Instance Normalization: output type not supported.");
930
931 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
932 "Reference Instance Normalization: input and output types mismatched.");
933
934 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
935 "Reference Instance Normalization: input and output shapes have different "
936 "num total elements.");
937
938 return supported;
939}
940
arovir011c7c81b2018-10-08 11:34:28 +0100941bool RefLayerSupport::IsL2NormalizationSupported(const TensorInfo& input,
942 const TensorInfo& output,
943 const L2NormalizationDescriptor& descriptor,
944 Optional<std::string&> reasonIfUnsupported) const
945{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100946 ignore_unused(descriptor);
Ferran Balaguerd73d14f2019-06-10 10:29:54 +0100947 // Define supported types
Matthew Jackson252df3a2019-09-11 09:19:18 +0100948 std::array<DataType, 4> supportedTypes =
Ferran Balaguerd73d14f2019-06-10 10:29:54 +0100949 {
950 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100951 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000952 DataType::QAsymmU8,
953 DataType::QSymmS16
Ferran Balaguerd73d14f2019-06-10 10:29:54 +0100954 };
955
956 bool supported = true;
957
958 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
959 "Reference L2normalization: input type not supported.");
960
961 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
962 "Reference L2normalization: output type not supported.");
963
964 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
965 "Reference L2normalization: input and output types mismatched.");
966
967 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
968 "Reference L2normalization: input and output shapes have different "
969 "num total elements.");
970
971 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100972}
973
Aron Virginas-Tare662a942019-10-14 15:12:00 +0100974bool RefLayerSupport::IsLogSoftmaxSupported(const TensorInfo& input,
975 const TensorInfo& output,
976 const LogSoftmaxDescriptor& descriptor,
977 Optional<std::string&> reasonIfUnsupported) const
978{
979 ignore_unused(descriptor);
980
981 std::array<DataType, 2> supportedTypes =
982 {
983 DataType::Float32,
984 DataType::Float16
985 };
986
987 bool supported = true;
988 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
989 "Reference LogSoftmax: input type not supported");
990
991 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
992 "Reference LogSoftmax: output type not supported");
993
994 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
995 "Reference LogSoftmax: input and output types do not match");
996
997 return supported;
998}
999
arovir011c7c81b2018-10-08 11:34:28 +01001000bool RefLayerSupport::IsLstmSupported(const TensorInfo& input,
1001 const TensorInfo& outputStateIn,
1002 const TensorInfo& cellStateIn,
1003 const TensorInfo& scratchBuffer,
1004 const TensorInfo& outputStateOut,
1005 const TensorInfo& cellStateOut,
1006 const TensorInfo& output,
1007 const LstmDescriptor& descriptor,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001008 const LstmInputParamsInfo& paramsInfo,
1009 Optional<std::string&> reasonIfUnsupported) const
arovir011c7c81b2018-10-08 11:34:28 +01001010{
telsoa01c577f2c2018-08-31 09:22:23 +01001011 ignore_unused(descriptor);
Jan Eilersd01a83c2019-07-03 18:20:40 +01001012 ignore_unused(paramsInfo);
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001013
1014 bool supported = true;
1015
1016 std::array<DataType,2> supportedTypes = {
Conor Kennedyb9971c92019-05-07 07:14:23 +01001017 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001018 DataType::QSymmS16
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001019 };
1020
Jan Eilersd01a83c2019-07-03 18:20:40 +01001021 // check inputs and outputs
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001022 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1023 "Reference Lstm: input is not a supported type.");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001024 supported &= CheckSupportRule(TypesAreEqual(input, outputStateIn), reasonIfUnsupported,
1025 "Reference Lstm: input and outputStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001026 supported &= CheckSupportRule(TypesAreEqual(input, cellStateIn), reasonIfUnsupported,
1027 "Reference Lstm: input and cellStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001028 supported &= CheckSupportRule(TypesAreEqual(input, scratchBuffer), reasonIfUnsupported,
1029 "Reference Lstm: input and scratchBuffer types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001030 supported &= CheckSupportRule(TypesAreEqual(input, outputStateOut), reasonIfUnsupported,
1031 "Reference Lstm: input and outputStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001032 supported &= CheckSupportRule(TypesAreEqual(input, cellStateOut), reasonIfUnsupported,
1033 "Reference Lstm: input and cellStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001034 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1035 "Reference Lstm: input and output types are mismatched");
Jan Eilersd01a83c2019-07-03 18:20:40 +01001036 // check layer parameters
Francis Murtaghbb590b42019-08-14 09:51:36 +01001037 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001038 "Reference Lstm: input and InputToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001039 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001040 "Reference Lstm: input and InputToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001041 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001042 "Reference Lstm: input and InputToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001043 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001044 "Reference Lstm: input and RecurrentToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001045 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001046 "Reference Lstm: input and RecurrentToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001047 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001048 "Reference Lstm: input and RecurrentToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001049 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001050 "Reference Lstm: input and ForgetGateBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001051 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001052 "Reference Lstm: input and CellBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001053 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001054 "Reference Lstm: input and OutputGateBias types are mismatched");
1055 if (!descriptor.m_CifgEnabled)
1056 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001057 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToInputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001058 "Reference Lstm: input and InputToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001059 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001060 reasonIfUnsupported,
1061 "Reference Lstm: input and RecurrentToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001062 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001063 "Reference Lstm: input and InputGateBias types are mismatched");
1064 if (descriptor.m_PeepholeEnabled)
1065 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001066 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001067 reasonIfUnsupported,
1068 "Reference Lstm: input and CellToInputWeights types are mismatched");
1069 }
1070 }
1071 if (descriptor.m_PeepholeEnabled)
1072 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001073 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001074 "Reference Lstm: input and CellToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001075 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001076 "Reference Lstm: input and CellToOutputWeights types are mismatched");
1077 }
1078 if (descriptor.m_ProjectionEnabled)
1079 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001080 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001081 "Reference Lstm: input and mProjectionWeights types are mismatched");
1082 if (paramsInfo.m_ProjectionBias != nullptr)
1083 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001084 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001085 "Reference Lstm: input and ProjectionBias types are mismatched");
1086 }
1087 }
1088 if (descriptor.m_LayerNormEnabled)
1089 {
1090 if (!descriptor.m_CifgEnabled)
1091 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001092 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001093 reasonIfUnsupported,
1094 "Reference Lstm: input and InputLayerNormWeights types are mismatched");
1095 }
Francis Murtaghbb590b42019-08-14 09:51:36 +01001096 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001097 reasonIfUnsupported,
1098 "Reference Lstm: input and ForgetLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001099 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001100 reasonIfUnsupported,
1101 "Reference Lstm: input and CellLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001102 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001103 reasonIfUnsupported,
1104 "Reference Lstm: input and OutputLayerNormWeights types are mismatched");
1105 }
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001106
1107 return supported;
telsoa01c577f2c2018-08-31 09:22:23 +01001108}
1109
saoste012df12b32018-11-28 16:57:20 +00001110bool RefLayerSupport::IsMaximumSupported(const TensorInfo& input0,
1111 const TensorInfo& input1,
1112 const TensorInfo& output,
1113 Optional<std::string&> reasonIfUnsupported) const
1114{
Sadik Armagan2999a022019-04-09 14:20:12 +01001115 bool supported = true;
1116
Keith Davis5204aa82020-01-27 15:24:59 +00001117 std::array<DataType,5> supportedTypes = {
Sadik Armagan2999a022019-04-09 14:20:12 +01001118 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001119 DataType::Float16,
Keith Davis5204aa82020-01-27 15:24:59 +00001120 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001121 DataType::QAsymmU8,
1122 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001123 };
1124
1125 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1126 "Reference maximum: input 0 is not a supported type.");
1127
1128 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1129 "Reference maximum: input 1 is not a supported type.");
1130
1131 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1132 "Reference maximum: output is not a supported type.");
1133
1134 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1135 "Reference maximum: input 0 and Input 1 types are mismatched");
1136
1137 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1138 "Reference maximum: input and output types are mismatched");
1139
1140 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1141 "Reference maximum: shapes are not suitable for implicit broadcast.");
1142
1143 return supported;
saoste012df12b32018-11-28 16:57:20 +00001144}
1145
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001146bool RefLayerSupport::IsMeanSupported(const TensorInfo& input,
1147 const TensorInfo& output,
1148 const MeanDescriptor& descriptor,
1149 Optional<std::string&> reasonIfUnsupported) const
narpra0132b90462018-09-13 11:07:48 +01001150{
James Conroy4d1ff582019-06-10 17:06:39 +01001151 bool supported = true;
1152 std::string meanLayerStr = "Mean";
1153 std::string outputTensorStr = "output";
1154
Matthew Jackson252df3a2019-09-11 09:19:18 +01001155 std::array<DataType,4> supportedTypes =
James Conroy4d1ff582019-06-10 17:06:39 +01001156 {
1157 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001158 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001159 DataType::QAsymmU8,
1160 DataType::QSymmS16
James Conroy4d1ff582019-06-10 17:06:39 +01001161 };
1162
1163 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1164 "Reference Mean: input type not supported.");
1165
1166 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1167 "Reference Mean: input and output types are mismatched");
1168
1169 if (descriptor.m_KeepDims)
1170 {
1171 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, input.GetNumDimensions()),
1172 reasonIfUnsupported,
1173 CreateIncorrectDimensionsErrorMsg(input.GetNumDimensions(),
1174 output.GetNumDimensions(),
1175 meanLayerStr, outputTensorStr).data());
1176 }
1177 else if (descriptor.m_Axis.empty())
1178 {
1179 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1180 reasonIfUnsupported,
1181 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1182 meanLayerStr, outputTensorStr).data());
1183 }
1184 else
1185 {
1186 auto outputDim = input.GetNumDimensions() - boost::numeric_cast<unsigned int>(descriptor.m_Axis.size());
1187
1188 if (outputDim > 0)
1189 {
1190 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, outputDim),
1191 reasonIfUnsupported,
1192 CreateIncorrectDimensionsErrorMsg(outputDim, output.GetNumDimensions(),
1193 meanLayerStr, outputTensorStr).data());
1194 }
1195 else
1196 {
1197 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1198 reasonIfUnsupported,
1199 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1200 meanLayerStr, outputTensorStr).data());
1201 }
1202 }
1203
1204 return supported;
narpra0132b90462018-09-13 11:07:48 +01001205}
1206
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001207bool RefLayerSupport::IsMergerSupported(const std::vector<const TensorInfo*> inputs,
Nikhil Raj8599a412018-11-19 14:51:07 +00001208 const TensorInfo& output,
Jim Flynne242f2d2019-05-22 14:24:13 +01001209 const MergerDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001210 Optional<std::string&> reasonIfUnsupported) const
1211{
Jim Flynne242f2d2019-05-22 14:24:13 +01001212 return IsConcatSupported(inputs, output, descriptor, reasonIfUnsupported);
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001213}
1214
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001215bool RefLayerSupport::IsMemCopySupported(const TensorInfo &input,
1216 const TensorInfo &output,
1217 Optional<std::string &> reasonIfUnsupported) const
1218{
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001219 bool supported = true;
1220
1221 std::array<DataType,5> supportedTypes =
1222 {
1223 DataType::Float32,
1224 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001225 DataType::QAsymmU8,
1226 DataType::QSymmS16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001227 DataType::Boolean
1228 };
1229
1230 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1231 "Reference MemCopy: input type not supported");
1232
1233 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1234 "Reference MemCopy: output type not supported");
1235
1236 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1237 "Reference MemCopy: input and output types are mismatched");
1238
1239 return supported;
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001240}
1241
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001242bool RefLayerSupport::IsMinimumSupported(const TensorInfo& input0,
1243 const TensorInfo& input1,
1244 const TensorInfo& output,
1245 Optional<std::string&> reasonIfUnsupported) const
1246{
Sadik Armagan2999a022019-04-09 14:20:12 +01001247 bool supported = true;
1248
Matthew Jackson9bff1442019-09-12 09:08:23 +01001249 std::array<DataType,4> supportedTypes = {
Sadik Armagan2999a022019-04-09 14:20:12 +01001250 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001251 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001252 DataType::QAsymmU8,
1253 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001254 };
1255
1256 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1257 "Reference minimum: input 0 is not a supported type.");
1258
1259 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1260 "Reference minimum: input 1 is not a supported type.");
1261
1262 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1263 "Reference minimum: output is not a supported type.");
1264
1265 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1266 "Reference minimum: input 0 and Input 1 types are mismatched");
1267
1268 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1269 "Reference minimum: input and output types are mismatched");
1270
1271 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1272 "Reference minimum: shapes are not suitable for implicit broadcast.");
1273
1274 return supported;
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001275}
1276
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001277bool RefLayerSupport::IsMultiplicationSupported(const TensorInfo& input0,
1278 const TensorInfo& input1,
1279 const TensorInfo& output,
1280 Optional<std::string&> reasonIfUnsupported) const
1281{
Sadik Armagan2999a022019-04-09 14:20:12 +01001282 bool supported = true;
1283
Keith Davis5204aa82020-01-27 15:24:59 +00001284 std::array<DataType,5> supportedTypes = {
Sadik Armagan2999a022019-04-09 14:20:12 +01001285 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001286 DataType::Float16,
Keith Davis5204aa82020-01-27 15:24:59 +00001287 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001288 DataType::QAsymmU8,
1289 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001290 };
1291
1292 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1293 "Reference multiplication: input 0 is not a supported type.");
1294
1295 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1296 "Reference multiplication: input 1 is not a supported type.");
1297
1298 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1299 "Reference multiplication: output is not a supported type.");
1300
1301 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1302 "Reference multiplication: input 0 and Input 1 types are mismatched");
1303
1304 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1305 "Reference multiplication: input and output types are mismatched");
1306
1307 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1308 "Reference multiplication: shapes are not suitable for implicit broadcast.");
1309
1310 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001311}
1312
1313bool RefLayerSupport::IsNormalizationSupported(const TensorInfo& input,
1314 const TensorInfo& output,
1315 const NormalizationDescriptor& descriptor,
1316 Optional<std::string&> reasonIfUnsupported) const
Nina Drozd661dfa72018-10-02 11:14:17 +01001317{
Nina Drozd661dfa72018-10-02 11:14:17 +01001318 ignore_unused(descriptor);
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001319
1320 // Define supported types
Matteo Martincigh6aeb7712019-06-05 17:23:29 +01001321 std::array<DataType, 4> supportedTypes =
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001322 {
1323 DataType::Float16,
1324 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001325 DataType::QAsymmU8,
1326 DataType::QSymmS16
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001327 };
1328
1329 bool supported = true;
1330
1331 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1332 "Reference normalization: input type not supported.");
1333
1334 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1335 "Reference normalization: output type not supported.");
1336
1337 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1338 "Reference normalization: input and output shapes have different "
1339 "num total elements.");
1340
1341 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001342}
1343
Derek Lamberti901ea112019-12-10 22:07:09 +00001344bool RefLayerSupport::IsOutputSupported(const TensorInfo& /*output*/,
1345 Optional<std::string&> /*reasonIfUnsupported*/) const
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001346{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +01001347 return true;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001348}
1349
1350bool RefLayerSupport::IsPadSupported(const TensorInfo& input,
1351 const TensorInfo& output,
1352 const PadDescriptor& descriptor,
1353 Optional<std::string&> reasonIfUnsupported) const
1354{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001355 ignore_unused(descriptor);
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001356 bool supported = true;
1357
1358 // Define supported output and inputs types.
Matthew Jackson252df3a2019-09-11 09:19:18 +01001359 std::array<DataType,4> supportedTypes =
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001360 {
1361 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001362 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001363 DataType::QAsymmU8,
1364 DataType::QSymmS16
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001365 };
1366
1367 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1368 "Reference pad: input is not a supported type.");
1369
1370 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1371 "Reference pad: output is not a supported type.");
1372
1373 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1374 "Reference pad: input and output types are mismatched.");
1375
1376 return supported;
Nina Drozd661dfa72018-10-02 11:14:17 +01001377}
1378
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001379bool RefLayerSupport::IsPermuteSupported(const TensorInfo& input,
1380 const TensorInfo& output,
1381 const PermuteDescriptor& descriptor,
1382 Optional<std::string&> reasonIfUnsupported) const
1383{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001384 ignore_unused(descriptor);
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001385 bool supported = true;
1386
1387 // Define supported output and inputs types.
1388 std::array<DataType,3> supportedTypes =
1389 {
1390 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001391 DataType::QAsymmU8,
1392 DataType::QSymmS16
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001393 };
1394
1395 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1396 "Reference permute: input is not a supported type.");
1397
1398 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1399 "Reference permute: output is not a supported type.");
1400
1401 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1402 "Reference permute: input and output types are mismatched.");
1403
1404 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001405}
1406
1407bool RefLayerSupport::IsPooling2dSupported(const TensorInfo& input,
1408 const TensorInfo& output,
1409 const Pooling2dDescriptor& descriptor,
1410 Optional<std::string&> reasonIfUnsupported) const
1411{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001412 ignore_unused(descriptor);
Teresa Charlina3b20472019-06-06 11:12:32 +01001413 bool supported = true;
1414
1415 // Define supported output and inputs types.
Matthew Jackson252df3a2019-09-11 09:19:18 +01001416 std::array<DataType,4> supportedTypes =
Teresa Charlina3b20472019-06-06 11:12:32 +01001417 {
1418 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001419 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001420 DataType::QAsymmU8,
1421 DataType::QSymmS16
Teresa Charlina3b20472019-06-06 11:12:32 +01001422 };
1423
1424 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1425 "Reference poolind2d: input is not a supported type.");
1426
1427 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1428 "Reference poolind2d: output is not a supported type.");
1429
1430 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1431 "Reference poolind2d: input and output types are mismatched.");
1432
1433 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001434}
1435
Derek Lamberti5f400d62019-03-25 15:41:58 +00001436bool RefLayerSupport::IsQuantizeSupported(const TensorInfo& input,
1437 const TensorInfo& output,
1438 Optional<std::string&> reasonIfUnsupported) const
1439{
1440 bool supported = true;
1441
Finn Williamsfd271062019-12-04 14:27:27 +00001442 // Define supported input types.
Ryan OShea9add1202020-02-07 10:06:33 +00001443 std::array<DataType,6> supportedInputTypes = {
Keith Davis5e51cd82020-01-29 16:52:59 +00001444 DataType::Float32,
Keith Davis3d8bc972020-02-04 09:31:47 +00001445 DataType::Float16,
Ryan OShea9add1202020-02-07 10:06:33 +00001446 DataType::QAsymmS8,
Keith Davis5e51cd82020-01-29 16:52:59 +00001447 DataType::QAsymmU8,
1448 DataType::QSymmS8,
1449 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001450 };
1451
1452 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
1453 "Reference quantize: input type not supported.");
1454
1455 // Define supported output types.
Ryan OShea9add1202020-02-07 10:06:33 +00001456 std::array<DataType,4> supportedOutputTypes = {
Derek Lambertif90c56d2020-01-10 17:14:08 +00001457 DataType::QAsymmU8,
Ryan OShea9add1202020-02-07 10:06:33 +00001458 DataType::QAsymmS8,
Finn Williamsfd271062019-12-04 14:27:27 +00001459 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001460 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001461 };
1462 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
1463 "Reference quantize: output type not supported.");
1464
1465 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1466 "Reference quantize: input and output shapes have different num total elements.");
1467
1468 return supported;
1469}
1470
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001471bool RefLayerSupport::IsReshapeSupported(const TensorInfo& input,
Kevin Maya023c402019-12-12 17:28:05 +00001472 const TensorInfo& output,
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001473 const ReshapeDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001474 Optional<std::string&> reasonIfUnsupported) const
1475{
Kevin Maya023c402019-12-12 17:28:05 +00001476 ignore_unused(output);
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001477 ignore_unused(descriptor);
Nina Drozd2f2778f2019-05-27 10:37:05 +01001478 // Define supported output types.
Keith Davis5204aa82020-01-27 15:24:59 +00001479 std::array<DataType,6> supportedOutputTypes =
Nina Drozd2f2778f2019-05-27 10:37:05 +01001480 {
1481 DataType::Float32,
1482 DataType::Float16,
Narumol Prangnawarat0718ee92019-09-13 16:53:38 +01001483 DataType::Signed32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001484 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +00001485 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001486 DataType::QSymmS16
Nina Drozd2f2778f2019-05-27 10:37:05 +01001487 };
1488 return CheckSupportRule(TypeAnyOf(input, supportedOutputTypes), reasonIfUnsupported,
1489 "Reference reshape: input type not supported.");
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001490}
1491
1492bool RefLayerSupport::IsResizeBilinearSupported(const TensorInfo& input,
Sadik Armaganc625f002018-12-17 11:32:16 +00001493 const TensorInfo& output,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001494 Optional<std::string&> reasonIfUnsupported) const
1495{
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001496 bool supported = true;
Matthew Jackson9bff1442019-09-12 09:08:23 +01001497 std::array<DataType,4> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001498 {
1499 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001500 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001501 DataType::QAsymmU8,
1502 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001503 };
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001504
1505 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1506 "Reference ResizeBilinear: input type not supported");
1507
1508 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1509 "Reference ResizeBilinear: output type not supported");
1510
1511 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1512 "Reference ResizeBilinear: input and output types not matching");
1513
1514 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001515}
1516
Teresa Charlin970f43b2019-07-01 13:51:07 +01001517bool RefLayerSupport::IsResizeSupported(const TensorInfo& input,
1518 const TensorInfo& output,
1519 const ResizeDescriptor& descriptor,
1520 Optional<std::string&> reasonIfUnsupported) const
1521{
Derek Lamberti901ea112019-12-10 22:07:09 +00001522 boost::ignore_unused(descriptor);
Teresa Charlin970f43b2019-07-01 13:51:07 +01001523 bool supported = true;
Keith Davis5204aa82020-01-27 15:24:59 +00001524 std::array<DataType,5> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001525 {
1526 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001527 DataType::Float16,
Keith Davis5204aa82020-01-27 15:24:59 +00001528 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001529 DataType::QAsymmU8,
1530 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001531 };
1532
1533 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1534 "Reference Resize: input type not supported");
1535
1536 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1537 "Reference Resize: output type not supported");
1538
1539 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1540 "Reference Resize: input and output types not matching");
1541
1542 return supported;
1543}
1544
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001545bool RefLayerSupport::IsRsqrtSupported(const TensorInfo& input,
1546 const TensorInfo& output,
1547 Optional<std::string&> reasonIfUnsupported) const
1548{
josh minor4a3c6102020-01-06 16:40:46 -06001549 return IsElementwiseUnarySupported(input,
1550 output,
1551 ElementwiseUnaryDescriptor(UnaryOperation::Rsqrt),
1552 reasonIfUnsupported);
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001553}
1554
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001555bool RefLayerSupport::IsSliceSupported(const TensorInfo& input,
1556 const TensorInfo& output,
1557 const SliceDescriptor& descriptor,
1558 Optional<std::string&> reasonIfUnsupported) const
1559{
Derek Lamberti901ea112019-12-10 22:07:09 +00001560 boost::ignore_unused(descriptor);
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001561 bool supported = true;
1562
1563 std::array<DataType, 3> supportedTypes =
1564 {
1565 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001566 DataType::QAsymmU8,
1567 DataType::QSymmS16
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001568 };
1569
1570 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1571 "Reference Slice: input type not supported");
1572
1573 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1574 "Reference Slice: output type not supported");
1575
1576 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1577 "Reference Slice: input and output types are mismatched");
1578
1579 return supported;
1580}
1581
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001582bool RefLayerSupport::IsSoftmaxSupported(const TensorInfo& input,
1583 const TensorInfo& output,
1584 const SoftmaxDescriptor& descriptor,
1585 Optional<std::string&> reasonIfUnsupported) const
1586{
Derek Lamberti901ea112019-12-10 22:07:09 +00001587 boost::ignore_unused(descriptor);
nikraj01248683f2019-05-29 16:46:50 +01001588 bool supported = true;
Matthew Jackson9bff1442019-09-12 09:08:23 +01001589 std::array<DataType,4> supportedTypes =
nikraj01248683f2019-05-29 16:46:50 +01001590 {
1591 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001592 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001593 DataType::QAsymmU8,
1594 DataType::QSymmS16
nikraj01248683f2019-05-29 16:46:50 +01001595 };
1596
1597 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001598 "Reference Softmax: output type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001599
1600 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001601 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001602
1603 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001604 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001605
1606 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001607}
1608
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001609bool RefLayerSupport::IsSpaceToBatchNdSupported(const TensorInfo& input,
1610 const TensorInfo& output,
1611 const SpaceToBatchNdDescriptor& descriptor,
1612 Optional<std::string&> reasonIfUnsupported) const
1613{
Derek Lamberti901ea112019-12-10 22:07:09 +00001614 boost::ignore_unused(descriptor);
nikraj01120522a2019-05-31 11:33:07 +01001615 bool supported = true;
Matthew Jackson9bff1442019-09-12 09:08:23 +01001616 std::array<DataType,4> supportedTypes =
nikraj01120522a2019-05-31 11:33:07 +01001617 {
1618 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001619 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001620 DataType::QAsymmU8,
1621 DataType::QSymmS16
nikraj01120522a2019-05-31 11:33:07 +01001622 };
1623
1624 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1625 "Reference SpaceToBatchNd: input type not supported");
1626
1627 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1628 "Reference SpaceToBatchNd: output type not supported");
1629
1630 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1631 "Reference SpaceToBatchNd: input and output types are mismatched");
1632
1633 return supported;
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001634}
1635
Keith Davisa57eccb2019-06-14 17:33:22 +01001636bool RefLayerSupport::IsSpaceToDepthSupported(const TensorInfo& input,
Keith Davis51910332019-06-26 15:28:43 +01001637 const TensorInfo& output,
1638 const SpaceToDepthDescriptor& descriptor,
1639 Optional<std::string&> reasonIfUnsupported) const
Keith Davisa57eccb2019-06-14 17:33:22 +01001640{
1641
1642 ignore_unused(descriptor);
1643 bool supported = true;
1644
Matthew Jackson9bff1442019-09-12 09:08:23 +01001645 std::array<DataType,4> supportedTypes =
Keith Davisa57eccb2019-06-14 17:33:22 +01001646 {
1647 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001648 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001649 DataType::QAsymmU8,
1650 DataType::QSymmS16
Keith Davisa57eccb2019-06-14 17:33:22 +01001651 };
1652
1653 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1654 "Reference SpaceToDepth: input type not supported");
1655
1656 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1657 "Reference SpaceToDepth: output type not supported");
1658
1659 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1660 "Reference SpaceToDepth: input and output types are mismatched");
1661
1662 return supported;
1663}
1664
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001665bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1666 const ViewsDescriptor& descriptor,
1667 Optional<std::string&> reasonIfUnsupported) const
1668{
1669 ignore_unused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001670 bool supported = true;
Matthew Jackson9bff1442019-09-12 09:08:23 +01001671 std::array<DataType,4> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001672 {
1673 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001674 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001675 DataType::QAsymmU8,
1676 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001677 };
1678
1679 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1680 "Reference splitter: input type not supported");
1681
1682 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001683}
1684
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001685bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1686 const std::vector<std::reference_wrapper<TensorInfo>>& outputs,
1687 const ViewsDescriptor& descriptor,
1688 Optional<std::string&> reasonIfUnsupported) const
1689{
1690 ignore_unused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001691 bool supported = true;
Matthew Jackson9bff1442019-09-12 09:08:23 +01001692 std::array<DataType,4> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001693 {
1694 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001695 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001696 DataType::QAsymmU8,
1697 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001698 };
1699
1700 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1701 "Reference splitter: output type not supported");
1702 for (const TensorInfo output : outputs)
1703 {
1704 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1705 "Reference splitter: input type not supported");
1706
1707 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1708 "Reference splitter: input and output types mismatched.");
1709 }
1710
1711 return supported;
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001712}
1713
Matthew Jackson81e601c2019-07-11 12:07:09 +01001714bool RefLayerSupport::IsStackSupported(const std::vector<const TensorInfo*>& inputs,
1715 const TensorInfo& output,
1716 const StackDescriptor& descriptor,
1717 Optional<std::string&> reasonIfUnsupported) const
1718{
1719 ignore_unused(descriptor);
1720
1721 bool supported = true;
Matthew Jacksone69c3992019-09-09 14:31:21 +01001722 std::array<DataType,4> supportedTypes =
Matthew Jackson81e601c2019-07-11 12:07:09 +01001723 {
1724 DataType::Float32,
Matthew Jacksone69c3992019-09-09 14:31:21 +01001725 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001726 DataType::QAsymmU8,
1727 DataType::QSymmS16
Matthew Jackson81e601c2019-07-11 12:07:09 +01001728 };
1729
1730 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1731 "Reference stack: output type not supported");
1732 for (const TensorInfo* input : inputs)
1733 {
1734 BOOST_ASSERT(input != nullptr);
1735 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
1736 "Reference stack: input type not supported");
1737
1738 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
1739 "Reference stack: input and output types mismatched.");
1740 }
1741
1742 return supported;
1743}
1744
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00001745bool RefLayerSupport::IsStridedSliceSupported(const TensorInfo& input,
1746 const TensorInfo& output,
1747 const StridedSliceDescriptor& descriptor,
1748 Optional<std::string&> reasonIfUnsupported) const
1749{
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00001750 ignore_unused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001751 bool supported = true;
1752
1753 std::array<DataType,3> supportedTypes =
1754 {
1755 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001756 DataType::QAsymmU8,
1757 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001758 };
1759
1760 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1761 "Reference StridedSlice: input type not supported");
1762
1763 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1764 "Reference StridedSlice: output type not supported");
1765
1766 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1767 "Reference StridedSlice: input and output types are mismatched");
1768
1769 return supported;
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00001770}
1771
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001772bool RefLayerSupport::IsSubtractionSupported(const TensorInfo& input0,
1773 const TensorInfo& input1,
1774 const TensorInfo& output,
1775 Optional<std::string&> reasonIfUnsupported) const
1776{
Sadik Armagan2999a022019-04-09 14:20:12 +01001777 bool supported = true;
1778
Matthew Jackson9bff1442019-09-12 09:08:23 +01001779 std::array<DataType,4> supportedTypes = {
Sadik Armagan2999a022019-04-09 14:20:12 +01001780 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001781 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001782 DataType::QAsymmU8,
1783 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001784 };
1785
1786 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1787 "Reference subtraction: input 0 is not a supported type.");
1788
1789 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1790 "Reference subtraction: input 1 is not a supported type.");
1791
1792 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1793 "Reference subtraction: output is not a supported type.");
1794
1795 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1796 "Reference subtraction: input 0 and Input 1 types are mismatched");
1797
1798 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1799 "Reference subtraction: input and output types are mismatched");
1800
1801 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1802 "Reference subtraction: shapes are not suitable for implicit broadcast.");
1803
1804 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001805}
1806
Matteo Martincighab9e5252019-06-13 17:27:46 +01001807bool RefLayerSupport::IsPreluSupported(const TensorInfo& input,
1808 const TensorInfo& alpha,
1809 const TensorInfo& output,
1810 Optional<std::string&> reasonIfUnsupported) const
1811{
1812 bool supported = true;
1813
Matthew Jackson9bff1442019-09-12 09:08:23 +01001814 std::array<DataType, 4> supportedTypes
Matteo Martincighab9e5252019-06-13 17:27:46 +01001815 {
1816 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001817 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001818 DataType::QAsymmU8,
1819 DataType::QSymmS16
Matteo Martincighab9e5252019-06-13 17:27:46 +01001820 };
1821
1822 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1823 "PReLU: input is not a supported type.");
1824
1825 supported &= CheckSupportRule(TypeAnyOf(alpha, supportedTypes), reasonIfUnsupported,
1826 "PReLU: alpha is not a supported type.");
1827
1828 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1829 "PReLU: output is not a supported type.");
1830
1831 supported &= CheckSupportRule(TypesAreEqual(input, alpha, output), reasonIfUnsupported,
1832 "PReLU: input, alpha and output types are mismatched");
1833
1834 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input, alpha, output), reasonIfUnsupported,
1835 "PReLU: shapes are not suitable for implicit broadcast");
1836
1837 return supported;
1838}
1839
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01001840bool RefLayerSupport::IsTransposeConvolution2dSupported(const TensorInfo& input,
1841 const TensorInfo& output,
1842 const TransposeConvolution2dDescriptor& descriptor,
1843 const TensorInfo& weights,
1844 const Optional<TensorInfo>& biases,
1845 Optional<std::string&> reasonIfUnsupported) const
1846{
Derek Lamberti901ea112019-12-10 22:07:09 +00001847 boost::ignore_unused(descriptor);
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01001848 bool supported = true;
1849
Matthew Jackson252df3a2019-09-11 09:19:18 +01001850 std::array<DataType,4> supportedTypes =
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01001851 {
1852 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001853 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001854 DataType::QAsymmU8,
1855 DataType::QSymmS16
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01001856 };
1857
1858 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1859 "Reference TransposeConvolution2d: input is not a supported type.");
1860
1861 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1862 "Reference TransposeConvolution2d: output is not a supported type.");
1863
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01001864 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1865 "Reference TransposeConvolution2d: input and output types mismatched.");
1866
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00001867
1868 const DataType inputType = input.GetDataType();
Derek Lambertif90c56d2020-01-10 17:14:08 +00001869 if (inputType == DataType::QAsymmU8)
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00001870 {
Derek Lambertid466a542020-01-22 15:37:29 +00001871 ARMNN_NO_DEPRECATE_WARN_BEGIN
1872 std::array<DataType, 3> supportedWeightTypes =
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00001873 {
Derek Lambertif90c56d2020-01-10 17:14:08 +00001874 DataType::QAsymmU8,
Derek Lambertid466a542020-01-22 15:37:29 +00001875 DataType::QSymmS8,
1876 DataType::QuantizedSymm8PerAxis //Deprecated
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00001877 };
Derek Lambertid466a542020-01-22 15:37:29 +00001878 ARMNN_NO_DEPRECATE_WARN_END
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00001879
1880 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
1881 "Reference TransposeConvolution2d: weights type not supported for "
1882 "quantized input.");
1883 }
1884 else
1885 {
1886 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
1887 "Reference TransposeConvolution2d: weights is not a supported type.");
1888
1889 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
1890 "Reference TransposeConvolution2d: input and weights types mismatched.");
1891 }
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01001892
1893 if (biases.has_value())
1894 {
Matthew Jackson252df3a2019-09-11 09:19:18 +01001895 std::array<DataType,3> biasesSupportedTypes =
Aron Virginas-Tar651aafe2019-08-05 11:52:05 +01001896 {
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01001897 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001898 DataType::Float16,
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01001899 DataType::Signed32
1900 };
1901 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
1902 "Reference TransposeConvolution2d: biases is not a supported type.");
1903 }
1904
1905 return supported;
1906}
1907
arovir011c7c81b2018-10-08 11:34:28 +01001908} // namespace armnn