blob: 1886d3253ba85aa3f89feb32855cf50045cb0eec [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
Teresa Charlin52664732020-06-29 16:27:03 +01002// Copyright © 2017 Arm Ltd and Contributors. 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
Teresa Charlinecb6b8e2020-05-22 18:08:23 +0100148 std::array<DataType,7> 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,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +0100154 DataType::QSymmS16,
155 DataType::Signed32
Derek Lamberti50db4e82019-03-13 14:16:15 +0000156 };
157
158 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
159 "Reference addition: input 0 is not a supported type.");
160
161 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
162 "Reference addition: input 1 is not a supported type.");
163
164 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
165 "Reference addition: output is not a supported type.");
166
167 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
168 "Reference addition: input 0 and Input 1 types are mismatched");
169
170 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
171 "Reference addition: input and output types are mismatched");
172
173 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
174 "Reference addition: shapes are not suitable for implicit broadcast.");
175
176 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100177}
178
Nikhil Raj68c2c902019-09-19 11:21:11 +0100179bool RefLayerSupport::IsArgMinMaxSupported(const armnn::TensorInfo &input, const armnn::TensorInfo &output,
180 const armnn::ArgMinMaxDescriptor &descriptor,
181 armnn::Optional<std::string &> reasonIfUnsupported) const
182{
Jan Eilers8eb25602020-03-09 12:13:48 +0000183 IgnoreUnused(descriptor);
Nikhil Raj68c2c902019-09-19 11:21:11 +0100184
Teresa Charline300b362020-05-25 10:01:03 +0100185 std::array<DataType, 7> supportedTypes =
Nikhil Raj68c2c902019-09-19 11:21:11 +0100186 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000187 DataType::BFloat16,
Teresa Charline300b362020-05-25 10:01:03 +0100188 DataType::Float16,
Nikhil Raj68c2c902019-09-19 11:21:11 +0100189 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +0100190 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000191 DataType::QAsymmU8,
192 DataType::QSymmS16,
Francis Murtagh1939df52019-11-13 15:21:09 +0000193 DataType::Signed32
Nikhil Raj68c2c902019-09-19 11:21:11 +0100194 };
195
196 bool supported = true;
197
198 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
199 "Reference ArgMinMax: input is not a supported type.");
200 supported &= CheckSupportRule(TypeIs(output, DataType::Signed32), reasonIfUnsupported,
201 "Reference ArgMinMax: output type not supported");
202
203 return supported;
204}
205
arovir011c7c81b2018-10-08 11:34:28 +0100206bool RefLayerSupport::IsBatchNormalizationSupported(const TensorInfo& input,
207 const TensorInfo& output,
208 const TensorInfo& mean,
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100209 const TensorInfo& variance,
arovir011c7c81b2018-10-08 11:34:28 +0100210 const TensorInfo& beta,
211 const TensorInfo& gamma,
212 const BatchNormalizationDescriptor& descriptor,
213 Optional<std::string&> reasonIfUnsupported) const
214{
Jan Eilers8eb25602020-03-09 12:13:48 +0000215 IgnoreUnused(descriptor);
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100216
Sadik Armagan303980c2020-04-17 12:45:14 +0100217 std::array<DataType, 6> supportedTypes =
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100218 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000219 DataType::BFloat16,
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100220 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100221 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100222 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000223 DataType::QAsymmU8,
224 DataType::QSymmS16
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100225 };
226
227 bool supported = true;
228
229 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
230 "Reference batch normalization: input is not a supported type.");
231
232 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
233 "Reference batch normalization: output is not a supported type.");
234
235 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
236 "Reference batch normalization: input and output types are mismatched");
237
238 supported &= CheckSupportRule(TypeAnyOf(mean, supportedTypes), reasonIfUnsupported,
239 "Reference batch normalization: mean is not a supported type.");
240
241 supported &= CheckSupportRule(TypeAnyOf(variance, supportedTypes), reasonIfUnsupported,
242 "Reference batch normalization: variance is not a supported type.");
243
244 supported &= CheckSupportRule(TypeAnyOf(beta, supportedTypes), reasonIfUnsupported,
245 "Reference batch normalization: beta is not a supported type.");
246
247 supported &= CheckSupportRule(TypeAnyOf(gamma, supportedTypes), reasonIfUnsupported,
248 "Reference batch normalization: gamma is not a supported type.");
249
250 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100251}
252
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000253bool RefLayerSupport::IsBatchToSpaceNdSupported(const TensorInfo& input,
254 const TensorInfo& output,
255 const BatchToSpaceNdDescriptor& descriptor,
256 Optional<std::string&> reasonIfUnsupported) const
257{
Jan Eilers8eb25602020-03-09 12:13:48 +0000258 IgnoreUnused(descriptor);
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100259
260 bool supported = true;
261
262 std::string batchToSpaceNdLayerStr = "batchToSpaceNd";
263 std::string inputTensorStr = "input";
264 std::string outputTensorStr = "output";
265
266 // Define supported types.
Sadik Armagan303980c2020-04-17 12:45:14 +0100267 std::array<DataType,6> supportedTypes =
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100268 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000269 DataType::BFloat16,
270 DataType::Float32,
271 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100272 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000273 DataType::QAsymmU8,
274 DataType::QSymmS16
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100275 };
276
277 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
278 "Reference BatchToSpaceNd: input type not supported.");
279
280 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
281 "Reference BatchToSpaceNd: output type not supported.");
282
283 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
284 "Reference BatchToSpaceNd: input and output types mismatched.");
285
286 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 4),
287 reasonIfUnsupported,
288 CreateIncorrectDimensionsErrorMsg(4,
289 output.GetNumDimensions(),
290 batchToSpaceNdLayerStr,
291 outputTensorStr).data());
292
293 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(input, 4),
294 reasonIfUnsupported,
295 CreateIncorrectDimensionsErrorMsg(4,
296 input.GetNumDimensions(),
297 batchToSpaceNdLayerStr,
298 inputTensorStr).data());
299
300 return supported;
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000301}
302
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100303bool RefLayerSupport::IsComparisonSupported(const TensorInfo& input0,
304 const TensorInfo& input1,
305 const TensorInfo& output,
306 const ComparisonDescriptor& descriptor,
307 Optional<std::string&> reasonIfUnsupported) const
308{
Jan Eilers8eb25602020-03-09 12:13:48 +0000309 IgnoreUnused(descriptor);
Sadik Armagan303980c2020-04-17 12:45:14 +0100310 std::array<DataType, 8> supportedInputTypes =
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100311 {
Sadik Armaganb60dd242020-03-19 13:53:16 +0000312 DataType::Boolean,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000313 DataType::BFloat16,
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100314 DataType::Float32,
315 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100316 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000317 DataType::QAsymmU8,
Sadik Armaganb60dd242020-03-19 13:53:16 +0000318 DataType::QSymmS16,
319 DataType::Signed32
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100320 };
321
322 bool supported = true;
323 supported &= CheckSupportRule(TypeAnyOf(input0, supportedInputTypes), reasonIfUnsupported,
324 "Reference comparison: input 0 is not a supported type");
325
326 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
327 "Reference comparison: input 0 and Input 1 types are mismatched");
328
329 supported &= CheckSupportRule(TypeIs(output, DataType::Boolean), reasonIfUnsupported,
330 "Reference comparison: output is not of type Boolean");
331
332 return supported;
333}
334
Jim Flynn906f9462019-05-10 13:55:21 +0100335bool RefLayerSupport::IsConcatSupported(const std::vector<const TensorInfo*> inputs,
336 const TensorInfo& output,
Jim Flynne242f2d2019-05-22 14:24:13 +0100337 const ConcatDescriptor& descriptor,
Jim Flynn906f9462019-05-10 13:55:21 +0100338 Optional<std::string&> reasonIfUnsupported) const
339{
Jan Eilers8eb25602020-03-09 12:13:48 +0000340 IgnoreUnused(descriptor);
Jim Flynne242f2d2019-05-22 14:24:13 +0100341
342 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000343 std::array<DataType,6> supportedTypes =
Jim Flynne242f2d2019-05-22 14:24:13 +0100344 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000345 DataType::BFloat16,
346 DataType::Float32,
347 DataType::Float16,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000348 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100349 DataType::QAsymmU8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000350 DataType::QSymmS16
Jim Flynne242f2d2019-05-22 14:24:13 +0100351 };
352
353 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
354 "Reference concatenation: output type not supported");
355 for (const TensorInfo* input : inputs)
356 {
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100357 ARMNN_ASSERT(input != nullptr);
Jim Flynne242f2d2019-05-22 14:24:13 +0100358 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
359 "Reference concatenation: input type not supported");
360
361 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
362 "Reference concatenation: input and output types mismatched.");
363 }
364
365 return supported;
Jim Flynn906f9462019-05-10 13:55:21 +0100366}
367
arovir011c7c81b2018-10-08 11:34:28 +0100368bool RefLayerSupport::IsConstantSupported(const TensorInfo& output,
369 Optional<std::string&> reasonIfUnsupported) const
370{
Teresa Charlin6fa8ce62020-05-25 16:16:44 +0100371 std::array<DataType,8> supportedTypes =
Jim Flynne242f2d2019-05-22 14:24:13 +0100372 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000373 DataType::BFloat16,
Teresa Charlin6fa8ce62020-05-25 16:16:44 +0100374 DataType::Float16,
Nina Drozd58ef2c62019-05-16 12:09:18 +0100375 DataType::Float32,
Keith Davis67e6c542020-02-19 10:08:33 +0000376 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100377 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +0000378 DataType::QSymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100379 DataType::QSymmS16,
380 DataType::Signed32
Nina Drozd58ef2c62019-05-16 12:09:18 +0100381 };
382
383 return CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
384 "Reference constant: output is not a supported type.");
arovir011c7c81b2018-10-08 11:34:28 +0100385}
386
Narumol Prangnawarat7ddbbae2020-03-13 10:26:05 +0000387bool RefLayerSupport::IsConvertBf16ToFp32Supported(const TensorInfo& input,
388 const TensorInfo& output,
389 Optional<std::string&> reasonIfUnsupported) const
390{
391 bool supported = true;
392
393 supported &= CheckSupportRule(TypeIs(input, DataType::BFloat16), reasonIfUnsupported,
394 "Reference for ConvertBf16ToFp32 layer: input type not supported");
395
396 supported &= CheckSupportRule(TypeIs(output, DataType::Float32), reasonIfUnsupported,
397 "Reference for ConvertBf16ToFp32 layer: output type not supported");
398
399 return supported;
400}
401
arovir011c7c81b2018-10-08 11:34:28 +0100402bool RefLayerSupport::IsConvertFp16ToFp32Supported(const TensorInfo& input,
403 const TensorInfo& output,
404 Optional<std::string&> reasonIfUnsupported) const
405{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100406 return (IsSupportedForDataTypeGeneric(reasonIfUnsupported,
407 input.GetDataType(),
408 &TrueFunc<>,
409 &FalseInputFuncF32<>,
narpra01db2b1602019-01-23 15:23:11 +0000410 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000411 &FalseFuncI32<>,
412 &FalseFuncU8<>) &&
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100413 IsSupportedForDataTypeGeneric(reasonIfUnsupported,
414 output.GetDataType(),
415 &FalseOutputFuncF16<>,
416 &TrueFunc<>,
narpra01db2b1602019-01-23 15:23:11 +0000417 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000418 &FalseFuncI32<>,
419 &FalseFuncU8<>));
arovir011c7c81b2018-10-08 11:34:28 +0100420}
421
Narumol Prangnawaratea54a012020-03-16 16:36:10 +0000422bool RefLayerSupport::IsConvertFp32ToBf16Supported(const TensorInfo& input,
423 const TensorInfo& output,
424 Optional<std::string&> reasonIfUnsupported) const
425{
426 bool supported = true;
427
428 supported &= CheckSupportRule(TypeIs(input, DataType::Float32), reasonIfUnsupported,
429 "Reference for ConvertFp32ToBf16 layer: input type not supported");
430
431 supported &= CheckSupportRule(TypeIs(output, DataType::BFloat16), reasonIfUnsupported,
432 "Reference for ConvertFp32ToBf16 layer: output type not supported");
433
434 return supported;
435}
436
arovir011c7c81b2018-10-08 11:34:28 +0100437bool RefLayerSupport::IsConvertFp32ToFp16Supported(const TensorInfo& input,
438 const TensorInfo& output,
439 Optional<std::string&> reasonIfUnsupported) const
440{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100441 return (IsSupportedForDataTypeGeneric(reasonIfUnsupported,
442 input.GetDataType(),
443 &FalseInputFuncF16<>,
444 &TrueFunc<>,
narpra01db2b1602019-01-23 15:23:11 +0000445 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000446 &FalseFuncI32<>,
447 &FalseFuncU8<>) &&
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100448 IsSupportedForDataTypeGeneric(reasonIfUnsupported,
449 output.GetDataType(),
450 &TrueFunc<>,
451 &FalseOutputFuncF32<>,
narpra01db2b1602019-01-23 15:23:11 +0000452 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000453 &FalseFuncI32<>,
454 &FalseFuncU8<>));
arovir011c7c81b2018-10-08 11:34:28 +0100455}
456
457bool RefLayerSupport::IsConvolution2dSupported(const TensorInfo& input,
458 const TensorInfo& output,
459 const Convolution2dDescriptor& descriptor,
460 const TensorInfo& weights,
461 const Optional<TensorInfo>& biases,
462 Optional<std::string&> reasonIfUnsupported) const
463{
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100464 bool supported = true;
465
466 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000467 std::array<DataType,7> supportedTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000468 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000469 DataType::BFloat16,
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000470 DataType::Float32,
471 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000472 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100473 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +0000474 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000475 DataType::QSymmS16
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100476 };
477
478 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000479 "Reference Convolution2d: input is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100480
481 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000482 "Reference Convolution2d: output is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100483
Narumol Prangnawarat57ef0082020-03-26 09:20:43 +0000484 // For Convolution2d, we allow to have BFloat16 input with Float32 output for optimization.
485 if (input.GetDataType() == DataType::BFloat16)
486 {
487 if (output.GetDataType() != DataType::BFloat16 && output.GetDataType() != DataType::Float32)
488 {
489 reasonIfUnsupported.value() += "Output tensor type must be BFloat16 or Float32 for BFloat16 input.\n";
490 supported = false;
491 }
492 }
493 else
494 {
495 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000496 "Reference Convolution2d: input and output types mismatched.");
Narumol Prangnawarat57ef0082020-03-26 09:20:43 +0000497 }
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100498
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000499 const DataType inputType = input.GetDataType();
Keith Davis0c2eeac2020-02-11 16:51:50 +0000500 if (IsQuantized8BitType(inputType))
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000501 {
Derek Lambertid466a542020-01-22 15:37:29 +0000502 ARMNN_NO_DEPRECATE_WARN_BEGIN
Keith Davis0c2eeac2020-02-11 16:51:50 +0000503 std::array<DataType, 4> supportedWeightTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000504 {
Sadik Armagan303980c2020-04-17 12:45:14 +0100505 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000506 DataType::QAsymmU8,
Derek Lambertid466a542020-01-22 15:37:29 +0000507 DataType::QSymmS8,
508 DataType::QuantizedSymm8PerAxis // deprecated
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000509 };
Derek Lambertid466a542020-01-22 15:37:29 +0000510 ARMNN_NO_DEPRECATE_WARN_END
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000511
512 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000513 "Reference Convolution2d: weights type not supported for quantized input.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000514 }
515 else
516 {
517 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000518 "Reference Convolution2d: weights is not a supported type.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000519
520 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000521 "Reference Convolution2d: input and weights types mismatched.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000522 }
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100523
524 if (biases.has_value())
525 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000526 std::array<DataType,4> biasesSupportedTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000527 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000528 DataType::BFloat16,
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000529 DataType::Float32,
530 DataType::Float16,
531 DataType::Signed32
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100532 };
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000533
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100534 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000535 "Reference Convolution2d: biases is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100536 }
Jan Eilers8eb25602020-03-09 12:13:48 +0000537 IgnoreUnused(descriptor);
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100538
539 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100540}
541
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000542bool RefLayerSupport::IsDebugSupported(const TensorInfo& input,
543 const TensorInfo& output,
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000544 Optional<std::string&> reasonIfUnsupported) const
545{
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100546 bool supported = true;
547
Narumol Prangnawarat403a1852020-03-12 14:24:13 +0000548 std::array<DataType, 8> supportedTypes =
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100549 {
Narumol Prangnawarat403a1852020-03-12 14:24:13 +0000550 DataType::BFloat16,
Aron Virginas-Tardb1a2832019-11-12 16:15:11 +0000551 DataType::Float16,
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100552 DataType::Float32,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000553 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100554 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +0000555 DataType::QSymmS8,
Narumol Prangnawaratd2d917d2020-01-09 10:16:39 +0000556 DataType::QSymmS16,
557 DataType::Signed32
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100558 };
559
560 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000561 "Reference for Debug layer: input type not supported");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100562
563 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000564 "Reference for Debug layer: output type not supported");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100565
566 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000567 "Reference for Debug layer: input and output types are mismatched");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100568
569 return supported;
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000570}
571
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100572bool RefLayerSupport::IsDepthToSpaceSupported(const TensorInfo& input,
573 const TensorInfo& output,
574 const DepthToSpaceDescriptor& descriptor,
575 Optional<std::string&> reasonIfUnsupported) const
576{
Jan Eilers8eb25602020-03-09 12:13:48 +0000577 IgnoreUnused(descriptor);
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100578 bool supported = true;
579
Sadik Armagan303980c2020-04-17 12:45:14 +0100580 std::array<DataType,6> supportedTypes =
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100581 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000582 DataType::BFloat16,
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100583 DataType::Float32,
584 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100585 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000586 DataType::QAsymmU8,
587 DataType::QSymmS16
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100588 };
589
590 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
591 "Reference DepthToSpace: input type not supported");
592
593 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
594 "Reference DepthToSpace: output type not supported");
595
596 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
597 "Reference DepthToSpace: input and output types are mismatched");
598
599 return supported;
600}
601
arovir011c7c81b2018-10-08 11:34:28 +0100602bool RefLayerSupport::IsDepthwiseConvolutionSupported(const TensorInfo& input,
603 const TensorInfo& output,
604 const DepthwiseConvolution2dDescriptor& descriptor,
605 const TensorInfo& weights,
606 const Optional<TensorInfo>& biases,
607 Optional<std::string&> reasonIfUnsupported) const
608{
Sadik Armagan303980c2020-04-17 12:45:14 +0100609 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100610 bool supported = true;
611
612 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000613 std::array<DataType,7> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100614 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000615 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100616 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100617 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000618 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000619 DataType::QAsymmU8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100620 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000621 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100622 };
623
624 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
625 "Reference DepthwiseConvolution2d: input is not a supported type.");
626
627 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
628 "Reference DepthwiseConvolution2d: output is not a supported type.");
629
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100630 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
631 "Reference DepthwiseConvolution2d: input and output types mismatched.");
632
Teresa Charlind8df0262019-11-11 12:28:15 +0000633 const DataType inputType = input.GetDataType();
Keith Davis0c2eeac2020-02-11 16:51:50 +0000634 if (IsQuantized8BitType(inputType))
Teresa Charlind8df0262019-11-11 12:28:15 +0000635 {
Sadik Armagan303980c2020-04-17 12:45:14 +0100636 ARMNN_NO_DEPRECATE_WARN_BEGIN
637 std::array<DataType, 4> supportedWeightTypes =
638 {
639 DataType::QAsymmS8,
640 DataType::QAsymmU8,
641 DataType::QSymmS8,
642 DataType::QuantizedSymm8PerAxis // deprecated
643 };
644 ARMNN_NO_DEPRECATE_WARN_END
Teresa Charlind8df0262019-11-11 12:28:15 +0000645
646 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
Sadik Armagan303980c2020-04-17 12:45:14 +0100647 "Reference DepthwiseConvolution2d: weights type not supported for "
648 "quantized input.");
Teresa Charlind8df0262019-11-11 12:28:15 +0000649 }
650 else
651 {
652 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
653 "Reference DepthwiseConvolution2d: weights is not a supported type.");
654
655 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
656 "Reference DepthwiseConvolution2d: input and weights types mismatched.");
657 }
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100658
659 if (biases.has_value())
660 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000661 std::array<DataType,4> biasesSupportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100662 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000663 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100664 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100665 DataType::Float16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100666 DataType::Signed32
667 };
668 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
669 "Reference DepthwiseConvolution2d: biases is not a supported type.");
670 }
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100671
672 return supported;
673
arovir011c7c81b2018-10-08 11:34:28 +0100674}
675
Nattapat Chaimanowong8a54ac02019-03-29 15:25:04 +0000676bool RefLayerSupport::IsDequantizeSupported(const TensorInfo& input,
677 const TensorInfo& output,
678 Optional<std::string&> reasonIfUnsupported) const
679{
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100680 bool supported = true;
681
Ryan OShea9add1202020-02-07 10:06:33 +0000682 std::array<DataType,4> supportedInputTypes = {
683 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000684 DataType::QAsymmU8,
Finn Williamsfd271062019-12-04 14:27:27 +0000685 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000686 DataType::QSymmS16
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100687 };
688
689 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000690 "Reference for Dequantize layer: input type not supported.");
691
692 supported &= CheckSupportRule( TypeNotPerAxisQuantized(input), reasonIfUnsupported,
693 "Reference for Dequantize layer: per-axis quantized input not support .");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100694
Derek Lambertid466a542020-01-22 15:37:29 +0000695 supported &= CheckSupportRule(TypeNotPerAxisQuantized(input), reasonIfUnsupported,
696 "Reference dequantize: per-axis quantized input not support .");
697
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000698 std::array<DataType,3> supportedOutputTypes = {
699 DataType::BFloat16,
Jan Eilersf7107932019-11-01 11:09:36 +0000700 DataType::Float32,
701 DataType::Float16
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100702 };
703
704 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000705 "Reference for Dequantize layer: output type not supported.");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100706
707 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000708 "Reference for Dequantize layer: input/output shapes have different num total "
709 "elements.");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100710
711 return supported;
Nattapat Chaimanowong8a54ac02019-03-29 15:25:04 +0000712}
713
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000714bool RefLayerSupport::IsDetectionPostProcessSupported(const TensorInfo& boxEncodings,
715 const TensorInfo& scores,
716 const TensorInfo& anchors,
717 const TensorInfo& detectionBoxes,
718 const TensorInfo& detectionClasses,
719 const TensorInfo& detectionScores,
720 const TensorInfo& numDetections,
721 const DetectionPostProcessDescriptor& descriptor,
722 Optional<std::string&> reasonIfUnsupported) const
Narumol Prangnawaratbc67cef2019-01-31 15:31:54 +0000723{
Jan Eilers8eb25602020-03-09 12:13:48 +0000724 IgnoreUnused(anchors, detectionBoxes, detectionClasses, detectionScores, numDetections, descriptor);
Derek Lamberti901ea112019-12-10 22:07:09 +0000725
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100726 bool supported = true;
727
Sadik Armagan303980c2020-04-17 12:45:14 +0100728 std::array<DataType,5> supportedInputTypes =
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100729 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000730 DataType::BFloat16,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100731 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +0100732 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000733 DataType::QAsymmU8,
734 DataType::QSymmS16
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100735 };
736
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000737 supported &= CheckSupportRule(TypeAnyOf(boxEncodings, supportedInputTypes), reasonIfUnsupported,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100738 "Reference DetectionPostProcess: input 0 is not a supported type.");
739
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000740 supported &= CheckSupportRule(TypeAnyOf(scores, supportedInputTypes), reasonIfUnsupported,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100741 "Reference DetectionPostProcess: input 1 is not a supported type.");
742
743 return supported;
Narumol Prangnawaratbc67cef2019-01-31 15:31:54 +0000744}
745
Pablo Tellof0bd6832019-04-26 17:58:13 +0100746bool RefLayerSupport::IsDilatedDepthwiseConvolutionSupported(const TensorInfo& input,
747 const TensorInfo& output,
748 const DepthwiseConvolution2dDescriptor& descriptor,
749 const TensorInfo& weights,
750 const Optional<TensorInfo>& biases,
751 Optional<std::string&> reasonIfUnsupported) const
752{
Aron Virginas-Taraece4ed2019-06-14 17:00:09 +0100753 return IsDepthwiseConvolutionSupported(input, output, descriptor, weights, biases, reasonIfUnsupported);
Pablo Tellof0bd6832019-04-26 17:58:13 +0100754}
755
Aron Virginas-Taraece4ed2019-06-14 17:00:09 +0100756bool RefLayerSupport::IsDivisionSupported(const TensorInfo& input0,
arovir011c7c81b2018-10-08 11:34:28 +0100757 const TensorInfo& input1,
758 const TensorInfo& output,
759 Optional<std::string&> reasonIfUnsupported) const
760{
Sadik Armagan2999a022019-04-09 14:20:12 +0100761 bool supported = true;
762
Teresa Charlinecb6b8e2020-05-22 18:08:23 +0100763 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000764 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +0100765 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100766 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100767 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000768 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +0100769 DataType::QSymmS16,
770 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +0100771 };
772
773 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
774 "Reference division: input 0 is not a supported type.");
775
776 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
777 "Reference division: input 1 is not a supported type.");
778
779 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
780 "Reference division: output is not a supported type.");
781
782 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
783 "Reference division: input 0 and Input 1 types are mismatched");
784
785 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
786 "Reference division: input and output types are mismatched");
787
788 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
789 "Reference division: shapes are not suitable for implicit broadcast.");
790
791 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100792}
793
josh minor4a3c6102020-01-06 16:40:46 -0600794bool RefLayerSupport::IsElementwiseUnarySupported(const TensorInfo& input,
795 const TensorInfo& output,
796 const ElementwiseUnaryDescriptor& descriptor,
797 Optional<std::string&> reasonIfUnsupported) const
798{
Jan Eilers8eb25602020-03-09 12:13:48 +0000799 IgnoreUnused(descriptor);
josh minor4a3c6102020-01-06 16:40:46 -0600800
Sadik Armagan303980c2020-04-17 12:45:14 +0100801 std::array<DataType, 7> supportedTypes =
josh minor4a3c6102020-01-06 16:40:46 -0600802 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000803 DataType::BFloat16,
josh minor4a3c6102020-01-06 16:40:46 -0600804 DataType::Float32,
805 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100806 DataType::QAsymmS8,
josh minor4a3c6102020-01-06 16:40:46 -0600807 DataType::QAsymmU8,
Sadik Armaganac472102020-03-24 09:54:36 +0000808 DataType::QSymmS16,
809 DataType::Signed32
josh minor4a3c6102020-01-06 16:40:46 -0600810 };
811
812 bool supported = true;
813
814 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
815 "Reference elementwise unary: input type not supported");
816
817 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
818 "Reference elementwise unary: output type not supported");
819
820 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
821 "Reference elementwise unary: input and output types not matching");
822
823 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
824 "Reference elementwise unary: input and output shapes"
825 "have different number of total elements");
826
827 return supported;
828}
829
FrancisMurtagh30cdfca2018-12-18 12:57:35 +0000830bool RefLayerSupport::IsEqualSupported(const TensorInfo& input0,
831 const TensorInfo& input1,
832 const TensorInfo& output,
833 Optional<std::string&> reasonIfUnsupported) const
834{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100835 return IsComparisonSupported(input0,
836 input1,
837 output,
838 ComparisonDescriptor(ComparisonOperation::Equal),
839 reasonIfUnsupported);
FrancisMurtagh30cdfca2018-12-18 12:57:35 +0000840}
841
arovir011c7c81b2018-10-08 11:34:28 +0100842bool RefLayerSupport::IsFakeQuantizationSupported(const TensorInfo& input,
843 const FakeQuantizationDescriptor& descriptor,
844 Optional<std::string&> reasonIfUnsupported) const
845{
Jan Eilers8eb25602020-03-09 12:13:48 +0000846 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100847 bool supported = true;
848
849 std::array<DataType,1> supportedTypes =
850 {
851 DataType::Float32
852 };
853
854 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
855 "Reference fake quantization: input type not supported.");
856
857 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100858}
859
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100860bool RefLayerSupport::IsFillSupported(const TensorInfo& input,
861 const TensorInfo& output,
862 const FillDescriptor& descriptor,
863 Optional<std::string&> reasonIfUnsupported) const
864{
865 IgnoreUnused(descriptor);
866 IgnoreUnused(output);
867
868 bool supported = true;
869
Sadik Armagana792a052020-06-23 16:22:23 +0100870 std::array<DataType,3> supportedTypes =
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100871 {
872 DataType::Float32,
Sadik Armagana792a052020-06-23 16:22:23 +0100873 DataType::Float16,
874 DataType::Signed32
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100875 };
876
877 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
878 "Reference Fill: input type not supported.");
879
Teresa Charlin44088502020-07-27 11:27:19 +0100880 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
881 "Reference Fill: output type not supported.");
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100882 return supported;
883}
884
arovir011c7c81b2018-10-08 11:34:28 +0100885bool RefLayerSupport::IsFloorSupported(const TensorInfo& input,
886 const TensorInfo& output,
887 Optional<std::string&> reasonIfUnsupported) const
888{
Jan Eilers8eb25602020-03-09 12:13:48 +0000889 IgnoreUnused(output);
James Conroy83735b12019-05-30 16:36:59 +0100890 bool supported = true;
891
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000892 std::array<DataType,4> supportedTypes =
James Conroy83735b12019-05-30 16:36:59 +0100893 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000894 DataType::BFloat16,
James Conroyb40d7102019-06-04 12:32:09 +0100895 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100896 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000897 DataType::QSymmS16
James Conroy83735b12019-05-30 16:36:59 +0100898 };
899
900 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
901 "Reference Floor: input type not supported.");
902
903 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
904 "Reference Floor: output type not supported.");
905
906 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100907}
908
909bool RefLayerSupport::IsFullyConnectedSupported(const TensorInfo& input,
910 const TensorInfo& output,
911 const TensorInfo& weights,
912 const TensorInfo& biases,
913 const FullyConnectedDescriptor& descriptor,
914 Optional<std::string&> reasonIfUnsupported) const
915{
Francis Murtagh46c09d02019-05-28 08:15:28 +0100916 bool supported = true;
917
918 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000919 std::array<DataType,6> supportedTypes =
Francis Murtagh46c09d02019-05-28 08:15:28 +0100920 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000921 DataType::BFloat16,
922 DataType::Float32,
923 DataType::Float16,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000924 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100925 DataType::QAsymmU8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000926 DataType::QSymmS16
Francis Murtagh46c09d02019-05-28 08:15:28 +0100927 };
928
929 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
930 "Reference Fully Connected: input type not supported.");
931
932 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
933 "Reference Fully Connected: output type not supported.");
934
Francis Murtagh46c09d02019-05-28 08:15:28 +0100935 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
936 "Reference Fully Connected: weights type not supported.");
937
Narumol Prangnawarat57ef0082020-03-26 09:20:43 +0000938 // For FullyConnected, we allow to have BFloat16 input with Float32 output for optimization.
939 if (input.GetDataType() == DataType::BFloat16)
940 {
941 if (output.GetDataType() != DataType::BFloat16 && output.GetDataType() != DataType::Float32)
942 {
943 reasonIfUnsupported.value() += "Output tensor type must be BFloat16 or Float32 for BFloat16 input.\n";
944 supported = false;
945 }
946 }
947 else
948 {
949 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
950 "Reference Fully Connected: input and output types mismatched.");
951 }
952
Jan Eilers1f45dc32020-06-15 11:43:03 +0100953 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
954 "Reference Fully Connected: weights is not a supported type.");
Francis Murtaghddb1d062020-03-10 13:51:45 +0000955
Jan Eilers1f45dc32020-06-15 11:43:03 +0100956 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
957 "Reference Fully Connected: input and weights types mismatched.");
Francis Murtagh46c09d02019-05-28 08:15:28 +0100958
959 if (descriptor.m_BiasEnabled)
960 {
961 // Defined supported types for bias
Sadik Armagandb73c982020-04-01 17:35:30 +0100962 std::array<DataType, 5>
Francis Murtagh46c09d02019-05-28 08:15:28 +0100963 supportedBiasTypes =
964 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000965 DataType::BFloat16,
Francis Murtagh46c09d02019-05-28 08:15:28 +0100966 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100967 DataType::Float16,
Sadik Armagandb73c982020-04-01 17:35:30 +0100968 DataType::Signed32,
969 DataType::QAsymmS8
Francis Murtagh46c09d02019-05-28 08:15:28 +0100970 };
971
972 supported &= CheckSupportRule(TypeAnyOf(biases, supportedBiasTypes), reasonIfUnsupported,
973 "Reference Fully Connected: bias type not supported.");
974
975 supported &= CheckSupportRule(BiasAndWeightsTypesMatch(biases, weights), reasonIfUnsupported,
976 "Reference Fully Connected: bias and weight types mismatch.");
977
978 supported &= CheckSupportRule(BiasAndWeightsTypesCompatible(weights, supportedBiasTypes), reasonIfUnsupported,
979 "Reference Fully Connected: bias type inferred from weights is incompatible.");
980
Narumol Prangnawarat366d7232020-04-29 12:58:17 +0100981 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(biases, 1U), reasonIfUnsupported,
982 "Reference Fully Connected: bias must have 1 dimension.");
983
Francis Murtagh46c09d02019-05-28 08:15:28 +0100984 }
985
986 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100987}
988
narpra014951d842019-01-18 16:53:53 +0000989bool RefLayerSupport::IsGatherSupported(const armnn::TensorInfo& input0,
990 const armnn::TensorInfo& input1,
991 const armnn::TensorInfo& output,
Teresa Charlin52664732020-06-29 16:27:03 +0100992 const GatherDescriptor& descriptor,
narpra014951d842019-01-18 16:53:53 +0000993 armnn::Optional<std::string&> reasonIfUnsupported) const
994{
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100995 bool supported = true;
Teresa Charlin3940d8b2020-05-29 16:47:23 +0100996 std::array<DataType,7> supportedTypes =
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100997 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000998 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100999 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001000 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001001 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001002 DataType::QAsymmU8,
Teresa Charlin3940d8b2020-05-29 16:47:23 +01001003 DataType::QSymmS16,
1004 DataType::Signed32
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +01001005 };
1006
Teresa Charlin52664732020-06-29 16:27:03 +01001007 if (descriptor.m_Axis != 0)
1008 {
1009 reasonIfUnsupported.value() += std::string("Reference Gather: axis not supported\n");
1010 supported &= false;
1011 }
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +01001012 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1013 "Reference Gather: input type not supported");
1014
1015 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1016 "Reference Gather: output type not supported");
1017
1018 supported &= CheckSupportRule(TypeIs(input1, DataType::Signed32), reasonIfUnsupported,
1019 "Reference Gather: indices (input1) type not supported");
1020
1021 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1022 "Reference Gather: input and output types not matching");
1023
1024 return supported;
narpra014951d842019-01-18 16:53:53 +00001025}
1026
FrancisMurtagh878f0232018-12-19 10:56:15 +00001027bool RefLayerSupport::IsGreaterSupported(const TensorInfo& input0,
1028 const TensorInfo& input1,
1029 const TensorInfo& output,
1030 Optional<std::string&> reasonIfUnsupported) const
1031{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +01001032 return IsComparisonSupported(input0,
1033 input1,
1034 output,
1035 ComparisonDescriptor(ComparisonOperation::Greater),
1036 reasonIfUnsupported);
FrancisMurtagh878f0232018-12-19 10:56:15 +00001037}
1038
Derek Lamberti901ea112019-12-10 22:07:09 +00001039bool RefLayerSupport::IsInputSupported(const TensorInfo& /*input*/,
1040 Optional<std::string&> /*reasonIfUnsupported*/) const
arovir011c7c81b2018-10-08 11:34:28 +01001041{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +01001042 return true;
arovir011c7c81b2018-10-08 11:34:28 +01001043}
1044
Kevin May09ca49c2019-10-09 12:37:34 +01001045bool RefLayerSupport::IsInstanceNormalizationSupported(const TensorInfo& input,
1046 const TensorInfo& output,
1047 const InstanceNormalizationDescriptor& descriptor,
1048 Optional<std::string&> reasonIfUnsupported) const
1049{
Jan Eilers8eb25602020-03-09 12:13:48 +00001050 IgnoreUnused(descriptor);
Kevin May09ca49c2019-10-09 12:37:34 +01001051 // Define supported types
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001052 std::array<DataType, 3> supportedTypes =
Kevin May09ca49c2019-10-09 12:37:34 +01001053 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001054 DataType::BFloat16,
Kevin May09ca49c2019-10-09 12:37:34 +01001055 DataType::Float32,
1056 DataType::Float16
1057 };
1058
1059 bool supported = true;
1060
1061 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1062 "Reference Instance Normalization: input type not supported.");
1063
1064 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1065 "Reference Instance Normalization: output type not supported.");
1066
1067 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1068 "Reference Instance Normalization: input and output types mismatched.");
1069
1070 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1071 "Reference Instance Normalization: input and output shapes have different "
1072 "num total elements.");
1073
1074 return supported;
1075}
1076
arovir011c7c81b2018-10-08 11:34:28 +01001077bool RefLayerSupport::IsL2NormalizationSupported(const TensorInfo& input,
1078 const TensorInfo& output,
1079 const L2NormalizationDescriptor& descriptor,
1080 Optional<std::string&> reasonIfUnsupported) const
1081{
Jan Eilers8eb25602020-03-09 12:13:48 +00001082 IgnoreUnused(descriptor);
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001083 // Define supported types
Sadik Armagan303980c2020-04-17 12:45:14 +01001084 std::array<DataType, 6> supportedTypes =
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001085 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001086 DataType::BFloat16,
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001087 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001088 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001089 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001090 DataType::QAsymmU8,
1091 DataType::QSymmS16
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001092 };
1093
1094 bool supported = true;
1095
1096 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1097 "Reference L2normalization: input type not supported.");
1098
1099 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1100 "Reference L2normalization: output type not supported.");
1101
1102 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1103 "Reference L2normalization: input and output types mismatched.");
1104
1105 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1106 "Reference L2normalization: input and output shapes have different "
1107 "num total elements.");
1108
1109 return supported;
arovir011c7c81b2018-10-08 11:34:28 +01001110}
1111
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001112bool RefLayerSupport::IsLogSoftmaxSupported(const TensorInfo& input,
1113 const TensorInfo& output,
1114 const LogSoftmaxDescriptor& descriptor,
1115 Optional<std::string&> reasonIfUnsupported) const
1116{
Jan Eilers8eb25602020-03-09 12:13:48 +00001117 IgnoreUnused(descriptor);
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001118
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001119 std::array<DataType, 3> supportedTypes =
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001120 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001121 DataType::BFloat16,
1122 DataType::Float32,
1123 DataType::Float16
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001124 };
1125
1126 bool supported = true;
1127 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1128 "Reference LogSoftmax: input type not supported");
1129
1130 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1131 "Reference LogSoftmax: output type not supported");
1132
1133 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1134 "Reference LogSoftmax: input and output types do not match");
1135
1136 return supported;
1137}
1138
arovir011c7c81b2018-10-08 11:34:28 +01001139bool RefLayerSupport::IsLstmSupported(const TensorInfo& input,
1140 const TensorInfo& outputStateIn,
1141 const TensorInfo& cellStateIn,
1142 const TensorInfo& scratchBuffer,
1143 const TensorInfo& outputStateOut,
1144 const TensorInfo& cellStateOut,
1145 const TensorInfo& output,
1146 const LstmDescriptor& descriptor,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001147 const LstmInputParamsInfo& paramsInfo,
1148 Optional<std::string&> reasonIfUnsupported) const
arovir011c7c81b2018-10-08 11:34:28 +01001149{
Jan Eilers8eb25602020-03-09 12:13:48 +00001150 IgnoreUnused(descriptor);
1151 IgnoreUnused(paramsInfo);
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001152
1153 bool supported = true;
1154
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001155 std::array<DataType,3> supportedTypes = {
1156 DataType::BFloat16,
Conor Kennedyb9971c92019-05-07 07:14:23 +01001157 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001158 DataType::QSymmS16
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001159 };
1160
Jan Eilersd01a83c2019-07-03 18:20:40 +01001161 // check inputs and outputs
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001162 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1163 "Reference Lstm: input is not a supported type.");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001164 supported &= CheckSupportRule(TypesAreEqual(input, outputStateIn), reasonIfUnsupported,
1165 "Reference Lstm: input and outputStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001166 supported &= CheckSupportRule(TypesAreEqual(input, cellStateIn), reasonIfUnsupported,
1167 "Reference Lstm: input and cellStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001168 supported &= CheckSupportRule(TypesAreEqual(input, scratchBuffer), reasonIfUnsupported,
1169 "Reference Lstm: input and scratchBuffer types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001170 supported &= CheckSupportRule(TypesAreEqual(input, outputStateOut), reasonIfUnsupported,
1171 "Reference Lstm: input and outputStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001172 supported &= CheckSupportRule(TypesAreEqual(input, cellStateOut), reasonIfUnsupported,
1173 "Reference Lstm: input and cellStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001174 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1175 "Reference Lstm: input and output types are mismatched");
Jan Eilersd01a83c2019-07-03 18:20:40 +01001176 // check layer parameters
Francis Murtaghbb590b42019-08-14 09:51:36 +01001177 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001178 "Reference Lstm: input and InputToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001179 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001180 "Reference Lstm: input and InputToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001181 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001182 "Reference Lstm: input and InputToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001183 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001184 "Reference Lstm: input and RecurrentToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001185 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001186 "Reference Lstm: input and RecurrentToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001187 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001188 "Reference Lstm: input and RecurrentToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001189 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001190 "Reference Lstm: input and ForgetGateBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001191 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001192 "Reference Lstm: input and CellBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001193 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001194 "Reference Lstm: input and OutputGateBias types are mismatched");
1195 if (!descriptor.m_CifgEnabled)
1196 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001197 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToInputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001198 "Reference Lstm: input and InputToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001199 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001200 reasonIfUnsupported,
1201 "Reference Lstm: input and RecurrentToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001202 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001203 "Reference Lstm: input and InputGateBias types are mismatched");
1204 if (descriptor.m_PeepholeEnabled)
1205 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001206 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001207 reasonIfUnsupported,
1208 "Reference Lstm: input and CellToInputWeights types are mismatched");
1209 }
1210 }
1211 if (descriptor.m_PeepholeEnabled)
1212 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001213 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001214 "Reference Lstm: input and CellToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001215 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001216 "Reference Lstm: input and CellToOutputWeights types are mismatched");
1217 }
1218 if (descriptor.m_ProjectionEnabled)
1219 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001220 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001221 "Reference Lstm: input and mProjectionWeights types are mismatched");
1222 if (paramsInfo.m_ProjectionBias != nullptr)
1223 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001224 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001225 "Reference Lstm: input and ProjectionBias types are mismatched");
1226 }
1227 }
1228 if (descriptor.m_LayerNormEnabled)
1229 {
1230 if (!descriptor.m_CifgEnabled)
1231 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001232 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001233 reasonIfUnsupported,
1234 "Reference Lstm: input and InputLayerNormWeights types are mismatched");
1235 }
Francis Murtaghbb590b42019-08-14 09:51:36 +01001236 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001237 reasonIfUnsupported,
1238 "Reference Lstm: input and ForgetLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001239 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001240 reasonIfUnsupported,
1241 "Reference Lstm: input and CellLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001242 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001243 reasonIfUnsupported,
1244 "Reference Lstm: input and OutputLayerNormWeights types are mismatched");
1245 }
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001246
1247 return supported;
telsoa01c577f2c2018-08-31 09:22:23 +01001248}
1249
saoste012df12b32018-11-28 16:57:20 +00001250bool RefLayerSupport::IsMaximumSupported(const TensorInfo& input0,
1251 const TensorInfo& input1,
1252 const TensorInfo& output,
1253 Optional<std::string&> reasonIfUnsupported) const
1254{
Sadik Armagan2999a022019-04-09 14:20:12 +01001255 bool supported = true;
1256
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001257 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001258 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001259 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001260 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001261 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001262 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001263 DataType::QSymmS16,
1264 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01001265 };
1266
1267 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1268 "Reference maximum: input 0 is not a supported type.");
1269
1270 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1271 "Reference maximum: input 1 is not a supported type.");
1272
1273 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1274 "Reference maximum: output is not a supported type.");
1275
1276 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1277 "Reference maximum: input 0 and Input 1 types are mismatched");
1278
1279 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1280 "Reference maximum: input and output types are mismatched");
1281
1282 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1283 "Reference maximum: shapes are not suitable for implicit broadcast.");
1284
1285 return supported;
saoste012df12b32018-11-28 16:57:20 +00001286}
1287
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001288bool RefLayerSupport::IsMeanSupported(const TensorInfo& input,
1289 const TensorInfo& output,
1290 const MeanDescriptor& descriptor,
1291 Optional<std::string&> reasonIfUnsupported) const
narpra0132b90462018-09-13 11:07:48 +01001292{
James Conroy4d1ff582019-06-10 17:06:39 +01001293 bool supported = true;
1294 std::string meanLayerStr = "Mean";
1295 std::string outputTensorStr = "output";
1296
Sadik Armagan303980c2020-04-17 12:45:14 +01001297 std::array<DataType,6> supportedTypes =
James Conroy4d1ff582019-06-10 17:06:39 +01001298 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001299 DataType::BFloat16,
James Conroy4d1ff582019-06-10 17:06:39 +01001300 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001301 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001302 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001303 DataType::QAsymmU8,
1304 DataType::QSymmS16
James Conroy4d1ff582019-06-10 17:06:39 +01001305 };
1306
1307 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1308 "Reference Mean: input type not supported.");
1309
1310 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1311 "Reference Mean: input and output types are mismatched");
1312
1313 if (descriptor.m_KeepDims)
1314 {
1315 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, input.GetNumDimensions()),
1316 reasonIfUnsupported,
1317 CreateIncorrectDimensionsErrorMsg(input.GetNumDimensions(),
1318 output.GetNumDimensions(),
1319 meanLayerStr, outputTensorStr).data());
1320 }
1321 else if (descriptor.m_Axis.empty())
1322 {
1323 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1324 reasonIfUnsupported,
1325 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1326 meanLayerStr, outputTensorStr).data());
1327 }
1328 else
1329 {
1330 auto outputDim = input.GetNumDimensions() - boost::numeric_cast<unsigned int>(descriptor.m_Axis.size());
1331
1332 if (outputDim > 0)
1333 {
1334 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, outputDim),
1335 reasonIfUnsupported,
1336 CreateIncorrectDimensionsErrorMsg(outputDim, output.GetNumDimensions(),
1337 meanLayerStr, outputTensorStr).data());
1338 }
1339 else
1340 {
1341 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1342 reasonIfUnsupported,
1343 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1344 meanLayerStr, outputTensorStr).data());
1345 }
1346 }
1347
1348 return supported;
narpra0132b90462018-09-13 11:07:48 +01001349}
1350
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001351bool RefLayerSupport::IsMergerSupported(const std::vector<const TensorInfo*> inputs,
Nikhil Raj8599a412018-11-19 14:51:07 +00001352 const TensorInfo& output,
Jim Flynne242f2d2019-05-22 14:24:13 +01001353 const MergerDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001354 Optional<std::string&> reasonIfUnsupported) const
1355{
Jim Flynne242f2d2019-05-22 14:24:13 +01001356 return IsConcatSupported(inputs, output, descriptor, reasonIfUnsupported);
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001357}
1358
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001359bool RefLayerSupport::IsMemCopySupported(const TensorInfo &input,
1360 const TensorInfo &output,
1361 Optional<std::string &> reasonIfUnsupported) const
1362{
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001363 bool supported = true;
1364
Sadik Armagan303980c2020-04-17 12:45:14 +01001365 std::array<DataType,7> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001366 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001367 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001368 DataType::Float32,
1369 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001370 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001371 DataType::QAsymmU8,
1372 DataType::QSymmS16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001373 DataType::Boolean
1374 };
1375
1376 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1377 "Reference MemCopy: input type not supported");
1378
1379 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1380 "Reference MemCopy: output type not supported");
1381
1382 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1383 "Reference MemCopy: input and output types are mismatched");
1384
1385 return supported;
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001386}
1387
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001388bool RefLayerSupport::IsMinimumSupported(const TensorInfo& input0,
1389 const TensorInfo& input1,
1390 const TensorInfo& output,
1391 Optional<std::string&> reasonIfUnsupported) const
1392{
Sadik Armagan2999a022019-04-09 14:20:12 +01001393 bool supported = true;
1394
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001395 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001396 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001397 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001398 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001399 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001400 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001401 DataType::QSymmS16,
1402 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01001403 };
1404
1405 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1406 "Reference minimum: input 0 is not a supported type.");
1407
1408 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1409 "Reference minimum: input 1 is not a supported type.");
1410
1411 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1412 "Reference minimum: output is not a supported type.");
1413
1414 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1415 "Reference minimum: input 0 and Input 1 types are mismatched");
1416
1417 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1418 "Reference minimum: input and output types are mismatched");
1419
1420 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1421 "Reference minimum: shapes are not suitable for implicit broadcast.");
1422
1423 return supported;
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001424}
1425
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001426bool RefLayerSupport::IsMultiplicationSupported(const TensorInfo& input0,
1427 const TensorInfo& input1,
1428 const TensorInfo& output,
1429 Optional<std::string&> reasonIfUnsupported) const
1430{
Sadik Armagan2999a022019-04-09 14:20:12 +01001431 bool supported = true;
1432
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001433 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001434 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001435 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001436 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001437 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001438 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001439 DataType::QSymmS16,
1440 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01001441 };
1442
1443 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1444 "Reference multiplication: input 0 is not a supported type.");
1445
1446 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1447 "Reference multiplication: input 1 is not a supported type.");
1448
1449 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1450 "Reference multiplication: output is not a supported type.");
1451
1452 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1453 "Reference multiplication: input 0 and Input 1 types are mismatched");
1454
1455 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1456 "Reference multiplication: input and output types are mismatched");
1457
1458 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1459 "Reference multiplication: shapes are not suitable for implicit broadcast.");
1460
1461 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001462}
1463
1464bool RefLayerSupport::IsNormalizationSupported(const TensorInfo& input,
1465 const TensorInfo& output,
1466 const NormalizationDescriptor& descriptor,
1467 Optional<std::string&> reasonIfUnsupported) const
Nina Drozd661dfa72018-10-02 11:14:17 +01001468{
Jan Eilers8eb25602020-03-09 12:13:48 +00001469 IgnoreUnused(descriptor);
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001470
1471 // Define supported types
Sadik Armagan303980c2020-04-17 12:45:14 +01001472 std::array<DataType, 6> supportedTypes =
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001473 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001474 DataType::BFloat16,
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001475 DataType::Float16,
1476 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001477 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001478 DataType::QAsymmU8,
1479 DataType::QSymmS16
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001480 };
1481
1482 bool supported = true;
1483
1484 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1485 "Reference normalization: input type not supported.");
1486
1487 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1488 "Reference normalization: output type not supported.");
1489
1490 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1491 "Reference normalization: input and output shapes have different "
1492 "num total elements.");
1493
1494 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001495}
1496
Derek Lamberti901ea112019-12-10 22:07:09 +00001497bool RefLayerSupport::IsOutputSupported(const TensorInfo& /*output*/,
1498 Optional<std::string&> /*reasonIfUnsupported*/) const
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001499{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +01001500 return true;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001501}
1502
1503bool RefLayerSupport::IsPadSupported(const TensorInfo& input,
1504 const TensorInfo& output,
1505 const PadDescriptor& descriptor,
1506 Optional<std::string&> reasonIfUnsupported) const
1507{
Jan Eilers8eb25602020-03-09 12:13:48 +00001508 IgnoreUnused(descriptor);
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001509 bool supported = true;
1510
1511 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01001512 std::array<DataType,6> supportedTypes =
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001513 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001514 DataType::BFloat16,
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001515 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001516 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001517 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001518 DataType::QAsymmU8,
1519 DataType::QSymmS16
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001520 };
1521
1522 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1523 "Reference pad: input is not a supported type.");
1524
1525 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1526 "Reference pad: output is not a supported type.");
1527
1528 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1529 "Reference pad: input and output types are mismatched.");
1530
1531 return supported;
Nina Drozd661dfa72018-10-02 11:14:17 +01001532}
1533
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001534bool RefLayerSupport::IsPermuteSupported(const TensorInfo& input,
1535 const TensorInfo& output,
1536 const PermuteDescriptor& descriptor,
1537 Optional<std::string&> reasonIfUnsupported) const
1538{
Jan Eilers8eb25602020-03-09 12:13:48 +00001539 IgnoreUnused(descriptor);
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001540 bool supported = true;
1541
1542 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01001543 std::array<DataType, 6> supportedTypes =
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001544 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001545 DataType::BFloat16,
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001546 DataType::Float32,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00001547 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001548 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001549 DataType::QAsymmU8,
1550 DataType::QSymmS16
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001551 };
1552
1553 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1554 "Reference permute: input is not a supported type.");
1555
1556 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1557 "Reference permute: output is not a supported type.");
1558
1559 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1560 "Reference permute: input and output types are mismatched.");
1561
1562 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001563}
1564
1565bool RefLayerSupport::IsPooling2dSupported(const TensorInfo& input,
1566 const TensorInfo& output,
1567 const Pooling2dDescriptor& descriptor,
1568 Optional<std::string&> reasonIfUnsupported) const
1569{
Jan Eilers8eb25602020-03-09 12:13:48 +00001570 IgnoreUnused(descriptor);
Teresa Charlina3b20472019-06-06 11:12:32 +01001571 bool supported = true;
1572
1573 // Define supported output and inputs types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001574 std::array<DataType,6> supportedTypes =
Teresa Charlina3b20472019-06-06 11:12:32 +01001575 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001576 DataType::BFloat16,
Teresa Charlina3b20472019-06-06 11:12:32 +01001577 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001578 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001579 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001580 DataType::QAsymmU8,
1581 DataType::QSymmS16
Teresa Charlina3b20472019-06-06 11:12:32 +01001582 };
1583
1584 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1585 "Reference poolind2d: input is not a supported type.");
1586
1587 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1588 "Reference poolind2d: output is not a supported type.");
1589
1590 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1591 "Reference poolind2d: input and output types are mismatched.");
1592
1593 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001594}
1595
James Conroy4f1f8992020-04-29 20:01:10 +01001596bool RefLayerSupport::IsQLstmSupported(const TensorInfo& input,
1597 const TensorInfo& previousOutputIn,
1598 const TensorInfo& previousCellStateIn,
1599 const TensorInfo& outputStateOut,
1600 const TensorInfo& cellStateOut,
1601 const TensorInfo& output,
1602 const QLstmDescriptor& descriptor,
1603 const LstmInputParamsInfo& paramsInfo,
1604 Optional<std::string&> reasonIfUnsupported) const
1605{
1606 IgnoreUnused(input);
1607 IgnoreUnused(previousOutputIn);
1608 IgnoreUnused(previousCellStateIn);
1609 IgnoreUnused(outputStateOut);
1610 IgnoreUnused(cellStateOut);
1611 IgnoreUnused(output);
1612 IgnoreUnused(descriptor);
1613 IgnoreUnused(paramsInfo);
1614
1615 IgnoreUnused(reasonIfUnsupported);
1616
1617 return true;
1618}
1619
Derek Lamberti5f400d62019-03-25 15:41:58 +00001620bool RefLayerSupport::IsQuantizeSupported(const TensorInfo& input,
1621 const TensorInfo& output,
1622 Optional<std::string&> reasonIfUnsupported) const
1623{
1624 bool supported = true;
1625
Finn Williamsfd271062019-12-04 14:27:27 +00001626 // Define supported input types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001627 std::array<DataType,7> supportedInputTypes = {
1628 DataType::BFloat16,
Keith Davis5e51cd82020-01-29 16:52:59 +00001629 DataType::Float32,
Keith Davis3d8bc972020-02-04 09:31:47 +00001630 DataType::Float16,
Ryan OShea9add1202020-02-07 10:06:33 +00001631 DataType::QAsymmS8,
Keith Davis5e51cd82020-01-29 16:52:59 +00001632 DataType::QAsymmU8,
1633 DataType::QSymmS8,
1634 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001635 };
1636
1637 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
1638 "Reference quantize: input type not supported.");
1639
1640 // Define supported output types.
Ryan OShea9add1202020-02-07 10:06:33 +00001641 std::array<DataType,4> supportedOutputTypes = {
Ryan OShea9add1202020-02-07 10:06:33 +00001642 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001643 DataType::QAsymmU8,
Finn Williamsfd271062019-12-04 14:27:27 +00001644 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001645 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001646 };
1647 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
1648 "Reference quantize: output type not supported.");
1649
1650 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1651 "Reference quantize: input and output shapes have different num total elements.");
1652
1653 return supported;
1654}
1655
Finn Williams2605b232020-06-10 15:53:46 +01001656bool RefLayerSupport::IsRankSupported(const TensorInfo& input,
1657 const TensorInfo& output,
1658 Optional<std::string&> reasonIfUnsupported) const
1659{
1660 IgnoreUnused(input);
1661 // Define supported output types.
1662 std::array<DataType,1> supportedOutputTypes =
1663 {
1664 DataType::Signed32,
1665 };
1666
1667 return CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
1668 "Reference rank: input type not supported.");
1669}
1670
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001671bool RefLayerSupport::IsReshapeSupported(const TensorInfo& input,
Kevin Maya023c402019-12-12 17:28:05 +00001672 const TensorInfo& output,
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001673 const ReshapeDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001674 Optional<std::string&> reasonIfUnsupported) const
1675{
Jan Eilers8eb25602020-03-09 12:13:48 +00001676 IgnoreUnused(output);
1677 IgnoreUnused(descriptor);
Nina Drozd2f2778f2019-05-27 10:37:05 +01001678 // Define supported output types.
Keith Davis0c2eeac2020-02-11 16:51:50 +00001679 std::array<DataType,7> supportedOutputTypes =
Nina Drozd2f2778f2019-05-27 10:37:05 +01001680 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001681 DataType::BFloat16,
Nina Drozd2f2778f2019-05-27 10:37:05 +01001682 DataType::Float32,
1683 DataType::Float16,
Narumol Prangnawarat0718ee92019-09-13 16:53:38 +01001684 DataType::Signed32,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001685 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001686 DataType::QAsymmU8,
1687 DataType::QSymmS16
Nina Drozd2f2778f2019-05-27 10:37:05 +01001688 };
Keith Davis0c2eeac2020-02-11 16:51:50 +00001689
Nina Drozd2f2778f2019-05-27 10:37:05 +01001690 return CheckSupportRule(TypeAnyOf(input, supportedOutputTypes), reasonIfUnsupported,
1691 "Reference reshape: input type not supported.");
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001692}
1693
1694bool RefLayerSupport::IsResizeBilinearSupported(const TensorInfo& input,
Sadik Armaganc625f002018-12-17 11:32:16 +00001695 const TensorInfo& output,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001696 Optional<std::string&> reasonIfUnsupported) const
1697{
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001698 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001699 std::array<DataType,6> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001700 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001701 DataType::BFloat16,
Teresa Charlin970f43b2019-07-01 13:51:07 +01001702 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001703 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001704 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001705 DataType::QAsymmU8,
1706 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001707 };
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001708
1709 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1710 "Reference ResizeBilinear: input type not supported");
1711
1712 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1713 "Reference ResizeBilinear: output type not supported");
1714
1715 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1716 "Reference ResizeBilinear: input and output types not matching");
1717
1718 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001719}
1720
Teresa Charlin970f43b2019-07-01 13:51:07 +01001721bool RefLayerSupport::IsResizeSupported(const TensorInfo& input,
1722 const TensorInfo& output,
1723 const ResizeDescriptor& descriptor,
1724 Optional<std::string&> reasonIfUnsupported) const
1725{
Jan Eilers8eb25602020-03-09 12:13:48 +00001726 IgnoreUnused(descriptor);
Teresa Charlin970f43b2019-07-01 13:51:07 +01001727 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001728 std::array<DataType,6> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001729 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001730 DataType::BFloat16,
Teresa Charlin970f43b2019-07-01 13:51:07 +01001731 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001732 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001733 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001734 DataType::QAsymmU8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001735 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001736 };
1737
1738 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1739 "Reference Resize: input type not supported");
1740
1741 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1742 "Reference Resize: output type not supported");
1743
1744 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1745 "Reference Resize: input and output types not matching");
1746
1747 return supported;
1748}
1749
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001750bool RefLayerSupport::IsRsqrtSupported(const TensorInfo& input,
1751 const TensorInfo& output,
1752 Optional<std::string&> reasonIfUnsupported) const
1753{
josh minor4a3c6102020-01-06 16:40:46 -06001754 return IsElementwiseUnarySupported(input,
1755 output,
1756 ElementwiseUnaryDescriptor(UnaryOperation::Rsqrt),
1757 reasonIfUnsupported);
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001758}
1759
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001760bool RefLayerSupport::IsSliceSupported(const TensorInfo& input,
1761 const TensorInfo& output,
1762 const SliceDescriptor& descriptor,
1763 Optional<std::string&> reasonIfUnsupported) const
1764{
Jan Eilers8eb25602020-03-09 12:13:48 +00001765 IgnoreUnused(descriptor);
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001766 bool supported = true;
1767
Sadik Armagan303980c2020-04-17 12:45:14 +01001768 std::array<DataType, 5> supportedTypes =
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001769 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001770 DataType::BFloat16,
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001771 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001772 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001773 DataType::QAsymmU8,
1774 DataType::QSymmS16
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001775 };
1776
1777 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1778 "Reference Slice: input type not supported");
1779
1780 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1781 "Reference Slice: output type not supported");
1782
1783 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1784 "Reference Slice: input and output types are mismatched");
1785
1786 return supported;
1787}
1788
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001789bool RefLayerSupport::IsSoftmaxSupported(const TensorInfo& input,
1790 const TensorInfo& output,
1791 const SoftmaxDescriptor& descriptor,
1792 Optional<std::string&> reasonIfUnsupported) const
1793{
Jan Eilers8eb25602020-03-09 12:13:48 +00001794 IgnoreUnused(descriptor);
nikraj01248683f2019-05-29 16:46:50 +01001795 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001796 std::array<DataType,7> supportedTypes =
nikraj01248683f2019-05-29 16:46:50 +01001797 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001798 DataType::BFloat16,
1799 DataType::Float32,
1800 DataType::Float16,
1801 DataType::QSymmS8,
1802 DataType::QAsymmS8,
1803 DataType::QAsymmU8,
1804 DataType::QSymmS16
nikraj01248683f2019-05-29 16:46:50 +01001805 };
1806
1807 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001808 "Reference Softmax: output type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001809
1810 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001811 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001812
1813 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001814 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001815
1816 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001817}
1818
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001819bool RefLayerSupport::IsSpaceToBatchNdSupported(const TensorInfo& input,
1820 const TensorInfo& output,
1821 const SpaceToBatchNdDescriptor& descriptor,
1822 Optional<std::string&> reasonIfUnsupported) const
1823{
Jan Eilers8eb25602020-03-09 12:13:48 +00001824 IgnoreUnused(descriptor);
nikraj01120522a2019-05-31 11:33:07 +01001825 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001826 std::array<DataType,6> supportedTypes =
nikraj01120522a2019-05-31 11:33:07 +01001827 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001828 DataType::BFloat16,
1829 DataType::Float32,
1830 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001831 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001832 DataType::QAsymmU8,
1833 DataType::QSymmS16
nikraj01120522a2019-05-31 11:33:07 +01001834 };
1835
1836 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1837 "Reference SpaceToBatchNd: input type not supported");
1838
1839 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1840 "Reference SpaceToBatchNd: output type not supported");
1841
1842 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1843 "Reference SpaceToBatchNd: input and output types are mismatched");
1844
1845 return supported;
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001846}
1847
Keith Davisa57eccb2019-06-14 17:33:22 +01001848bool RefLayerSupport::IsSpaceToDepthSupported(const TensorInfo& input,
Keith Davis51910332019-06-26 15:28:43 +01001849 const TensorInfo& output,
1850 const SpaceToDepthDescriptor& descriptor,
1851 Optional<std::string&> reasonIfUnsupported) const
Keith Davisa57eccb2019-06-14 17:33:22 +01001852{
1853
Jan Eilers8eb25602020-03-09 12:13:48 +00001854 IgnoreUnused(descriptor);
Keith Davisa57eccb2019-06-14 17:33:22 +01001855 bool supported = true;
1856
Sadik Armagan303980c2020-04-17 12:45:14 +01001857 std::array<DataType,6> supportedTypes =
Keith Davisa57eccb2019-06-14 17:33:22 +01001858 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001859 DataType::BFloat16,
Keith Davisa57eccb2019-06-14 17:33:22 +01001860 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001861 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001862 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001863 DataType::QAsymmU8,
1864 DataType::QSymmS16
Keith Davisa57eccb2019-06-14 17:33:22 +01001865 };
1866
1867 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1868 "Reference SpaceToDepth: input type not supported");
1869
1870 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1871 "Reference SpaceToDepth: output type not supported");
1872
1873 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1874 "Reference SpaceToDepth: input and output types are mismatched");
1875
1876 return supported;
1877}
1878
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001879bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1880 const ViewsDescriptor& descriptor,
1881 Optional<std::string&> reasonIfUnsupported) const
1882{
Jan Eilers8eb25602020-03-09 12:13:48 +00001883 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001884 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001885 std::array<DataType,6> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001886 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001887 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001888 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001889 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001890 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001891 DataType::QAsymmU8,
1892 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001893 };
1894
1895 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1896 "Reference splitter: input type not supported");
1897
1898 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001899}
1900
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001901bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1902 const std::vector<std::reference_wrapper<TensorInfo>>& outputs,
1903 const ViewsDescriptor& descriptor,
1904 Optional<std::string&> reasonIfUnsupported) const
1905{
Jan Eilers8eb25602020-03-09 12:13:48 +00001906 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001907 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001908 std::array<DataType,6> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001909 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001910 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001911 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001912 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001913 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001914 DataType::QAsymmU8,
1915 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001916 };
1917
1918 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1919 "Reference splitter: output type not supported");
1920 for (const TensorInfo output : outputs)
1921 {
1922 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1923 "Reference splitter: input type not supported");
1924
1925 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1926 "Reference splitter: input and output types mismatched.");
1927 }
1928
1929 return supported;
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001930}
1931
Matthew Jackson81e601c2019-07-11 12:07:09 +01001932bool RefLayerSupport::IsStackSupported(const std::vector<const TensorInfo*>& inputs,
1933 const TensorInfo& output,
1934 const StackDescriptor& descriptor,
1935 Optional<std::string&> reasonIfUnsupported) const
1936{
Jan Eilers8eb25602020-03-09 12:13:48 +00001937 IgnoreUnused(descriptor);
Matthew Jackson81e601c2019-07-11 12:07:09 +01001938
1939 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001940 std::array<DataType,6> supportedTypes =
Matthew Jackson81e601c2019-07-11 12:07:09 +01001941 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001942 DataType::BFloat16,
Matthew Jackson81e601c2019-07-11 12:07:09 +01001943 DataType::Float32,
Matthew Jacksone69c3992019-09-09 14:31:21 +01001944 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001945 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001946 DataType::QAsymmU8,
1947 DataType::QSymmS16
Matthew Jackson81e601c2019-07-11 12:07:09 +01001948 };
1949
1950 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1951 "Reference stack: output type not supported");
1952 for (const TensorInfo* input : inputs)
1953 {
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +01001954 ARMNN_ASSERT(input != nullptr);
Matthew Jackson81e601c2019-07-11 12:07:09 +01001955 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
1956 "Reference stack: input type not supported");
1957
1958 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
1959 "Reference stack: input and output types mismatched.");
1960 }
1961
1962 return supported;
1963}
1964
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00001965bool RefLayerSupport::IsStridedSliceSupported(const TensorInfo& input,
1966 const TensorInfo& output,
1967 const StridedSliceDescriptor& descriptor,
1968 Optional<std::string&> reasonIfUnsupported) const
1969{
Jan Eilers8eb25602020-03-09 12:13:48 +00001970 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001971 bool supported = true;
1972
Sadik Armagan303980c2020-04-17 12:45:14 +01001973 std::array<DataType,5> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001974 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001975 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001976 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001977 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001978 DataType::QAsymmU8,
1979 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001980 };
1981
1982 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1983 "Reference StridedSlice: input type not supported");
1984
1985 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1986 "Reference StridedSlice: output type not supported");
1987
1988 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1989 "Reference StridedSlice: input and output types are mismatched");
1990
1991 return supported;
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00001992}
1993
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001994bool RefLayerSupport::IsSubtractionSupported(const TensorInfo& input0,
1995 const TensorInfo& input1,
1996 const TensorInfo& output,
1997 Optional<std::string&> reasonIfUnsupported) const
1998{
Sadik Armagan2999a022019-04-09 14:20:12 +01001999 bool supported = true;
2000
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01002001 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002002 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01002003 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01002004 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002005 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002006 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01002007 DataType::QSymmS16,
2008 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01002009 };
2010
2011 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
2012 "Reference subtraction: input 0 is not a supported type.");
2013
2014 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
2015 "Reference subtraction: input 1 is not a supported type.");
2016
2017 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2018 "Reference subtraction: output is not a supported type.");
2019
2020 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
2021 "Reference subtraction: input 0 and Input 1 types are mismatched");
2022
2023 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
2024 "Reference subtraction: input and output types are mismatched");
2025
2026 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
2027 "Reference subtraction: shapes are not suitable for implicit broadcast.");
2028
2029 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01002030}
2031
Matteo Martincighab9e5252019-06-13 17:27:46 +01002032bool RefLayerSupport::IsPreluSupported(const TensorInfo& input,
2033 const TensorInfo& alpha,
2034 const TensorInfo& output,
2035 Optional<std::string&> reasonIfUnsupported) const
2036{
2037 bool supported = true;
2038
Teresa Charlin3940d8b2020-05-29 16:47:23 +01002039 std::array<DataType, 6> supportedTypes
Matteo Martincighab9e5252019-06-13 17:27:46 +01002040 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002041 DataType::BFloat16,
Matteo Martincighab9e5252019-06-13 17:27:46 +01002042 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01002043 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002044 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002045 DataType::QAsymmU8,
Teresa Charlin3940d8b2020-05-29 16:47:23 +01002046 DataType::QSymmS16
Matteo Martincighab9e5252019-06-13 17:27:46 +01002047 };
2048
2049 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2050 "PReLU: input is not a supported type.");
2051
2052 supported &= CheckSupportRule(TypeAnyOf(alpha, supportedTypes), reasonIfUnsupported,
2053 "PReLU: alpha is not a supported type.");
2054
2055 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2056 "PReLU: output is not a supported type.");
2057
2058 supported &= CheckSupportRule(TypesAreEqual(input, alpha, output), reasonIfUnsupported,
2059 "PReLU: input, alpha and output types are mismatched");
2060
2061 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input, alpha, output), reasonIfUnsupported,
2062 "PReLU: shapes are not suitable for implicit broadcast");
2063
2064 return supported;
2065}
2066
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002067bool RefLayerSupport::IsTransposeConvolution2dSupported(const TensorInfo& input,
2068 const TensorInfo& output,
2069 const TransposeConvolution2dDescriptor& descriptor,
2070 const TensorInfo& weights,
2071 const Optional<TensorInfo>& biases,
2072 Optional<std::string&> reasonIfUnsupported) const
2073{
Jan Eilers8eb25602020-03-09 12:13:48 +00002074 IgnoreUnused(descriptor);
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002075 bool supported = true;
2076
Sadik Armagan303980c2020-04-17 12:45:14 +01002077 std::array<DataType,7> supportedTypes =
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002078 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002079 DataType::BFloat16,
2080 DataType::Float32,
2081 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002082 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002083 DataType::QAsymmU8,
Sadik Armagan303980c2020-04-17 12:45:14 +01002084 DataType::QSymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002085 DataType::QSymmS16
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002086 };
2087
2088 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2089 "Reference TransposeConvolution2d: input is not a supported type.");
2090
2091 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2092 "Reference TransposeConvolution2d: output is not a supported type.");
2093
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002094 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2095 "Reference TransposeConvolution2d: input and output types mismatched.");
2096
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002097
2098 const DataType inputType = input.GetDataType();
Sadik Armagan303980c2020-04-17 12:45:14 +01002099 if (IsQuantized8BitType(inputType))
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002100 {
Derek Lambertid466a542020-01-22 15:37:29 +00002101 ARMNN_NO_DEPRECATE_WARN_BEGIN
Sadik Armagan303980c2020-04-17 12:45:14 +01002102 std::array<DataType, 4> supportedWeightTypes =
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002103 {
Sadik Armagan303980c2020-04-17 12:45:14 +01002104 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002105 DataType::QAsymmU8,
Derek Lambertid466a542020-01-22 15:37:29 +00002106 DataType::QSymmS8,
2107 DataType::QuantizedSymm8PerAxis //Deprecated
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002108 };
Derek Lambertid466a542020-01-22 15:37:29 +00002109 ARMNN_NO_DEPRECATE_WARN_END
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002110
2111 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
2112 "Reference TransposeConvolution2d: weights type not supported for "
2113 "quantized input.");
2114 }
2115 else
2116 {
2117 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
2118 "Reference TransposeConvolution2d: weights is not a supported type.");
2119
2120 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
2121 "Reference TransposeConvolution2d: input and weights types mismatched.");
2122 }
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002123
2124 if (biases.has_value())
2125 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002126 std::array<DataType,4> biasesSupportedTypes =
Aron Virginas-Tar651aafe2019-08-05 11:52:05 +01002127 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002128 DataType::BFloat16,
2129 DataType::Float32,
2130 DataType::Float16,
2131 DataType::Signed32
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002132 };
2133 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
2134 "Reference TransposeConvolution2d: biases is not a supported type.");
2135 }
2136
2137 return supported;
2138}
2139
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002140bool RefLayerSupport::IsTransposeSupported(const TensorInfo& input,
2141 const TensorInfo& output,
2142 const TransposeDescriptor& descriptor,
2143 Optional<std::string&> reasonIfUnsupported) const
2144{
Jan Eilers8eb25602020-03-09 12:13:48 +00002145 IgnoreUnused(descriptor);
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002146 bool supported = true;
2147
2148 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01002149 std::array<DataType, 6> supportedTypes =
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002150 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002151 DataType::BFloat16,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002152 DataType::Float32,
2153 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002154 DataType::QAsymmS8,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002155 DataType::QAsymmU8,
2156 DataType::QSymmS16
2157 };
2158
2159 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2160 "Reference transpose: input is not a supported type.");
2161
2162 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2163 "Reference transpose: output is not a supported type.");
2164
2165 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2166 "Reference transpose: input and output types are mismatched.");
2167
2168 return supported;
2169}
2170
arovir011c7c81b2018-10-08 11:34:28 +01002171} // namespace armnn