blob: 551a7b58677cd133707b22734388ad8b9421939a [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 Beck3cc9a622018-10-12 10:38:31 +01007
Keith Davis0c2eeac2020-02-11 16:51:50 +00008#include <armnn/TypesUtils.hpp>
telsoa014fcda012018-03-09 14:13:49 +00009#include <armnn/Types.hpp>
Derek Lamberti50db4e82019-03-13 14:16:15 +000010#include <armnn/Descriptors.hpp>
Jan Eilers8eb25602020-03-09 12:13:48 +000011#include <armnn/utility/IgnoreUnused.hpp>
telsoa014fcda012018-03-09 14:13:49 +000012
Matteo Martincighe011d202019-11-28 11:35:47 +000013#include <LayerSupportCommon.hpp>
Derek Lambertif674aa02019-08-01 15:56:25 +010014#include <backendsCommon/LayerSupportRules.hpp>
Matteo Martincighe011d202019-11-28 11:35:47 +000015
Matteo Martincighe011d202019-11-28 11:35:47 +000016#include <boost/cast.hpp>
telsoa014fcda012018-03-09 14:13:49 +000017
Derek Lamberti50db4e82019-03-13 14:16:15 +000018#include <vector>
Derek Lamberti50db4e82019-03-13 14:16:15 +000019#include <array>
20
telsoa014fcda012018-03-09 14:13:49 +000021using namespace boost;
22
23namespace armnn
24{
25
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +010026namespace
27{
28
29template<typename Float32Func, typename Uint8Func, typename ... Params>
30bool IsSupportedForDataTypeRef(Optional<std::string&> reasonIfUnsupported,
31 DataType dataType,
32 Float32Func floatFuncPtr,
33 Uint8Func uint8FuncPtr,
34 Params&&... params)
35{
36 return IsSupportedForDataTypeGeneric(reasonIfUnsupported,
37 dataType,
38 &FalseFunc<Params...>,
39 floatFuncPtr,
40 uint8FuncPtr,
narpra01db2b1602019-01-23 15:23:11 +000041 &FalseFunc<Params...>,
kevmay012b4d88e2019-01-24 14:05:09 +000042 &FalseFunc<Params...>,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +010043 std::forward<Params>(params)...);
44}
45
46} // anonymous namespace
47
James Conroy4d1ff582019-06-10 17:06:39 +010048namespace
49{
50
51std::string CreateIncorrectDimensionsErrorMsg(unsigned int expected,
52 unsigned int actual,
53 std::string& layerStr,
54 std::string& tensorName)
55{
56 std::string errorMsg = "Reference " + layerStr + ": Expected " + std::to_string(expected) + " dimensions but got" +
57 " " + std::to_string(actual) + " dimensions instead, for the '" + tensorName + "' tensor.";
58
59 return errorMsg;
60}
61
62} // anonymous namespace
Derek Lamberti50db4e82019-03-13 14:16:15 +000063
Sadik Armagan9199e582019-09-05 17:35:31 +010064bool RefLayerSupport::IsAbsSupported(const TensorInfo& input, const TensorInfo& output,
65 Optional<std::string&> reasonIfUnsupported) const
66{
josh minor4a3c6102020-01-06 16:40:46 -060067 return IsElementwiseUnarySupported(input,
68 output,
69 ElementwiseUnaryDescriptor(UnaryOperation::Abs),
70 reasonIfUnsupported);
Sadik Armagan9199e582019-09-05 17:35:31 +010071}
72
arovir011c7c81b2018-10-08 11:34:28 +010073bool RefLayerSupport::IsActivationSupported(const TensorInfo& input,
74 const TensorInfo& output,
75 const ActivationDescriptor& descriptor,
76 Optional<std::string&> reasonIfUnsupported) const
77{
Derek Lamberti50db4e82019-03-13 14:16:15 +000078 bool supported = true;
79
80 // Define supported types.
Keith Davis0c2eeac2020-02-11 16:51:50 +000081 std::array<DataType,6> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +000082 DataType::BFloat16,
Derek Lamberti50db4e82019-03-13 14:16:15 +000083 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +010084 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +000085 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +000086 DataType::QAsymmU8,
87 DataType::QSymmS16
Derek Lamberti50db4e82019-03-13 14:16:15 +000088 };
89
90 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
91 "Reference activation: input type not supported.");
92
93 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
94 "Reference activation: output type not supported.");
95
96 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
97 "Reference activation: input and output types mismatched.");
98
99 supported &= CheckSupportRule(ShapesAreSameRank(input, output), reasonIfUnsupported,
100 "Reference activation: input and output shapes are of different rank.");
101
102
103 struct ActivationFunctionSupported : public Rule
104 {
105 ActivationFunctionSupported(const ActivationDescriptor& desc)
106 {
107 switch(desc.m_Function)
108 {
109 case ActivationFunction::Abs:
110 case ActivationFunction::BoundedReLu:
David Monahan3b3c3812020-02-25 09:03:29 +0000111 case ActivationFunction::Elu:
Colm Donelan03fbeaf2020-02-26 15:39:23 +0000112 case ActivationFunction::HardSwish:
Derek Lamberti50db4e82019-03-13 14:16:15 +0000113 case ActivationFunction::LeakyReLu:
114 case ActivationFunction::Linear:
115 case ActivationFunction::ReLu:
116 case ActivationFunction::Sigmoid:
117 case ActivationFunction::SoftReLu:
118 case ActivationFunction::Sqrt:
119 case ActivationFunction::Square:
120 case ActivationFunction::TanH:
121 {
122 m_Res = true;
123 break;
124 }
125 default:
126 {
127 m_Res = false;
128 break;
129 }
130 }
131 }
132 };
133
134 // Function is supported
135 supported &= CheckSupportRule(ActivationFunctionSupported(descriptor), reasonIfUnsupported,
136 "Reference activation: function not supported.");
137
138 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100139}
140
141bool RefLayerSupport::IsAdditionSupported(const TensorInfo& input0,
142 const TensorInfo& input1,
143 const TensorInfo& output,
144 Optional<std::string&> reasonIfUnsupported) const
145{
Derek Lamberti50db4e82019-03-13 14:16:15 +0000146 bool supported = true;
147
Keith Davis0c2eeac2020-02-11 16:51:50 +0000148 std::array<DataType,6> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000149 DataType::BFloat16,
Derek Lamberti50db4e82019-03-13 14:16:15 +0000150 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100151 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000152 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000153 DataType::QAsymmU8,
154 DataType::QSymmS16
Derek Lamberti50db4e82019-03-13 14:16:15 +0000155 };
156
157 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
158 "Reference addition: input 0 is not a supported type.");
159
160 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
161 "Reference addition: input 1 is not a supported type.");
162
163 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
164 "Reference addition: output is not a supported type.");
165
166 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
167 "Reference addition: input 0 and Input 1 types are mismatched");
168
169 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
170 "Reference addition: input and output types are mismatched");
171
172 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
173 "Reference addition: shapes are not suitable for implicit broadcast.");
174
175 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100176}
177
Nikhil Raj68c2c902019-09-19 11:21:11 +0100178bool RefLayerSupport::IsArgMinMaxSupported(const armnn::TensorInfo &input, const armnn::TensorInfo &output,
179 const armnn::ArgMinMaxDescriptor &descriptor,
180 armnn::Optional<std::string &> reasonIfUnsupported) const
181{
Jan Eilers8eb25602020-03-09 12:13:48 +0000182 IgnoreUnused(descriptor);
Nikhil Raj68c2c902019-09-19 11:21:11 +0100183
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000184 std::array<DataType, 5> supportedTypes =
Nikhil Raj68c2c902019-09-19 11:21:11 +0100185 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000186 DataType::BFloat16,
Nikhil Raj68c2c902019-09-19 11:21:11 +0100187 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{
Jan Eilers8eb25602020-03-09 12:13:48 +0000212 IgnoreUnused(descriptor);
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100213
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000214 std::array<DataType, 5> supportedTypes =
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100215 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000216 DataType::BFloat16,
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100217 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100218 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000219 DataType::QAsymmU8,
220 DataType::QSymmS16
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100221 };
222
223 bool supported = true;
224
225 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
226 "Reference batch normalization: input is not a supported type.");
227
228 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
229 "Reference batch normalization: output is not a supported type.");
230
231 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
232 "Reference batch normalization: input and output types are mismatched");
233
234 supported &= CheckSupportRule(TypeAnyOf(mean, supportedTypes), reasonIfUnsupported,
235 "Reference batch normalization: mean is not a supported type.");
236
237 supported &= CheckSupportRule(TypeAnyOf(variance, supportedTypes), reasonIfUnsupported,
238 "Reference batch normalization: variance is not a supported type.");
239
240 supported &= CheckSupportRule(TypeAnyOf(beta, supportedTypes), reasonIfUnsupported,
241 "Reference batch normalization: beta is not a supported type.");
242
243 supported &= CheckSupportRule(TypeAnyOf(gamma, supportedTypes), reasonIfUnsupported,
244 "Reference batch normalization: gamma is not a supported type.");
245
246 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100247}
248
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000249bool RefLayerSupport::IsBatchToSpaceNdSupported(const TensorInfo& input,
250 const TensorInfo& output,
251 const BatchToSpaceNdDescriptor& descriptor,
252 Optional<std::string&> reasonIfUnsupported) const
253{
Jan Eilers8eb25602020-03-09 12:13:48 +0000254 IgnoreUnused(descriptor);
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100255
256 bool supported = true;
257
258 std::string batchToSpaceNdLayerStr = "batchToSpaceNd";
259 std::string inputTensorStr = "input";
260 std::string outputTensorStr = "output";
261
262 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000263 std::array<DataType,5> supportedTypes =
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100264 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000265 DataType::BFloat16,
266 DataType::Float32,
267 DataType::Float16,
268 DataType::QAsymmU8,
269 DataType::QSymmS16
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100270 };
271
272 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
273 "Reference BatchToSpaceNd: input type not supported.");
274
275 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
276 "Reference BatchToSpaceNd: output type not supported.");
277
278 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
279 "Reference BatchToSpaceNd: input and output types mismatched.");
280
281 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 4),
282 reasonIfUnsupported,
283 CreateIncorrectDimensionsErrorMsg(4,
284 output.GetNumDimensions(),
285 batchToSpaceNdLayerStr,
286 outputTensorStr).data());
287
288 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(input, 4),
289 reasonIfUnsupported,
290 CreateIncorrectDimensionsErrorMsg(4,
291 input.GetNumDimensions(),
292 batchToSpaceNdLayerStr,
293 inputTensorStr).data());
294
295 return supported;
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000296}
297
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100298bool RefLayerSupport::IsComparisonSupported(const TensorInfo& input0,
299 const TensorInfo& input1,
300 const TensorInfo& output,
301 const ComparisonDescriptor& descriptor,
302 Optional<std::string&> reasonIfUnsupported) const
303{
Jan Eilers8eb25602020-03-09 12:13:48 +0000304 IgnoreUnused(descriptor);
Sadik Armaganb60dd242020-03-19 13:53:16 +0000305 std::array<DataType, 7> supportedInputTypes =
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100306 {
Sadik Armaganb60dd242020-03-19 13:53:16 +0000307 DataType::Boolean,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000308 DataType::BFloat16,
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100309 DataType::Float32,
310 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000311 DataType::QAsymmU8,
Sadik Armaganb60dd242020-03-19 13:53:16 +0000312 DataType::QSymmS16,
313 DataType::Signed32
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100314 };
315
316 bool supported = true;
317 supported &= CheckSupportRule(TypeAnyOf(input0, supportedInputTypes), reasonIfUnsupported,
318 "Reference comparison: input 0 is not a supported type");
319
320 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
321 "Reference comparison: input 0 and Input 1 types are mismatched");
322
323 supported &= CheckSupportRule(TypeIs(output, DataType::Boolean), reasonIfUnsupported,
324 "Reference comparison: output is not of type Boolean");
325
326 return supported;
327}
328
Jim Flynn906f9462019-05-10 13:55:21 +0100329bool RefLayerSupport::IsConcatSupported(const std::vector<const TensorInfo*> inputs,
330 const TensorInfo& output,
Jim Flynne242f2d2019-05-22 14:24:13 +0100331 const ConcatDescriptor& descriptor,
Jim Flynn906f9462019-05-10 13:55:21 +0100332 Optional<std::string&> reasonIfUnsupported) const
333{
Jan Eilers8eb25602020-03-09 12:13:48 +0000334 IgnoreUnused(descriptor);
Jim Flynne242f2d2019-05-22 14:24:13 +0100335
336 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000337 std::array<DataType,6> supportedTypes =
Jim Flynne242f2d2019-05-22 14:24:13 +0100338 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000339 DataType::BFloat16,
340 DataType::Float32,
341 DataType::Float16,
342 DataType::QAsymmU8,
343 DataType::QAsymmS8,
344 DataType::QSymmS16
Jim Flynne242f2d2019-05-22 14:24:13 +0100345 };
346
347 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
348 "Reference concatenation: output type not supported");
349 for (const TensorInfo* input : inputs)
350 {
Matthew Jackson81e601c2019-07-11 12:07:09 +0100351 BOOST_ASSERT(input != nullptr);
Jim Flynne242f2d2019-05-22 14:24:13 +0100352 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
353 "Reference concatenation: input type not supported");
354
355 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
356 "Reference concatenation: input and output types mismatched.");
357 }
358
359 return supported;
Jim Flynn906f9462019-05-10 13:55:21 +0100360}
361
arovir011c7c81b2018-10-08 11:34:28 +0100362bool RefLayerSupport::IsConstantSupported(const TensorInfo& output,
363 Optional<std::string&> reasonIfUnsupported) const
364{
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000365 std::array<DataType,7> supportedTypes =
Jim Flynne242f2d2019-05-22 14:24:13 +0100366 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000367 DataType::BFloat16,
Nina Drozd58ef2c62019-05-16 12:09:18 +0100368 DataType::Float32,
369 DataType::Signed32,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000370 DataType::QAsymmU8,
Keith Davis67e6c542020-02-19 10:08:33 +0000371 DataType::QAsymmS8,
Keith Davis5204aa82020-01-27 15:24:59 +0000372 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000373 DataType::QSymmS16
Nina Drozd58ef2c62019-05-16 12:09:18 +0100374 };
375
376 return CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
377 "Reference constant: output is not a supported type.");
arovir011c7c81b2018-10-08 11:34:28 +0100378}
379
Narumol Prangnawarat7ddbbae2020-03-13 10:26:05 +0000380bool RefLayerSupport::IsConvertBf16ToFp32Supported(const TensorInfo& input,
381 const TensorInfo& output,
382 Optional<std::string&> reasonIfUnsupported) const
383{
384 bool supported = true;
385
386 supported &= CheckSupportRule(TypeIs(input, DataType::BFloat16), reasonIfUnsupported,
387 "Reference for ConvertBf16ToFp32 layer: input type not supported");
388
389 supported &= CheckSupportRule(TypeIs(output, DataType::Float32), reasonIfUnsupported,
390 "Reference for ConvertBf16ToFp32 layer: output type not supported");
391
392 return supported;
393}
394
arovir011c7c81b2018-10-08 11:34:28 +0100395bool RefLayerSupport::IsConvertFp16ToFp32Supported(const TensorInfo& input,
396 const TensorInfo& output,
397 Optional<std::string&> reasonIfUnsupported) const
398{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100399 return (IsSupportedForDataTypeGeneric(reasonIfUnsupported,
400 input.GetDataType(),
401 &TrueFunc<>,
402 &FalseInputFuncF32<>,
narpra01db2b1602019-01-23 15:23:11 +0000403 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000404 &FalseFuncI32<>,
405 &FalseFuncU8<>) &&
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100406 IsSupportedForDataTypeGeneric(reasonIfUnsupported,
407 output.GetDataType(),
408 &FalseOutputFuncF16<>,
409 &TrueFunc<>,
narpra01db2b1602019-01-23 15:23:11 +0000410 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000411 &FalseFuncI32<>,
412 &FalseFuncU8<>));
arovir011c7c81b2018-10-08 11:34:28 +0100413}
414
Narumol Prangnawaratea54a012020-03-16 16:36:10 +0000415bool RefLayerSupport::IsConvertFp32ToBf16Supported(const TensorInfo& input,
416 const TensorInfo& output,
417 Optional<std::string&> reasonIfUnsupported) const
418{
419 bool supported = true;
420
421 supported &= CheckSupportRule(TypeIs(input, DataType::Float32), reasonIfUnsupported,
422 "Reference for ConvertFp32ToBf16 layer: input type not supported");
423
424 supported &= CheckSupportRule(TypeIs(output, DataType::BFloat16), reasonIfUnsupported,
425 "Reference for ConvertFp32ToBf16 layer: output type not supported");
426
427 return supported;
428}
429
arovir011c7c81b2018-10-08 11:34:28 +0100430bool RefLayerSupport::IsConvertFp32ToFp16Supported(const TensorInfo& input,
431 const TensorInfo& output,
432 Optional<std::string&> reasonIfUnsupported) const
433{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100434 return (IsSupportedForDataTypeGeneric(reasonIfUnsupported,
435 input.GetDataType(),
436 &FalseInputFuncF16<>,
437 &TrueFunc<>,
narpra01db2b1602019-01-23 15:23:11 +0000438 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000439 &FalseFuncI32<>,
440 &FalseFuncU8<>) &&
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100441 IsSupportedForDataTypeGeneric(reasonIfUnsupported,
442 output.GetDataType(),
443 &TrueFunc<>,
444 &FalseOutputFuncF32<>,
narpra01db2b1602019-01-23 15:23:11 +0000445 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000446 &FalseFuncI32<>,
447 &FalseFuncU8<>));
arovir011c7c81b2018-10-08 11:34:28 +0100448}
449
450bool RefLayerSupport::IsConvolution2dSupported(const TensorInfo& input,
451 const TensorInfo& output,
452 const Convolution2dDescriptor& descriptor,
453 const TensorInfo& weights,
454 const Optional<TensorInfo>& biases,
455 Optional<std::string&> reasonIfUnsupported) const
456{
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100457 bool supported = true;
458
459 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000460 std::array<DataType,7> supportedTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000461 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000462 DataType::BFloat16,
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000463 DataType::Float32,
464 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000465 DataType::QAsymmU8,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000466 DataType::QAsymmS8,
Keith Davis5204aa82020-01-27 15:24:59 +0000467 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000468 DataType::QSymmS16
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100469 };
470
471 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000472 "Reference Convolution2d: input is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100473
474 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000475 "Reference Convolution2d: output is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100476
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100477 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000478 "Reference Convolution2d: input and output types mismatched.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100479
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000480 const DataType inputType = input.GetDataType();
Keith Davis0c2eeac2020-02-11 16:51:50 +0000481 if (IsQuantized8BitType(inputType))
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000482 {
Derek Lambertid466a542020-01-22 15:37:29 +0000483 ARMNN_NO_DEPRECATE_WARN_BEGIN
Keith Davis0c2eeac2020-02-11 16:51:50 +0000484 std::array<DataType, 4> supportedWeightTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000485 {
Derek Lambertif90c56d2020-01-10 17:14:08 +0000486 DataType::QAsymmU8,
Derek Lambertid466a542020-01-22 15:37:29 +0000487 DataType::QSymmS8,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000488 DataType::QAsymmS8,
Derek Lambertid466a542020-01-22 15:37:29 +0000489 DataType::QuantizedSymm8PerAxis // deprecated
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000490 };
Derek Lambertid466a542020-01-22 15:37:29 +0000491 ARMNN_NO_DEPRECATE_WARN_END
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000492
493 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000494 "Reference Convolution2d: weights type not supported for quantized input.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000495 }
496 else
497 {
498 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000499 "Reference Convolution2d: weights is not a supported type.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000500
501 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000502 "Reference Convolution2d: input and weights types mismatched.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000503 }
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100504
505 if (biases.has_value())
506 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000507 std::array<DataType,4> biasesSupportedTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000508 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000509 DataType::BFloat16,
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000510 DataType::Float32,
511 DataType::Float16,
512 DataType::Signed32
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100513 };
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000514
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100515 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000516 "Reference Convolution2d: biases is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100517 }
Jan Eilers8eb25602020-03-09 12:13:48 +0000518 IgnoreUnused(descriptor);
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100519
520 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100521}
522
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000523bool RefLayerSupport::IsDebugSupported(const TensorInfo& input,
524 const TensorInfo& output,
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000525 Optional<std::string&> reasonIfUnsupported) const
526{
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100527 bool supported = true;
528
Narumol Prangnawarat403a1852020-03-12 14:24:13 +0000529 std::array<DataType, 8> supportedTypes =
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100530 {
Narumol Prangnawarat403a1852020-03-12 14:24:13 +0000531 DataType::BFloat16,
Aron Virginas-Tardb1a2832019-11-12 16:15:11 +0000532 DataType::Float16,
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100533 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000534 DataType::QAsymmU8,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000535 DataType::QAsymmS8,
Keith Davis5204aa82020-01-27 15:24:59 +0000536 DataType::QSymmS8,
Narumol Prangnawaratd2d917d2020-01-09 10:16:39 +0000537 DataType::QSymmS16,
538 DataType::Signed32
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100539 };
540
541 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000542 "Reference for Debug layer: input type not supported");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100543
544 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000545 "Reference for Debug layer: output type not supported");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100546
547 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000548 "Reference for Debug layer: input and output types are mismatched");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100549
550 return supported;
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000551}
552
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100553bool RefLayerSupport::IsDepthToSpaceSupported(const TensorInfo& input,
554 const TensorInfo& output,
555 const DepthToSpaceDescriptor& descriptor,
556 Optional<std::string&> reasonIfUnsupported) const
557{
Jan Eilers8eb25602020-03-09 12:13:48 +0000558 IgnoreUnused(descriptor);
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100559 bool supported = true;
560
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000561 std::array<DataType,5> supportedTypes =
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100562 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000563 DataType::BFloat16,
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100564 DataType::Float32,
565 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000566 DataType::QAsymmU8,
567 DataType::QSymmS16
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100568 };
569
570 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
571 "Reference DepthToSpace: input type not supported");
572
573 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
574 "Reference DepthToSpace: output type not supported");
575
576 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
577 "Reference DepthToSpace: input and output types are mismatched");
578
579 return supported;
580}
581
arovir011c7c81b2018-10-08 11:34:28 +0100582bool RefLayerSupport::IsDepthwiseConvolutionSupported(const TensorInfo& input,
583 const TensorInfo& output,
584 const DepthwiseConvolution2dDescriptor& descriptor,
585 const TensorInfo& weights,
586 const Optional<TensorInfo>& biases,
587 Optional<std::string&> reasonIfUnsupported) const
588{
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100589 bool supported = true;
590
591 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000592 std::array<DataType,7> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100593 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000594 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100595 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100596 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000597 DataType::QSymmS8,
598 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000599 DataType::QAsymmU8,
600 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100601 };
602
603 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
604 "Reference DepthwiseConvolution2d: input is not a supported type.");
605
606 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
607 "Reference DepthwiseConvolution2d: output is not a supported type.");
608
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100609 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
610 "Reference DepthwiseConvolution2d: input and output types mismatched.");
611
Derek Lambertid466a542020-01-22 15:37:29 +0000612 ARMNN_NO_DEPRECATE_WARN_BEGIN
613 std::array<DataType, 3> supportedWeightTypes =
614 {
615 DataType::QAsymmU8,
616 DataType::QSymmS8,
617 DataType::QuantizedSymm8PerAxis // deprecated
618 };
619 ARMNN_NO_DEPRECATE_WARN_END
620
Teresa Charlind8df0262019-11-11 12:28:15 +0000621 const DataType inputType = input.GetDataType();
Keith Davis0c2eeac2020-02-11 16:51:50 +0000622 if (IsQuantized8BitType(inputType))
Teresa Charlind8df0262019-11-11 12:28:15 +0000623 {
Teresa Charlind8df0262019-11-11 12:28:15 +0000624
625 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
626 "Reference convolution2d: weights type not supported for quantized input.");
627 }
628 else
629 {
630 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
631 "Reference DepthwiseConvolution2d: weights is not a supported type.");
632
633 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
634 "Reference DepthwiseConvolution2d: input and weights types mismatched.");
635 }
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100636
637 if (biases.has_value())
638 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000639 std::array<DataType,4> biasesSupportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100640 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000641 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100642 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100643 DataType::Float16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100644 DataType::Signed32
645 };
646 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
647 "Reference DepthwiseConvolution2d: biases is not a supported type.");
648 }
Jan Eilers8eb25602020-03-09 12:13:48 +0000649 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100650
651 return supported;
652
arovir011c7c81b2018-10-08 11:34:28 +0100653}
654
Nattapat Chaimanowong8a54ac02019-03-29 15:25:04 +0000655bool RefLayerSupport::IsDequantizeSupported(const TensorInfo& input,
656 const TensorInfo& output,
657 Optional<std::string&> reasonIfUnsupported) const
658{
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100659 bool supported = true;
660
Ryan OShea9add1202020-02-07 10:06:33 +0000661 std::array<DataType,4> supportedInputTypes = {
662 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000663 DataType::QAsymmU8,
Finn Williamsfd271062019-12-04 14:27:27 +0000664 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000665 DataType::QSymmS16
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100666 };
667
668 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000669 "Reference for Dequantize layer: input type not supported.");
670
671 supported &= CheckSupportRule( TypeNotPerAxisQuantized(input), reasonIfUnsupported,
672 "Reference for Dequantize layer: per-axis quantized input not support .");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100673
Derek Lambertid466a542020-01-22 15:37:29 +0000674 supported &= CheckSupportRule(TypeNotPerAxisQuantized(input), reasonIfUnsupported,
675 "Reference dequantize: per-axis quantized input not support .");
676
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000677 std::array<DataType,3> supportedOutputTypes = {
678 DataType::BFloat16,
Jan Eilersf7107932019-11-01 11:09:36 +0000679 DataType::Float32,
680 DataType::Float16
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100681 };
682
683 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000684 "Reference for Dequantize layer: output type not supported.");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100685
686 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000687 "Reference for Dequantize layer: input/output shapes have different num total "
688 "elements.");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100689
690 return supported;
Nattapat Chaimanowong8a54ac02019-03-29 15:25:04 +0000691}
692
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000693bool RefLayerSupport::IsDetectionPostProcessSupported(const TensorInfo& boxEncodings,
694 const TensorInfo& scores,
695 const TensorInfo& anchors,
696 const TensorInfo& detectionBoxes,
697 const TensorInfo& detectionClasses,
698 const TensorInfo& detectionScores,
699 const TensorInfo& numDetections,
700 const DetectionPostProcessDescriptor& descriptor,
701 Optional<std::string&> reasonIfUnsupported) const
Narumol Prangnawaratbc67cef2019-01-31 15:31:54 +0000702{
Jan Eilers8eb25602020-03-09 12:13:48 +0000703 IgnoreUnused(anchors, detectionBoxes, detectionClasses, detectionScores, numDetections, descriptor);
Derek Lamberti901ea112019-12-10 22:07:09 +0000704
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100705 bool supported = true;
706
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000707 std::array<DataType,4> supportedInputTypes =
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100708 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000709 DataType::BFloat16,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100710 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000711 DataType::QAsymmU8,
712 DataType::QSymmS16
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100713 };
714
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000715 supported &= CheckSupportRule(TypeAnyOf(boxEncodings, supportedInputTypes), reasonIfUnsupported,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100716 "Reference DetectionPostProcess: input 0 is not a supported type.");
717
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000718 supported &= CheckSupportRule(TypeAnyOf(scores, supportedInputTypes), reasonIfUnsupported,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100719 "Reference DetectionPostProcess: input 1 is not a supported type.");
720
721 return supported;
Narumol Prangnawaratbc67cef2019-01-31 15:31:54 +0000722}
723
Pablo Tellof0bd6832019-04-26 17:58:13 +0100724bool RefLayerSupport::IsDilatedDepthwiseConvolutionSupported(const TensorInfo& input,
725 const TensorInfo& output,
726 const DepthwiseConvolution2dDescriptor& descriptor,
727 const TensorInfo& weights,
728 const Optional<TensorInfo>& biases,
729 Optional<std::string&> reasonIfUnsupported) const
730{
Aron Virginas-Taraece4ed2019-06-14 17:00:09 +0100731 return IsDepthwiseConvolutionSupported(input, output, descriptor, weights, biases, reasonIfUnsupported);
Pablo Tellof0bd6832019-04-26 17:58:13 +0100732}
733
Aron Virginas-Taraece4ed2019-06-14 17:00:09 +0100734bool RefLayerSupport::IsDivisionSupported(const TensorInfo& input0,
arovir011c7c81b2018-10-08 11:34:28 +0100735 const TensorInfo& input1,
736 const TensorInfo& output,
737 Optional<std::string&> reasonIfUnsupported) const
738{
Sadik Armagan2999a022019-04-09 14:20:12 +0100739 bool supported = true;
740
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000741 std::array<DataType,5> supportedTypes = {
742 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +0100743 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100744 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000745 DataType::QAsymmU8,
746 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +0100747 };
748
749 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
750 "Reference division: input 0 is not a supported type.");
751
752 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
753 "Reference division: input 1 is not a supported type.");
754
755 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
756 "Reference division: output is not a supported type.");
757
758 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
759 "Reference division: input 0 and Input 1 types are mismatched");
760
761 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
762 "Reference division: input and output types are mismatched");
763
764 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
765 "Reference division: shapes are not suitable for implicit broadcast.");
766
767 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100768}
769
josh minor4a3c6102020-01-06 16:40:46 -0600770bool RefLayerSupport::IsElementwiseUnarySupported(const TensorInfo& input,
771 const TensorInfo& output,
772 const ElementwiseUnaryDescriptor& descriptor,
773 Optional<std::string&> reasonIfUnsupported) const
774{
Jan Eilers8eb25602020-03-09 12:13:48 +0000775 IgnoreUnused(descriptor);
josh minor4a3c6102020-01-06 16:40:46 -0600776
Sadik Armaganac472102020-03-24 09:54:36 +0000777 std::array<DataType, 6> supportedTypes =
josh minor4a3c6102020-01-06 16:40:46 -0600778 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000779 DataType::BFloat16,
josh minor4a3c6102020-01-06 16:40:46 -0600780 DataType::Float32,
781 DataType::Float16,
782 DataType::QAsymmU8,
Sadik Armaganac472102020-03-24 09:54:36 +0000783 DataType::QSymmS16,
784 DataType::Signed32
josh minor4a3c6102020-01-06 16:40:46 -0600785 };
786
787 bool supported = true;
788
789 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
790 "Reference elementwise unary: input type not supported");
791
792 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
793 "Reference elementwise unary: output type not supported");
794
795 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
796 "Reference elementwise unary: input and output types not matching");
797
798 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
799 "Reference elementwise unary: input and output shapes"
800 "have different number of total elements");
801
802 return supported;
803}
804
FrancisMurtagh30cdfca2018-12-18 12:57:35 +0000805bool RefLayerSupport::IsEqualSupported(const TensorInfo& input0,
806 const TensorInfo& input1,
807 const TensorInfo& output,
808 Optional<std::string&> reasonIfUnsupported) const
809{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100810 return IsComparisonSupported(input0,
811 input1,
812 output,
813 ComparisonDescriptor(ComparisonOperation::Equal),
814 reasonIfUnsupported);
FrancisMurtagh30cdfca2018-12-18 12:57:35 +0000815}
816
arovir011c7c81b2018-10-08 11:34:28 +0100817bool RefLayerSupport::IsFakeQuantizationSupported(const TensorInfo& input,
818 const FakeQuantizationDescriptor& descriptor,
819 Optional<std::string&> reasonIfUnsupported) const
820{
Jan Eilers8eb25602020-03-09 12:13:48 +0000821 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100822 bool supported = true;
823
824 std::array<DataType,1> supportedTypes =
825 {
826 DataType::Float32
827 };
828
829 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
830 "Reference fake quantization: input type not supported.");
831
832 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100833}
834
835bool RefLayerSupport::IsFloorSupported(const TensorInfo& input,
836 const TensorInfo& output,
837 Optional<std::string&> reasonIfUnsupported) const
838{
Jan Eilers8eb25602020-03-09 12:13:48 +0000839 IgnoreUnused(output);
James Conroy83735b12019-05-30 16:36:59 +0100840 bool supported = true;
841
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000842 std::array<DataType,4> supportedTypes =
James Conroy83735b12019-05-30 16:36:59 +0100843 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000844 DataType::BFloat16,
James Conroyb40d7102019-06-04 12:32:09 +0100845 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100846 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000847 DataType::QSymmS16
James Conroy83735b12019-05-30 16:36:59 +0100848 };
849
850 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
851 "Reference Floor: input type not supported.");
852
853 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
854 "Reference Floor: output type not supported.");
855
856 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100857}
858
859bool RefLayerSupport::IsFullyConnectedSupported(const TensorInfo& input,
860 const TensorInfo& output,
861 const TensorInfo& weights,
862 const TensorInfo& biases,
863 const FullyConnectedDescriptor& descriptor,
864 Optional<std::string&> reasonIfUnsupported) const
865{
Francis Murtagh46c09d02019-05-28 08:15:28 +0100866 bool supported = true;
867
868 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000869 std::array<DataType,6> supportedTypes =
Francis Murtagh46c09d02019-05-28 08:15:28 +0100870 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000871 DataType::BFloat16,
872 DataType::Float32,
873 DataType::Float16,
874 DataType::QAsymmU8,
875 DataType::QAsymmS8,
876 DataType::QSymmS16
Francis Murtagh46c09d02019-05-28 08:15:28 +0100877 };
878
879 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
880 "Reference Fully Connected: input type not supported.");
881
882 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
883 "Reference Fully Connected: output type not supported.");
884
885 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
886 "Reference Fully Connected: input and output types mismatched.");
887
888 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
889 "Reference Fully Connected: weights type not supported.");
890
Francis Murtaghddb1d062020-03-10 13:51:45 +0000891 ARMNN_NO_DEPRECATE_WARN_BEGIN
892 std::array<DataType, 3> supportedWeightTypes =
893 {
894 DataType::QAsymmU8,
895 DataType::QSymmS8,
896 DataType::QuantizedSymm8PerAxis // deprecated
897 };
898 ARMNN_NO_DEPRECATE_WARN_END
899
900 if (IsQuantized8BitType(input.GetDataType()))
901 {
902
903 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
904 "Reference Fully Connected: weights type not supported for quantized input.");
905 }
906 else
907 {
908 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
909 "Reference Fully Connected: weights is not a supported type.");
910
911 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
912 "Reference Fully Connected: input and weights types mismatched.");
913 }
Francis Murtagh46c09d02019-05-28 08:15:28 +0100914
915 if (descriptor.m_BiasEnabled)
916 {
917 // Defined supported types for bias
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000918 std::array<DataType, 4>
Francis Murtagh46c09d02019-05-28 08:15:28 +0100919 supportedBiasTypes =
920 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000921 DataType::BFloat16,
Francis Murtagh46c09d02019-05-28 08:15:28 +0100922 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100923 DataType::Float16,
Francis Murtagh46c09d02019-05-28 08:15:28 +0100924 DataType::Signed32
925 };
926
927 supported &= CheckSupportRule(TypeAnyOf(biases, supportedBiasTypes), reasonIfUnsupported,
928 "Reference Fully Connected: bias type not supported.");
929
930 supported &= CheckSupportRule(BiasAndWeightsTypesMatch(biases, weights), reasonIfUnsupported,
931 "Reference Fully Connected: bias and weight types mismatch.");
932
933 supported &= CheckSupportRule(BiasAndWeightsTypesCompatible(weights, supportedBiasTypes), reasonIfUnsupported,
934 "Reference Fully Connected: bias type inferred from weights is incompatible.");
935
936 }
937
938 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100939}
940
narpra014951d842019-01-18 16:53:53 +0000941bool RefLayerSupport::IsGatherSupported(const armnn::TensorInfo& input0,
942 const armnn::TensorInfo& input1,
943 const armnn::TensorInfo& output,
944 armnn::Optional<std::string&> reasonIfUnsupported) const
945{
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100946 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000947 std::array<DataType,5> supportedTypes =
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100948 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000949 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100950 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100951 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000952 DataType::QAsymmU8,
953 DataType::QSymmS16
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100954 };
955
956 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
957 "Reference Gather: input type not supported");
958
959 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
960 "Reference Gather: output type not supported");
961
962 supported &= CheckSupportRule(TypeIs(input1, DataType::Signed32), reasonIfUnsupported,
963 "Reference Gather: indices (input1) type not supported");
964
965 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
966 "Reference Gather: input and output types not matching");
967
968 return supported;
narpra014951d842019-01-18 16:53:53 +0000969}
970
FrancisMurtagh878f0232018-12-19 10:56:15 +0000971bool RefLayerSupport::IsGreaterSupported(const TensorInfo& input0,
972 const TensorInfo& input1,
973 const TensorInfo& output,
974 Optional<std::string&> reasonIfUnsupported) const
975{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100976 return IsComparisonSupported(input0,
977 input1,
978 output,
979 ComparisonDescriptor(ComparisonOperation::Greater),
980 reasonIfUnsupported);
FrancisMurtagh878f0232018-12-19 10:56:15 +0000981}
982
Derek Lamberti901ea112019-12-10 22:07:09 +0000983bool RefLayerSupport::IsInputSupported(const TensorInfo& /*input*/,
984 Optional<std::string&> /*reasonIfUnsupported*/) const
arovir011c7c81b2018-10-08 11:34:28 +0100985{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +0100986 return true;
arovir011c7c81b2018-10-08 11:34:28 +0100987}
988
Kevin May09ca49c2019-10-09 12:37:34 +0100989bool RefLayerSupport::IsInstanceNormalizationSupported(const TensorInfo& input,
990 const TensorInfo& output,
991 const InstanceNormalizationDescriptor& descriptor,
992 Optional<std::string&> reasonIfUnsupported) const
993{
Jan Eilers8eb25602020-03-09 12:13:48 +0000994 IgnoreUnused(descriptor);
Kevin May09ca49c2019-10-09 12:37:34 +0100995 // Define supported types
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000996 std::array<DataType, 3> supportedTypes =
Kevin May09ca49c2019-10-09 12:37:34 +0100997 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000998 DataType::BFloat16,
Kevin May09ca49c2019-10-09 12:37:34 +0100999 DataType::Float32,
1000 DataType::Float16
1001 };
1002
1003 bool supported = true;
1004
1005 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1006 "Reference Instance Normalization: input type not supported.");
1007
1008 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1009 "Reference Instance Normalization: output type not supported.");
1010
1011 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1012 "Reference Instance Normalization: input and output types mismatched.");
1013
1014 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1015 "Reference Instance Normalization: input and output shapes have different "
1016 "num total elements.");
1017
1018 return supported;
1019}
1020
arovir011c7c81b2018-10-08 11:34:28 +01001021bool RefLayerSupport::IsL2NormalizationSupported(const TensorInfo& input,
1022 const TensorInfo& output,
1023 const L2NormalizationDescriptor& descriptor,
1024 Optional<std::string&> reasonIfUnsupported) const
1025{
Jan Eilers8eb25602020-03-09 12:13:48 +00001026 IgnoreUnused(descriptor);
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001027 // Define supported types
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001028 std::array<DataType, 5> supportedTypes =
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001029 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001030 DataType::BFloat16,
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001031 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001032 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001033 DataType::QAsymmU8,
1034 DataType::QSymmS16
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001035 };
1036
1037 bool supported = true;
1038
1039 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1040 "Reference L2normalization: input type not supported.");
1041
1042 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1043 "Reference L2normalization: output type not supported.");
1044
1045 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1046 "Reference L2normalization: input and output types mismatched.");
1047
1048 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1049 "Reference L2normalization: input and output shapes have different "
1050 "num total elements.");
1051
1052 return supported;
arovir011c7c81b2018-10-08 11:34:28 +01001053}
1054
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001055bool RefLayerSupport::IsLogSoftmaxSupported(const TensorInfo& input,
1056 const TensorInfo& output,
1057 const LogSoftmaxDescriptor& descriptor,
1058 Optional<std::string&> reasonIfUnsupported) const
1059{
Jan Eilers8eb25602020-03-09 12:13:48 +00001060 IgnoreUnused(descriptor);
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001061
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001062 std::array<DataType, 3> supportedTypes =
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001063 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001064 DataType::BFloat16,
1065 DataType::Float32,
1066 DataType::Float16
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001067 };
1068
1069 bool supported = true;
1070 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1071 "Reference LogSoftmax: input type not supported");
1072
1073 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1074 "Reference LogSoftmax: output type not supported");
1075
1076 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1077 "Reference LogSoftmax: input and output types do not match");
1078
1079 return supported;
1080}
1081
arovir011c7c81b2018-10-08 11:34:28 +01001082bool RefLayerSupport::IsLstmSupported(const TensorInfo& input,
1083 const TensorInfo& outputStateIn,
1084 const TensorInfo& cellStateIn,
1085 const TensorInfo& scratchBuffer,
1086 const TensorInfo& outputStateOut,
1087 const TensorInfo& cellStateOut,
1088 const TensorInfo& output,
1089 const LstmDescriptor& descriptor,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001090 const LstmInputParamsInfo& paramsInfo,
1091 Optional<std::string&> reasonIfUnsupported) const
arovir011c7c81b2018-10-08 11:34:28 +01001092{
Jan Eilers8eb25602020-03-09 12:13:48 +00001093 IgnoreUnused(descriptor);
1094 IgnoreUnused(paramsInfo);
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001095
1096 bool supported = true;
1097
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001098 std::array<DataType,3> supportedTypes = {
1099 DataType::BFloat16,
Conor Kennedyb9971c92019-05-07 07:14:23 +01001100 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001101 DataType::QSymmS16
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001102 };
1103
Jan Eilersd01a83c2019-07-03 18:20:40 +01001104 // check inputs and outputs
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001105 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1106 "Reference Lstm: input is not a supported type.");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001107 supported &= CheckSupportRule(TypesAreEqual(input, outputStateIn), reasonIfUnsupported,
1108 "Reference Lstm: input and outputStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001109 supported &= CheckSupportRule(TypesAreEqual(input, cellStateIn), reasonIfUnsupported,
1110 "Reference Lstm: input and cellStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001111 supported &= CheckSupportRule(TypesAreEqual(input, scratchBuffer), reasonIfUnsupported,
1112 "Reference Lstm: input and scratchBuffer types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001113 supported &= CheckSupportRule(TypesAreEqual(input, outputStateOut), reasonIfUnsupported,
1114 "Reference Lstm: input and outputStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001115 supported &= CheckSupportRule(TypesAreEqual(input, cellStateOut), reasonIfUnsupported,
1116 "Reference Lstm: input and cellStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001117 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1118 "Reference Lstm: input and output types are mismatched");
Jan Eilersd01a83c2019-07-03 18:20:40 +01001119 // check layer parameters
Francis Murtaghbb590b42019-08-14 09:51:36 +01001120 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001121 "Reference Lstm: input and InputToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001122 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001123 "Reference Lstm: input and InputToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001124 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001125 "Reference Lstm: input and InputToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001126 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001127 "Reference Lstm: input and RecurrentToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001128 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001129 "Reference Lstm: input and RecurrentToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001130 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001131 "Reference Lstm: input and RecurrentToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001132 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001133 "Reference Lstm: input and ForgetGateBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001134 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001135 "Reference Lstm: input and CellBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001136 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001137 "Reference Lstm: input and OutputGateBias types are mismatched");
1138 if (!descriptor.m_CifgEnabled)
1139 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001140 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToInputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001141 "Reference Lstm: input and InputToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001142 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001143 reasonIfUnsupported,
1144 "Reference Lstm: input and RecurrentToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001145 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001146 "Reference Lstm: input and InputGateBias types are mismatched");
1147 if (descriptor.m_PeepholeEnabled)
1148 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001149 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001150 reasonIfUnsupported,
1151 "Reference Lstm: input and CellToInputWeights types are mismatched");
1152 }
1153 }
1154 if (descriptor.m_PeepholeEnabled)
1155 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001156 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001157 "Reference Lstm: input and CellToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001158 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001159 "Reference Lstm: input and CellToOutputWeights types are mismatched");
1160 }
1161 if (descriptor.m_ProjectionEnabled)
1162 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001163 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001164 "Reference Lstm: input and mProjectionWeights types are mismatched");
1165 if (paramsInfo.m_ProjectionBias != nullptr)
1166 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001167 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001168 "Reference Lstm: input and ProjectionBias types are mismatched");
1169 }
1170 }
1171 if (descriptor.m_LayerNormEnabled)
1172 {
1173 if (!descriptor.m_CifgEnabled)
1174 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001175 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001176 reasonIfUnsupported,
1177 "Reference Lstm: input and InputLayerNormWeights types are mismatched");
1178 }
Francis Murtaghbb590b42019-08-14 09:51:36 +01001179 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001180 reasonIfUnsupported,
1181 "Reference Lstm: input and ForgetLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001182 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001183 reasonIfUnsupported,
1184 "Reference Lstm: input and CellLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001185 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001186 reasonIfUnsupported,
1187 "Reference Lstm: input and OutputLayerNormWeights types are mismatched");
1188 }
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001189
1190 return supported;
telsoa01c577f2c2018-08-31 09:22:23 +01001191}
1192
saoste012df12b32018-11-28 16:57:20 +00001193bool RefLayerSupport::IsMaximumSupported(const TensorInfo& input0,
1194 const TensorInfo& input1,
1195 const TensorInfo& output,
1196 Optional<std::string&> reasonIfUnsupported) const
1197{
Sadik Armagan2999a022019-04-09 14:20:12 +01001198 bool supported = true;
1199
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001200 std::array<DataType,6> supportedTypes = {
1201 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001202 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001203 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001204 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001205 DataType::QAsymmU8,
1206 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001207 };
1208
1209 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1210 "Reference maximum: input 0 is not a supported type.");
1211
1212 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1213 "Reference maximum: input 1 is not a supported type.");
1214
1215 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1216 "Reference maximum: output is not a supported type.");
1217
1218 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1219 "Reference maximum: input 0 and Input 1 types are mismatched");
1220
1221 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1222 "Reference maximum: input and output types are mismatched");
1223
1224 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1225 "Reference maximum: shapes are not suitable for implicit broadcast.");
1226
1227 return supported;
saoste012df12b32018-11-28 16:57:20 +00001228}
1229
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001230bool RefLayerSupport::IsMeanSupported(const TensorInfo& input,
1231 const TensorInfo& output,
1232 const MeanDescriptor& descriptor,
1233 Optional<std::string&> reasonIfUnsupported) const
narpra0132b90462018-09-13 11:07:48 +01001234{
James Conroy4d1ff582019-06-10 17:06:39 +01001235 bool supported = true;
1236 std::string meanLayerStr = "Mean";
1237 std::string outputTensorStr = "output";
1238
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001239 std::array<DataType,5> supportedTypes =
James Conroy4d1ff582019-06-10 17:06:39 +01001240 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001241 DataType::BFloat16,
James Conroy4d1ff582019-06-10 17:06:39 +01001242 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001243 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001244 DataType::QAsymmU8,
1245 DataType::QSymmS16
James Conroy4d1ff582019-06-10 17:06:39 +01001246 };
1247
1248 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1249 "Reference Mean: input type not supported.");
1250
1251 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1252 "Reference Mean: input and output types are mismatched");
1253
1254 if (descriptor.m_KeepDims)
1255 {
1256 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, input.GetNumDimensions()),
1257 reasonIfUnsupported,
1258 CreateIncorrectDimensionsErrorMsg(input.GetNumDimensions(),
1259 output.GetNumDimensions(),
1260 meanLayerStr, outputTensorStr).data());
1261 }
1262 else if (descriptor.m_Axis.empty())
1263 {
1264 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1265 reasonIfUnsupported,
1266 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1267 meanLayerStr, outputTensorStr).data());
1268 }
1269 else
1270 {
1271 auto outputDim = input.GetNumDimensions() - boost::numeric_cast<unsigned int>(descriptor.m_Axis.size());
1272
1273 if (outputDim > 0)
1274 {
1275 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, outputDim),
1276 reasonIfUnsupported,
1277 CreateIncorrectDimensionsErrorMsg(outputDim, output.GetNumDimensions(),
1278 meanLayerStr, outputTensorStr).data());
1279 }
1280 else
1281 {
1282 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1283 reasonIfUnsupported,
1284 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1285 meanLayerStr, outputTensorStr).data());
1286 }
1287 }
1288
1289 return supported;
narpra0132b90462018-09-13 11:07:48 +01001290}
1291
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001292bool RefLayerSupport::IsMergerSupported(const std::vector<const TensorInfo*> inputs,
Nikhil Raj8599a412018-11-19 14:51:07 +00001293 const TensorInfo& output,
Jim Flynne242f2d2019-05-22 14:24:13 +01001294 const MergerDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001295 Optional<std::string&> reasonIfUnsupported) const
1296{
Jim Flynne242f2d2019-05-22 14:24:13 +01001297 return IsConcatSupported(inputs, output, descriptor, reasonIfUnsupported);
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001298}
1299
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001300bool RefLayerSupport::IsMemCopySupported(const TensorInfo &input,
1301 const TensorInfo &output,
1302 Optional<std::string &> reasonIfUnsupported) const
1303{
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001304 bool supported = true;
1305
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001306 std::array<DataType,6> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001307 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001308 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001309 DataType::Float32,
1310 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001311 DataType::QAsymmU8,
1312 DataType::QSymmS16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001313 DataType::Boolean
1314 };
1315
1316 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1317 "Reference MemCopy: input type not supported");
1318
1319 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1320 "Reference MemCopy: output type not supported");
1321
1322 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1323 "Reference MemCopy: input and output types are mismatched");
1324
1325 return supported;
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001326}
1327
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001328bool RefLayerSupport::IsMinimumSupported(const TensorInfo& input0,
1329 const TensorInfo& input1,
1330 const TensorInfo& output,
1331 Optional<std::string&> reasonIfUnsupported) const
1332{
Sadik Armagan2999a022019-04-09 14:20:12 +01001333 bool supported = true;
1334
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001335 std::array<DataType,5> supportedTypes = {
1336 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001337 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001338 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001339 DataType::QAsymmU8,
1340 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001341 };
1342
1343 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1344 "Reference minimum: input 0 is not a supported type.");
1345
1346 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1347 "Reference minimum: input 1 is not a supported type.");
1348
1349 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1350 "Reference minimum: output is not a supported type.");
1351
1352 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1353 "Reference minimum: input 0 and Input 1 types are mismatched");
1354
1355 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1356 "Reference minimum: input and output types are mismatched");
1357
1358 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1359 "Reference minimum: shapes are not suitable for implicit broadcast.");
1360
1361 return supported;
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001362}
1363
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001364bool RefLayerSupport::IsMultiplicationSupported(const TensorInfo& input0,
1365 const TensorInfo& input1,
1366 const TensorInfo& output,
1367 Optional<std::string&> reasonIfUnsupported) const
1368{
Sadik Armagan2999a022019-04-09 14:20:12 +01001369 bool supported = true;
1370
Keith Davis67e6c542020-02-19 10:08:33 +00001371 std::array<DataType,6> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001372 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001373 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001374 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001375 DataType::QAsymmU8,
Keith Davis67e6c542020-02-19 10:08:33 +00001376 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001377 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001378 };
1379
1380 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1381 "Reference multiplication: input 0 is not a supported type.");
1382
1383 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1384 "Reference multiplication: input 1 is not a supported type.");
1385
1386 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1387 "Reference multiplication: output is not a supported type.");
1388
1389 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1390 "Reference multiplication: input 0 and Input 1 types are mismatched");
1391
1392 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1393 "Reference multiplication: input and output types are mismatched");
1394
1395 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1396 "Reference multiplication: shapes are not suitable for implicit broadcast.");
1397
1398 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001399}
1400
1401bool RefLayerSupport::IsNormalizationSupported(const TensorInfo& input,
1402 const TensorInfo& output,
1403 const NormalizationDescriptor& descriptor,
1404 Optional<std::string&> reasonIfUnsupported) const
Nina Drozd661dfa72018-10-02 11:14:17 +01001405{
Jan Eilers8eb25602020-03-09 12:13:48 +00001406 IgnoreUnused(descriptor);
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001407
1408 // Define supported types
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001409 std::array<DataType, 5> supportedTypes =
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001410 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001411 DataType::BFloat16,
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001412 DataType::Float16,
1413 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001414 DataType::QAsymmU8,
1415 DataType::QSymmS16
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001416 };
1417
1418 bool supported = true;
1419
1420 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1421 "Reference normalization: input type not supported.");
1422
1423 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1424 "Reference normalization: output type not supported.");
1425
1426 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1427 "Reference normalization: input and output shapes have different "
1428 "num total elements.");
1429
1430 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001431}
1432
Derek Lamberti901ea112019-12-10 22:07:09 +00001433bool RefLayerSupport::IsOutputSupported(const TensorInfo& /*output*/,
1434 Optional<std::string&> /*reasonIfUnsupported*/) const
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001435{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +01001436 return true;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001437}
1438
1439bool RefLayerSupport::IsPadSupported(const TensorInfo& input,
1440 const TensorInfo& output,
1441 const PadDescriptor& descriptor,
1442 Optional<std::string&> reasonIfUnsupported) const
1443{
Jan Eilers8eb25602020-03-09 12:13:48 +00001444 IgnoreUnused(descriptor);
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001445 bool supported = true;
1446
1447 // Define supported output and inputs types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001448 std::array<DataType,5> supportedTypes =
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001449 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001450 DataType::BFloat16,
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001451 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001452 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001453 DataType::QAsymmU8,
1454 DataType::QSymmS16
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001455 };
1456
1457 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1458 "Reference pad: input is not a supported type.");
1459
1460 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1461 "Reference pad: output is not a supported type.");
1462
1463 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1464 "Reference pad: input and output types are mismatched.");
1465
1466 return supported;
Nina Drozd661dfa72018-10-02 11:14:17 +01001467}
1468
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001469bool RefLayerSupport::IsPermuteSupported(const TensorInfo& input,
1470 const TensorInfo& output,
1471 const PermuteDescriptor& descriptor,
1472 Optional<std::string&> reasonIfUnsupported) const
1473{
Jan Eilers8eb25602020-03-09 12:13:48 +00001474 IgnoreUnused(descriptor);
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001475 bool supported = true;
1476
1477 // Define supported output and inputs types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001478 std::array<DataType, 5> supportedTypes =
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001479 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001480 DataType::BFloat16,
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001481 DataType::Float32,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00001482 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001483 DataType::QAsymmU8,
1484 DataType::QSymmS16
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001485 };
1486
1487 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1488 "Reference permute: input is not a supported type.");
1489
1490 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1491 "Reference permute: output is not a supported type.");
1492
1493 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1494 "Reference permute: input and output types are mismatched.");
1495
1496 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001497}
1498
1499bool RefLayerSupport::IsPooling2dSupported(const TensorInfo& input,
1500 const TensorInfo& output,
1501 const Pooling2dDescriptor& descriptor,
1502 Optional<std::string&> reasonIfUnsupported) const
1503{
Jan Eilers8eb25602020-03-09 12:13:48 +00001504 IgnoreUnused(descriptor);
Teresa Charlina3b20472019-06-06 11:12:32 +01001505 bool supported = true;
1506
1507 // Define supported output and inputs types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001508 std::array<DataType,6> supportedTypes =
Teresa Charlina3b20472019-06-06 11:12:32 +01001509 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001510 DataType::BFloat16,
Teresa Charlina3b20472019-06-06 11:12:32 +01001511 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001512 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001513 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001514 DataType::QAsymmU8,
1515 DataType::QSymmS16
Teresa Charlina3b20472019-06-06 11:12:32 +01001516 };
1517
1518 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1519 "Reference poolind2d: input is not a supported type.");
1520
1521 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1522 "Reference poolind2d: output is not a supported type.");
1523
1524 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1525 "Reference poolind2d: input and output types are mismatched.");
1526
1527 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001528}
1529
Derek Lamberti5f400d62019-03-25 15:41:58 +00001530bool RefLayerSupport::IsQuantizeSupported(const TensorInfo& input,
1531 const TensorInfo& output,
1532 Optional<std::string&> reasonIfUnsupported) const
1533{
1534 bool supported = true;
1535
Finn Williamsfd271062019-12-04 14:27:27 +00001536 // Define supported input types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001537 std::array<DataType,7> supportedInputTypes = {
1538 DataType::BFloat16,
Keith Davis5e51cd82020-01-29 16:52:59 +00001539 DataType::Float32,
Keith Davis3d8bc972020-02-04 09:31:47 +00001540 DataType::Float16,
Ryan OShea9add1202020-02-07 10:06:33 +00001541 DataType::QAsymmS8,
Keith Davis5e51cd82020-01-29 16:52:59 +00001542 DataType::QAsymmU8,
1543 DataType::QSymmS8,
1544 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001545 };
1546
1547 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
1548 "Reference quantize: input type not supported.");
1549
1550 // Define supported output types.
Ryan OShea9add1202020-02-07 10:06:33 +00001551 std::array<DataType,4> supportedOutputTypes = {
Derek Lambertif90c56d2020-01-10 17:14:08 +00001552 DataType::QAsymmU8,
Ryan OShea9add1202020-02-07 10:06:33 +00001553 DataType::QAsymmS8,
Finn Williamsfd271062019-12-04 14:27:27 +00001554 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001555 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001556 };
1557 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
1558 "Reference quantize: output type not supported.");
1559
1560 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1561 "Reference quantize: input and output shapes have different num total elements.");
1562
1563 return supported;
1564}
1565
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001566bool RefLayerSupport::IsReshapeSupported(const TensorInfo& input,
Kevin Maya023c402019-12-12 17:28:05 +00001567 const TensorInfo& output,
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001568 const ReshapeDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001569 Optional<std::string&> reasonIfUnsupported) const
1570{
Jan Eilers8eb25602020-03-09 12:13:48 +00001571 IgnoreUnused(output);
1572 IgnoreUnused(descriptor);
Nina Drozd2f2778f2019-05-27 10:37:05 +01001573 // Define supported output types.
Keith Davis0c2eeac2020-02-11 16:51:50 +00001574 std::array<DataType,7> supportedOutputTypes =
Nina Drozd2f2778f2019-05-27 10:37:05 +01001575 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001576 DataType::BFloat16,
Nina Drozd2f2778f2019-05-27 10:37:05 +01001577 DataType::Float32,
1578 DataType::Float16,
Narumol Prangnawarat0718ee92019-09-13 16:53:38 +01001579 DataType::Signed32,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001580 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001581 DataType::QAsymmU8,
1582 DataType::QSymmS16
Nina Drozd2f2778f2019-05-27 10:37:05 +01001583 };
Keith Davis0c2eeac2020-02-11 16:51:50 +00001584
Nina Drozd2f2778f2019-05-27 10:37:05 +01001585 return CheckSupportRule(TypeAnyOf(input, supportedOutputTypes), reasonIfUnsupported,
1586 "Reference reshape: input type not supported.");
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001587}
1588
1589bool RefLayerSupport::IsResizeBilinearSupported(const TensorInfo& input,
Sadik Armaganc625f002018-12-17 11:32:16 +00001590 const TensorInfo& output,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001591 Optional<std::string&> reasonIfUnsupported) const
1592{
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001593 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001594 std::array<DataType,5> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001595 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001596 DataType::BFloat16,
Teresa Charlin970f43b2019-07-01 13:51:07 +01001597 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001598 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001599 DataType::QAsymmU8,
1600 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001601 };
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001602
1603 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1604 "Reference ResizeBilinear: input type not supported");
1605
1606 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1607 "Reference ResizeBilinear: output type not supported");
1608
1609 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1610 "Reference ResizeBilinear: input and output types not matching");
1611
1612 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001613}
1614
Teresa Charlin970f43b2019-07-01 13:51:07 +01001615bool RefLayerSupport::IsResizeSupported(const TensorInfo& input,
1616 const TensorInfo& output,
1617 const ResizeDescriptor& descriptor,
1618 Optional<std::string&> reasonIfUnsupported) const
1619{
Jan Eilers8eb25602020-03-09 12:13:48 +00001620 IgnoreUnused(descriptor);
Teresa Charlin970f43b2019-07-01 13:51:07 +01001621 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001622 std::array<DataType,6> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001623 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001624 DataType::BFloat16,
Teresa Charlin970f43b2019-07-01 13:51:07 +01001625 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001626 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001627 DataType::QAsymmU8,
Keith Davis67e6c542020-02-19 10:08:33 +00001628 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001629 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001630 };
1631
1632 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1633 "Reference Resize: input type not supported");
1634
1635 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1636 "Reference Resize: output type not supported");
1637
1638 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1639 "Reference Resize: input and output types not matching");
1640
1641 return supported;
1642}
1643
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001644bool RefLayerSupport::IsRsqrtSupported(const TensorInfo& input,
1645 const TensorInfo& output,
1646 Optional<std::string&> reasonIfUnsupported) const
1647{
josh minor4a3c6102020-01-06 16:40:46 -06001648 return IsElementwiseUnarySupported(input,
1649 output,
1650 ElementwiseUnaryDescriptor(UnaryOperation::Rsqrt),
1651 reasonIfUnsupported);
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001652}
1653
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001654bool RefLayerSupport::IsSliceSupported(const TensorInfo& input,
1655 const TensorInfo& output,
1656 const SliceDescriptor& descriptor,
1657 Optional<std::string&> reasonIfUnsupported) const
1658{
Jan Eilers8eb25602020-03-09 12:13:48 +00001659 IgnoreUnused(descriptor);
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001660 bool supported = true;
1661
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001662 std::array<DataType, 4> supportedTypes =
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001663 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001664 DataType::BFloat16,
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001665 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001666 DataType::QAsymmU8,
1667 DataType::QSymmS16
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001668 };
1669
1670 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1671 "Reference Slice: input type not supported");
1672
1673 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1674 "Reference Slice: output type not supported");
1675
1676 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1677 "Reference Slice: input and output types are mismatched");
1678
1679 return supported;
1680}
1681
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001682bool RefLayerSupport::IsSoftmaxSupported(const TensorInfo& input,
1683 const TensorInfo& output,
1684 const SoftmaxDescriptor& descriptor,
1685 Optional<std::string&> reasonIfUnsupported) const
1686{
Jan Eilers8eb25602020-03-09 12:13:48 +00001687 IgnoreUnused(descriptor);
nikraj01248683f2019-05-29 16:46:50 +01001688 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001689 std::array<DataType,7> supportedTypes =
nikraj01248683f2019-05-29 16:46:50 +01001690 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001691 DataType::BFloat16,
1692 DataType::Float32,
1693 DataType::Float16,
1694 DataType::QSymmS8,
1695 DataType::QAsymmS8,
1696 DataType::QAsymmU8,
1697 DataType::QSymmS16
nikraj01248683f2019-05-29 16:46:50 +01001698 };
1699
1700 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001701 "Reference Softmax: output type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001702
1703 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001704 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001705
1706 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001707 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001708
1709 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001710}
1711
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001712bool RefLayerSupport::IsSpaceToBatchNdSupported(const TensorInfo& input,
1713 const TensorInfo& output,
1714 const SpaceToBatchNdDescriptor& descriptor,
1715 Optional<std::string&> reasonIfUnsupported) const
1716{
Jan Eilers8eb25602020-03-09 12:13:48 +00001717 IgnoreUnused(descriptor);
nikraj01120522a2019-05-31 11:33:07 +01001718 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001719 std::array<DataType,5> supportedTypes =
nikraj01120522a2019-05-31 11:33:07 +01001720 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001721 DataType::BFloat16,
1722 DataType::Float32,
1723 DataType::Float16,
1724 DataType::QAsymmU8,
1725 DataType::QSymmS16
nikraj01120522a2019-05-31 11:33:07 +01001726 };
1727
1728 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1729 "Reference SpaceToBatchNd: input type not supported");
1730
1731 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1732 "Reference SpaceToBatchNd: output type not supported");
1733
1734 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1735 "Reference SpaceToBatchNd: input and output types are mismatched");
1736
1737 return supported;
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001738}
1739
Keith Davisa57eccb2019-06-14 17:33:22 +01001740bool RefLayerSupport::IsSpaceToDepthSupported(const TensorInfo& input,
Keith Davis51910332019-06-26 15:28:43 +01001741 const TensorInfo& output,
1742 const SpaceToDepthDescriptor& descriptor,
1743 Optional<std::string&> reasonIfUnsupported) const
Keith Davisa57eccb2019-06-14 17:33:22 +01001744{
1745
Jan Eilers8eb25602020-03-09 12:13:48 +00001746 IgnoreUnused(descriptor);
Keith Davisa57eccb2019-06-14 17:33:22 +01001747 bool supported = true;
1748
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001749 std::array<DataType,5> supportedTypes =
Keith Davisa57eccb2019-06-14 17:33:22 +01001750 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001751 DataType::BFloat16,
Keith Davisa57eccb2019-06-14 17:33:22 +01001752 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001753 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001754 DataType::QAsymmU8,
1755 DataType::QSymmS16
Keith Davisa57eccb2019-06-14 17:33:22 +01001756 };
1757
1758 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1759 "Reference SpaceToDepth: input type not supported");
1760
1761 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1762 "Reference SpaceToDepth: output type not supported");
1763
1764 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1765 "Reference SpaceToDepth: input and output types are mismatched");
1766
1767 return supported;
1768}
1769
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001770bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1771 const ViewsDescriptor& descriptor,
1772 Optional<std::string&> reasonIfUnsupported) const
1773{
Jan Eilers8eb25602020-03-09 12:13:48 +00001774 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001775 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001776 std::array<DataType,5> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001777 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001778 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001779 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001780 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001781 DataType::QAsymmU8,
1782 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001783 };
1784
1785 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1786 "Reference splitter: input type not supported");
1787
1788 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001789}
1790
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001791bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1792 const std::vector<std::reference_wrapper<TensorInfo>>& outputs,
1793 const ViewsDescriptor& descriptor,
1794 Optional<std::string&> reasonIfUnsupported) const
1795{
Jan Eilers8eb25602020-03-09 12:13:48 +00001796 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001797 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001798 std::array<DataType,5> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001799 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001800 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001801 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001802 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001803 DataType::QAsymmU8,
1804 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001805 };
1806
1807 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1808 "Reference splitter: output type not supported");
1809 for (const TensorInfo output : outputs)
1810 {
1811 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1812 "Reference splitter: input type not supported");
1813
1814 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1815 "Reference splitter: input and output types mismatched.");
1816 }
1817
1818 return supported;
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001819}
1820
Matthew Jackson81e601c2019-07-11 12:07:09 +01001821bool RefLayerSupport::IsStackSupported(const std::vector<const TensorInfo*>& inputs,
1822 const TensorInfo& output,
1823 const StackDescriptor& descriptor,
1824 Optional<std::string&> reasonIfUnsupported) const
1825{
Jan Eilers8eb25602020-03-09 12:13:48 +00001826 IgnoreUnused(descriptor);
Matthew Jackson81e601c2019-07-11 12:07:09 +01001827
1828 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001829 std::array<DataType,5> supportedTypes =
Matthew Jackson81e601c2019-07-11 12:07:09 +01001830 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001831 DataType::BFloat16,
Matthew Jackson81e601c2019-07-11 12:07:09 +01001832 DataType::Float32,
Matthew Jacksone69c3992019-09-09 14:31:21 +01001833 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001834 DataType::QAsymmU8,
1835 DataType::QSymmS16
Matthew Jackson81e601c2019-07-11 12:07:09 +01001836 };
1837
1838 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1839 "Reference stack: output type not supported");
1840 for (const TensorInfo* input : inputs)
1841 {
1842 BOOST_ASSERT(input != nullptr);
1843 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
1844 "Reference stack: input type not supported");
1845
1846 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
1847 "Reference stack: input and output types mismatched.");
1848 }
1849
1850 return supported;
1851}
1852
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00001853bool RefLayerSupport::IsStridedSliceSupported(const TensorInfo& input,
1854 const TensorInfo& output,
1855 const StridedSliceDescriptor& descriptor,
1856 Optional<std::string&> reasonIfUnsupported) const
1857{
Jan Eilers8eb25602020-03-09 12:13:48 +00001858 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001859 bool supported = true;
1860
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001861 std::array<DataType,4> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001862 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001863 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001864 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001865 DataType::QAsymmU8,
1866 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001867 };
1868
1869 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1870 "Reference StridedSlice: input type not supported");
1871
1872 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1873 "Reference StridedSlice: output type not supported");
1874
1875 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1876 "Reference StridedSlice: input and output types are mismatched");
1877
1878 return supported;
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00001879}
1880
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001881bool RefLayerSupport::IsSubtractionSupported(const TensorInfo& input0,
1882 const TensorInfo& input1,
1883 const TensorInfo& output,
1884 Optional<std::string&> reasonIfUnsupported) const
1885{
Sadik Armagan2999a022019-04-09 14:20:12 +01001886 bool supported = true;
1887
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001888 std::array<DataType,5> supportedTypes = {
1889 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001890 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001891 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001892 DataType::QAsymmU8,
1893 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001894 };
1895
1896 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1897 "Reference subtraction: input 0 is not a supported type.");
1898
1899 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1900 "Reference subtraction: input 1 is not a supported type.");
1901
1902 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1903 "Reference subtraction: output is not a supported type.");
1904
1905 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1906 "Reference subtraction: input 0 and Input 1 types are mismatched");
1907
1908 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1909 "Reference subtraction: input and output types are mismatched");
1910
1911 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1912 "Reference subtraction: shapes are not suitable for implicit broadcast.");
1913
1914 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001915}
1916
Matteo Martincighab9e5252019-06-13 17:27:46 +01001917bool RefLayerSupport::IsPreluSupported(const TensorInfo& input,
1918 const TensorInfo& alpha,
1919 const TensorInfo& output,
1920 Optional<std::string&> reasonIfUnsupported) const
1921{
1922 bool supported = true;
1923
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001924 std::array<DataType, 5> supportedTypes
Matteo Martincighab9e5252019-06-13 17:27:46 +01001925 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001926 DataType::BFloat16,
Matteo Martincighab9e5252019-06-13 17:27:46 +01001927 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001928 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001929 DataType::QAsymmU8,
1930 DataType::QSymmS16
Matteo Martincighab9e5252019-06-13 17:27:46 +01001931 };
1932
1933 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1934 "PReLU: input is not a supported type.");
1935
1936 supported &= CheckSupportRule(TypeAnyOf(alpha, supportedTypes), reasonIfUnsupported,
1937 "PReLU: alpha is not a supported type.");
1938
1939 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1940 "PReLU: output is not a supported type.");
1941
1942 supported &= CheckSupportRule(TypesAreEqual(input, alpha, output), reasonIfUnsupported,
1943 "PReLU: input, alpha and output types are mismatched");
1944
1945 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input, alpha, output), reasonIfUnsupported,
1946 "PReLU: shapes are not suitable for implicit broadcast");
1947
1948 return supported;
1949}
1950
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01001951bool RefLayerSupport::IsTransposeConvolution2dSupported(const TensorInfo& input,
1952 const TensorInfo& output,
1953 const TransposeConvolution2dDescriptor& descriptor,
1954 const TensorInfo& weights,
1955 const Optional<TensorInfo>& biases,
1956 Optional<std::string&> reasonIfUnsupported) const
1957{
Jan Eilers8eb25602020-03-09 12:13:48 +00001958 IgnoreUnused(descriptor);
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01001959 bool supported = true;
1960
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001961 std::array<DataType,5> supportedTypes =
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01001962 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001963 DataType::BFloat16,
1964 DataType::Float32,
1965 DataType::Float16,
1966 DataType::QAsymmU8,
1967 DataType::QSymmS16
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01001968 };
1969
1970 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1971 "Reference TransposeConvolution2d: input is not a supported type.");
1972
1973 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1974 "Reference TransposeConvolution2d: output is not a supported type.");
1975
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01001976 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1977 "Reference TransposeConvolution2d: input and output types mismatched.");
1978
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00001979
1980 const DataType inputType = input.GetDataType();
Derek Lambertif90c56d2020-01-10 17:14:08 +00001981 if (inputType == DataType::QAsymmU8)
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00001982 {
Derek Lambertid466a542020-01-22 15:37:29 +00001983 ARMNN_NO_DEPRECATE_WARN_BEGIN
1984 std::array<DataType, 3> supportedWeightTypes =
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00001985 {
Derek Lambertif90c56d2020-01-10 17:14:08 +00001986 DataType::QAsymmU8,
Derek Lambertid466a542020-01-22 15:37:29 +00001987 DataType::QSymmS8,
1988 DataType::QuantizedSymm8PerAxis //Deprecated
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00001989 };
Derek Lambertid466a542020-01-22 15:37:29 +00001990 ARMNN_NO_DEPRECATE_WARN_END
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00001991
1992 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
1993 "Reference TransposeConvolution2d: weights type not supported for "
1994 "quantized input.");
1995 }
1996 else
1997 {
1998 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
1999 "Reference TransposeConvolution2d: weights is not a supported type.");
2000
2001 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
2002 "Reference TransposeConvolution2d: input and weights types mismatched.");
2003 }
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002004
2005 if (biases.has_value())
2006 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002007 std::array<DataType,4> biasesSupportedTypes =
Aron Virginas-Tar651aafe2019-08-05 11:52:05 +01002008 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002009 DataType::BFloat16,
2010 DataType::Float32,
2011 DataType::Float16,
2012 DataType::Signed32
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002013 };
2014 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
2015 "Reference TransposeConvolution2d: biases is not a supported type.");
2016 }
2017
2018 return supported;
2019}
2020
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002021bool RefLayerSupport::IsTransposeSupported(const TensorInfo& input,
2022 const TensorInfo& output,
2023 const TransposeDescriptor& descriptor,
2024 Optional<std::string&> reasonIfUnsupported) const
2025{
Jan Eilers8eb25602020-03-09 12:13:48 +00002026 IgnoreUnused(descriptor);
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002027 bool supported = true;
2028
2029 // Define supported output and inputs types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002030 std::array<DataType, 5> supportedTypes =
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002031 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002032 DataType::BFloat16,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002033 DataType::Float32,
2034 DataType::Float16,
2035 DataType::QAsymmU8,
2036 DataType::QSymmS16
2037 };
2038
2039 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2040 "Reference transpose: input is not a supported type.");
2041
2042 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2043 "Reference transpose: output is not a supported type.");
2044
2045 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2046 "Reference transpose: input and output types are mismatched.");
2047
2048 return supported;
2049}
2050
arovir011c7c81b2018-10-08 11:34:28 +01002051} // namespace armnn