blob: 87d29219522715000b5505434e77dc88335d7d84 [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
Sadik Armagan303980c2020-04-17 12:45:14 +0100184 std::array<DataType, 6> 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,
Sadik Armagan303980c2020-04-17 12:45:14 +0100188 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000189 DataType::QAsymmU8,
190 DataType::QSymmS16,
Francis Murtagh1939df52019-11-13 15:21:09 +0000191 DataType::Signed32
Nikhil Raj68c2c902019-09-19 11:21:11 +0100192 };
193
194 bool supported = true;
195
196 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
197 "Reference ArgMinMax: input is not a supported type.");
198 supported &= CheckSupportRule(TypeIs(output, DataType::Signed32), reasonIfUnsupported,
199 "Reference ArgMinMax: output type not supported");
200
201 return supported;
202}
203
arovir011c7c81b2018-10-08 11:34:28 +0100204bool RefLayerSupport::IsBatchNormalizationSupported(const TensorInfo& input,
205 const TensorInfo& output,
206 const TensorInfo& mean,
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100207 const TensorInfo& variance,
arovir011c7c81b2018-10-08 11:34:28 +0100208 const TensorInfo& beta,
209 const TensorInfo& gamma,
210 const BatchNormalizationDescriptor& descriptor,
211 Optional<std::string&> reasonIfUnsupported) const
212{
Jan Eilers8eb25602020-03-09 12:13:48 +0000213 IgnoreUnused(descriptor);
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100214
Sadik Armagan303980c2020-04-17 12:45:14 +0100215 std::array<DataType, 6> supportedTypes =
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100216 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000217 DataType::BFloat16,
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100218 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100219 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100220 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000221 DataType::QAsymmU8,
222 DataType::QSymmS16
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100223 };
224
225 bool supported = true;
226
227 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
228 "Reference batch normalization: input is not a supported type.");
229
230 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
231 "Reference batch normalization: output is not a supported type.");
232
233 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
234 "Reference batch normalization: input and output types are mismatched");
235
236 supported &= CheckSupportRule(TypeAnyOf(mean, supportedTypes), reasonIfUnsupported,
237 "Reference batch normalization: mean is not a supported type.");
238
239 supported &= CheckSupportRule(TypeAnyOf(variance, supportedTypes), reasonIfUnsupported,
240 "Reference batch normalization: variance is not a supported type.");
241
242 supported &= CheckSupportRule(TypeAnyOf(beta, supportedTypes), reasonIfUnsupported,
243 "Reference batch normalization: beta is not a supported type.");
244
245 supported &= CheckSupportRule(TypeAnyOf(gamma, supportedTypes), reasonIfUnsupported,
246 "Reference batch normalization: gamma is not a supported type.");
247
248 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100249}
250
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000251bool RefLayerSupport::IsBatchToSpaceNdSupported(const TensorInfo& input,
252 const TensorInfo& output,
253 const BatchToSpaceNdDescriptor& descriptor,
254 Optional<std::string&> reasonIfUnsupported) const
255{
Jan Eilers8eb25602020-03-09 12:13:48 +0000256 IgnoreUnused(descriptor);
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100257
258 bool supported = true;
259
260 std::string batchToSpaceNdLayerStr = "batchToSpaceNd";
261 std::string inputTensorStr = "input";
262 std::string outputTensorStr = "output";
263
264 // Define supported types.
Sadik Armagan303980c2020-04-17 12:45:14 +0100265 std::array<DataType,6> supportedTypes =
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100266 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000267 DataType::BFloat16,
268 DataType::Float32,
269 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100270 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000271 DataType::QAsymmU8,
272 DataType::QSymmS16
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100273 };
274
275 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
276 "Reference BatchToSpaceNd: input type not supported.");
277
278 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
279 "Reference BatchToSpaceNd: output type not supported.");
280
281 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
282 "Reference BatchToSpaceNd: input and output types mismatched.");
283
284 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 4),
285 reasonIfUnsupported,
286 CreateIncorrectDimensionsErrorMsg(4,
287 output.GetNumDimensions(),
288 batchToSpaceNdLayerStr,
289 outputTensorStr).data());
290
291 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(input, 4),
292 reasonIfUnsupported,
293 CreateIncorrectDimensionsErrorMsg(4,
294 input.GetNumDimensions(),
295 batchToSpaceNdLayerStr,
296 inputTensorStr).data());
297
298 return supported;
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000299}
300
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100301bool RefLayerSupport::IsComparisonSupported(const TensorInfo& input0,
302 const TensorInfo& input1,
303 const TensorInfo& output,
304 const ComparisonDescriptor& descriptor,
305 Optional<std::string&> reasonIfUnsupported) const
306{
Jan Eilers8eb25602020-03-09 12:13:48 +0000307 IgnoreUnused(descriptor);
Sadik Armagan303980c2020-04-17 12:45:14 +0100308 std::array<DataType, 8> supportedInputTypes =
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100309 {
Sadik Armaganb60dd242020-03-19 13:53:16 +0000310 DataType::Boolean,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000311 DataType::BFloat16,
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100312 DataType::Float32,
313 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100314 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000315 DataType::QAsymmU8,
Sadik Armaganb60dd242020-03-19 13:53:16 +0000316 DataType::QSymmS16,
317 DataType::Signed32
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100318 };
319
320 bool supported = true;
321 supported &= CheckSupportRule(TypeAnyOf(input0, supportedInputTypes), reasonIfUnsupported,
322 "Reference comparison: input 0 is not a supported type");
323
324 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
325 "Reference comparison: input 0 and Input 1 types are mismatched");
326
327 supported &= CheckSupportRule(TypeIs(output, DataType::Boolean), reasonIfUnsupported,
328 "Reference comparison: output is not of type Boolean");
329
330 return supported;
331}
332
Jim Flynn906f9462019-05-10 13:55:21 +0100333bool RefLayerSupport::IsConcatSupported(const std::vector<const TensorInfo*> inputs,
334 const TensorInfo& output,
Jim Flynne242f2d2019-05-22 14:24:13 +0100335 const ConcatDescriptor& descriptor,
Jim Flynn906f9462019-05-10 13:55:21 +0100336 Optional<std::string&> reasonIfUnsupported) const
337{
Jan Eilers8eb25602020-03-09 12:13:48 +0000338 IgnoreUnused(descriptor);
Jim Flynne242f2d2019-05-22 14:24:13 +0100339
340 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000341 std::array<DataType,6> supportedTypes =
Jim Flynne242f2d2019-05-22 14:24:13 +0100342 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000343 DataType::BFloat16,
344 DataType::Float32,
345 DataType::Float16,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000346 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100347 DataType::QAsymmU8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000348 DataType::QSymmS16
Jim Flynne242f2d2019-05-22 14:24:13 +0100349 };
350
351 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
352 "Reference concatenation: output type not supported");
353 for (const TensorInfo* input : inputs)
354 {
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100355 ARMNN_ASSERT(input != nullptr);
Jim Flynne242f2d2019-05-22 14:24:13 +0100356 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
357 "Reference concatenation: input type not supported");
358
359 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
360 "Reference concatenation: input and output types mismatched.");
361 }
362
363 return supported;
Jim Flynn906f9462019-05-10 13:55:21 +0100364}
365
arovir011c7c81b2018-10-08 11:34:28 +0100366bool RefLayerSupport::IsConstantSupported(const TensorInfo& output,
367 Optional<std::string&> reasonIfUnsupported) const
368{
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000369 std::array<DataType,7> supportedTypes =
Jim Flynne242f2d2019-05-22 14:24:13 +0100370 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000371 DataType::BFloat16,
Nina Drozd58ef2c62019-05-16 12:09:18 +0100372 DataType::Float32,
Keith Davis67e6c542020-02-19 10:08:33 +0000373 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100374 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +0000375 DataType::QSymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100376 DataType::QSymmS16,
377 DataType::Signed32
Nina Drozd58ef2c62019-05-16 12:09:18 +0100378 };
379
380 return CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
381 "Reference constant: output is not a supported type.");
arovir011c7c81b2018-10-08 11:34:28 +0100382}
383
Narumol Prangnawarat7ddbbae2020-03-13 10:26:05 +0000384bool RefLayerSupport::IsConvertBf16ToFp32Supported(const TensorInfo& input,
385 const TensorInfo& output,
386 Optional<std::string&> reasonIfUnsupported) const
387{
388 bool supported = true;
389
390 supported &= CheckSupportRule(TypeIs(input, DataType::BFloat16), reasonIfUnsupported,
391 "Reference for ConvertBf16ToFp32 layer: input type not supported");
392
393 supported &= CheckSupportRule(TypeIs(output, DataType::Float32), reasonIfUnsupported,
394 "Reference for ConvertBf16ToFp32 layer: output type not supported");
395
396 return supported;
397}
398
arovir011c7c81b2018-10-08 11:34:28 +0100399bool RefLayerSupport::IsConvertFp16ToFp32Supported(const TensorInfo& input,
400 const TensorInfo& output,
401 Optional<std::string&> reasonIfUnsupported) const
402{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100403 return (IsSupportedForDataTypeGeneric(reasonIfUnsupported,
404 input.GetDataType(),
405 &TrueFunc<>,
406 &FalseInputFuncF32<>,
narpra01db2b1602019-01-23 15:23:11 +0000407 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000408 &FalseFuncI32<>,
409 &FalseFuncU8<>) &&
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100410 IsSupportedForDataTypeGeneric(reasonIfUnsupported,
411 output.GetDataType(),
412 &FalseOutputFuncF16<>,
413 &TrueFunc<>,
narpra01db2b1602019-01-23 15:23:11 +0000414 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000415 &FalseFuncI32<>,
416 &FalseFuncU8<>));
arovir011c7c81b2018-10-08 11:34:28 +0100417}
418
Narumol Prangnawaratea54a012020-03-16 16:36:10 +0000419bool RefLayerSupport::IsConvertFp32ToBf16Supported(const TensorInfo& input,
420 const TensorInfo& output,
421 Optional<std::string&> reasonIfUnsupported) const
422{
423 bool supported = true;
424
425 supported &= CheckSupportRule(TypeIs(input, DataType::Float32), reasonIfUnsupported,
426 "Reference for ConvertFp32ToBf16 layer: input type not supported");
427
428 supported &= CheckSupportRule(TypeIs(output, DataType::BFloat16), reasonIfUnsupported,
429 "Reference for ConvertFp32ToBf16 layer: output type not supported");
430
431 return supported;
432}
433
arovir011c7c81b2018-10-08 11:34:28 +0100434bool RefLayerSupport::IsConvertFp32ToFp16Supported(const TensorInfo& input,
435 const TensorInfo& output,
436 Optional<std::string&> reasonIfUnsupported) const
437{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100438 return (IsSupportedForDataTypeGeneric(reasonIfUnsupported,
439 input.GetDataType(),
440 &FalseInputFuncF16<>,
441 &TrueFunc<>,
narpra01db2b1602019-01-23 15:23:11 +0000442 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000443 &FalseFuncI32<>,
444 &FalseFuncU8<>) &&
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100445 IsSupportedForDataTypeGeneric(reasonIfUnsupported,
446 output.GetDataType(),
447 &TrueFunc<>,
448 &FalseOutputFuncF32<>,
narpra01db2b1602019-01-23 15:23:11 +0000449 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000450 &FalseFuncI32<>,
451 &FalseFuncU8<>));
arovir011c7c81b2018-10-08 11:34:28 +0100452}
453
454bool RefLayerSupport::IsConvolution2dSupported(const TensorInfo& input,
455 const TensorInfo& output,
456 const Convolution2dDescriptor& descriptor,
457 const TensorInfo& weights,
458 const Optional<TensorInfo>& biases,
459 Optional<std::string&> reasonIfUnsupported) const
460{
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100461 bool supported = true;
462
463 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000464 std::array<DataType,7> supportedTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000465 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000466 DataType::BFloat16,
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000467 DataType::Float32,
468 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000469 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100470 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +0000471 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000472 DataType::QSymmS16
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100473 };
474
475 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000476 "Reference Convolution2d: input is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100477
478 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000479 "Reference Convolution2d: output is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100480
Narumol Prangnawarat57ef0082020-03-26 09:20:43 +0000481 // For Convolution2d, we allow to have BFloat16 input with Float32 output for optimization.
482 if (input.GetDataType() == DataType::BFloat16)
483 {
484 if (output.GetDataType() != DataType::BFloat16 && output.GetDataType() != DataType::Float32)
485 {
486 reasonIfUnsupported.value() += "Output tensor type must be BFloat16 or Float32 for BFloat16 input.\n";
487 supported = false;
488 }
489 }
490 else
491 {
492 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000493 "Reference Convolution2d: input and output types mismatched.");
Narumol Prangnawarat57ef0082020-03-26 09:20:43 +0000494 }
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100495
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000496 const DataType inputType = input.GetDataType();
Keith Davis0c2eeac2020-02-11 16:51:50 +0000497 if (IsQuantized8BitType(inputType))
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000498 {
Derek Lambertid466a542020-01-22 15:37:29 +0000499 ARMNN_NO_DEPRECATE_WARN_BEGIN
Keith Davis0c2eeac2020-02-11 16:51:50 +0000500 std::array<DataType, 4> supportedWeightTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000501 {
Sadik Armagan303980c2020-04-17 12:45:14 +0100502 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000503 DataType::QAsymmU8,
Derek Lambertid466a542020-01-22 15:37:29 +0000504 DataType::QSymmS8,
505 DataType::QuantizedSymm8PerAxis // deprecated
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000506 };
Derek Lambertid466a542020-01-22 15:37:29 +0000507 ARMNN_NO_DEPRECATE_WARN_END
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000508
509 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000510 "Reference Convolution2d: weights type not supported for quantized input.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000511 }
512 else
513 {
514 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000515 "Reference Convolution2d: weights is not a supported type.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000516
517 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000518 "Reference Convolution2d: input and weights types mismatched.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000519 }
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100520
521 if (biases.has_value())
522 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000523 std::array<DataType,4> biasesSupportedTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000524 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000525 DataType::BFloat16,
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000526 DataType::Float32,
527 DataType::Float16,
528 DataType::Signed32
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100529 };
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000530
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100531 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000532 "Reference Convolution2d: biases is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100533 }
Jan Eilers8eb25602020-03-09 12:13:48 +0000534 IgnoreUnused(descriptor);
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100535
536 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100537}
538
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000539bool RefLayerSupport::IsDebugSupported(const TensorInfo& input,
540 const TensorInfo& output,
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000541 Optional<std::string&> reasonIfUnsupported) const
542{
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100543 bool supported = true;
544
Narumol Prangnawarat403a1852020-03-12 14:24:13 +0000545 std::array<DataType, 8> supportedTypes =
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100546 {
Narumol Prangnawarat403a1852020-03-12 14:24:13 +0000547 DataType::BFloat16,
Aron Virginas-Tardb1a2832019-11-12 16:15:11 +0000548 DataType::Float16,
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100549 DataType::Float32,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000550 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100551 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +0000552 DataType::QSymmS8,
Narumol Prangnawaratd2d917d2020-01-09 10:16:39 +0000553 DataType::QSymmS16,
554 DataType::Signed32
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100555 };
556
557 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000558 "Reference for Debug layer: input type not supported");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100559
560 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000561 "Reference for Debug layer: output type not supported");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100562
563 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000564 "Reference for Debug layer: input and output types are mismatched");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100565
566 return supported;
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000567}
568
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100569bool RefLayerSupport::IsDepthToSpaceSupported(const TensorInfo& input,
570 const TensorInfo& output,
571 const DepthToSpaceDescriptor& descriptor,
572 Optional<std::string&> reasonIfUnsupported) const
573{
Jan Eilers8eb25602020-03-09 12:13:48 +0000574 IgnoreUnused(descriptor);
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100575 bool supported = true;
576
Sadik Armagan303980c2020-04-17 12:45:14 +0100577 std::array<DataType,6> supportedTypes =
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100578 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000579 DataType::BFloat16,
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100580 DataType::Float32,
581 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100582 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000583 DataType::QAsymmU8,
584 DataType::QSymmS16
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100585 };
586
587 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
588 "Reference DepthToSpace: input type not supported");
589
590 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
591 "Reference DepthToSpace: output type not supported");
592
593 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
594 "Reference DepthToSpace: input and output types are mismatched");
595
596 return supported;
597}
598
arovir011c7c81b2018-10-08 11:34:28 +0100599bool RefLayerSupport::IsDepthwiseConvolutionSupported(const TensorInfo& input,
600 const TensorInfo& output,
601 const DepthwiseConvolution2dDescriptor& descriptor,
602 const TensorInfo& weights,
603 const Optional<TensorInfo>& biases,
604 Optional<std::string&> reasonIfUnsupported) const
605{
Sadik Armagan303980c2020-04-17 12:45:14 +0100606 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100607 bool supported = true;
608
609 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000610 std::array<DataType,7> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100611 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000612 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100613 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100614 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000615 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000616 DataType::QAsymmU8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100617 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000618 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100619 };
620
621 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
622 "Reference DepthwiseConvolution2d: input is not a supported type.");
623
624 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
625 "Reference DepthwiseConvolution2d: output is not a supported type.");
626
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100627 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
628 "Reference DepthwiseConvolution2d: input and output types mismatched.");
629
Teresa Charlind8df0262019-11-11 12:28:15 +0000630 const DataType inputType = input.GetDataType();
Keith Davis0c2eeac2020-02-11 16:51:50 +0000631 if (IsQuantized8BitType(inputType))
Teresa Charlind8df0262019-11-11 12:28:15 +0000632 {
Sadik Armagan303980c2020-04-17 12:45:14 +0100633 ARMNN_NO_DEPRECATE_WARN_BEGIN
634 std::array<DataType, 4> supportedWeightTypes =
635 {
636 DataType::QAsymmS8,
637 DataType::QAsymmU8,
638 DataType::QSymmS8,
639 DataType::QuantizedSymm8PerAxis // deprecated
640 };
641 ARMNN_NO_DEPRECATE_WARN_END
Teresa Charlind8df0262019-11-11 12:28:15 +0000642
643 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
Sadik Armagan303980c2020-04-17 12:45:14 +0100644 "Reference DepthwiseConvolution2d: weights type not supported for "
645 "quantized input.");
Teresa Charlind8df0262019-11-11 12:28:15 +0000646 }
647 else
648 {
649 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
650 "Reference DepthwiseConvolution2d: weights is not a supported type.");
651
652 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
653 "Reference DepthwiseConvolution2d: input and weights types mismatched.");
654 }
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100655
656 if (biases.has_value())
657 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000658 std::array<DataType,4> biasesSupportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100659 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000660 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100661 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100662 DataType::Float16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100663 DataType::Signed32
664 };
665 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
666 "Reference DepthwiseConvolution2d: biases is not a supported type.");
667 }
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100668
669 return supported;
670
arovir011c7c81b2018-10-08 11:34:28 +0100671}
672
Nattapat Chaimanowong8a54ac02019-03-29 15:25:04 +0000673bool RefLayerSupport::IsDequantizeSupported(const TensorInfo& input,
674 const TensorInfo& output,
675 Optional<std::string&> reasonIfUnsupported) const
676{
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100677 bool supported = true;
678
Ryan OShea9add1202020-02-07 10:06:33 +0000679 std::array<DataType,4> supportedInputTypes = {
680 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000681 DataType::QAsymmU8,
Finn Williamsfd271062019-12-04 14:27:27 +0000682 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000683 DataType::QSymmS16
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100684 };
685
686 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000687 "Reference for Dequantize layer: input type not supported.");
688
689 supported &= CheckSupportRule( TypeNotPerAxisQuantized(input), reasonIfUnsupported,
690 "Reference for Dequantize layer: per-axis quantized input not support .");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100691
Derek Lambertid466a542020-01-22 15:37:29 +0000692 supported &= CheckSupportRule(TypeNotPerAxisQuantized(input), reasonIfUnsupported,
693 "Reference dequantize: per-axis quantized input not support .");
694
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000695 std::array<DataType,3> supportedOutputTypes = {
696 DataType::BFloat16,
Jan Eilersf7107932019-11-01 11:09:36 +0000697 DataType::Float32,
698 DataType::Float16
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100699 };
700
701 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000702 "Reference for Dequantize layer: output type not supported.");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100703
704 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000705 "Reference for Dequantize layer: input/output shapes have different num total "
706 "elements.");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100707
708 return supported;
Nattapat Chaimanowong8a54ac02019-03-29 15:25:04 +0000709}
710
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000711bool RefLayerSupport::IsDetectionPostProcessSupported(const TensorInfo& boxEncodings,
712 const TensorInfo& scores,
713 const TensorInfo& anchors,
714 const TensorInfo& detectionBoxes,
715 const TensorInfo& detectionClasses,
716 const TensorInfo& detectionScores,
717 const TensorInfo& numDetections,
718 const DetectionPostProcessDescriptor& descriptor,
719 Optional<std::string&> reasonIfUnsupported) const
Narumol Prangnawaratbc67cef2019-01-31 15:31:54 +0000720{
Jan Eilers8eb25602020-03-09 12:13:48 +0000721 IgnoreUnused(anchors, detectionBoxes, detectionClasses, detectionScores, numDetections, descriptor);
Derek Lamberti901ea112019-12-10 22:07:09 +0000722
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100723 bool supported = true;
724
Sadik Armagan303980c2020-04-17 12:45:14 +0100725 std::array<DataType,5> supportedInputTypes =
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100726 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000727 DataType::BFloat16,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100728 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +0100729 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000730 DataType::QAsymmU8,
731 DataType::QSymmS16
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100732 };
733
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000734 supported &= CheckSupportRule(TypeAnyOf(boxEncodings, supportedInputTypes), reasonIfUnsupported,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100735 "Reference DetectionPostProcess: input 0 is not a supported type.");
736
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000737 supported &= CheckSupportRule(TypeAnyOf(scores, supportedInputTypes), reasonIfUnsupported,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100738 "Reference DetectionPostProcess: input 1 is not a supported type.");
739
740 return supported;
Narumol Prangnawaratbc67cef2019-01-31 15:31:54 +0000741}
742
Pablo Tellof0bd6832019-04-26 17:58:13 +0100743bool RefLayerSupport::IsDilatedDepthwiseConvolutionSupported(const TensorInfo& input,
744 const TensorInfo& output,
745 const DepthwiseConvolution2dDescriptor& descriptor,
746 const TensorInfo& weights,
747 const Optional<TensorInfo>& biases,
748 Optional<std::string&> reasonIfUnsupported) const
749{
Aron Virginas-Taraece4ed2019-06-14 17:00:09 +0100750 return IsDepthwiseConvolutionSupported(input, output, descriptor, weights, biases, reasonIfUnsupported);
Pablo Tellof0bd6832019-04-26 17:58:13 +0100751}
752
Aron Virginas-Taraece4ed2019-06-14 17:00:09 +0100753bool RefLayerSupport::IsDivisionSupported(const TensorInfo& input0,
arovir011c7c81b2018-10-08 11:34:28 +0100754 const TensorInfo& input1,
755 const TensorInfo& output,
756 Optional<std::string&> reasonIfUnsupported) const
757{
Sadik Armagan2999a022019-04-09 14:20:12 +0100758 bool supported = true;
759
Sadik Armagan303980c2020-04-17 12:45:14 +0100760 std::array<DataType,6> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000761 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +0100762 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100763 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100764 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000765 DataType::QAsymmU8,
766 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +0100767 };
768
769 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
770 "Reference division: input 0 is not a supported type.");
771
772 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
773 "Reference division: input 1 is not a supported type.");
774
775 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
776 "Reference division: output is not a supported type.");
777
778 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
779 "Reference division: input 0 and Input 1 types are mismatched");
780
781 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
782 "Reference division: input and output types are mismatched");
783
784 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
785 "Reference division: shapes are not suitable for implicit broadcast.");
786
787 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100788}
789
josh minor4a3c6102020-01-06 16:40:46 -0600790bool RefLayerSupport::IsElementwiseUnarySupported(const TensorInfo& input,
791 const TensorInfo& output,
792 const ElementwiseUnaryDescriptor& descriptor,
793 Optional<std::string&> reasonIfUnsupported) const
794{
Jan Eilers8eb25602020-03-09 12:13:48 +0000795 IgnoreUnused(descriptor);
josh minor4a3c6102020-01-06 16:40:46 -0600796
Sadik Armagan303980c2020-04-17 12:45:14 +0100797 std::array<DataType, 7> supportedTypes =
josh minor4a3c6102020-01-06 16:40:46 -0600798 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000799 DataType::BFloat16,
josh minor4a3c6102020-01-06 16:40:46 -0600800 DataType::Float32,
801 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100802 DataType::QAsymmS8,
josh minor4a3c6102020-01-06 16:40:46 -0600803 DataType::QAsymmU8,
Sadik Armaganac472102020-03-24 09:54:36 +0000804 DataType::QSymmS16,
805 DataType::Signed32
josh minor4a3c6102020-01-06 16:40:46 -0600806 };
807
808 bool supported = true;
809
810 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
811 "Reference elementwise unary: input type not supported");
812
813 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
814 "Reference elementwise unary: output type not supported");
815
816 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
817 "Reference elementwise unary: input and output types not matching");
818
819 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
820 "Reference elementwise unary: input and output shapes"
821 "have different number of total elements");
822
823 return supported;
824}
825
FrancisMurtagh30cdfca2018-12-18 12:57:35 +0000826bool RefLayerSupport::IsEqualSupported(const TensorInfo& input0,
827 const TensorInfo& input1,
828 const TensorInfo& output,
829 Optional<std::string&> reasonIfUnsupported) const
830{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100831 return IsComparisonSupported(input0,
832 input1,
833 output,
834 ComparisonDescriptor(ComparisonOperation::Equal),
835 reasonIfUnsupported);
FrancisMurtagh30cdfca2018-12-18 12:57:35 +0000836}
837
arovir011c7c81b2018-10-08 11:34:28 +0100838bool RefLayerSupport::IsFakeQuantizationSupported(const TensorInfo& input,
839 const FakeQuantizationDescriptor& descriptor,
840 Optional<std::string&> reasonIfUnsupported) const
841{
Jan Eilers8eb25602020-03-09 12:13:48 +0000842 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100843 bool supported = true;
844
845 std::array<DataType,1> supportedTypes =
846 {
847 DataType::Float32
848 };
849
850 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
851 "Reference fake quantization: input type not supported.");
852
853 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100854}
855
856bool RefLayerSupport::IsFloorSupported(const TensorInfo& input,
857 const TensorInfo& output,
858 Optional<std::string&> reasonIfUnsupported) const
859{
Jan Eilers8eb25602020-03-09 12:13:48 +0000860 IgnoreUnused(output);
James Conroy83735b12019-05-30 16:36:59 +0100861 bool supported = true;
862
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000863 std::array<DataType,4> supportedTypes =
James Conroy83735b12019-05-30 16:36:59 +0100864 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000865 DataType::BFloat16,
James Conroyb40d7102019-06-04 12:32:09 +0100866 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100867 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000868 DataType::QSymmS16
James Conroy83735b12019-05-30 16:36:59 +0100869 };
870
871 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
872 "Reference Floor: input type not supported.");
873
874 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
875 "Reference Floor: output type not supported.");
876
877 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100878}
879
880bool RefLayerSupport::IsFullyConnectedSupported(const TensorInfo& input,
881 const TensorInfo& output,
882 const TensorInfo& weights,
883 const TensorInfo& biases,
884 const FullyConnectedDescriptor& descriptor,
885 Optional<std::string&> reasonIfUnsupported) const
886{
Francis Murtagh46c09d02019-05-28 08:15:28 +0100887 bool supported = true;
888
889 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000890 std::array<DataType,6> supportedTypes =
Francis Murtagh46c09d02019-05-28 08:15:28 +0100891 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000892 DataType::BFloat16,
893 DataType::Float32,
894 DataType::Float16,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000895 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100896 DataType::QAsymmU8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000897 DataType::QSymmS16
Francis Murtagh46c09d02019-05-28 08:15:28 +0100898 };
899
900 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
901 "Reference Fully Connected: input type not supported.");
902
903 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
904 "Reference Fully Connected: output type not supported.");
905
Francis Murtagh46c09d02019-05-28 08:15:28 +0100906 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
907 "Reference Fully Connected: weights type not supported.");
908
Narumol Prangnawarat57ef0082020-03-26 09:20:43 +0000909 // For FullyConnected, we allow to have BFloat16 input with Float32 output for optimization.
910 if (input.GetDataType() == DataType::BFloat16)
911 {
912 if (output.GetDataType() != DataType::BFloat16 && output.GetDataType() != DataType::Float32)
913 {
914 reasonIfUnsupported.value() += "Output tensor type must be BFloat16 or Float32 for BFloat16 input.\n";
915 supported = false;
916 }
917 }
918 else
919 {
920 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
921 "Reference Fully Connected: input and output types mismatched.");
922 }
923
Francis Murtaghddb1d062020-03-10 13:51:45 +0000924 ARMNN_NO_DEPRECATE_WARN_BEGIN
Sadik Armagan303980c2020-04-17 12:45:14 +0100925 std::array<DataType, 4> supportedWeightTypes =
Francis Murtaghddb1d062020-03-10 13:51:45 +0000926 {
Sadik Armagan303980c2020-04-17 12:45:14 +0100927 DataType::QAsymmS8,
Francis Murtaghddb1d062020-03-10 13:51:45 +0000928 DataType::QAsymmU8,
929 DataType::QSymmS8,
930 DataType::QuantizedSymm8PerAxis // deprecated
931 };
932 ARMNN_NO_DEPRECATE_WARN_END
933
934 if (IsQuantized8BitType(input.GetDataType()))
935 {
936
937 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
938 "Reference Fully Connected: weights type not supported for quantized input.");
939 }
940 else
941 {
942 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
943 "Reference Fully Connected: weights is not a supported type.");
944
945 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
946 "Reference Fully Connected: input and weights types mismatched.");
947 }
Francis Murtagh46c09d02019-05-28 08:15:28 +0100948
949 if (descriptor.m_BiasEnabled)
950 {
951 // Defined supported types for bias
Sadik Armagandb73c982020-04-01 17:35:30 +0100952 std::array<DataType, 5>
Francis Murtagh46c09d02019-05-28 08:15:28 +0100953 supportedBiasTypes =
954 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000955 DataType::BFloat16,
Francis Murtagh46c09d02019-05-28 08:15:28 +0100956 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100957 DataType::Float16,
Sadik Armagandb73c982020-04-01 17:35:30 +0100958 DataType::Signed32,
959 DataType::QAsymmS8
Francis Murtagh46c09d02019-05-28 08:15:28 +0100960 };
961
962 supported &= CheckSupportRule(TypeAnyOf(biases, supportedBiasTypes), reasonIfUnsupported,
963 "Reference Fully Connected: bias type not supported.");
964
965 supported &= CheckSupportRule(BiasAndWeightsTypesMatch(biases, weights), reasonIfUnsupported,
966 "Reference Fully Connected: bias and weight types mismatch.");
967
968 supported &= CheckSupportRule(BiasAndWeightsTypesCompatible(weights, supportedBiasTypes), reasonIfUnsupported,
969 "Reference Fully Connected: bias type inferred from weights is incompatible.");
970
Narumol Prangnawarat366d7232020-04-29 12:58:17 +0100971 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(biases, 1U), reasonIfUnsupported,
972 "Reference Fully Connected: bias must have 1 dimension.");
973
Francis Murtagh46c09d02019-05-28 08:15:28 +0100974 }
975
976 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100977}
978
narpra014951d842019-01-18 16:53:53 +0000979bool RefLayerSupport::IsGatherSupported(const armnn::TensorInfo& input0,
980 const armnn::TensorInfo& input1,
981 const armnn::TensorInfo& output,
982 armnn::Optional<std::string&> reasonIfUnsupported) const
983{
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100984 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +0100985 std::array<DataType,6> supportedTypes =
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100986 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000987 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100988 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100989 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100990 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000991 DataType::QAsymmU8,
992 DataType::QSymmS16
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100993 };
994
995 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
996 "Reference Gather: input type not supported");
997
998 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
999 "Reference Gather: output type not supported");
1000
1001 supported &= CheckSupportRule(TypeIs(input1, DataType::Signed32), reasonIfUnsupported,
1002 "Reference Gather: indices (input1) type not supported");
1003
1004 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1005 "Reference Gather: input and output types not matching");
1006
1007 return supported;
narpra014951d842019-01-18 16:53:53 +00001008}
1009
FrancisMurtagh878f0232018-12-19 10:56:15 +00001010bool RefLayerSupport::IsGreaterSupported(const TensorInfo& input0,
1011 const TensorInfo& input1,
1012 const TensorInfo& output,
1013 Optional<std::string&> reasonIfUnsupported) const
1014{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +01001015 return IsComparisonSupported(input0,
1016 input1,
1017 output,
1018 ComparisonDescriptor(ComparisonOperation::Greater),
1019 reasonIfUnsupported);
FrancisMurtagh878f0232018-12-19 10:56:15 +00001020}
1021
Derek Lamberti901ea112019-12-10 22:07:09 +00001022bool RefLayerSupport::IsInputSupported(const TensorInfo& /*input*/,
1023 Optional<std::string&> /*reasonIfUnsupported*/) const
arovir011c7c81b2018-10-08 11:34:28 +01001024{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +01001025 return true;
arovir011c7c81b2018-10-08 11:34:28 +01001026}
1027
Kevin May09ca49c2019-10-09 12:37:34 +01001028bool RefLayerSupport::IsInstanceNormalizationSupported(const TensorInfo& input,
1029 const TensorInfo& output,
1030 const InstanceNormalizationDescriptor& descriptor,
1031 Optional<std::string&> reasonIfUnsupported) const
1032{
Jan Eilers8eb25602020-03-09 12:13:48 +00001033 IgnoreUnused(descriptor);
Kevin May09ca49c2019-10-09 12:37:34 +01001034 // Define supported types
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001035 std::array<DataType, 3> supportedTypes =
Kevin May09ca49c2019-10-09 12:37:34 +01001036 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001037 DataType::BFloat16,
Kevin May09ca49c2019-10-09 12:37:34 +01001038 DataType::Float32,
1039 DataType::Float16
1040 };
1041
1042 bool supported = true;
1043
1044 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1045 "Reference Instance Normalization: input type not supported.");
1046
1047 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1048 "Reference Instance Normalization: output type not supported.");
1049
1050 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1051 "Reference Instance Normalization: input and output types mismatched.");
1052
1053 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1054 "Reference Instance Normalization: input and output shapes have different "
1055 "num total elements.");
1056
1057 return supported;
1058}
1059
arovir011c7c81b2018-10-08 11:34:28 +01001060bool RefLayerSupport::IsL2NormalizationSupported(const TensorInfo& input,
1061 const TensorInfo& output,
1062 const L2NormalizationDescriptor& descriptor,
1063 Optional<std::string&> reasonIfUnsupported) const
1064{
Jan Eilers8eb25602020-03-09 12:13:48 +00001065 IgnoreUnused(descriptor);
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001066 // Define supported types
Sadik Armagan303980c2020-04-17 12:45:14 +01001067 std::array<DataType, 6> supportedTypes =
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001068 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001069 DataType::BFloat16,
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001070 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001071 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001072 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001073 DataType::QAsymmU8,
1074 DataType::QSymmS16
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001075 };
1076
1077 bool supported = true;
1078
1079 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1080 "Reference L2normalization: input type not supported.");
1081
1082 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1083 "Reference L2normalization: output type not supported.");
1084
1085 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1086 "Reference L2normalization: input and output types mismatched.");
1087
1088 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1089 "Reference L2normalization: input and output shapes have different "
1090 "num total elements.");
1091
1092 return supported;
arovir011c7c81b2018-10-08 11:34:28 +01001093}
1094
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001095bool RefLayerSupport::IsLogSoftmaxSupported(const TensorInfo& input,
1096 const TensorInfo& output,
1097 const LogSoftmaxDescriptor& descriptor,
1098 Optional<std::string&> reasonIfUnsupported) const
1099{
Jan Eilers8eb25602020-03-09 12:13:48 +00001100 IgnoreUnused(descriptor);
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001101
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001102 std::array<DataType, 3> supportedTypes =
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001103 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001104 DataType::BFloat16,
1105 DataType::Float32,
1106 DataType::Float16
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001107 };
1108
1109 bool supported = true;
1110 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1111 "Reference LogSoftmax: input type not supported");
1112
1113 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1114 "Reference LogSoftmax: output type not supported");
1115
1116 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1117 "Reference LogSoftmax: input and output types do not match");
1118
1119 return supported;
1120}
1121
arovir011c7c81b2018-10-08 11:34:28 +01001122bool RefLayerSupport::IsLstmSupported(const TensorInfo& input,
1123 const TensorInfo& outputStateIn,
1124 const TensorInfo& cellStateIn,
1125 const TensorInfo& scratchBuffer,
1126 const TensorInfo& outputStateOut,
1127 const TensorInfo& cellStateOut,
1128 const TensorInfo& output,
1129 const LstmDescriptor& descriptor,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001130 const LstmInputParamsInfo& paramsInfo,
1131 Optional<std::string&> reasonIfUnsupported) const
arovir011c7c81b2018-10-08 11:34:28 +01001132{
Jan Eilers8eb25602020-03-09 12:13:48 +00001133 IgnoreUnused(descriptor);
1134 IgnoreUnused(paramsInfo);
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001135
1136 bool supported = true;
1137
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001138 std::array<DataType,3> supportedTypes = {
1139 DataType::BFloat16,
Conor Kennedyb9971c92019-05-07 07:14:23 +01001140 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001141 DataType::QSymmS16
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001142 };
1143
Jan Eilersd01a83c2019-07-03 18:20:40 +01001144 // check inputs and outputs
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001145 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1146 "Reference Lstm: input is not a supported type.");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001147 supported &= CheckSupportRule(TypesAreEqual(input, outputStateIn), reasonIfUnsupported,
1148 "Reference Lstm: input and outputStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001149 supported &= CheckSupportRule(TypesAreEqual(input, cellStateIn), reasonIfUnsupported,
1150 "Reference Lstm: input and cellStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001151 supported &= CheckSupportRule(TypesAreEqual(input, scratchBuffer), reasonIfUnsupported,
1152 "Reference Lstm: input and scratchBuffer types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001153 supported &= CheckSupportRule(TypesAreEqual(input, outputStateOut), reasonIfUnsupported,
1154 "Reference Lstm: input and outputStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001155 supported &= CheckSupportRule(TypesAreEqual(input, cellStateOut), reasonIfUnsupported,
1156 "Reference Lstm: input and cellStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001157 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1158 "Reference Lstm: input and output types are mismatched");
Jan Eilersd01a83c2019-07-03 18:20:40 +01001159 // check layer parameters
Francis Murtaghbb590b42019-08-14 09:51:36 +01001160 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001161 "Reference Lstm: input and InputToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001162 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001163 "Reference Lstm: input and InputToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001164 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001165 "Reference Lstm: input and InputToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001166 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001167 "Reference Lstm: input and RecurrentToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001168 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001169 "Reference Lstm: input and RecurrentToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001170 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001171 "Reference Lstm: input and RecurrentToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001172 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001173 "Reference Lstm: input and ForgetGateBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001174 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001175 "Reference Lstm: input and CellBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001176 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001177 "Reference Lstm: input and OutputGateBias types are mismatched");
1178 if (!descriptor.m_CifgEnabled)
1179 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001180 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToInputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001181 "Reference Lstm: input and InputToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001182 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001183 reasonIfUnsupported,
1184 "Reference Lstm: input and RecurrentToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001185 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001186 "Reference Lstm: input and InputGateBias types are mismatched");
1187 if (descriptor.m_PeepholeEnabled)
1188 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001189 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001190 reasonIfUnsupported,
1191 "Reference Lstm: input and CellToInputWeights types are mismatched");
1192 }
1193 }
1194 if (descriptor.m_PeepholeEnabled)
1195 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001196 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001197 "Reference Lstm: input and CellToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001198 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001199 "Reference Lstm: input and CellToOutputWeights types are mismatched");
1200 }
1201 if (descriptor.m_ProjectionEnabled)
1202 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001203 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001204 "Reference Lstm: input and mProjectionWeights types are mismatched");
1205 if (paramsInfo.m_ProjectionBias != nullptr)
1206 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001207 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001208 "Reference Lstm: input and ProjectionBias types are mismatched");
1209 }
1210 }
1211 if (descriptor.m_LayerNormEnabled)
1212 {
1213 if (!descriptor.m_CifgEnabled)
1214 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001215 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001216 reasonIfUnsupported,
1217 "Reference Lstm: input and InputLayerNormWeights types are mismatched");
1218 }
Francis Murtaghbb590b42019-08-14 09:51:36 +01001219 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001220 reasonIfUnsupported,
1221 "Reference Lstm: input and ForgetLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001222 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001223 reasonIfUnsupported,
1224 "Reference Lstm: input and CellLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001225 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001226 reasonIfUnsupported,
1227 "Reference Lstm: input and OutputLayerNormWeights types are mismatched");
1228 }
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001229
1230 return supported;
telsoa01c577f2c2018-08-31 09:22:23 +01001231}
1232
saoste012df12b32018-11-28 16:57:20 +00001233bool RefLayerSupport::IsMaximumSupported(const TensorInfo& input0,
1234 const TensorInfo& input1,
1235 const TensorInfo& output,
1236 Optional<std::string&> reasonIfUnsupported) const
1237{
Sadik Armagan2999a022019-04-09 14:20:12 +01001238 bool supported = true;
1239
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001240 std::array<DataType,6> supportedTypes = {
1241 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001242 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001243 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001244 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001245 DataType::QAsymmU8,
1246 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001247 };
1248
1249 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1250 "Reference maximum: input 0 is not a supported type.");
1251
1252 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1253 "Reference maximum: input 1 is not a supported type.");
1254
1255 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1256 "Reference maximum: output is not a supported type.");
1257
1258 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1259 "Reference maximum: input 0 and Input 1 types are mismatched");
1260
1261 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1262 "Reference maximum: input and output types are mismatched");
1263
1264 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1265 "Reference maximum: shapes are not suitable for implicit broadcast.");
1266
1267 return supported;
saoste012df12b32018-11-28 16:57:20 +00001268}
1269
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001270bool RefLayerSupport::IsMeanSupported(const TensorInfo& input,
1271 const TensorInfo& output,
1272 const MeanDescriptor& descriptor,
1273 Optional<std::string&> reasonIfUnsupported) const
narpra0132b90462018-09-13 11:07:48 +01001274{
James Conroy4d1ff582019-06-10 17:06:39 +01001275 bool supported = true;
1276 std::string meanLayerStr = "Mean";
1277 std::string outputTensorStr = "output";
1278
Sadik Armagan303980c2020-04-17 12:45:14 +01001279 std::array<DataType,6> supportedTypes =
James Conroy4d1ff582019-06-10 17:06:39 +01001280 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001281 DataType::BFloat16,
James Conroy4d1ff582019-06-10 17:06:39 +01001282 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001283 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001284 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001285 DataType::QAsymmU8,
1286 DataType::QSymmS16
James Conroy4d1ff582019-06-10 17:06:39 +01001287 };
1288
1289 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1290 "Reference Mean: input type not supported.");
1291
1292 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1293 "Reference Mean: input and output types are mismatched");
1294
1295 if (descriptor.m_KeepDims)
1296 {
1297 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, input.GetNumDimensions()),
1298 reasonIfUnsupported,
1299 CreateIncorrectDimensionsErrorMsg(input.GetNumDimensions(),
1300 output.GetNumDimensions(),
1301 meanLayerStr, outputTensorStr).data());
1302 }
1303 else if (descriptor.m_Axis.empty())
1304 {
1305 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1306 reasonIfUnsupported,
1307 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1308 meanLayerStr, outputTensorStr).data());
1309 }
1310 else
1311 {
1312 auto outputDim = input.GetNumDimensions() - boost::numeric_cast<unsigned int>(descriptor.m_Axis.size());
1313
1314 if (outputDim > 0)
1315 {
1316 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, outputDim),
1317 reasonIfUnsupported,
1318 CreateIncorrectDimensionsErrorMsg(outputDim, output.GetNumDimensions(),
1319 meanLayerStr, outputTensorStr).data());
1320 }
1321 else
1322 {
1323 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1324 reasonIfUnsupported,
1325 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1326 meanLayerStr, outputTensorStr).data());
1327 }
1328 }
1329
1330 return supported;
narpra0132b90462018-09-13 11:07:48 +01001331}
1332
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001333bool RefLayerSupport::IsMergerSupported(const std::vector<const TensorInfo*> inputs,
Nikhil Raj8599a412018-11-19 14:51:07 +00001334 const TensorInfo& output,
Jim Flynne242f2d2019-05-22 14:24:13 +01001335 const MergerDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001336 Optional<std::string&> reasonIfUnsupported) const
1337{
Jim Flynne242f2d2019-05-22 14:24:13 +01001338 return IsConcatSupported(inputs, output, descriptor, reasonIfUnsupported);
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001339}
1340
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001341bool RefLayerSupport::IsMemCopySupported(const TensorInfo &input,
1342 const TensorInfo &output,
1343 Optional<std::string &> reasonIfUnsupported) const
1344{
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001345 bool supported = true;
1346
Sadik Armagan303980c2020-04-17 12:45:14 +01001347 std::array<DataType,7> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001348 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001349 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001350 DataType::Float32,
1351 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001352 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001353 DataType::QAsymmU8,
1354 DataType::QSymmS16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001355 DataType::Boolean
1356 };
1357
1358 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1359 "Reference MemCopy: input type not supported");
1360
1361 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1362 "Reference MemCopy: output type not supported");
1363
1364 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1365 "Reference MemCopy: input and output types are mismatched");
1366
1367 return supported;
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001368}
1369
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001370bool RefLayerSupport::IsMinimumSupported(const TensorInfo& input0,
1371 const TensorInfo& input1,
1372 const TensorInfo& output,
1373 Optional<std::string&> reasonIfUnsupported) const
1374{
Sadik Armagan2999a022019-04-09 14:20:12 +01001375 bool supported = true;
1376
Sadik Armagan303980c2020-04-17 12:45:14 +01001377 std::array<DataType,6> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001378 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001379 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001380 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001381 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001382 DataType::QAsymmU8,
1383 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001384 };
1385
1386 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1387 "Reference minimum: input 0 is not a supported type.");
1388
1389 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1390 "Reference minimum: input 1 is not a supported type.");
1391
1392 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1393 "Reference minimum: output is not a supported type.");
1394
1395 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1396 "Reference minimum: input 0 and Input 1 types are mismatched");
1397
1398 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1399 "Reference minimum: input and output types are mismatched");
1400
1401 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1402 "Reference minimum: shapes are not suitable for implicit broadcast.");
1403
1404 return supported;
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001405}
1406
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001407bool RefLayerSupport::IsMultiplicationSupported(const TensorInfo& input0,
1408 const TensorInfo& input1,
1409 const TensorInfo& output,
1410 Optional<std::string&> reasonIfUnsupported) const
1411{
Sadik Armagan2999a022019-04-09 14:20:12 +01001412 bool supported = true;
1413
Keith Davis67e6c542020-02-19 10:08:33 +00001414 std::array<DataType,6> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001415 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001416 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001417 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001418 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001419 DataType::QAsymmU8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001420 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001421 };
1422
1423 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1424 "Reference multiplication: input 0 is not a supported type.");
1425
1426 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1427 "Reference multiplication: input 1 is not a supported type.");
1428
1429 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1430 "Reference multiplication: output is not a supported type.");
1431
1432 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1433 "Reference multiplication: input 0 and Input 1 types are mismatched");
1434
1435 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1436 "Reference multiplication: input and output types are mismatched");
1437
1438 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1439 "Reference multiplication: shapes are not suitable for implicit broadcast.");
1440
1441 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001442}
1443
1444bool RefLayerSupport::IsNormalizationSupported(const TensorInfo& input,
1445 const TensorInfo& output,
1446 const NormalizationDescriptor& descriptor,
1447 Optional<std::string&> reasonIfUnsupported) const
Nina Drozd661dfa72018-10-02 11:14:17 +01001448{
Jan Eilers8eb25602020-03-09 12:13:48 +00001449 IgnoreUnused(descriptor);
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001450
1451 // Define supported types
Sadik Armagan303980c2020-04-17 12:45:14 +01001452 std::array<DataType, 6> supportedTypes =
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001453 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001454 DataType::BFloat16,
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001455 DataType::Float16,
1456 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001457 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001458 DataType::QAsymmU8,
1459 DataType::QSymmS16
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001460 };
1461
1462 bool supported = true;
1463
1464 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1465 "Reference normalization: input type not supported.");
1466
1467 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1468 "Reference normalization: output type not supported.");
1469
1470 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1471 "Reference normalization: input and output shapes have different "
1472 "num total elements.");
1473
1474 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001475}
1476
Derek Lamberti901ea112019-12-10 22:07:09 +00001477bool RefLayerSupport::IsOutputSupported(const TensorInfo& /*output*/,
1478 Optional<std::string&> /*reasonIfUnsupported*/) const
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001479{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +01001480 return true;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001481}
1482
1483bool RefLayerSupport::IsPadSupported(const TensorInfo& input,
1484 const TensorInfo& output,
1485 const PadDescriptor& descriptor,
1486 Optional<std::string&> reasonIfUnsupported) const
1487{
Jan Eilers8eb25602020-03-09 12:13:48 +00001488 IgnoreUnused(descriptor);
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001489 bool supported = true;
1490
1491 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01001492 std::array<DataType,6> supportedTypes =
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001493 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001494 DataType::BFloat16,
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001495 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001496 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001497 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001498 DataType::QAsymmU8,
1499 DataType::QSymmS16
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001500 };
1501
1502 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1503 "Reference pad: input is not a supported type.");
1504
1505 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1506 "Reference pad: output is not a supported type.");
1507
1508 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1509 "Reference pad: input and output types are mismatched.");
1510
1511 return supported;
Nina Drozd661dfa72018-10-02 11:14:17 +01001512}
1513
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001514bool RefLayerSupport::IsPermuteSupported(const TensorInfo& input,
1515 const TensorInfo& output,
1516 const PermuteDescriptor& descriptor,
1517 Optional<std::string&> reasonIfUnsupported) const
1518{
Jan Eilers8eb25602020-03-09 12:13:48 +00001519 IgnoreUnused(descriptor);
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001520 bool supported = true;
1521
1522 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01001523 std::array<DataType, 6> supportedTypes =
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001524 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001525 DataType::BFloat16,
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001526 DataType::Float32,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00001527 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001528 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001529 DataType::QAsymmU8,
1530 DataType::QSymmS16
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001531 };
1532
1533 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1534 "Reference permute: input is not a supported type.");
1535
1536 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1537 "Reference permute: output is not a supported type.");
1538
1539 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1540 "Reference permute: input and output types are mismatched.");
1541
1542 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001543}
1544
1545bool RefLayerSupport::IsPooling2dSupported(const TensorInfo& input,
1546 const TensorInfo& output,
1547 const Pooling2dDescriptor& descriptor,
1548 Optional<std::string&> reasonIfUnsupported) const
1549{
Jan Eilers8eb25602020-03-09 12:13:48 +00001550 IgnoreUnused(descriptor);
Teresa Charlina3b20472019-06-06 11:12:32 +01001551 bool supported = true;
1552
1553 // Define supported output and inputs types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001554 std::array<DataType,6> supportedTypes =
Teresa Charlina3b20472019-06-06 11:12:32 +01001555 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001556 DataType::BFloat16,
Teresa Charlina3b20472019-06-06 11:12:32 +01001557 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001558 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001559 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001560 DataType::QAsymmU8,
1561 DataType::QSymmS16
Teresa Charlina3b20472019-06-06 11:12:32 +01001562 };
1563
1564 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1565 "Reference poolind2d: input is not a supported type.");
1566
1567 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1568 "Reference poolind2d: output is not a supported type.");
1569
1570 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1571 "Reference poolind2d: input and output types are mismatched.");
1572
1573 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001574}
1575
Derek Lamberti5f400d62019-03-25 15:41:58 +00001576bool RefLayerSupport::IsQuantizeSupported(const TensorInfo& input,
1577 const TensorInfo& output,
1578 Optional<std::string&> reasonIfUnsupported) const
1579{
1580 bool supported = true;
1581
Finn Williamsfd271062019-12-04 14:27:27 +00001582 // Define supported input types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001583 std::array<DataType,7> supportedInputTypes = {
1584 DataType::BFloat16,
Keith Davis5e51cd82020-01-29 16:52:59 +00001585 DataType::Float32,
Keith Davis3d8bc972020-02-04 09:31:47 +00001586 DataType::Float16,
Ryan OShea9add1202020-02-07 10:06:33 +00001587 DataType::QAsymmS8,
Keith Davis5e51cd82020-01-29 16:52:59 +00001588 DataType::QAsymmU8,
1589 DataType::QSymmS8,
1590 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001591 };
1592
1593 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
1594 "Reference quantize: input type not supported.");
1595
1596 // Define supported output types.
Ryan OShea9add1202020-02-07 10:06:33 +00001597 std::array<DataType,4> supportedOutputTypes = {
Ryan OShea9add1202020-02-07 10:06:33 +00001598 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001599 DataType::QAsymmU8,
Finn Williamsfd271062019-12-04 14:27:27 +00001600 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001601 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001602 };
1603 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
1604 "Reference quantize: output type not supported.");
1605
1606 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1607 "Reference quantize: input and output shapes have different num total elements.");
1608
1609 return supported;
1610}
1611
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001612bool RefLayerSupport::IsReshapeSupported(const TensorInfo& input,
Kevin Maya023c402019-12-12 17:28:05 +00001613 const TensorInfo& output,
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001614 const ReshapeDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001615 Optional<std::string&> reasonIfUnsupported) const
1616{
Jan Eilers8eb25602020-03-09 12:13:48 +00001617 IgnoreUnused(output);
1618 IgnoreUnused(descriptor);
Nina Drozd2f2778f2019-05-27 10:37:05 +01001619 // Define supported output types.
Keith Davis0c2eeac2020-02-11 16:51:50 +00001620 std::array<DataType,7> supportedOutputTypes =
Nina Drozd2f2778f2019-05-27 10:37:05 +01001621 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001622 DataType::BFloat16,
Nina Drozd2f2778f2019-05-27 10:37:05 +01001623 DataType::Float32,
1624 DataType::Float16,
Narumol Prangnawarat0718ee92019-09-13 16:53:38 +01001625 DataType::Signed32,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001626 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001627 DataType::QAsymmU8,
1628 DataType::QSymmS16
Nina Drozd2f2778f2019-05-27 10:37:05 +01001629 };
Keith Davis0c2eeac2020-02-11 16:51:50 +00001630
Nina Drozd2f2778f2019-05-27 10:37:05 +01001631 return CheckSupportRule(TypeAnyOf(input, supportedOutputTypes), reasonIfUnsupported,
1632 "Reference reshape: input type not supported.");
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001633}
1634
1635bool RefLayerSupport::IsResizeBilinearSupported(const TensorInfo& input,
Sadik Armaganc625f002018-12-17 11:32:16 +00001636 const TensorInfo& output,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001637 Optional<std::string&> reasonIfUnsupported) const
1638{
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001639 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001640 std::array<DataType,6> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001641 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001642 DataType::BFloat16,
Teresa Charlin970f43b2019-07-01 13:51:07 +01001643 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001644 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001645 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001646 DataType::QAsymmU8,
1647 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001648 };
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001649
1650 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1651 "Reference ResizeBilinear: input type not supported");
1652
1653 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1654 "Reference ResizeBilinear: output type not supported");
1655
1656 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1657 "Reference ResizeBilinear: input and output types not matching");
1658
1659 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001660}
1661
Teresa Charlin970f43b2019-07-01 13:51:07 +01001662bool RefLayerSupport::IsResizeSupported(const TensorInfo& input,
1663 const TensorInfo& output,
1664 const ResizeDescriptor& descriptor,
1665 Optional<std::string&> reasonIfUnsupported) const
1666{
Jan Eilers8eb25602020-03-09 12:13:48 +00001667 IgnoreUnused(descriptor);
Teresa Charlin970f43b2019-07-01 13:51:07 +01001668 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001669 std::array<DataType,6> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001670 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001671 DataType::BFloat16,
Teresa Charlin970f43b2019-07-01 13:51:07 +01001672 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001673 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001674 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001675 DataType::QAsymmU8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001676 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001677 };
1678
1679 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1680 "Reference Resize: input type not supported");
1681
1682 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1683 "Reference Resize: output type not supported");
1684
1685 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1686 "Reference Resize: input and output types not matching");
1687
1688 return supported;
1689}
1690
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001691bool RefLayerSupport::IsRsqrtSupported(const TensorInfo& input,
1692 const TensorInfo& output,
1693 Optional<std::string&> reasonIfUnsupported) const
1694{
josh minor4a3c6102020-01-06 16:40:46 -06001695 return IsElementwiseUnarySupported(input,
1696 output,
1697 ElementwiseUnaryDescriptor(UnaryOperation::Rsqrt),
1698 reasonIfUnsupported);
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001699}
1700
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001701bool RefLayerSupport::IsSliceSupported(const TensorInfo& input,
1702 const TensorInfo& output,
1703 const SliceDescriptor& descriptor,
1704 Optional<std::string&> reasonIfUnsupported) const
1705{
Jan Eilers8eb25602020-03-09 12:13:48 +00001706 IgnoreUnused(descriptor);
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001707 bool supported = true;
1708
Sadik Armagan303980c2020-04-17 12:45:14 +01001709 std::array<DataType, 5> supportedTypes =
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001710 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001711 DataType::BFloat16,
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001712 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001713 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001714 DataType::QAsymmU8,
1715 DataType::QSymmS16
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001716 };
1717
1718 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1719 "Reference Slice: input type not supported");
1720
1721 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1722 "Reference Slice: output type not supported");
1723
1724 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1725 "Reference Slice: input and output types are mismatched");
1726
1727 return supported;
1728}
1729
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001730bool RefLayerSupport::IsSoftmaxSupported(const TensorInfo& input,
1731 const TensorInfo& output,
1732 const SoftmaxDescriptor& descriptor,
1733 Optional<std::string&> reasonIfUnsupported) const
1734{
Jan Eilers8eb25602020-03-09 12:13:48 +00001735 IgnoreUnused(descriptor);
nikraj01248683f2019-05-29 16:46:50 +01001736 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001737 std::array<DataType,7> supportedTypes =
nikraj01248683f2019-05-29 16:46:50 +01001738 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001739 DataType::BFloat16,
1740 DataType::Float32,
1741 DataType::Float16,
1742 DataType::QSymmS8,
1743 DataType::QAsymmS8,
1744 DataType::QAsymmU8,
1745 DataType::QSymmS16
nikraj01248683f2019-05-29 16:46:50 +01001746 };
1747
1748 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001749 "Reference Softmax: output type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001750
1751 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001752 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001753
1754 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001755 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001756
1757 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001758}
1759
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001760bool RefLayerSupport::IsSpaceToBatchNdSupported(const TensorInfo& input,
1761 const TensorInfo& output,
1762 const SpaceToBatchNdDescriptor& descriptor,
1763 Optional<std::string&> reasonIfUnsupported) const
1764{
Jan Eilers8eb25602020-03-09 12:13:48 +00001765 IgnoreUnused(descriptor);
nikraj01120522a2019-05-31 11:33:07 +01001766 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001767 std::array<DataType,6> supportedTypes =
nikraj01120522a2019-05-31 11:33:07 +01001768 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001769 DataType::BFloat16,
1770 DataType::Float32,
1771 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001772 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001773 DataType::QAsymmU8,
1774 DataType::QSymmS16
nikraj01120522a2019-05-31 11:33:07 +01001775 };
1776
1777 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1778 "Reference SpaceToBatchNd: input type not supported");
1779
1780 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1781 "Reference SpaceToBatchNd: output type not supported");
1782
1783 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1784 "Reference SpaceToBatchNd: input and output types are mismatched");
1785
1786 return supported;
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001787}
1788
Keith Davisa57eccb2019-06-14 17:33:22 +01001789bool RefLayerSupport::IsSpaceToDepthSupported(const TensorInfo& input,
Keith Davis51910332019-06-26 15:28:43 +01001790 const TensorInfo& output,
1791 const SpaceToDepthDescriptor& descriptor,
1792 Optional<std::string&> reasonIfUnsupported) const
Keith Davisa57eccb2019-06-14 17:33:22 +01001793{
1794
Jan Eilers8eb25602020-03-09 12:13:48 +00001795 IgnoreUnused(descriptor);
Keith Davisa57eccb2019-06-14 17:33:22 +01001796 bool supported = true;
1797
Sadik Armagan303980c2020-04-17 12:45:14 +01001798 std::array<DataType,6> supportedTypes =
Keith Davisa57eccb2019-06-14 17:33:22 +01001799 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001800 DataType::BFloat16,
Keith Davisa57eccb2019-06-14 17:33:22 +01001801 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001802 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001803 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001804 DataType::QAsymmU8,
1805 DataType::QSymmS16
Keith Davisa57eccb2019-06-14 17:33:22 +01001806 };
1807
1808 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1809 "Reference SpaceToDepth: input type not supported");
1810
1811 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1812 "Reference SpaceToDepth: output type not supported");
1813
1814 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1815 "Reference SpaceToDepth: input and output types are mismatched");
1816
1817 return supported;
1818}
1819
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001820bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1821 const ViewsDescriptor& descriptor,
1822 Optional<std::string&> reasonIfUnsupported) const
1823{
Jan Eilers8eb25602020-03-09 12:13:48 +00001824 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001825 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001826 std::array<DataType,6> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001827 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001828 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001829 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001830 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001831 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001832 DataType::QAsymmU8,
1833 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001834 };
1835
1836 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1837 "Reference splitter: input type not supported");
1838
1839 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001840}
1841
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001842bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1843 const std::vector<std::reference_wrapper<TensorInfo>>& outputs,
1844 const ViewsDescriptor& descriptor,
1845 Optional<std::string&> reasonIfUnsupported) const
1846{
Jan Eilers8eb25602020-03-09 12:13:48 +00001847 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001848 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001849 std::array<DataType,6> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001850 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001851 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001852 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001853 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001854 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001855 DataType::QAsymmU8,
1856 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001857 };
1858
1859 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1860 "Reference splitter: output type not supported");
1861 for (const TensorInfo output : outputs)
1862 {
1863 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1864 "Reference splitter: input type not supported");
1865
1866 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1867 "Reference splitter: input and output types mismatched.");
1868 }
1869
1870 return supported;
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001871}
1872
Matthew Jackson81e601c2019-07-11 12:07:09 +01001873bool RefLayerSupport::IsStackSupported(const std::vector<const TensorInfo*>& inputs,
1874 const TensorInfo& output,
1875 const StackDescriptor& descriptor,
1876 Optional<std::string&> reasonIfUnsupported) const
1877{
Jan Eilers8eb25602020-03-09 12:13:48 +00001878 IgnoreUnused(descriptor);
Matthew Jackson81e601c2019-07-11 12:07:09 +01001879
1880 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001881 std::array<DataType,6> supportedTypes =
Matthew Jackson81e601c2019-07-11 12:07:09 +01001882 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001883 DataType::BFloat16,
Matthew Jackson81e601c2019-07-11 12:07:09 +01001884 DataType::Float32,
Matthew Jacksone69c3992019-09-09 14:31:21 +01001885 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001886 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001887 DataType::QAsymmU8,
1888 DataType::QSymmS16
Matthew Jackson81e601c2019-07-11 12:07:09 +01001889 };
1890
1891 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1892 "Reference stack: output type not supported");
1893 for (const TensorInfo* input : inputs)
1894 {
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +01001895 ARMNN_ASSERT(input != nullptr);
Matthew Jackson81e601c2019-07-11 12:07:09 +01001896 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
1897 "Reference stack: input type not supported");
1898
1899 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
1900 "Reference stack: input and output types mismatched.");
1901 }
1902
1903 return supported;
1904}
1905
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00001906bool RefLayerSupport::IsStridedSliceSupported(const TensorInfo& input,
1907 const TensorInfo& output,
1908 const StridedSliceDescriptor& descriptor,
1909 Optional<std::string&> reasonIfUnsupported) const
1910{
Jan Eilers8eb25602020-03-09 12:13:48 +00001911 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001912 bool supported = true;
1913
Sadik Armagan303980c2020-04-17 12:45:14 +01001914 std::array<DataType,5> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001915 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001916 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001917 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001918 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001919 DataType::QAsymmU8,
1920 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001921 };
1922
1923 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1924 "Reference StridedSlice: input type not supported");
1925
1926 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1927 "Reference StridedSlice: output type not supported");
1928
1929 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1930 "Reference StridedSlice: input and output types are mismatched");
1931
1932 return supported;
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00001933}
1934
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001935bool RefLayerSupport::IsSubtractionSupported(const TensorInfo& input0,
1936 const TensorInfo& input1,
1937 const TensorInfo& output,
1938 Optional<std::string&> reasonIfUnsupported) const
1939{
Sadik Armagan2999a022019-04-09 14:20:12 +01001940 bool supported = true;
1941
Sadik Armagan303980c2020-04-17 12:45:14 +01001942 std::array<DataType,6> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001943 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001944 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001945 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001946 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001947 DataType::QAsymmU8,
1948 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001949 };
1950
1951 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1952 "Reference subtraction: input 0 is not a supported type.");
1953
1954 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1955 "Reference subtraction: input 1 is not a supported type.");
1956
1957 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1958 "Reference subtraction: output is not a supported type.");
1959
1960 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1961 "Reference subtraction: input 0 and Input 1 types are mismatched");
1962
1963 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1964 "Reference subtraction: input and output types are mismatched");
1965
1966 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1967 "Reference subtraction: shapes are not suitable for implicit broadcast.");
1968
1969 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001970}
1971
Matteo Martincighab9e5252019-06-13 17:27:46 +01001972bool RefLayerSupport::IsPreluSupported(const TensorInfo& input,
1973 const TensorInfo& alpha,
1974 const TensorInfo& output,
1975 Optional<std::string&> reasonIfUnsupported) const
1976{
1977 bool supported = true;
1978
Sadik Armagan303980c2020-04-17 12:45:14 +01001979 std::array<DataType, 6> supportedTypes
Matteo Martincighab9e5252019-06-13 17:27:46 +01001980 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001981 DataType::BFloat16,
Matteo Martincighab9e5252019-06-13 17:27:46 +01001982 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001983 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001984 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001985 DataType::QAsymmU8,
1986 DataType::QSymmS16
Matteo Martincighab9e5252019-06-13 17:27:46 +01001987 };
1988
1989 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1990 "PReLU: input is not a supported type.");
1991
1992 supported &= CheckSupportRule(TypeAnyOf(alpha, supportedTypes), reasonIfUnsupported,
1993 "PReLU: alpha is not a supported type.");
1994
1995 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1996 "PReLU: output is not a supported type.");
1997
1998 supported &= CheckSupportRule(TypesAreEqual(input, alpha, output), reasonIfUnsupported,
1999 "PReLU: input, alpha and output types are mismatched");
2000
2001 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input, alpha, output), reasonIfUnsupported,
2002 "PReLU: shapes are not suitable for implicit broadcast");
2003
2004 return supported;
2005}
2006
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002007bool RefLayerSupport::IsTransposeConvolution2dSupported(const TensorInfo& input,
2008 const TensorInfo& output,
2009 const TransposeConvolution2dDescriptor& descriptor,
2010 const TensorInfo& weights,
2011 const Optional<TensorInfo>& biases,
2012 Optional<std::string&> reasonIfUnsupported) const
2013{
Jan Eilers8eb25602020-03-09 12:13:48 +00002014 IgnoreUnused(descriptor);
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002015 bool supported = true;
2016
Sadik Armagan303980c2020-04-17 12:45:14 +01002017 std::array<DataType,7> supportedTypes =
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002018 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002019 DataType::BFloat16,
2020 DataType::Float32,
2021 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002022 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002023 DataType::QAsymmU8,
Sadik Armagan303980c2020-04-17 12:45:14 +01002024 DataType::QSymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002025 DataType::QSymmS16
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002026 };
2027
2028 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2029 "Reference TransposeConvolution2d: input is not a supported type.");
2030
2031 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2032 "Reference TransposeConvolution2d: output is not a supported type.");
2033
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002034 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2035 "Reference TransposeConvolution2d: input and output types mismatched.");
2036
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002037
2038 const DataType inputType = input.GetDataType();
Sadik Armagan303980c2020-04-17 12:45:14 +01002039 if (IsQuantized8BitType(inputType))
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002040 {
Derek Lambertid466a542020-01-22 15:37:29 +00002041 ARMNN_NO_DEPRECATE_WARN_BEGIN
Sadik Armagan303980c2020-04-17 12:45:14 +01002042 std::array<DataType, 4> supportedWeightTypes =
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002043 {
Sadik Armagan303980c2020-04-17 12:45:14 +01002044 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002045 DataType::QAsymmU8,
Derek Lambertid466a542020-01-22 15:37:29 +00002046 DataType::QSymmS8,
2047 DataType::QuantizedSymm8PerAxis //Deprecated
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002048 };
Derek Lambertid466a542020-01-22 15:37:29 +00002049 ARMNN_NO_DEPRECATE_WARN_END
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002050
2051 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
2052 "Reference TransposeConvolution2d: weights type not supported for "
2053 "quantized input.");
2054 }
2055 else
2056 {
2057 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
2058 "Reference TransposeConvolution2d: weights is not a supported type.");
2059
2060 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
2061 "Reference TransposeConvolution2d: input and weights types mismatched.");
2062 }
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002063
2064 if (biases.has_value())
2065 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002066 std::array<DataType,4> biasesSupportedTypes =
Aron Virginas-Tar651aafe2019-08-05 11:52:05 +01002067 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002068 DataType::BFloat16,
2069 DataType::Float32,
2070 DataType::Float16,
2071 DataType::Signed32
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002072 };
2073 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
2074 "Reference TransposeConvolution2d: biases is not a supported type.");
2075 }
2076
2077 return supported;
2078}
2079
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002080bool RefLayerSupport::IsTransposeSupported(const TensorInfo& input,
2081 const TensorInfo& output,
2082 const TransposeDescriptor& descriptor,
2083 Optional<std::string&> reasonIfUnsupported) const
2084{
Jan Eilers8eb25602020-03-09 12:13:48 +00002085 IgnoreUnused(descriptor);
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002086 bool supported = true;
2087
2088 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01002089 std::array<DataType, 6> supportedTypes =
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002090 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002091 DataType::BFloat16,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002092 DataType::Float32,
2093 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002094 DataType::QAsymmS8,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002095 DataType::QAsymmU8,
2096 DataType::QSymmS16
2097 };
2098
2099 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2100 "Reference transpose: input is not a supported type.");
2101
2102 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2103 "Reference transpose: output is not a supported type.");
2104
2105 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2106 "Reference transpose: input and output types are mismatched.");
2107
2108 return supported;
2109}
2110
arovir011c7c81b2018-10-08 11:34:28 +01002111} // namespace armnn