blob: 65ae14ff4029a66033f6bfdc7d1daaed71e71768 [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
971 }
972
973 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100974}
975
narpra014951d842019-01-18 16:53:53 +0000976bool RefLayerSupport::IsGatherSupported(const armnn::TensorInfo& input0,
977 const armnn::TensorInfo& input1,
978 const armnn::TensorInfo& output,
979 armnn::Optional<std::string&> reasonIfUnsupported) const
980{
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100981 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +0100982 std::array<DataType,6> supportedTypes =
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100983 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000984 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100985 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100986 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100987 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000988 DataType::QAsymmU8,
989 DataType::QSymmS16
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100990 };
991
992 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
993 "Reference Gather: input type not supported");
994
995 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
996 "Reference Gather: output type not supported");
997
998 supported &= CheckSupportRule(TypeIs(input1, DataType::Signed32), reasonIfUnsupported,
999 "Reference Gather: indices (input1) type not supported");
1000
1001 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1002 "Reference Gather: input and output types not matching");
1003
1004 return supported;
narpra014951d842019-01-18 16:53:53 +00001005}
1006
FrancisMurtagh878f0232018-12-19 10:56:15 +00001007bool RefLayerSupport::IsGreaterSupported(const TensorInfo& input0,
1008 const TensorInfo& input1,
1009 const TensorInfo& output,
1010 Optional<std::string&> reasonIfUnsupported) const
1011{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +01001012 return IsComparisonSupported(input0,
1013 input1,
1014 output,
1015 ComparisonDescriptor(ComparisonOperation::Greater),
1016 reasonIfUnsupported);
FrancisMurtagh878f0232018-12-19 10:56:15 +00001017}
1018
Derek Lamberti901ea112019-12-10 22:07:09 +00001019bool RefLayerSupport::IsInputSupported(const TensorInfo& /*input*/,
1020 Optional<std::string&> /*reasonIfUnsupported*/) const
arovir011c7c81b2018-10-08 11:34:28 +01001021{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +01001022 return true;
arovir011c7c81b2018-10-08 11:34:28 +01001023}
1024
Kevin May09ca49c2019-10-09 12:37:34 +01001025bool RefLayerSupport::IsInstanceNormalizationSupported(const TensorInfo& input,
1026 const TensorInfo& output,
1027 const InstanceNormalizationDescriptor& descriptor,
1028 Optional<std::string&> reasonIfUnsupported) const
1029{
Jan Eilers8eb25602020-03-09 12:13:48 +00001030 IgnoreUnused(descriptor);
Kevin May09ca49c2019-10-09 12:37:34 +01001031 // Define supported types
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001032 std::array<DataType, 3> supportedTypes =
Kevin May09ca49c2019-10-09 12:37:34 +01001033 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001034 DataType::BFloat16,
Kevin May09ca49c2019-10-09 12:37:34 +01001035 DataType::Float32,
1036 DataType::Float16
1037 };
1038
1039 bool supported = true;
1040
1041 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1042 "Reference Instance Normalization: input type not supported.");
1043
1044 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1045 "Reference Instance Normalization: output type not supported.");
1046
1047 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1048 "Reference Instance Normalization: input and output types mismatched.");
1049
1050 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1051 "Reference Instance Normalization: input and output shapes have different "
1052 "num total elements.");
1053
1054 return supported;
1055}
1056
arovir011c7c81b2018-10-08 11:34:28 +01001057bool RefLayerSupport::IsL2NormalizationSupported(const TensorInfo& input,
1058 const TensorInfo& output,
1059 const L2NormalizationDescriptor& descriptor,
1060 Optional<std::string&> reasonIfUnsupported) const
1061{
Jan Eilers8eb25602020-03-09 12:13:48 +00001062 IgnoreUnused(descriptor);
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001063 // Define supported types
Sadik Armagan303980c2020-04-17 12:45:14 +01001064 std::array<DataType, 6> supportedTypes =
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001065 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001066 DataType::BFloat16,
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001067 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001068 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001069 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001070 DataType::QAsymmU8,
1071 DataType::QSymmS16
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001072 };
1073
1074 bool supported = true;
1075
1076 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1077 "Reference L2normalization: input type not supported.");
1078
1079 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1080 "Reference L2normalization: output type not supported.");
1081
1082 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1083 "Reference L2normalization: input and output types mismatched.");
1084
1085 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1086 "Reference L2normalization: input and output shapes have different "
1087 "num total elements.");
1088
1089 return supported;
arovir011c7c81b2018-10-08 11:34:28 +01001090}
1091
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001092bool RefLayerSupport::IsLogSoftmaxSupported(const TensorInfo& input,
1093 const TensorInfo& output,
1094 const LogSoftmaxDescriptor& descriptor,
1095 Optional<std::string&> reasonIfUnsupported) const
1096{
Jan Eilers8eb25602020-03-09 12:13:48 +00001097 IgnoreUnused(descriptor);
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001098
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001099 std::array<DataType, 3> supportedTypes =
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001100 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001101 DataType::BFloat16,
1102 DataType::Float32,
1103 DataType::Float16
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001104 };
1105
1106 bool supported = true;
1107 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1108 "Reference LogSoftmax: input type not supported");
1109
1110 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1111 "Reference LogSoftmax: output type not supported");
1112
1113 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1114 "Reference LogSoftmax: input and output types do not match");
1115
1116 return supported;
1117}
1118
arovir011c7c81b2018-10-08 11:34:28 +01001119bool RefLayerSupport::IsLstmSupported(const TensorInfo& input,
1120 const TensorInfo& outputStateIn,
1121 const TensorInfo& cellStateIn,
1122 const TensorInfo& scratchBuffer,
1123 const TensorInfo& outputStateOut,
1124 const TensorInfo& cellStateOut,
1125 const TensorInfo& output,
1126 const LstmDescriptor& descriptor,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001127 const LstmInputParamsInfo& paramsInfo,
1128 Optional<std::string&> reasonIfUnsupported) const
arovir011c7c81b2018-10-08 11:34:28 +01001129{
Jan Eilers8eb25602020-03-09 12:13:48 +00001130 IgnoreUnused(descriptor);
1131 IgnoreUnused(paramsInfo);
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001132
1133 bool supported = true;
1134
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001135 std::array<DataType,3> supportedTypes = {
1136 DataType::BFloat16,
Conor Kennedyb9971c92019-05-07 07:14:23 +01001137 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001138 DataType::QSymmS16
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001139 };
1140
Jan Eilersd01a83c2019-07-03 18:20:40 +01001141 // check inputs and outputs
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001142 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1143 "Reference Lstm: input is not a supported type.");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001144 supported &= CheckSupportRule(TypesAreEqual(input, outputStateIn), reasonIfUnsupported,
1145 "Reference Lstm: input and outputStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001146 supported &= CheckSupportRule(TypesAreEqual(input, cellStateIn), reasonIfUnsupported,
1147 "Reference Lstm: input and cellStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001148 supported &= CheckSupportRule(TypesAreEqual(input, scratchBuffer), reasonIfUnsupported,
1149 "Reference Lstm: input and scratchBuffer types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001150 supported &= CheckSupportRule(TypesAreEqual(input, outputStateOut), reasonIfUnsupported,
1151 "Reference Lstm: input and outputStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001152 supported &= CheckSupportRule(TypesAreEqual(input, cellStateOut), reasonIfUnsupported,
1153 "Reference Lstm: input and cellStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001154 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1155 "Reference Lstm: input and output types are mismatched");
Jan Eilersd01a83c2019-07-03 18:20:40 +01001156 // check layer parameters
Francis Murtaghbb590b42019-08-14 09:51:36 +01001157 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001158 "Reference Lstm: input and InputToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001159 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001160 "Reference Lstm: input and InputToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001161 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001162 "Reference Lstm: input and InputToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001163 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001164 "Reference Lstm: input and RecurrentToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001165 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001166 "Reference Lstm: input and RecurrentToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001167 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001168 "Reference Lstm: input and RecurrentToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001169 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001170 "Reference Lstm: input and ForgetGateBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001171 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001172 "Reference Lstm: input and CellBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001173 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001174 "Reference Lstm: input and OutputGateBias types are mismatched");
1175 if (!descriptor.m_CifgEnabled)
1176 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001177 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToInputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001178 "Reference Lstm: input and InputToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001179 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001180 reasonIfUnsupported,
1181 "Reference Lstm: input and RecurrentToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001182 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001183 "Reference Lstm: input and InputGateBias types are mismatched");
1184 if (descriptor.m_PeepholeEnabled)
1185 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001186 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001187 reasonIfUnsupported,
1188 "Reference Lstm: input and CellToInputWeights types are mismatched");
1189 }
1190 }
1191 if (descriptor.m_PeepholeEnabled)
1192 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001193 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001194 "Reference Lstm: input and CellToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001195 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001196 "Reference Lstm: input and CellToOutputWeights types are mismatched");
1197 }
1198 if (descriptor.m_ProjectionEnabled)
1199 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001200 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001201 "Reference Lstm: input and mProjectionWeights types are mismatched");
1202 if (paramsInfo.m_ProjectionBias != nullptr)
1203 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001204 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001205 "Reference Lstm: input and ProjectionBias types are mismatched");
1206 }
1207 }
1208 if (descriptor.m_LayerNormEnabled)
1209 {
1210 if (!descriptor.m_CifgEnabled)
1211 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001212 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001213 reasonIfUnsupported,
1214 "Reference Lstm: input and InputLayerNormWeights types are mismatched");
1215 }
Francis Murtaghbb590b42019-08-14 09:51:36 +01001216 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001217 reasonIfUnsupported,
1218 "Reference Lstm: input and ForgetLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001219 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001220 reasonIfUnsupported,
1221 "Reference Lstm: input and CellLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001222 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001223 reasonIfUnsupported,
1224 "Reference Lstm: input and OutputLayerNormWeights types are mismatched");
1225 }
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001226
1227 return supported;
telsoa01c577f2c2018-08-31 09:22:23 +01001228}
1229
saoste012df12b32018-11-28 16:57:20 +00001230bool RefLayerSupport::IsMaximumSupported(const TensorInfo& input0,
1231 const TensorInfo& input1,
1232 const TensorInfo& output,
1233 Optional<std::string&> reasonIfUnsupported) const
1234{
Sadik Armagan2999a022019-04-09 14:20:12 +01001235 bool supported = true;
1236
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001237 std::array<DataType,6> supportedTypes = {
1238 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001239 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001240 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001241 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001242 DataType::QAsymmU8,
1243 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001244 };
1245
1246 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1247 "Reference maximum: input 0 is not a supported type.");
1248
1249 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1250 "Reference maximum: input 1 is not a supported type.");
1251
1252 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1253 "Reference maximum: output is not a supported type.");
1254
1255 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1256 "Reference maximum: input 0 and Input 1 types are mismatched");
1257
1258 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1259 "Reference maximum: input and output types are mismatched");
1260
1261 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1262 "Reference maximum: shapes are not suitable for implicit broadcast.");
1263
1264 return supported;
saoste012df12b32018-11-28 16:57:20 +00001265}
1266
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001267bool RefLayerSupport::IsMeanSupported(const TensorInfo& input,
1268 const TensorInfo& output,
1269 const MeanDescriptor& descriptor,
1270 Optional<std::string&> reasonIfUnsupported) const
narpra0132b90462018-09-13 11:07:48 +01001271{
James Conroy4d1ff582019-06-10 17:06:39 +01001272 bool supported = true;
1273 std::string meanLayerStr = "Mean";
1274 std::string outputTensorStr = "output";
1275
Sadik Armagan303980c2020-04-17 12:45:14 +01001276 std::array<DataType,6> supportedTypes =
James Conroy4d1ff582019-06-10 17:06:39 +01001277 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001278 DataType::BFloat16,
James Conroy4d1ff582019-06-10 17:06:39 +01001279 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001280 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001281 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001282 DataType::QAsymmU8,
1283 DataType::QSymmS16
James Conroy4d1ff582019-06-10 17:06:39 +01001284 };
1285
1286 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1287 "Reference Mean: input type not supported.");
1288
1289 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1290 "Reference Mean: input and output types are mismatched");
1291
1292 if (descriptor.m_KeepDims)
1293 {
1294 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, input.GetNumDimensions()),
1295 reasonIfUnsupported,
1296 CreateIncorrectDimensionsErrorMsg(input.GetNumDimensions(),
1297 output.GetNumDimensions(),
1298 meanLayerStr, outputTensorStr).data());
1299 }
1300 else if (descriptor.m_Axis.empty())
1301 {
1302 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1303 reasonIfUnsupported,
1304 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1305 meanLayerStr, outputTensorStr).data());
1306 }
1307 else
1308 {
1309 auto outputDim = input.GetNumDimensions() - boost::numeric_cast<unsigned int>(descriptor.m_Axis.size());
1310
1311 if (outputDim > 0)
1312 {
1313 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, outputDim),
1314 reasonIfUnsupported,
1315 CreateIncorrectDimensionsErrorMsg(outputDim, output.GetNumDimensions(),
1316 meanLayerStr, outputTensorStr).data());
1317 }
1318 else
1319 {
1320 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1321 reasonIfUnsupported,
1322 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1323 meanLayerStr, outputTensorStr).data());
1324 }
1325 }
1326
1327 return supported;
narpra0132b90462018-09-13 11:07:48 +01001328}
1329
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001330bool RefLayerSupport::IsMergerSupported(const std::vector<const TensorInfo*> inputs,
Nikhil Raj8599a412018-11-19 14:51:07 +00001331 const TensorInfo& output,
Jim Flynne242f2d2019-05-22 14:24:13 +01001332 const MergerDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001333 Optional<std::string&> reasonIfUnsupported) const
1334{
Jim Flynne242f2d2019-05-22 14:24:13 +01001335 return IsConcatSupported(inputs, output, descriptor, reasonIfUnsupported);
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001336}
1337
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001338bool RefLayerSupport::IsMemCopySupported(const TensorInfo &input,
1339 const TensorInfo &output,
1340 Optional<std::string &> reasonIfUnsupported) const
1341{
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001342 bool supported = true;
1343
Sadik Armagan303980c2020-04-17 12:45:14 +01001344 std::array<DataType,7> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001345 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001346 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001347 DataType::Float32,
1348 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001349 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001350 DataType::QAsymmU8,
1351 DataType::QSymmS16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001352 DataType::Boolean
1353 };
1354
1355 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1356 "Reference MemCopy: input type not supported");
1357
1358 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1359 "Reference MemCopy: output type not supported");
1360
1361 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1362 "Reference MemCopy: input and output types are mismatched");
1363
1364 return supported;
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001365}
1366
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001367bool RefLayerSupport::IsMinimumSupported(const TensorInfo& input0,
1368 const TensorInfo& input1,
1369 const TensorInfo& output,
1370 Optional<std::string&> reasonIfUnsupported) const
1371{
Sadik Armagan2999a022019-04-09 14:20:12 +01001372 bool supported = true;
1373
Sadik Armagan303980c2020-04-17 12:45:14 +01001374 std::array<DataType,6> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001375 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001376 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001377 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001378 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001379 DataType::QAsymmU8,
1380 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001381 };
1382
1383 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1384 "Reference minimum: input 0 is not a supported type.");
1385
1386 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1387 "Reference minimum: input 1 is not a supported type.");
1388
1389 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1390 "Reference minimum: output is not a supported type.");
1391
1392 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1393 "Reference minimum: input 0 and Input 1 types are mismatched");
1394
1395 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1396 "Reference minimum: input and output types are mismatched");
1397
1398 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1399 "Reference minimum: shapes are not suitable for implicit broadcast.");
1400
1401 return supported;
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001402}
1403
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001404bool RefLayerSupport::IsMultiplicationSupported(const TensorInfo& input0,
1405 const TensorInfo& input1,
1406 const TensorInfo& output,
1407 Optional<std::string&> reasonIfUnsupported) const
1408{
Sadik Armagan2999a022019-04-09 14:20:12 +01001409 bool supported = true;
1410
Keith Davis67e6c542020-02-19 10:08:33 +00001411 std::array<DataType,6> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001412 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001413 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001414 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001415 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001416 DataType::QAsymmU8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001417 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001418 };
1419
1420 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1421 "Reference multiplication: input 0 is not a supported type.");
1422
1423 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1424 "Reference multiplication: input 1 is not a supported type.");
1425
1426 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1427 "Reference multiplication: output is not a supported type.");
1428
1429 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1430 "Reference multiplication: input 0 and Input 1 types are mismatched");
1431
1432 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1433 "Reference multiplication: input and output types are mismatched");
1434
1435 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1436 "Reference multiplication: shapes are not suitable for implicit broadcast.");
1437
1438 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001439}
1440
1441bool RefLayerSupport::IsNormalizationSupported(const TensorInfo& input,
1442 const TensorInfo& output,
1443 const NormalizationDescriptor& descriptor,
1444 Optional<std::string&> reasonIfUnsupported) const
Nina Drozd661dfa72018-10-02 11:14:17 +01001445{
Jan Eilers8eb25602020-03-09 12:13:48 +00001446 IgnoreUnused(descriptor);
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001447
1448 // Define supported types
Sadik Armagan303980c2020-04-17 12:45:14 +01001449 std::array<DataType, 6> supportedTypes =
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001450 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001451 DataType::BFloat16,
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001452 DataType::Float16,
1453 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001454 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001455 DataType::QAsymmU8,
1456 DataType::QSymmS16
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001457 };
1458
1459 bool supported = true;
1460
1461 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1462 "Reference normalization: input type not supported.");
1463
1464 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1465 "Reference normalization: output type not supported.");
1466
1467 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1468 "Reference normalization: input and output shapes have different "
1469 "num total elements.");
1470
1471 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001472}
1473
Derek Lamberti901ea112019-12-10 22:07:09 +00001474bool RefLayerSupport::IsOutputSupported(const TensorInfo& /*output*/,
1475 Optional<std::string&> /*reasonIfUnsupported*/) const
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001476{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +01001477 return true;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001478}
1479
1480bool RefLayerSupport::IsPadSupported(const TensorInfo& input,
1481 const TensorInfo& output,
1482 const PadDescriptor& descriptor,
1483 Optional<std::string&> reasonIfUnsupported) const
1484{
Jan Eilers8eb25602020-03-09 12:13:48 +00001485 IgnoreUnused(descriptor);
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001486 bool supported = true;
1487
1488 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01001489 std::array<DataType,6> supportedTypes =
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001490 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001491 DataType::BFloat16,
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001492 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001493 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001494 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001495 DataType::QAsymmU8,
1496 DataType::QSymmS16
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001497 };
1498
1499 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1500 "Reference pad: input is not a supported type.");
1501
1502 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1503 "Reference pad: output is not a supported type.");
1504
1505 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1506 "Reference pad: input and output types are mismatched.");
1507
1508 return supported;
Nina Drozd661dfa72018-10-02 11:14:17 +01001509}
1510
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001511bool RefLayerSupport::IsPermuteSupported(const TensorInfo& input,
1512 const TensorInfo& output,
1513 const PermuteDescriptor& descriptor,
1514 Optional<std::string&> reasonIfUnsupported) const
1515{
Jan Eilers8eb25602020-03-09 12:13:48 +00001516 IgnoreUnused(descriptor);
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001517 bool supported = true;
1518
1519 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01001520 std::array<DataType, 6> supportedTypes =
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001521 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001522 DataType::BFloat16,
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001523 DataType::Float32,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00001524 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001525 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001526 DataType::QAsymmU8,
1527 DataType::QSymmS16
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001528 };
1529
1530 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1531 "Reference permute: input is not a supported type.");
1532
1533 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1534 "Reference permute: output is not a supported type.");
1535
1536 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1537 "Reference permute: input and output types are mismatched.");
1538
1539 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001540}
1541
1542bool RefLayerSupport::IsPooling2dSupported(const TensorInfo& input,
1543 const TensorInfo& output,
1544 const Pooling2dDescriptor& descriptor,
1545 Optional<std::string&> reasonIfUnsupported) const
1546{
Jan Eilers8eb25602020-03-09 12:13:48 +00001547 IgnoreUnused(descriptor);
Teresa Charlina3b20472019-06-06 11:12:32 +01001548 bool supported = true;
1549
1550 // Define supported output and inputs types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001551 std::array<DataType,6> supportedTypes =
Teresa Charlina3b20472019-06-06 11:12:32 +01001552 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001553 DataType::BFloat16,
Teresa Charlina3b20472019-06-06 11:12:32 +01001554 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001555 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001556 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001557 DataType::QAsymmU8,
1558 DataType::QSymmS16
Teresa Charlina3b20472019-06-06 11:12:32 +01001559 };
1560
1561 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1562 "Reference poolind2d: input is not a supported type.");
1563
1564 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1565 "Reference poolind2d: output is not a supported type.");
1566
1567 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1568 "Reference poolind2d: input and output types are mismatched.");
1569
1570 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001571}
1572
Derek Lamberti5f400d62019-03-25 15:41:58 +00001573bool RefLayerSupport::IsQuantizeSupported(const TensorInfo& input,
1574 const TensorInfo& output,
1575 Optional<std::string&> reasonIfUnsupported) const
1576{
1577 bool supported = true;
1578
Finn Williamsfd271062019-12-04 14:27:27 +00001579 // Define supported input types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001580 std::array<DataType,7> supportedInputTypes = {
1581 DataType::BFloat16,
Keith Davis5e51cd82020-01-29 16:52:59 +00001582 DataType::Float32,
Keith Davis3d8bc972020-02-04 09:31:47 +00001583 DataType::Float16,
Ryan OShea9add1202020-02-07 10:06:33 +00001584 DataType::QAsymmS8,
Keith Davis5e51cd82020-01-29 16:52:59 +00001585 DataType::QAsymmU8,
1586 DataType::QSymmS8,
1587 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001588 };
1589
1590 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
1591 "Reference quantize: input type not supported.");
1592
1593 // Define supported output types.
Ryan OShea9add1202020-02-07 10:06:33 +00001594 std::array<DataType,4> supportedOutputTypes = {
Ryan OShea9add1202020-02-07 10:06:33 +00001595 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001596 DataType::QAsymmU8,
Finn Williamsfd271062019-12-04 14:27:27 +00001597 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001598 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001599 };
1600 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
1601 "Reference quantize: output type not supported.");
1602
1603 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1604 "Reference quantize: input and output shapes have different num total elements.");
1605
1606 return supported;
1607}
1608
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001609bool RefLayerSupport::IsReshapeSupported(const TensorInfo& input,
Kevin Maya023c402019-12-12 17:28:05 +00001610 const TensorInfo& output,
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001611 const ReshapeDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001612 Optional<std::string&> reasonIfUnsupported) const
1613{
Jan Eilers8eb25602020-03-09 12:13:48 +00001614 IgnoreUnused(output);
1615 IgnoreUnused(descriptor);
Nina Drozd2f2778f2019-05-27 10:37:05 +01001616 // Define supported output types.
Keith Davis0c2eeac2020-02-11 16:51:50 +00001617 std::array<DataType,7> supportedOutputTypes =
Nina Drozd2f2778f2019-05-27 10:37:05 +01001618 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001619 DataType::BFloat16,
Nina Drozd2f2778f2019-05-27 10:37:05 +01001620 DataType::Float32,
1621 DataType::Float16,
Narumol Prangnawarat0718ee92019-09-13 16:53:38 +01001622 DataType::Signed32,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001623 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001624 DataType::QAsymmU8,
1625 DataType::QSymmS16
Nina Drozd2f2778f2019-05-27 10:37:05 +01001626 };
Keith Davis0c2eeac2020-02-11 16:51:50 +00001627
Nina Drozd2f2778f2019-05-27 10:37:05 +01001628 return CheckSupportRule(TypeAnyOf(input, supportedOutputTypes), reasonIfUnsupported,
1629 "Reference reshape: input type not supported.");
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001630}
1631
1632bool RefLayerSupport::IsResizeBilinearSupported(const TensorInfo& input,
Sadik Armaganc625f002018-12-17 11:32:16 +00001633 const TensorInfo& output,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001634 Optional<std::string&> reasonIfUnsupported) const
1635{
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001636 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001637 std::array<DataType,6> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001638 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001639 DataType::BFloat16,
Teresa Charlin970f43b2019-07-01 13:51:07 +01001640 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001641 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001642 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001643 DataType::QAsymmU8,
1644 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001645 };
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001646
1647 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1648 "Reference ResizeBilinear: input type not supported");
1649
1650 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1651 "Reference ResizeBilinear: output type not supported");
1652
1653 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1654 "Reference ResizeBilinear: input and output types not matching");
1655
1656 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001657}
1658
Teresa Charlin970f43b2019-07-01 13:51:07 +01001659bool RefLayerSupport::IsResizeSupported(const TensorInfo& input,
1660 const TensorInfo& output,
1661 const ResizeDescriptor& descriptor,
1662 Optional<std::string&> reasonIfUnsupported) const
1663{
Jan Eilers8eb25602020-03-09 12:13:48 +00001664 IgnoreUnused(descriptor);
Teresa Charlin970f43b2019-07-01 13:51:07 +01001665 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001666 std::array<DataType,6> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001667 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001668 DataType::BFloat16,
Teresa Charlin970f43b2019-07-01 13:51:07 +01001669 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001670 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001671 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001672 DataType::QAsymmU8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001673 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001674 };
1675
1676 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1677 "Reference Resize: input type not supported");
1678
1679 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1680 "Reference Resize: output type not supported");
1681
1682 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1683 "Reference Resize: input and output types not matching");
1684
1685 return supported;
1686}
1687
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001688bool RefLayerSupport::IsRsqrtSupported(const TensorInfo& input,
1689 const TensorInfo& output,
1690 Optional<std::string&> reasonIfUnsupported) const
1691{
josh minor4a3c6102020-01-06 16:40:46 -06001692 return IsElementwiseUnarySupported(input,
1693 output,
1694 ElementwiseUnaryDescriptor(UnaryOperation::Rsqrt),
1695 reasonIfUnsupported);
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001696}
1697
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001698bool RefLayerSupport::IsSliceSupported(const TensorInfo& input,
1699 const TensorInfo& output,
1700 const SliceDescriptor& descriptor,
1701 Optional<std::string&> reasonIfUnsupported) const
1702{
Jan Eilers8eb25602020-03-09 12:13:48 +00001703 IgnoreUnused(descriptor);
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001704 bool supported = true;
1705
Sadik Armagan303980c2020-04-17 12:45:14 +01001706 std::array<DataType, 5> supportedTypes =
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001707 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001708 DataType::BFloat16,
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001709 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001710 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001711 DataType::QAsymmU8,
1712 DataType::QSymmS16
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001713 };
1714
1715 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1716 "Reference Slice: input type not supported");
1717
1718 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1719 "Reference Slice: output type not supported");
1720
1721 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1722 "Reference Slice: input and output types are mismatched");
1723
1724 return supported;
1725}
1726
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001727bool RefLayerSupport::IsSoftmaxSupported(const TensorInfo& input,
1728 const TensorInfo& output,
1729 const SoftmaxDescriptor& descriptor,
1730 Optional<std::string&> reasonIfUnsupported) const
1731{
Jan Eilers8eb25602020-03-09 12:13:48 +00001732 IgnoreUnused(descriptor);
nikraj01248683f2019-05-29 16:46:50 +01001733 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001734 std::array<DataType,7> supportedTypes =
nikraj01248683f2019-05-29 16:46:50 +01001735 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001736 DataType::BFloat16,
1737 DataType::Float32,
1738 DataType::Float16,
1739 DataType::QSymmS8,
1740 DataType::QAsymmS8,
1741 DataType::QAsymmU8,
1742 DataType::QSymmS16
nikraj01248683f2019-05-29 16:46:50 +01001743 };
1744
1745 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001746 "Reference Softmax: output type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001747
1748 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001749 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001750
1751 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001752 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001753
1754 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001755}
1756
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001757bool RefLayerSupport::IsSpaceToBatchNdSupported(const TensorInfo& input,
1758 const TensorInfo& output,
1759 const SpaceToBatchNdDescriptor& descriptor,
1760 Optional<std::string&> reasonIfUnsupported) const
1761{
Jan Eilers8eb25602020-03-09 12:13:48 +00001762 IgnoreUnused(descriptor);
nikraj01120522a2019-05-31 11:33:07 +01001763 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001764 std::array<DataType,6> supportedTypes =
nikraj01120522a2019-05-31 11:33:07 +01001765 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001766 DataType::BFloat16,
1767 DataType::Float32,
1768 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001769 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001770 DataType::QAsymmU8,
1771 DataType::QSymmS16
nikraj01120522a2019-05-31 11:33:07 +01001772 };
1773
1774 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1775 "Reference SpaceToBatchNd: input type not supported");
1776
1777 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1778 "Reference SpaceToBatchNd: output type not supported");
1779
1780 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1781 "Reference SpaceToBatchNd: input and output types are mismatched");
1782
1783 return supported;
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001784}
1785
Keith Davisa57eccb2019-06-14 17:33:22 +01001786bool RefLayerSupport::IsSpaceToDepthSupported(const TensorInfo& input,
Keith Davis51910332019-06-26 15:28:43 +01001787 const TensorInfo& output,
1788 const SpaceToDepthDescriptor& descriptor,
1789 Optional<std::string&> reasonIfUnsupported) const
Keith Davisa57eccb2019-06-14 17:33:22 +01001790{
1791
Jan Eilers8eb25602020-03-09 12:13:48 +00001792 IgnoreUnused(descriptor);
Keith Davisa57eccb2019-06-14 17:33:22 +01001793 bool supported = true;
1794
Sadik Armagan303980c2020-04-17 12:45:14 +01001795 std::array<DataType,6> supportedTypes =
Keith Davisa57eccb2019-06-14 17:33:22 +01001796 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001797 DataType::BFloat16,
Keith Davisa57eccb2019-06-14 17:33:22 +01001798 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001799 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001800 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001801 DataType::QAsymmU8,
1802 DataType::QSymmS16
Keith Davisa57eccb2019-06-14 17:33:22 +01001803 };
1804
1805 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1806 "Reference SpaceToDepth: input type not supported");
1807
1808 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1809 "Reference SpaceToDepth: output type not supported");
1810
1811 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1812 "Reference SpaceToDepth: input and output types are mismatched");
1813
1814 return supported;
1815}
1816
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001817bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1818 const ViewsDescriptor& descriptor,
1819 Optional<std::string&> reasonIfUnsupported) const
1820{
Jan Eilers8eb25602020-03-09 12:13:48 +00001821 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001822 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001823 std::array<DataType,6> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001824 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001825 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001826 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001827 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001828 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001829 DataType::QAsymmU8,
1830 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001831 };
1832
1833 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1834 "Reference splitter: input type not supported");
1835
1836 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001837}
1838
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001839bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1840 const std::vector<std::reference_wrapper<TensorInfo>>& outputs,
1841 const ViewsDescriptor& descriptor,
1842 Optional<std::string&> reasonIfUnsupported) const
1843{
Jan Eilers8eb25602020-03-09 12:13:48 +00001844 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001845 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001846 std::array<DataType,6> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001847 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001848 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001849 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001850 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001851 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001852 DataType::QAsymmU8,
1853 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001854 };
1855
1856 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1857 "Reference splitter: output type not supported");
1858 for (const TensorInfo output : outputs)
1859 {
1860 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1861 "Reference splitter: input type not supported");
1862
1863 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1864 "Reference splitter: input and output types mismatched.");
1865 }
1866
1867 return supported;
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001868}
1869
Matthew Jackson81e601c2019-07-11 12:07:09 +01001870bool RefLayerSupport::IsStackSupported(const std::vector<const TensorInfo*>& inputs,
1871 const TensorInfo& output,
1872 const StackDescriptor& descriptor,
1873 Optional<std::string&> reasonIfUnsupported) const
1874{
Jan Eilers8eb25602020-03-09 12:13:48 +00001875 IgnoreUnused(descriptor);
Matthew Jackson81e601c2019-07-11 12:07:09 +01001876
1877 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001878 std::array<DataType,6> supportedTypes =
Matthew Jackson81e601c2019-07-11 12:07:09 +01001879 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001880 DataType::BFloat16,
Matthew Jackson81e601c2019-07-11 12:07:09 +01001881 DataType::Float32,
Matthew Jacksone69c3992019-09-09 14:31:21 +01001882 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001883 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001884 DataType::QAsymmU8,
1885 DataType::QSymmS16
Matthew Jackson81e601c2019-07-11 12:07:09 +01001886 };
1887
1888 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1889 "Reference stack: output type not supported");
1890 for (const TensorInfo* input : inputs)
1891 {
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +01001892 ARMNN_ASSERT(input != nullptr);
Matthew Jackson81e601c2019-07-11 12:07:09 +01001893 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
1894 "Reference stack: input type not supported");
1895
1896 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
1897 "Reference stack: input and output types mismatched.");
1898 }
1899
1900 return supported;
1901}
1902
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00001903bool RefLayerSupport::IsStridedSliceSupported(const TensorInfo& input,
1904 const TensorInfo& output,
1905 const StridedSliceDescriptor& descriptor,
1906 Optional<std::string&> reasonIfUnsupported) const
1907{
Jan Eilers8eb25602020-03-09 12:13:48 +00001908 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001909 bool supported = true;
1910
Sadik Armagan303980c2020-04-17 12:45:14 +01001911 std::array<DataType,5> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001912 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001913 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001914 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001915 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001916 DataType::QAsymmU8,
1917 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001918 };
1919
1920 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1921 "Reference StridedSlice: input type not supported");
1922
1923 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1924 "Reference StridedSlice: output type not supported");
1925
1926 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1927 "Reference StridedSlice: input and output types are mismatched");
1928
1929 return supported;
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00001930}
1931
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001932bool RefLayerSupport::IsSubtractionSupported(const TensorInfo& input0,
1933 const TensorInfo& input1,
1934 const TensorInfo& output,
1935 Optional<std::string&> reasonIfUnsupported) const
1936{
Sadik Armagan2999a022019-04-09 14:20:12 +01001937 bool supported = true;
1938
Sadik Armagan303980c2020-04-17 12:45:14 +01001939 std::array<DataType,6> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001940 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001941 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001942 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001943 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001944 DataType::QAsymmU8,
1945 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001946 };
1947
1948 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1949 "Reference subtraction: input 0 is not a supported type.");
1950
1951 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1952 "Reference subtraction: input 1 is not a supported type.");
1953
1954 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1955 "Reference subtraction: output is not a supported type.");
1956
1957 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1958 "Reference subtraction: input 0 and Input 1 types are mismatched");
1959
1960 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1961 "Reference subtraction: input and output types are mismatched");
1962
1963 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1964 "Reference subtraction: shapes are not suitable for implicit broadcast.");
1965
1966 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001967}
1968
Matteo Martincighab9e5252019-06-13 17:27:46 +01001969bool RefLayerSupport::IsPreluSupported(const TensorInfo& input,
1970 const TensorInfo& alpha,
1971 const TensorInfo& output,
1972 Optional<std::string&> reasonIfUnsupported) const
1973{
1974 bool supported = true;
1975
Sadik Armagan303980c2020-04-17 12:45:14 +01001976 std::array<DataType, 6> supportedTypes
Matteo Martincighab9e5252019-06-13 17:27:46 +01001977 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001978 DataType::BFloat16,
Matteo Martincighab9e5252019-06-13 17:27:46 +01001979 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001980 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001981 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001982 DataType::QAsymmU8,
1983 DataType::QSymmS16
Matteo Martincighab9e5252019-06-13 17:27:46 +01001984 };
1985
1986 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1987 "PReLU: input is not a supported type.");
1988
1989 supported &= CheckSupportRule(TypeAnyOf(alpha, supportedTypes), reasonIfUnsupported,
1990 "PReLU: alpha is not a supported type.");
1991
1992 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1993 "PReLU: output is not a supported type.");
1994
1995 supported &= CheckSupportRule(TypesAreEqual(input, alpha, output), reasonIfUnsupported,
1996 "PReLU: input, alpha and output types are mismatched");
1997
1998 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input, alpha, output), reasonIfUnsupported,
1999 "PReLU: shapes are not suitable for implicit broadcast");
2000
2001 return supported;
2002}
2003
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002004bool RefLayerSupport::IsTransposeConvolution2dSupported(const TensorInfo& input,
2005 const TensorInfo& output,
2006 const TransposeConvolution2dDescriptor& descriptor,
2007 const TensorInfo& weights,
2008 const Optional<TensorInfo>& biases,
2009 Optional<std::string&> reasonIfUnsupported) const
2010{
Jan Eilers8eb25602020-03-09 12:13:48 +00002011 IgnoreUnused(descriptor);
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002012 bool supported = true;
2013
Sadik Armagan303980c2020-04-17 12:45:14 +01002014 std::array<DataType,7> supportedTypes =
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002015 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002016 DataType::BFloat16,
2017 DataType::Float32,
2018 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002019 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002020 DataType::QAsymmU8,
Sadik Armagan303980c2020-04-17 12:45:14 +01002021 DataType::QSymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002022 DataType::QSymmS16
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002023 };
2024
2025 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2026 "Reference TransposeConvolution2d: input is not a supported type.");
2027
2028 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2029 "Reference TransposeConvolution2d: output is not a supported type.");
2030
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002031 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2032 "Reference TransposeConvolution2d: input and output types mismatched.");
2033
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002034
2035 const DataType inputType = input.GetDataType();
Sadik Armagan303980c2020-04-17 12:45:14 +01002036 if (IsQuantized8BitType(inputType))
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002037 {
Derek Lambertid466a542020-01-22 15:37:29 +00002038 ARMNN_NO_DEPRECATE_WARN_BEGIN
Sadik Armagan303980c2020-04-17 12:45:14 +01002039 std::array<DataType, 4> supportedWeightTypes =
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002040 {
Sadik Armagan303980c2020-04-17 12:45:14 +01002041 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002042 DataType::QAsymmU8,
Derek Lambertid466a542020-01-22 15:37:29 +00002043 DataType::QSymmS8,
2044 DataType::QuantizedSymm8PerAxis //Deprecated
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002045 };
Derek Lambertid466a542020-01-22 15:37:29 +00002046 ARMNN_NO_DEPRECATE_WARN_END
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002047
2048 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
2049 "Reference TransposeConvolution2d: weights type not supported for "
2050 "quantized input.");
2051 }
2052 else
2053 {
2054 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
2055 "Reference TransposeConvolution2d: weights is not a supported type.");
2056
2057 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
2058 "Reference TransposeConvolution2d: input and weights types mismatched.");
2059 }
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002060
2061 if (biases.has_value())
2062 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002063 std::array<DataType,4> biasesSupportedTypes =
Aron Virginas-Tar651aafe2019-08-05 11:52:05 +01002064 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002065 DataType::BFloat16,
2066 DataType::Float32,
2067 DataType::Float16,
2068 DataType::Signed32
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002069 };
2070 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
2071 "Reference TransposeConvolution2d: biases is not a supported type.");
2072 }
2073
2074 return supported;
2075}
2076
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002077bool RefLayerSupport::IsTransposeSupported(const TensorInfo& input,
2078 const TensorInfo& output,
2079 const TransposeDescriptor& descriptor,
2080 Optional<std::string&> reasonIfUnsupported) const
2081{
Jan Eilers8eb25602020-03-09 12:13:48 +00002082 IgnoreUnused(descriptor);
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002083 bool supported = true;
2084
2085 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01002086 std::array<DataType, 6> supportedTypes =
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002087 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002088 DataType::BFloat16,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002089 DataType::Float32,
2090 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002091 DataType::QAsymmS8,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002092 DataType::QAsymmU8,
2093 DataType::QSymmS16
2094 };
2095
2096 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2097 "Reference transpose: input is not a supported type.");
2098
2099 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2100 "Reference transpose: output is not a supported type.");
2101
2102 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2103 "Reference transpose: input and output types are mismatched.");
2104
2105 return supported;
2106}
2107
arovir011c7c81b2018-10-08 11:34:28 +01002108} // namespace armnn