blob: 8ca18b51b0a6cd06a27ac5c8b91a5209388dc15f [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5
telsoa014fcda012018-03-09 14:13:49 +00006#include "RefLayerSupport.hpp"
David Beck3cc9a622018-10-12 10:38:31 +01007
Keith Davis0c2eeac2020-02-11 16:51:50 +00008#include <armnn/TypesUtils.hpp>
telsoa014fcda012018-03-09 14:13:49 +00009#include <armnn/Types.hpp>
Derek Lamberti50db4e82019-03-13 14:16:15 +000010#include <armnn/Descriptors.hpp>
Jan Eilers8eb25602020-03-09 12:13:48 +000011#include <armnn/utility/IgnoreUnused.hpp>
telsoa014fcda012018-03-09 14:13:49 +000012
Matteo Martincighe011d202019-11-28 11:35:47 +000013#include <LayerSupportCommon.hpp>
Derek Lambertif674aa02019-08-01 15:56:25 +010014#include <backendsCommon/LayerSupportRules.hpp>
Matteo Martincighe011d202019-11-28 11:35:47 +000015
Matteo Martincighe011d202019-11-28 11:35:47 +000016#include <boost/cast.hpp>
telsoa014fcda012018-03-09 14:13:49 +000017
Derek Lamberti50db4e82019-03-13 14:16:15 +000018#include <vector>
Derek Lamberti50db4e82019-03-13 14:16:15 +000019#include <array>
20
telsoa014fcda012018-03-09 14:13:49 +000021using namespace boost;
22
23namespace armnn
24{
25
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +010026namespace
27{
28
29template<typename Float32Func, typename Uint8Func, typename ... Params>
30bool IsSupportedForDataTypeRef(Optional<std::string&> reasonIfUnsupported,
31 DataType dataType,
32 Float32Func floatFuncPtr,
33 Uint8Func uint8FuncPtr,
34 Params&&... params)
35{
36 return IsSupportedForDataTypeGeneric(reasonIfUnsupported,
37 dataType,
38 &FalseFunc<Params...>,
39 floatFuncPtr,
40 uint8FuncPtr,
narpra01db2b1602019-01-23 15:23:11 +000041 &FalseFunc<Params...>,
kevmay012b4d88e2019-01-24 14:05:09 +000042 &FalseFunc<Params...>,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +010043 std::forward<Params>(params)...);
44}
45
46} // anonymous namespace
47
James Conroy4d1ff582019-06-10 17:06:39 +010048namespace
49{
50
51std::string CreateIncorrectDimensionsErrorMsg(unsigned int expected,
52 unsigned int actual,
53 std::string& layerStr,
54 std::string& tensorName)
55{
56 std::string errorMsg = "Reference " + layerStr + ": Expected " + std::to_string(expected) + " dimensions but got" +
57 " " + std::to_string(actual) + " dimensions instead, for the '" + tensorName + "' tensor.";
58
59 return errorMsg;
60}
61
62} // anonymous namespace
Derek Lamberti50db4e82019-03-13 14:16:15 +000063
Sadik Armagan9199e582019-09-05 17:35:31 +010064bool RefLayerSupport::IsAbsSupported(const TensorInfo& input, const TensorInfo& output,
65 Optional<std::string&> reasonIfUnsupported) const
66{
josh minor4a3c6102020-01-06 16:40:46 -060067 return IsElementwiseUnarySupported(input,
68 output,
69 ElementwiseUnaryDescriptor(UnaryOperation::Abs),
70 reasonIfUnsupported);
Sadik Armagan9199e582019-09-05 17:35:31 +010071}
72
arovir011c7c81b2018-10-08 11:34:28 +010073bool RefLayerSupport::IsActivationSupported(const TensorInfo& input,
74 const TensorInfo& output,
75 const ActivationDescriptor& descriptor,
76 Optional<std::string&> reasonIfUnsupported) const
77{
Derek Lamberti50db4e82019-03-13 14:16:15 +000078 bool supported = true;
79
80 // Define supported types.
Keith Davis0c2eeac2020-02-11 16:51:50 +000081 std::array<DataType,6> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +000082 DataType::BFloat16,
Derek Lamberti50db4e82019-03-13 14:16:15 +000083 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +010084 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +000085 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +000086 DataType::QAsymmU8,
87 DataType::QSymmS16
Derek Lamberti50db4e82019-03-13 14:16:15 +000088 };
89
90 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
91 "Reference activation: input type not supported.");
92
93 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
94 "Reference activation: output type not supported.");
95
96 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
97 "Reference activation: input and output types mismatched.");
98
99 supported &= CheckSupportRule(ShapesAreSameRank(input, output), reasonIfUnsupported,
100 "Reference activation: input and output shapes are of different rank.");
101
102
103 struct ActivationFunctionSupported : public Rule
104 {
105 ActivationFunctionSupported(const ActivationDescriptor& desc)
106 {
107 switch(desc.m_Function)
108 {
109 case ActivationFunction::Abs:
110 case ActivationFunction::BoundedReLu:
David Monahan3b3c3812020-02-25 09:03:29 +0000111 case ActivationFunction::Elu:
Colm Donelan03fbeaf2020-02-26 15:39:23 +0000112 case ActivationFunction::HardSwish:
Derek Lamberti50db4e82019-03-13 14:16:15 +0000113 case ActivationFunction::LeakyReLu:
114 case ActivationFunction::Linear:
115 case ActivationFunction::ReLu:
116 case ActivationFunction::Sigmoid:
117 case ActivationFunction::SoftReLu:
118 case ActivationFunction::Sqrt:
119 case ActivationFunction::Square:
120 case ActivationFunction::TanH:
121 {
122 m_Res = true;
123 break;
124 }
125 default:
126 {
127 m_Res = false;
128 break;
129 }
130 }
131 }
132 };
133
134 // Function is supported
135 supported &= CheckSupportRule(ActivationFunctionSupported(descriptor), reasonIfUnsupported,
136 "Reference activation: function not supported.");
137
138 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100139}
140
141bool RefLayerSupport::IsAdditionSupported(const TensorInfo& input0,
142 const TensorInfo& input1,
143 const TensorInfo& output,
144 Optional<std::string&> reasonIfUnsupported) const
145{
Derek Lamberti50db4e82019-03-13 14:16:15 +0000146 bool supported = true;
147
Keith Davis0c2eeac2020-02-11 16:51:50 +0000148 std::array<DataType,6> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000149 DataType::BFloat16,
Derek Lamberti50db4e82019-03-13 14:16:15 +0000150 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100151 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000152 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000153 DataType::QAsymmU8,
154 DataType::QSymmS16
Derek Lamberti50db4e82019-03-13 14:16:15 +0000155 };
156
157 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
158 "Reference addition: input 0 is not a supported type.");
159
160 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
161 "Reference addition: input 1 is not a supported type.");
162
163 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
164 "Reference addition: output is not a supported type.");
165
166 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
167 "Reference addition: input 0 and Input 1 types are mismatched");
168
169 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
170 "Reference addition: input and output types are mismatched");
171
172 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
173 "Reference addition: shapes are not suitable for implicit broadcast.");
174
175 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100176}
177
Nikhil Raj68c2c902019-09-19 11:21:11 +0100178bool RefLayerSupport::IsArgMinMaxSupported(const armnn::TensorInfo &input, const armnn::TensorInfo &output,
179 const armnn::ArgMinMaxDescriptor &descriptor,
180 armnn::Optional<std::string &> reasonIfUnsupported) const
181{
Jan Eilers8eb25602020-03-09 12:13:48 +0000182 IgnoreUnused(descriptor);
Nikhil Raj68c2c902019-09-19 11:21:11 +0100183
Teresa Charline300b362020-05-25 10:01:03 +0100184 std::array<DataType, 7> supportedTypes =
Nikhil Raj68c2c902019-09-19 11:21:11 +0100185 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000186 DataType::BFloat16,
Teresa Charline300b362020-05-25 10:01:03 +0100187 DataType::Float16,
Nikhil Raj68c2c902019-09-19 11:21:11 +0100188 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +0100189 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000190 DataType::QAsymmU8,
191 DataType::QSymmS16,
Francis Murtagh1939df52019-11-13 15:21:09 +0000192 DataType::Signed32
Nikhil Raj68c2c902019-09-19 11:21:11 +0100193 };
194
195 bool supported = true;
196
197 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
198 "Reference ArgMinMax: input is not a supported type.");
199 supported &= CheckSupportRule(TypeIs(output, DataType::Signed32), reasonIfUnsupported,
200 "Reference ArgMinMax: output type not supported");
201
202 return supported;
203}
204
arovir011c7c81b2018-10-08 11:34:28 +0100205bool RefLayerSupport::IsBatchNormalizationSupported(const TensorInfo& input,
206 const TensorInfo& output,
207 const TensorInfo& mean,
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100208 const TensorInfo& variance,
arovir011c7c81b2018-10-08 11:34:28 +0100209 const TensorInfo& beta,
210 const TensorInfo& gamma,
211 const BatchNormalizationDescriptor& descriptor,
212 Optional<std::string&> reasonIfUnsupported) const
213{
Jan Eilers8eb25602020-03-09 12:13:48 +0000214 IgnoreUnused(descriptor);
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100215
Sadik Armagan303980c2020-04-17 12:45:14 +0100216 std::array<DataType, 6> supportedTypes =
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100217 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000218 DataType::BFloat16,
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100219 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100220 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100221 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000222 DataType::QAsymmU8,
223 DataType::QSymmS16
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100224 };
225
226 bool supported = true;
227
228 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
229 "Reference batch normalization: input is not a supported type.");
230
231 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
232 "Reference batch normalization: output is not a supported type.");
233
234 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
235 "Reference batch normalization: input and output types are mismatched");
236
237 supported &= CheckSupportRule(TypeAnyOf(mean, supportedTypes), reasonIfUnsupported,
238 "Reference batch normalization: mean is not a supported type.");
239
240 supported &= CheckSupportRule(TypeAnyOf(variance, supportedTypes), reasonIfUnsupported,
241 "Reference batch normalization: variance is not a supported type.");
242
243 supported &= CheckSupportRule(TypeAnyOf(beta, supportedTypes), reasonIfUnsupported,
244 "Reference batch normalization: beta is not a supported type.");
245
246 supported &= CheckSupportRule(TypeAnyOf(gamma, supportedTypes), reasonIfUnsupported,
247 "Reference batch normalization: gamma is not a supported type.");
248
249 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100250}
251
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000252bool RefLayerSupport::IsBatchToSpaceNdSupported(const TensorInfo& input,
253 const TensorInfo& output,
254 const BatchToSpaceNdDescriptor& descriptor,
255 Optional<std::string&> reasonIfUnsupported) const
256{
Jan Eilers8eb25602020-03-09 12:13:48 +0000257 IgnoreUnused(descriptor);
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100258
259 bool supported = true;
260
261 std::string batchToSpaceNdLayerStr = "batchToSpaceNd";
262 std::string inputTensorStr = "input";
263 std::string outputTensorStr = "output";
264
265 // Define supported types.
Sadik Armagan303980c2020-04-17 12:45:14 +0100266 std::array<DataType,6> supportedTypes =
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100267 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000268 DataType::BFloat16,
269 DataType::Float32,
270 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100271 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000272 DataType::QAsymmU8,
273 DataType::QSymmS16
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100274 };
275
276 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
277 "Reference BatchToSpaceNd: input type not supported.");
278
279 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
280 "Reference BatchToSpaceNd: output type not supported.");
281
282 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
283 "Reference BatchToSpaceNd: input and output types mismatched.");
284
285 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 4),
286 reasonIfUnsupported,
287 CreateIncorrectDimensionsErrorMsg(4,
288 output.GetNumDimensions(),
289 batchToSpaceNdLayerStr,
290 outputTensorStr).data());
291
292 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(input, 4),
293 reasonIfUnsupported,
294 CreateIncorrectDimensionsErrorMsg(4,
295 input.GetNumDimensions(),
296 batchToSpaceNdLayerStr,
297 inputTensorStr).data());
298
299 return supported;
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000300}
301
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100302bool RefLayerSupport::IsComparisonSupported(const TensorInfo& input0,
303 const TensorInfo& input1,
304 const TensorInfo& output,
305 const ComparisonDescriptor& descriptor,
306 Optional<std::string&> reasonIfUnsupported) const
307{
Jan Eilers8eb25602020-03-09 12:13:48 +0000308 IgnoreUnused(descriptor);
Sadik Armagan303980c2020-04-17 12:45:14 +0100309 std::array<DataType, 8> supportedInputTypes =
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100310 {
Sadik Armaganb60dd242020-03-19 13:53:16 +0000311 DataType::Boolean,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000312 DataType::BFloat16,
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100313 DataType::Float32,
314 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100315 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000316 DataType::QAsymmU8,
Sadik Armaganb60dd242020-03-19 13:53:16 +0000317 DataType::QSymmS16,
318 DataType::Signed32
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100319 };
320
321 bool supported = true;
322 supported &= CheckSupportRule(TypeAnyOf(input0, supportedInputTypes), reasonIfUnsupported,
323 "Reference comparison: input 0 is not a supported type");
324
325 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
326 "Reference comparison: input 0 and Input 1 types are mismatched");
327
328 supported &= CheckSupportRule(TypeIs(output, DataType::Boolean), reasonIfUnsupported,
329 "Reference comparison: output is not of type Boolean");
330
331 return supported;
332}
333
Jim Flynn906f9462019-05-10 13:55:21 +0100334bool RefLayerSupport::IsConcatSupported(const std::vector<const TensorInfo*> inputs,
335 const TensorInfo& output,
Jim Flynne242f2d2019-05-22 14:24:13 +0100336 const ConcatDescriptor& descriptor,
Jim Flynn906f9462019-05-10 13:55:21 +0100337 Optional<std::string&> reasonIfUnsupported) const
338{
Jan Eilers8eb25602020-03-09 12:13:48 +0000339 IgnoreUnused(descriptor);
Jim Flynne242f2d2019-05-22 14:24:13 +0100340
341 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000342 std::array<DataType,6> supportedTypes =
Jim Flynne242f2d2019-05-22 14:24:13 +0100343 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000344 DataType::BFloat16,
345 DataType::Float32,
346 DataType::Float16,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000347 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100348 DataType::QAsymmU8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000349 DataType::QSymmS16
Jim Flynne242f2d2019-05-22 14:24:13 +0100350 };
351
352 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
353 "Reference concatenation: output type not supported");
354 for (const TensorInfo* input : inputs)
355 {
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100356 ARMNN_ASSERT(input != nullptr);
Jim Flynne242f2d2019-05-22 14:24:13 +0100357 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
358 "Reference concatenation: input type not supported");
359
360 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
361 "Reference concatenation: input and output types mismatched.");
362 }
363
364 return supported;
Jim Flynn906f9462019-05-10 13:55:21 +0100365}
366
arovir011c7c81b2018-10-08 11:34:28 +0100367bool RefLayerSupport::IsConstantSupported(const TensorInfo& output,
368 Optional<std::string&> reasonIfUnsupported) const
369{
Teresa Charlin6fa8ce62020-05-25 16:16:44 +0100370 std::array<DataType,8> supportedTypes =
Jim Flynne242f2d2019-05-22 14:24:13 +0100371 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000372 DataType::BFloat16,
Teresa Charlin6fa8ce62020-05-25 16:16:44 +0100373 DataType::Float16,
Nina Drozd58ef2c62019-05-16 12:09:18 +0100374 DataType::Float32,
Keith Davis67e6c542020-02-19 10:08:33 +0000375 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100376 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +0000377 DataType::QSymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100378 DataType::QSymmS16,
379 DataType::Signed32
Nina Drozd58ef2c62019-05-16 12:09:18 +0100380 };
381
382 return CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
383 "Reference constant: output is not a supported type.");
arovir011c7c81b2018-10-08 11:34:28 +0100384}
385
Narumol Prangnawarat7ddbbae2020-03-13 10:26:05 +0000386bool RefLayerSupport::IsConvertBf16ToFp32Supported(const TensorInfo& input,
387 const TensorInfo& output,
388 Optional<std::string&> reasonIfUnsupported) const
389{
390 bool supported = true;
391
392 supported &= CheckSupportRule(TypeIs(input, DataType::BFloat16), reasonIfUnsupported,
393 "Reference for ConvertBf16ToFp32 layer: input type not supported");
394
395 supported &= CheckSupportRule(TypeIs(output, DataType::Float32), reasonIfUnsupported,
396 "Reference for ConvertBf16ToFp32 layer: output type not supported");
397
398 return supported;
399}
400
arovir011c7c81b2018-10-08 11:34:28 +0100401bool RefLayerSupport::IsConvertFp16ToFp32Supported(const TensorInfo& input,
402 const TensorInfo& output,
403 Optional<std::string&> reasonIfUnsupported) const
404{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100405 return (IsSupportedForDataTypeGeneric(reasonIfUnsupported,
406 input.GetDataType(),
407 &TrueFunc<>,
408 &FalseInputFuncF32<>,
narpra01db2b1602019-01-23 15:23:11 +0000409 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000410 &FalseFuncI32<>,
411 &FalseFuncU8<>) &&
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100412 IsSupportedForDataTypeGeneric(reasonIfUnsupported,
413 output.GetDataType(),
414 &FalseOutputFuncF16<>,
415 &TrueFunc<>,
narpra01db2b1602019-01-23 15:23:11 +0000416 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000417 &FalseFuncI32<>,
418 &FalseFuncU8<>));
arovir011c7c81b2018-10-08 11:34:28 +0100419}
420
Narumol Prangnawaratea54a012020-03-16 16:36:10 +0000421bool RefLayerSupport::IsConvertFp32ToBf16Supported(const TensorInfo& input,
422 const TensorInfo& output,
423 Optional<std::string&> reasonIfUnsupported) const
424{
425 bool supported = true;
426
427 supported &= CheckSupportRule(TypeIs(input, DataType::Float32), reasonIfUnsupported,
428 "Reference for ConvertFp32ToBf16 layer: input type not supported");
429
430 supported &= CheckSupportRule(TypeIs(output, DataType::BFloat16), reasonIfUnsupported,
431 "Reference for ConvertFp32ToBf16 layer: output type not supported");
432
433 return supported;
434}
435
arovir011c7c81b2018-10-08 11:34:28 +0100436bool RefLayerSupport::IsConvertFp32ToFp16Supported(const TensorInfo& input,
437 const TensorInfo& output,
438 Optional<std::string&> reasonIfUnsupported) const
439{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100440 return (IsSupportedForDataTypeGeneric(reasonIfUnsupported,
441 input.GetDataType(),
442 &FalseInputFuncF16<>,
443 &TrueFunc<>,
narpra01db2b1602019-01-23 15:23:11 +0000444 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000445 &FalseFuncI32<>,
446 &FalseFuncU8<>) &&
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100447 IsSupportedForDataTypeGeneric(reasonIfUnsupported,
448 output.GetDataType(),
449 &TrueFunc<>,
450 &FalseOutputFuncF32<>,
narpra01db2b1602019-01-23 15:23:11 +0000451 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000452 &FalseFuncI32<>,
453 &FalseFuncU8<>));
arovir011c7c81b2018-10-08 11:34:28 +0100454}
455
456bool RefLayerSupport::IsConvolution2dSupported(const TensorInfo& input,
457 const TensorInfo& output,
458 const Convolution2dDescriptor& descriptor,
459 const TensorInfo& weights,
460 const Optional<TensorInfo>& biases,
461 Optional<std::string&> reasonIfUnsupported) const
462{
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100463 bool supported = true;
464
465 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000466 std::array<DataType,7> supportedTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000467 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000468 DataType::BFloat16,
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000469 DataType::Float32,
470 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000471 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100472 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +0000473 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000474 DataType::QSymmS16
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100475 };
476
477 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000478 "Reference Convolution2d: input is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100479
480 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000481 "Reference Convolution2d: output is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100482
Narumol Prangnawarat57ef0082020-03-26 09:20:43 +0000483 // For Convolution2d, we allow to have BFloat16 input with Float32 output for optimization.
484 if (input.GetDataType() == DataType::BFloat16)
485 {
486 if (output.GetDataType() != DataType::BFloat16 && output.GetDataType() != DataType::Float32)
487 {
488 reasonIfUnsupported.value() += "Output tensor type must be BFloat16 or Float32 for BFloat16 input.\n";
489 supported = false;
490 }
491 }
492 else
493 {
494 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000495 "Reference Convolution2d: input and output types mismatched.");
Narumol Prangnawarat57ef0082020-03-26 09:20:43 +0000496 }
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100497
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000498 const DataType inputType = input.GetDataType();
Keith Davis0c2eeac2020-02-11 16:51:50 +0000499 if (IsQuantized8BitType(inputType))
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000500 {
Derek Lambertid466a542020-01-22 15:37:29 +0000501 ARMNN_NO_DEPRECATE_WARN_BEGIN
Keith Davis0c2eeac2020-02-11 16:51:50 +0000502 std::array<DataType, 4> supportedWeightTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000503 {
Sadik Armagan303980c2020-04-17 12:45:14 +0100504 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000505 DataType::QAsymmU8,
Derek Lambertid466a542020-01-22 15:37:29 +0000506 DataType::QSymmS8,
507 DataType::QuantizedSymm8PerAxis // deprecated
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000508 };
Derek Lambertid466a542020-01-22 15:37:29 +0000509 ARMNN_NO_DEPRECATE_WARN_END
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000510
511 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000512 "Reference Convolution2d: weights type not supported for quantized input.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000513 }
514 else
515 {
516 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000517 "Reference Convolution2d: weights is not a supported type.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000518
519 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000520 "Reference Convolution2d: input and weights types mismatched.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000521 }
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100522
523 if (biases.has_value())
524 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000525 std::array<DataType,4> biasesSupportedTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000526 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000527 DataType::BFloat16,
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000528 DataType::Float32,
529 DataType::Float16,
530 DataType::Signed32
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100531 };
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000532
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100533 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000534 "Reference Convolution2d: biases is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100535 }
Jan Eilers8eb25602020-03-09 12:13:48 +0000536 IgnoreUnused(descriptor);
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100537
538 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100539}
540
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000541bool RefLayerSupport::IsDebugSupported(const TensorInfo& input,
542 const TensorInfo& output,
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000543 Optional<std::string&> reasonIfUnsupported) const
544{
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100545 bool supported = true;
546
Narumol Prangnawarat403a1852020-03-12 14:24:13 +0000547 std::array<DataType, 8> supportedTypes =
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100548 {
Narumol Prangnawarat403a1852020-03-12 14:24:13 +0000549 DataType::BFloat16,
Aron Virginas-Tardb1a2832019-11-12 16:15:11 +0000550 DataType::Float16,
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100551 DataType::Float32,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000552 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100553 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +0000554 DataType::QSymmS8,
Narumol Prangnawaratd2d917d2020-01-09 10:16:39 +0000555 DataType::QSymmS16,
556 DataType::Signed32
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100557 };
558
559 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000560 "Reference for Debug layer: input type not supported");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100561
562 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000563 "Reference for Debug layer: output type not supported");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100564
565 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000566 "Reference for Debug layer: input and output types are mismatched");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100567
568 return supported;
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000569}
570
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100571bool RefLayerSupport::IsDepthToSpaceSupported(const TensorInfo& input,
572 const TensorInfo& output,
573 const DepthToSpaceDescriptor& descriptor,
574 Optional<std::string&> reasonIfUnsupported) const
575{
Jan Eilers8eb25602020-03-09 12:13:48 +0000576 IgnoreUnused(descriptor);
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100577 bool supported = true;
578
Sadik Armagan303980c2020-04-17 12:45:14 +0100579 std::array<DataType,6> supportedTypes =
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100580 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000581 DataType::BFloat16,
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100582 DataType::Float32,
583 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100584 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000585 DataType::QAsymmU8,
586 DataType::QSymmS16
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100587 };
588
589 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
590 "Reference DepthToSpace: input type not supported");
591
592 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
593 "Reference DepthToSpace: output type not supported");
594
595 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
596 "Reference DepthToSpace: input and output types are mismatched");
597
598 return supported;
599}
600
arovir011c7c81b2018-10-08 11:34:28 +0100601bool RefLayerSupport::IsDepthwiseConvolutionSupported(const TensorInfo& input,
602 const TensorInfo& output,
603 const DepthwiseConvolution2dDescriptor& descriptor,
604 const TensorInfo& weights,
605 const Optional<TensorInfo>& biases,
606 Optional<std::string&> reasonIfUnsupported) const
607{
Sadik Armagan303980c2020-04-17 12:45:14 +0100608 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100609 bool supported = true;
610
611 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000612 std::array<DataType,7> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100613 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000614 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100615 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100616 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000617 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000618 DataType::QAsymmU8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100619 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000620 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100621 };
622
623 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
624 "Reference DepthwiseConvolution2d: input is not a supported type.");
625
626 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
627 "Reference DepthwiseConvolution2d: output is not a supported type.");
628
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100629 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
630 "Reference DepthwiseConvolution2d: input and output types mismatched.");
631
Teresa Charlind8df0262019-11-11 12:28:15 +0000632 const DataType inputType = input.GetDataType();
Keith Davis0c2eeac2020-02-11 16:51:50 +0000633 if (IsQuantized8BitType(inputType))
Teresa Charlind8df0262019-11-11 12:28:15 +0000634 {
Sadik Armagan303980c2020-04-17 12:45:14 +0100635 ARMNN_NO_DEPRECATE_WARN_BEGIN
636 std::array<DataType, 4> supportedWeightTypes =
637 {
638 DataType::QAsymmS8,
639 DataType::QAsymmU8,
640 DataType::QSymmS8,
641 DataType::QuantizedSymm8PerAxis // deprecated
642 };
643 ARMNN_NO_DEPRECATE_WARN_END
Teresa Charlind8df0262019-11-11 12:28:15 +0000644
645 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
Sadik Armagan303980c2020-04-17 12:45:14 +0100646 "Reference DepthwiseConvolution2d: weights type not supported for "
647 "quantized input.");
Teresa Charlind8df0262019-11-11 12:28:15 +0000648 }
649 else
650 {
651 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
652 "Reference DepthwiseConvolution2d: weights is not a supported type.");
653
654 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
655 "Reference DepthwiseConvolution2d: input and weights types mismatched.");
656 }
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100657
658 if (biases.has_value())
659 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000660 std::array<DataType,4> biasesSupportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100661 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000662 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100663 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100664 DataType::Float16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100665 DataType::Signed32
666 };
667 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
668 "Reference DepthwiseConvolution2d: biases is not a supported type.");
669 }
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100670
671 return supported;
672
arovir011c7c81b2018-10-08 11:34:28 +0100673}
674
Nattapat Chaimanowong8a54ac02019-03-29 15:25:04 +0000675bool RefLayerSupport::IsDequantizeSupported(const TensorInfo& input,
676 const TensorInfo& output,
677 Optional<std::string&> reasonIfUnsupported) const
678{
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100679 bool supported = true;
680
Ryan OShea9add1202020-02-07 10:06:33 +0000681 std::array<DataType,4> supportedInputTypes = {
682 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000683 DataType::QAsymmU8,
Finn Williamsfd271062019-12-04 14:27:27 +0000684 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000685 DataType::QSymmS16
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100686 };
687
688 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000689 "Reference for Dequantize layer: input type not supported.");
690
691 supported &= CheckSupportRule( TypeNotPerAxisQuantized(input), reasonIfUnsupported,
692 "Reference for Dequantize layer: per-axis quantized input not support .");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100693
Derek Lambertid466a542020-01-22 15:37:29 +0000694 supported &= CheckSupportRule(TypeNotPerAxisQuantized(input), reasonIfUnsupported,
695 "Reference dequantize: per-axis quantized input not support .");
696
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000697 std::array<DataType,3> supportedOutputTypes = {
698 DataType::BFloat16,
Jan Eilersf7107932019-11-01 11:09:36 +0000699 DataType::Float32,
700 DataType::Float16
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100701 };
702
703 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000704 "Reference for Dequantize layer: output type not supported.");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100705
706 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000707 "Reference for Dequantize layer: input/output shapes have different num total "
708 "elements.");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100709
710 return supported;
Nattapat Chaimanowong8a54ac02019-03-29 15:25:04 +0000711}
712
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000713bool RefLayerSupport::IsDetectionPostProcessSupported(const TensorInfo& boxEncodings,
714 const TensorInfo& scores,
715 const TensorInfo& anchors,
716 const TensorInfo& detectionBoxes,
717 const TensorInfo& detectionClasses,
718 const TensorInfo& detectionScores,
719 const TensorInfo& numDetections,
720 const DetectionPostProcessDescriptor& descriptor,
721 Optional<std::string&> reasonIfUnsupported) const
Narumol Prangnawaratbc67cef2019-01-31 15:31:54 +0000722{
Jan Eilers8eb25602020-03-09 12:13:48 +0000723 IgnoreUnused(anchors, detectionBoxes, detectionClasses, detectionScores, numDetections, descriptor);
Derek Lamberti901ea112019-12-10 22:07:09 +0000724
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100725 bool supported = true;
726
Sadik Armagan303980c2020-04-17 12:45:14 +0100727 std::array<DataType,5> supportedInputTypes =
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100728 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000729 DataType::BFloat16,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100730 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +0100731 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000732 DataType::QAsymmU8,
733 DataType::QSymmS16
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100734 };
735
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000736 supported &= CheckSupportRule(TypeAnyOf(boxEncodings, supportedInputTypes), reasonIfUnsupported,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100737 "Reference DetectionPostProcess: input 0 is not a supported type.");
738
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000739 supported &= CheckSupportRule(TypeAnyOf(scores, supportedInputTypes), reasonIfUnsupported,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100740 "Reference DetectionPostProcess: input 1 is not a supported type.");
741
742 return supported;
Narumol Prangnawaratbc67cef2019-01-31 15:31:54 +0000743}
744
Pablo Tellof0bd6832019-04-26 17:58:13 +0100745bool RefLayerSupport::IsDilatedDepthwiseConvolutionSupported(const TensorInfo& input,
746 const TensorInfo& output,
747 const DepthwiseConvolution2dDescriptor& descriptor,
748 const TensorInfo& weights,
749 const Optional<TensorInfo>& biases,
750 Optional<std::string&> reasonIfUnsupported) const
751{
Aron Virginas-Taraece4ed2019-06-14 17:00:09 +0100752 return IsDepthwiseConvolutionSupported(input, output, descriptor, weights, biases, reasonIfUnsupported);
Pablo Tellof0bd6832019-04-26 17:58:13 +0100753}
754
Aron Virginas-Taraece4ed2019-06-14 17:00:09 +0100755bool RefLayerSupport::IsDivisionSupported(const TensorInfo& input0,
arovir011c7c81b2018-10-08 11:34:28 +0100756 const TensorInfo& input1,
757 const TensorInfo& output,
758 Optional<std::string&> reasonIfUnsupported) const
759{
Sadik Armagan2999a022019-04-09 14:20:12 +0100760 bool supported = true;
761
Sadik Armagan303980c2020-04-17 12:45:14 +0100762 std::array<DataType,6> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000763 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +0100764 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100765 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100766 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000767 DataType::QAsymmU8,
768 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +0100769 };
770
771 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
772 "Reference division: input 0 is not a supported type.");
773
774 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
775 "Reference division: input 1 is not a supported type.");
776
777 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
778 "Reference division: output is not a supported type.");
779
780 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
781 "Reference division: input 0 and Input 1 types are mismatched");
782
783 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
784 "Reference division: input and output types are mismatched");
785
786 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
787 "Reference division: shapes are not suitable for implicit broadcast.");
788
789 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100790}
791
josh minor4a3c6102020-01-06 16:40:46 -0600792bool RefLayerSupport::IsElementwiseUnarySupported(const TensorInfo& input,
793 const TensorInfo& output,
794 const ElementwiseUnaryDescriptor& descriptor,
795 Optional<std::string&> reasonIfUnsupported) const
796{
Jan Eilers8eb25602020-03-09 12:13:48 +0000797 IgnoreUnused(descriptor);
josh minor4a3c6102020-01-06 16:40:46 -0600798
Sadik Armagan303980c2020-04-17 12:45:14 +0100799 std::array<DataType, 7> supportedTypes =
josh minor4a3c6102020-01-06 16:40:46 -0600800 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000801 DataType::BFloat16,
josh minor4a3c6102020-01-06 16:40:46 -0600802 DataType::Float32,
803 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100804 DataType::QAsymmS8,
josh minor4a3c6102020-01-06 16:40:46 -0600805 DataType::QAsymmU8,
Sadik Armaganac472102020-03-24 09:54:36 +0000806 DataType::QSymmS16,
807 DataType::Signed32
josh minor4a3c6102020-01-06 16:40:46 -0600808 };
809
810 bool supported = true;
811
812 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
813 "Reference elementwise unary: input type not supported");
814
815 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
816 "Reference elementwise unary: output type not supported");
817
818 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
819 "Reference elementwise unary: input and output types not matching");
820
821 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
822 "Reference elementwise unary: input and output shapes"
823 "have different number of total elements");
824
825 return supported;
826}
827
FrancisMurtagh30cdfca2018-12-18 12:57:35 +0000828bool RefLayerSupport::IsEqualSupported(const TensorInfo& input0,
829 const TensorInfo& input1,
830 const TensorInfo& output,
831 Optional<std::string&> reasonIfUnsupported) const
832{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100833 return IsComparisonSupported(input0,
834 input1,
835 output,
836 ComparisonDescriptor(ComparisonOperation::Equal),
837 reasonIfUnsupported);
FrancisMurtagh30cdfca2018-12-18 12:57:35 +0000838}
839
arovir011c7c81b2018-10-08 11:34:28 +0100840bool RefLayerSupport::IsFakeQuantizationSupported(const TensorInfo& input,
841 const FakeQuantizationDescriptor& descriptor,
842 Optional<std::string&> reasonIfUnsupported) const
843{
Jan Eilers8eb25602020-03-09 12:13:48 +0000844 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100845 bool supported = true;
846
847 std::array<DataType,1> supportedTypes =
848 {
849 DataType::Float32
850 };
851
852 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
853 "Reference fake quantization: input type not supported.");
854
855 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100856}
857
858bool RefLayerSupport::IsFloorSupported(const TensorInfo& input,
859 const TensorInfo& output,
860 Optional<std::string&> reasonIfUnsupported) const
861{
Jan Eilers8eb25602020-03-09 12:13:48 +0000862 IgnoreUnused(output);
James Conroy83735b12019-05-30 16:36:59 +0100863 bool supported = true;
864
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000865 std::array<DataType,4> supportedTypes =
James Conroy83735b12019-05-30 16:36:59 +0100866 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000867 DataType::BFloat16,
James Conroyb40d7102019-06-04 12:32:09 +0100868 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100869 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000870 DataType::QSymmS16
James Conroy83735b12019-05-30 16:36:59 +0100871 };
872
873 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
874 "Reference Floor: input type not supported.");
875
876 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
877 "Reference Floor: output type not supported.");
878
879 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100880}
881
882bool RefLayerSupport::IsFullyConnectedSupported(const TensorInfo& input,
883 const TensorInfo& output,
884 const TensorInfo& weights,
885 const TensorInfo& biases,
886 const FullyConnectedDescriptor& descriptor,
887 Optional<std::string&> reasonIfUnsupported) const
888{
Francis Murtagh46c09d02019-05-28 08:15:28 +0100889 bool supported = true;
890
891 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000892 std::array<DataType,6> supportedTypes =
Francis Murtagh46c09d02019-05-28 08:15:28 +0100893 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000894 DataType::BFloat16,
895 DataType::Float32,
896 DataType::Float16,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000897 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100898 DataType::QAsymmU8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000899 DataType::QSymmS16
Francis Murtagh46c09d02019-05-28 08:15:28 +0100900 };
901
902 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
903 "Reference Fully Connected: input type not supported.");
904
905 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
906 "Reference Fully Connected: output type not supported.");
907
Francis Murtagh46c09d02019-05-28 08:15:28 +0100908 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
909 "Reference Fully Connected: weights type not supported.");
910
Narumol Prangnawarat57ef0082020-03-26 09:20:43 +0000911 // For FullyConnected, we allow to have BFloat16 input with Float32 output for optimization.
912 if (input.GetDataType() == DataType::BFloat16)
913 {
914 if (output.GetDataType() != DataType::BFloat16 && output.GetDataType() != DataType::Float32)
915 {
916 reasonIfUnsupported.value() += "Output tensor type must be BFloat16 or Float32 for BFloat16 input.\n";
917 supported = false;
918 }
919 }
920 else
921 {
922 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
923 "Reference Fully Connected: input and output types mismatched.");
924 }
925
Francis Murtaghddb1d062020-03-10 13:51:45 +0000926 ARMNN_NO_DEPRECATE_WARN_BEGIN
Sadik Armagan303980c2020-04-17 12:45:14 +0100927 std::array<DataType, 4> supportedWeightTypes =
Francis Murtaghddb1d062020-03-10 13:51:45 +0000928 {
Sadik Armagan303980c2020-04-17 12:45:14 +0100929 DataType::QAsymmS8,
Francis Murtaghddb1d062020-03-10 13:51:45 +0000930 DataType::QAsymmU8,
931 DataType::QSymmS8,
932 DataType::QuantizedSymm8PerAxis // deprecated
933 };
934 ARMNN_NO_DEPRECATE_WARN_END
935
936 if (IsQuantized8BitType(input.GetDataType()))
937 {
938
939 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
940 "Reference Fully Connected: weights type not supported for quantized input.");
941 }
942 else
943 {
944 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
945 "Reference Fully Connected: weights is not a supported type.");
946
947 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
948 "Reference Fully Connected: input and weights types mismatched.");
949 }
Francis Murtagh46c09d02019-05-28 08:15:28 +0100950
951 if (descriptor.m_BiasEnabled)
952 {
953 // Defined supported types for bias
Sadik Armagandb73c982020-04-01 17:35:30 +0100954 std::array<DataType, 5>
Francis Murtagh46c09d02019-05-28 08:15:28 +0100955 supportedBiasTypes =
956 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000957 DataType::BFloat16,
Francis Murtagh46c09d02019-05-28 08:15:28 +0100958 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100959 DataType::Float16,
Sadik Armagandb73c982020-04-01 17:35:30 +0100960 DataType::Signed32,
961 DataType::QAsymmS8
Francis Murtagh46c09d02019-05-28 08:15:28 +0100962 };
963
964 supported &= CheckSupportRule(TypeAnyOf(biases, supportedBiasTypes), reasonIfUnsupported,
965 "Reference Fully Connected: bias type not supported.");
966
967 supported &= CheckSupportRule(BiasAndWeightsTypesMatch(biases, weights), reasonIfUnsupported,
968 "Reference Fully Connected: bias and weight types mismatch.");
969
970 supported &= CheckSupportRule(BiasAndWeightsTypesCompatible(weights, supportedBiasTypes), reasonIfUnsupported,
971 "Reference Fully Connected: bias type inferred from weights is incompatible.");
972
Narumol Prangnawarat366d7232020-04-29 12:58:17 +0100973 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(biases, 1U), reasonIfUnsupported,
974 "Reference Fully Connected: bias must have 1 dimension.");
975
Francis Murtagh46c09d02019-05-28 08:15:28 +0100976 }
977
978 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100979}
980
narpra014951d842019-01-18 16:53:53 +0000981bool RefLayerSupport::IsGatherSupported(const armnn::TensorInfo& input0,
982 const armnn::TensorInfo& input1,
983 const armnn::TensorInfo& output,
984 armnn::Optional<std::string&> reasonIfUnsupported) const
985{
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100986 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +0100987 std::array<DataType,6> supportedTypes =
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100988 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000989 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100990 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100991 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100992 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000993 DataType::QAsymmU8,
994 DataType::QSymmS16
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100995 };
996
997 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
998 "Reference Gather: input type not supported");
999
1000 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1001 "Reference Gather: output type not supported");
1002
1003 supported &= CheckSupportRule(TypeIs(input1, DataType::Signed32), reasonIfUnsupported,
1004 "Reference Gather: indices (input1) type not supported");
1005
1006 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1007 "Reference Gather: input and output types not matching");
1008
1009 return supported;
narpra014951d842019-01-18 16:53:53 +00001010}
1011
FrancisMurtagh878f0232018-12-19 10:56:15 +00001012bool RefLayerSupport::IsGreaterSupported(const TensorInfo& input0,
1013 const TensorInfo& input1,
1014 const TensorInfo& output,
1015 Optional<std::string&> reasonIfUnsupported) const
1016{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +01001017 return IsComparisonSupported(input0,
1018 input1,
1019 output,
1020 ComparisonDescriptor(ComparisonOperation::Greater),
1021 reasonIfUnsupported);
FrancisMurtagh878f0232018-12-19 10:56:15 +00001022}
1023
Derek Lamberti901ea112019-12-10 22:07:09 +00001024bool RefLayerSupport::IsInputSupported(const TensorInfo& /*input*/,
1025 Optional<std::string&> /*reasonIfUnsupported*/) const
arovir011c7c81b2018-10-08 11:34:28 +01001026{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +01001027 return true;
arovir011c7c81b2018-10-08 11:34:28 +01001028}
1029
Kevin May09ca49c2019-10-09 12:37:34 +01001030bool RefLayerSupport::IsInstanceNormalizationSupported(const TensorInfo& input,
1031 const TensorInfo& output,
1032 const InstanceNormalizationDescriptor& descriptor,
1033 Optional<std::string&> reasonIfUnsupported) const
1034{
Jan Eilers8eb25602020-03-09 12:13:48 +00001035 IgnoreUnused(descriptor);
Kevin May09ca49c2019-10-09 12:37:34 +01001036 // Define supported types
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001037 std::array<DataType, 3> supportedTypes =
Kevin May09ca49c2019-10-09 12:37:34 +01001038 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001039 DataType::BFloat16,
Kevin May09ca49c2019-10-09 12:37:34 +01001040 DataType::Float32,
1041 DataType::Float16
1042 };
1043
1044 bool supported = true;
1045
1046 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1047 "Reference Instance Normalization: input type not supported.");
1048
1049 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1050 "Reference Instance Normalization: output type not supported.");
1051
1052 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1053 "Reference Instance Normalization: input and output types mismatched.");
1054
1055 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1056 "Reference Instance Normalization: input and output shapes have different "
1057 "num total elements.");
1058
1059 return supported;
1060}
1061
arovir011c7c81b2018-10-08 11:34:28 +01001062bool RefLayerSupport::IsL2NormalizationSupported(const TensorInfo& input,
1063 const TensorInfo& output,
1064 const L2NormalizationDescriptor& descriptor,
1065 Optional<std::string&> reasonIfUnsupported) const
1066{
Jan Eilers8eb25602020-03-09 12:13:48 +00001067 IgnoreUnused(descriptor);
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001068 // Define supported types
Sadik Armagan303980c2020-04-17 12:45:14 +01001069 std::array<DataType, 6> supportedTypes =
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001070 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001071 DataType::BFloat16,
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001072 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001073 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001074 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001075 DataType::QAsymmU8,
1076 DataType::QSymmS16
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001077 };
1078
1079 bool supported = true;
1080
1081 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1082 "Reference L2normalization: input type not supported.");
1083
1084 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1085 "Reference L2normalization: output type not supported.");
1086
1087 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1088 "Reference L2normalization: input and output types mismatched.");
1089
1090 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1091 "Reference L2normalization: input and output shapes have different "
1092 "num total elements.");
1093
1094 return supported;
arovir011c7c81b2018-10-08 11:34:28 +01001095}
1096
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001097bool RefLayerSupport::IsLogSoftmaxSupported(const TensorInfo& input,
1098 const TensorInfo& output,
1099 const LogSoftmaxDescriptor& descriptor,
1100 Optional<std::string&> reasonIfUnsupported) const
1101{
Jan Eilers8eb25602020-03-09 12:13:48 +00001102 IgnoreUnused(descriptor);
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001103
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001104 std::array<DataType, 3> supportedTypes =
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001105 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001106 DataType::BFloat16,
1107 DataType::Float32,
1108 DataType::Float16
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001109 };
1110
1111 bool supported = true;
1112 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1113 "Reference LogSoftmax: input type not supported");
1114
1115 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1116 "Reference LogSoftmax: output type not supported");
1117
1118 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1119 "Reference LogSoftmax: input and output types do not match");
1120
1121 return supported;
1122}
1123
arovir011c7c81b2018-10-08 11:34:28 +01001124bool RefLayerSupport::IsLstmSupported(const TensorInfo& input,
1125 const TensorInfo& outputStateIn,
1126 const TensorInfo& cellStateIn,
1127 const TensorInfo& scratchBuffer,
1128 const TensorInfo& outputStateOut,
1129 const TensorInfo& cellStateOut,
1130 const TensorInfo& output,
1131 const LstmDescriptor& descriptor,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001132 const LstmInputParamsInfo& paramsInfo,
1133 Optional<std::string&> reasonIfUnsupported) const
arovir011c7c81b2018-10-08 11:34:28 +01001134{
Jan Eilers8eb25602020-03-09 12:13:48 +00001135 IgnoreUnused(descriptor);
1136 IgnoreUnused(paramsInfo);
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001137
1138 bool supported = true;
1139
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001140 std::array<DataType,3> supportedTypes = {
1141 DataType::BFloat16,
Conor Kennedyb9971c92019-05-07 07:14:23 +01001142 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001143 DataType::QSymmS16
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001144 };
1145
Jan Eilersd01a83c2019-07-03 18:20:40 +01001146 // check inputs and outputs
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001147 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1148 "Reference Lstm: input is not a supported type.");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001149 supported &= CheckSupportRule(TypesAreEqual(input, outputStateIn), reasonIfUnsupported,
1150 "Reference Lstm: input and outputStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001151 supported &= CheckSupportRule(TypesAreEqual(input, cellStateIn), reasonIfUnsupported,
1152 "Reference Lstm: input and cellStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001153 supported &= CheckSupportRule(TypesAreEqual(input, scratchBuffer), reasonIfUnsupported,
1154 "Reference Lstm: input and scratchBuffer types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001155 supported &= CheckSupportRule(TypesAreEqual(input, outputStateOut), reasonIfUnsupported,
1156 "Reference Lstm: input and outputStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001157 supported &= CheckSupportRule(TypesAreEqual(input, cellStateOut), reasonIfUnsupported,
1158 "Reference Lstm: input and cellStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001159 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1160 "Reference Lstm: input and output types are mismatched");
Jan Eilersd01a83c2019-07-03 18:20:40 +01001161 // check layer parameters
Francis Murtaghbb590b42019-08-14 09:51:36 +01001162 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001163 "Reference Lstm: input and InputToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001164 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001165 "Reference Lstm: input and InputToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001166 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001167 "Reference Lstm: input and InputToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001168 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001169 "Reference Lstm: input and RecurrentToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001170 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001171 "Reference Lstm: input and RecurrentToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001172 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001173 "Reference Lstm: input and RecurrentToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001174 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001175 "Reference Lstm: input and ForgetGateBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001176 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001177 "Reference Lstm: input and CellBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001178 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001179 "Reference Lstm: input and OutputGateBias types are mismatched");
1180 if (!descriptor.m_CifgEnabled)
1181 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001182 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToInputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001183 "Reference Lstm: input and InputToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001184 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001185 reasonIfUnsupported,
1186 "Reference Lstm: input and RecurrentToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001187 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001188 "Reference Lstm: input and InputGateBias types are mismatched");
1189 if (descriptor.m_PeepholeEnabled)
1190 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001191 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001192 reasonIfUnsupported,
1193 "Reference Lstm: input and CellToInputWeights types are mismatched");
1194 }
1195 }
1196 if (descriptor.m_PeepholeEnabled)
1197 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001198 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001199 "Reference Lstm: input and CellToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001200 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001201 "Reference Lstm: input and CellToOutputWeights types are mismatched");
1202 }
1203 if (descriptor.m_ProjectionEnabled)
1204 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001205 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001206 "Reference Lstm: input and mProjectionWeights types are mismatched");
1207 if (paramsInfo.m_ProjectionBias != nullptr)
1208 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001209 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001210 "Reference Lstm: input and ProjectionBias types are mismatched");
1211 }
1212 }
1213 if (descriptor.m_LayerNormEnabled)
1214 {
1215 if (!descriptor.m_CifgEnabled)
1216 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001217 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001218 reasonIfUnsupported,
1219 "Reference Lstm: input and InputLayerNormWeights types are mismatched");
1220 }
Francis Murtaghbb590b42019-08-14 09:51:36 +01001221 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001222 reasonIfUnsupported,
1223 "Reference Lstm: input and ForgetLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001224 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001225 reasonIfUnsupported,
1226 "Reference Lstm: input and CellLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001227 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001228 reasonIfUnsupported,
1229 "Reference Lstm: input and OutputLayerNormWeights types are mismatched");
1230 }
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001231
1232 return supported;
telsoa01c577f2c2018-08-31 09:22:23 +01001233}
1234
saoste012df12b32018-11-28 16:57:20 +00001235bool RefLayerSupport::IsMaximumSupported(const TensorInfo& input0,
1236 const TensorInfo& input1,
1237 const TensorInfo& output,
1238 Optional<std::string&> reasonIfUnsupported) const
1239{
Sadik Armagan2999a022019-04-09 14:20:12 +01001240 bool supported = true;
1241
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001242 std::array<DataType,6> supportedTypes = {
1243 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001244 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001245 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001246 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001247 DataType::QAsymmU8,
1248 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001249 };
1250
1251 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1252 "Reference maximum: input 0 is not a supported type.");
1253
1254 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1255 "Reference maximum: input 1 is not a supported type.");
1256
1257 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1258 "Reference maximum: output is not a supported type.");
1259
1260 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1261 "Reference maximum: input 0 and Input 1 types are mismatched");
1262
1263 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1264 "Reference maximum: input and output types are mismatched");
1265
1266 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1267 "Reference maximum: shapes are not suitable for implicit broadcast.");
1268
1269 return supported;
saoste012df12b32018-11-28 16:57:20 +00001270}
1271
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001272bool RefLayerSupport::IsMeanSupported(const TensorInfo& input,
1273 const TensorInfo& output,
1274 const MeanDescriptor& descriptor,
1275 Optional<std::string&> reasonIfUnsupported) const
narpra0132b90462018-09-13 11:07:48 +01001276{
James Conroy4d1ff582019-06-10 17:06:39 +01001277 bool supported = true;
1278 std::string meanLayerStr = "Mean";
1279 std::string outputTensorStr = "output";
1280
Sadik Armagan303980c2020-04-17 12:45:14 +01001281 std::array<DataType,6> supportedTypes =
James Conroy4d1ff582019-06-10 17:06:39 +01001282 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001283 DataType::BFloat16,
James Conroy4d1ff582019-06-10 17:06:39 +01001284 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001285 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001286 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001287 DataType::QAsymmU8,
1288 DataType::QSymmS16
James Conroy4d1ff582019-06-10 17:06:39 +01001289 };
1290
1291 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1292 "Reference Mean: input type not supported.");
1293
1294 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1295 "Reference Mean: input and output types are mismatched");
1296
1297 if (descriptor.m_KeepDims)
1298 {
1299 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, input.GetNumDimensions()),
1300 reasonIfUnsupported,
1301 CreateIncorrectDimensionsErrorMsg(input.GetNumDimensions(),
1302 output.GetNumDimensions(),
1303 meanLayerStr, outputTensorStr).data());
1304 }
1305 else if (descriptor.m_Axis.empty())
1306 {
1307 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1308 reasonIfUnsupported,
1309 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1310 meanLayerStr, outputTensorStr).data());
1311 }
1312 else
1313 {
1314 auto outputDim = input.GetNumDimensions() - boost::numeric_cast<unsigned int>(descriptor.m_Axis.size());
1315
1316 if (outputDim > 0)
1317 {
1318 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, outputDim),
1319 reasonIfUnsupported,
1320 CreateIncorrectDimensionsErrorMsg(outputDim, output.GetNumDimensions(),
1321 meanLayerStr, outputTensorStr).data());
1322 }
1323 else
1324 {
1325 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1326 reasonIfUnsupported,
1327 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1328 meanLayerStr, outputTensorStr).data());
1329 }
1330 }
1331
1332 return supported;
narpra0132b90462018-09-13 11:07:48 +01001333}
1334
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001335bool RefLayerSupport::IsMergerSupported(const std::vector<const TensorInfo*> inputs,
Nikhil Raj8599a412018-11-19 14:51:07 +00001336 const TensorInfo& output,
Jim Flynne242f2d2019-05-22 14:24:13 +01001337 const MergerDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001338 Optional<std::string&> reasonIfUnsupported) const
1339{
Jim Flynne242f2d2019-05-22 14:24:13 +01001340 return IsConcatSupported(inputs, output, descriptor, reasonIfUnsupported);
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001341}
1342
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001343bool RefLayerSupport::IsMemCopySupported(const TensorInfo &input,
1344 const TensorInfo &output,
1345 Optional<std::string &> reasonIfUnsupported) const
1346{
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001347 bool supported = true;
1348
Sadik Armagan303980c2020-04-17 12:45:14 +01001349 std::array<DataType,7> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001350 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001351 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001352 DataType::Float32,
1353 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001354 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001355 DataType::QAsymmU8,
1356 DataType::QSymmS16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001357 DataType::Boolean
1358 };
1359
1360 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1361 "Reference MemCopy: input type not supported");
1362
1363 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1364 "Reference MemCopy: output type not supported");
1365
1366 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1367 "Reference MemCopy: input and output types are mismatched");
1368
1369 return supported;
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001370}
1371
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001372bool RefLayerSupport::IsMinimumSupported(const TensorInfo& input0,
1373 const TensorInfo& input1,
1374 const TensorInfo& output,
1375 Optional<std::string&> reasonIfUnsupported) const
1376{
Sadik Armagan2999a022019-04-09 14:20:12 +01001377 bool supported = true;
1378
Sadik Armagan303980c2020-04-17 12:45:14 +01001379 std::array<DataType,6> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001380 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001381 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001382 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001383 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001384 DataType::QAsymmU8,
1385 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001386 };
1387
1388 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1389 "Reference minimum: input 0 is not a supported type.");
1390
1391 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1392 "Reference minimum: input 1 is not a supported type.");
1393
1394 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1395 "Reference minimum: output is not a supported type.");
1396
1397 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1398 "Reference minimum: input 0 and Input 1 types are mismatched");
1399
1400 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1401 "Reference minimum: input and output types are mismatched");
1402
1403 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1404 "Reference minimum: shapes are not suitable for implicit broadcast.");
1405
1406 return supported;
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001407}
1408
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001409bool RefLayerSupport::IsMultiplicationSupported(const TensorInfo& input0,
1410 const TensorInfo& input1,
1411 const TensorInfo& output,
1412 Optional<std::string&> reasonIfUnsupported) const
1413{
Sadik Armagan2999a022019-04-09 14:20:12 +01001414 bool supported = true;
1415
Keith Davis67e6c542020-02-19 10:08:33 +00001416 std::array<DataType,6> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001417 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001418 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001419 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001420 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001421 DataType::QAsymmU8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001422 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001423 };
1424
1425 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1426 "Reference multiplication: input 0 is not a supported type.");
1427
1428 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1429 "Reference multiplication: input 1 is not a supported type.");
1430
1431 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1432 "Reference multiplication: output is not a supported type.");
1433
1434 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1435 "Reference multiplication: input 0 and Input 1 types are mismatched");
1436
1437 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1438 "Reference multiplication: input and output types are mismatched");
1439
1440 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1441 "Reference multiplication: shapes are not suitable for implicit broadcast.");
1442
1443 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001444}
1445
1446bool RefLayerSupport::IsNormalizationSupported(const TensorInfo& input,
1447 const TensorInfo& output,
1448 const NormalizationDescriptor& descriptor,
1449 Optional<std::string&> reasonIfUnsupported) const
Nina Drozd661dfa72018-10-02 11:14:17 +01001450{
Jan Eilers8eb25602020-03-09 12:13:48 +00001451 IgnoreUnused(descriptor);
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001452
1453 // Define supported types
Sadik Armagan303980c2020-04-17 12:45:14 +01001454 std::array<DataType, 6> supportedTypes =
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001455 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001456 DataType::BFloat16,
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001457 DataType::Float16,
1458 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001459 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001460 DataType::QAsymmU8,
1461 DataType::QSymmS16
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001462 };
1463
1464 bool supported = true;
1465
1466 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1467 "Reference normalization: input type not supported.");
1468
1469 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1470 "Reference normalization: output type not supported.");
1471
1472 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1473 "Reference normalization: input and output shapes have different "
1474 "num total elements.");
1475
1476 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001477}
1478
Derek Lamberti901ea112019-12-10 22:07:09 +00001479bool RefLayerSupport::IsOutputSupported(const TensorInfo& /*output*/,
1480 Optional<std::string&> /*reasonIfUnsupported*/) const
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001481{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +01001482 return true;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001483}
1484
1485bool RefLayerSupport::IsPadSupported(const TensorInfo& input,
1486 const TensorInfo& output,
1487 const PadDescriptor& descriptor,
1488 Optional<std::string&> reasonIfUnsupported) const
1489{
Jan Eilers8eb25602020-03-09 12:13:48 +00001490 IgnoreUnused(descriptor);
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001491 bool supported = true;
1492
1493 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01001494 std::array<DataType,6> supportedTypes =
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001495 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001496 DataType::BFloat16,
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001497 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001498 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001499 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001500 DataType::QAsymmU8,
1501 DataType::QSymmS16
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001502 };
1503
1504 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1505 "Reference pad: input is not a supported type.");
1506
1507 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1508 "Reference pad: output is not a supported type.");
1509
1510 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1511 "Reference pad: input and output types are mismatched.");
1512
1513 return supported;
Nina Drozd661dfa72018-10-02 11:14:17 +01001514}
1515
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001516bool RefLayerSupport::IsPermuteSupported(const TensorInfo& input,
1517 const TensorInfo& output,
1518 const PermuteDescriptor& descriptor,
1519 Optional<std::string&> reasonIfUnsupported) const
1520{
Jan Eilers8eb25602020-03-09 12:13:48 +00001521 IgnoreUnused(descriptor);
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001522 bool supported = true;
1523
1524 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01001525 std::array<DataType, 6> supportedTypes =
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001526 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001527 DataType::BFloat16,
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001528 DataType::Float32,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00001529 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001530 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001531 DataType::QAsymmU8,
1532 DataType::QSymmS16
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001533 };
1534
1535 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1536 "Reference permute: input is not a supported type.");
1537
1538 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1539 "Reference permute: output is not a supported type.");
1540
1541 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1542 "Reference permute: input and output types are mismatched.");
1543
1544 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001545}
1546
1547bool RefLayerSupport::IsPooling2dSupported(const TensorInfo& input,
1548 const TensorInfo& output,
1549 const Pooling2dDescriptor& descriptor,
1550 Optional<std::string&> reasonIfUnsupported) const
1551{
Jan Eilers8eb25602020-03-09 12:13:48 +00001552 IgnoreUnused(descriptor);
Teresa Charlina3b20472019-06-06 11:12:32 +01001553 bool supported = true;
1554
1555 // Define supported output and inputs types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001556 std::array<DataType,6> supportedTypes =
Teresa Charlina3b20472019-06-06 11:12:32 +01001557 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001558 DataType::BFloat16,
Teresa Charlina3b20472019-06-06 11:12:32 +01001559 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001560 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001561 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001562 DataType::QAsymmU8,
1563 DataType::QSymmS16
Teresa Charlina3b20472019-06-06 11:12:32 +01001564 };
1565
1566 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1567 "Reference poolind2d: input is not a supported type.");
1568
1569 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1570 "Reference poolind2d: output is not a supported type.");
1571
1572 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1573 "Reference poolind2d: input and output types are mismatched.");
1574
1575 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001576}
1577
James Conroy4f1f8992020-04-29 20:01:10 +01001578bool RefLayerSupport::IsQLstmSupported(const TensorInfo& input,
1579 const TensorInfo& previousOutputIn,
1580 const TensorInfo& previousCellStateIn,
1581 const TensorInfo& outputStateOut,
1582 const TensorInfo& cellStateOut,
1583 const TensorInfo& output,
1584 const QLstmDescriptor& descriptor,
1585 const LstmInputParamsInfo& paramsInfo,
1586 Optional<std::string&> reasonIfUnsupported) const
1587{
1588 IgnoreUnused(input);
1589 IgnoreUnused(previousOutputIn);
1590 IgnoreUnused(previousCellStateIn);
1591 IgnoreUnused(outputStateOut);
1592 IgnoreUnused(cellStateOut);
1593 IgnoreUnused(output);
1594 IgnoreUnused(descriptor);
1595 IgnoreUnused(paramsInfo);
1596
1597 IgnoreUnused(reasonIfUnsupported);
1598
1599 return true;
1600}
1601
Derek Lamberti5f400d62019-03-25 15:41:58 +00001602bool RefLayerSupport::IsQuantizeSupported(const TensorInfo& input,
1603 const TensorInfo& output,
1604 Optional<std::string&> reasonIfUnsupported) const
1605{
1606 bool supported = true;
1607
Finn Williamsfd271062019-12-04 14:27:27 +00001608 // Define supported input types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001609 std::array<DataType,7> supportedInputTypes = {
1610 DataType::BFloat16,
Keith Davis5e51cd82020-01-29 16:52:59 +00001611 DataType::Float32,
Keith Davis3d8bc972020-02-04 09:31:47 +00001612 DataType::Float16,
Ryan OShea9add1202020-02-07 10:06:33 +00001613 DataType::QAsymmS8,
Keith Davis5e51cd82020-01-29 16:52:59 +00001614 DataType::QAsymmU8,
1615 DataType::QSymmS8,
1616 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001617 };
1618
1619 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
1620 "Reference quantize: input type not supported.");
1621
1622 // Define supported output types.
Ryan OShea9add1202020-02-07 10:06:33 +00001623 std::array<DataType,4> supportedOutputTypes = {
Ryan OShea9add1202020-02-07 10:06:33 +00001624 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001625 DataType::QAsymmU8,
Finn Williamsfd271062019-12-04 14:27:27 +00001626 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001627 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001628 };
1629 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
1630 "Reference quantize: output type not supported.");
1631
1632 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1633 "Reference quantize: input and output shapes have different num total elements.");
1634
1635 return supported;
1636}
1637
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001638bool RefLayerSupport::IsReshapeSupported(const TensorInfo& input,
Kevin Maya023c402019-12-12 17:28:05 +00001639 const TensorInfo& output,
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001640 const ReshapeDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001641 Optional<std::string&> reasonIfUnsupported) const
1642{
Jan Eilers8eb25602020-03-09 12:13:48 +00001643 IgnoreUnused(output);
1644 IgnoreUnused(descriptor);
Nina Drozd2f2778f2019-05-27 10:37:05 +01001645 // Define supported output types.
Keith Davis0c2eeac2020-02-11 16:51:50 +00001646 std::array<DataType,7> supportedOutputTypes =
Nina Drozd2f2778f2019-05-27 10:37:05 +01001647 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001648 DataType::BFloat16,
Nina Drozd2f2778f2019-05-27 10:37:05 +01001649 DataType::Float32,
1650 DataType::Float16,
Narumol Prangnawarat0718ee92019-09-13 16:53:38 +01001651 DataType::Signed32,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001652 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001653 DataType::QAsymmU8,
1654 DataType::QSymmS16
Nina Drozd2f2778f2019-05-27 10:37:05 +01001655 };
Keith Davis0c2eeac2020-02-11 16:51:50 +00001656
Nina Drozd2f2778f2019-05-27 10:37:05 +01001657 return CheckSupportRule(TypeAnyOf(input, supportedOutputTypes), reasonIfUnsupported,
1658 "Reference reshape: input type not supported.");
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001659}
1660
1661bool RefLayerSupport::IsResizeBilinearSupported(const TensorInfo& input,
Sadik Armaganc625f002018-12-17 11:32:16 +00001662 const TensorInfo& output,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001663 Optional<std::string&> reasonIfUnsupported) const
1664{
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001665 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001666 std::array<DataType,6> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001667 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001668 DataType::BFloat16,
Teresa Charlin970f43b2019-07-01 13:51:07 +01001669 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001670 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001671 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001672 DataType::QAsymmU8,
1673 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001674 };
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001675
1676 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1677 "Reference ResizeBilinear: input type not supported");
1678
1679 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1680 "Reference ResizeBilinear: output type not supported");
1681
1682 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1683 "Reference ResizeBilinear: input and output types not matching");
1684
1685 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001686}
1687
Teresa Charlin970f43b2019-07-01 13:51:07 +01001688bool RefLayerSupport::IsResizeSupported(const TensorInfo& input,
1689 const TensorInfo& output,
1690 const ResizeDescriptor& descriptor,
1691 Optional<std::string&> reasonIfUnsupported) const
1692{
Jan Eilers8eb25602020-03-09 12:13:48 +00001693 IgnoreUnused(descriptor);
Teresa Charlin970f43b2019-07-01 13:51:07 +01001694 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001695 std::array<DataType,6> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001696 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001697 DataType::BFloat16,
Teresa Charlin970f43b2019-07-01 13:51:07 +01001698 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001699 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001700 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001701 DataType::QAsymmU8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001702 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001703 };
1704
1705 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1706 "Reference Resize: input type not supported");
1707
1708 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1709 "Reference Resize: output type not supported");
1710
1711 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1712 "Reference Resize: input and output types not matching");
1713
1714 return supported;
1715}
1716
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001717bool RefLayerSupport::IsRsqrtSupported(const TensorInfo& input,
1718 const TensorInfo& output,
1719 Optional<std::string&> reasonIfUnsupported) const
1720{
josh minor4a3c6102020-01-06 16:40:46 -06001721 return IsElementwiseUnarySupported(input,
1722 output,
1723 ElementwiseUnaryDescriptor(UnaryOperation::Rsqrt),
1724 reasonIfUnsupported);
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001725}
1726
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001727bool RefLayerSupport::IsSliceSupported(const TensorInfo& input,
1728 const TensorInfo& output,
1729 const SliceDescriptor& descriptor,
1730 Optional<std::string&> reasonIfUnsupported) const
1731{
Jan Eilers8eb25602020-03-09 12:13:48 +00001732 IgnoreUnused(descriptor);
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001733 bool supported = true;
1734
Sadik Armagan303980c2020-04-17 12:45:14 +01001735 std::array<DataType, 5> supportedTypes =
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001736 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001737 DataType::BFloat16,
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001738 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001739 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001740 DataType::QAsymmU8,
1741 DataType::QSymmS16
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001742 };
1743
1744 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1745 "Reference Slice: input type not supported");
1746
1747 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1748 "Reference Slice: output type not supported");
1749
1750 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1751 "Reference Slice: input and output types are mismatched");
1752
1753 return supported;
1754}
1755
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001756bool RefLayerSupport::IsSoftmaxSupported(const TensorInfo& input,
1757 const TensorInfo& output,
1758 const SoftmaxDescriptor& descriptor,
1759 Optional<std::string&> reasonIfUnsupported) const
1760{
Jan Eilers8eb25602020-03-09 12:13:48 +00001761 IgnoreUnused(descriptor);
nikraj01248683f2019-05-29 16:46:50 +01001762 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001763 std::array<DataType,7> supportedTypes =
nikraj01248683f2019-05-29 16:46:50 +01001764 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001765 DataType::BFloat16,
1766 DataType::Float32,
1767 DataType::Float16,
1768 DataType::QSymmS8,
1769 DataType::QAsymmS8,
1770 DataType::QAsymmU8,
1771 DataType::QSymmS16
nikraj01248683f2019-05-29 16:46:50 +01001772 };
1773
1774 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001775 "Reference Softmax: output type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001776
1777 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001778 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001779
1780 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001781 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001782
1783 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001784}
1785
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001786bool RefLayerSupport::IsSpaceToBatchNdSupported(const TensorInfo& input,
1787 const TensorInfo& output,
1788 const SpaceToBatchNdDescriptor& descriptor,
1789 Optional<std::string&> reasonIfUnsupported) const
1790{
Jan Eilers8eb25602020-03-09 12:13:48 +00001791 IgnoreUnused(descriptor);
nikraj01120522a2019-05-31 11:33:07 +01001792 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001793 std::array<DataType,6> supportedTypes =
nikraj01120522a2019-05-31 11:33:07 +01001794 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001795 DataType::BFloat16,
1796 DataType::Float32,
1797 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001798 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001799 DataType::QAsymmU8,
1800 DataType::QSymmS16
nikraj01120522a2019-05-31 11:33:07 +01001801 };
1802
1803 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1804 "Reference SpaceToBatchNd: input type not supported");
1805
1806 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1807 "Reference SpaceToBatchNd: output type not supported");
1808
1809 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1810 "Reference SpaceToBatchNd: input and output types are mismatched");
1811
1812 return supported;
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001813}
1814
Keith Davisa57eccb2019-06-14 17:33:22 +01001815bool RefLayerSupport::IsSpaceToDepthSupported(const TensorInfo& input,
Keith Davis51910332019-06-26 15:28:43 +01001816 const TensorInfo& output,
1817 const SpaceToDepthDescriptor& descriptor,
1818 Optional<std::string&> reasonIfUnsupported) const
Keith Davisa57eccb2019-06-14 17:33:22 +01001819{
1820
Jan Eilers8eb25602020-03-09 12:13:48 +00001821 IgnoreUnused(descriptor);
Keith Davisa57eccb2019-06-14 17:33:22 +01001822 bool supported = true;
1823
Sadik Armagan303980c2020-04-17 12:45:14 +01001824 std::array<DataType,6> supportedTypes =
Keith Davisa57eccb2019-06-14 17:33:22 +01001825 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001826 DataType::BFloat16,
Keith Davisa57eccb2019-06-14 17:33:22 +01001827 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001828 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001829 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001830 DataType::QAsymmU8,
1831 DataType::QSymmS16
Keith Davisa57eccb2019-06-14 17:33:22 +01001832 };
1833
1834 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1835 "Reference SpaceToDepth: input type not supported");
1836
1837 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1838 "Reference SpaceToDepth: output type not supported");
1839
1840 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1841 "Reference SpaceToDepth: input and output types are mismatched");
1842
1843 return supported;
1844}
1845
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001846bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1847 const ViewsDescriptor& descriptor,
1848 Optional<std::string&> reasonIfUnsupported) const
1849{
Jan Eilers8eb25602020-03-09 12:13:48 +00001850 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001851 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001852 std::array<DataType,6> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001853 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001854 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001855 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001856 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001857 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001858 DataType::QAsymmU8,
1859 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001860 };
1861
1862 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1863 "Reference splitter: input type not supported");
1864
1865 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001866}
1867
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001868bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1869 const std::vector<std::reference_wrapper<TensorInfo>>& outputs,
1870 const ViewsDescriptor& descriptor,
1871 Optional<std::string&> reasonIfUnsupported) const
1872{
Jan Eilers8eb25602020-03-09 12:13:48 +00001873 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001874 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001875 std::array<DataType,6> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001876 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001877 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001878 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001879 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001880 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001881 DataType::QAsymmU8,
1882 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001883 };
1884
1885 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1886 "Reference splitter: output type not supported");
1887 for (const TensorInfo output : outputs)
1888 {
1889 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1890 "Reference splitter: input type not supported");
1891
1892 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1893 "Reference splitter: input and output types mismatched.");
1894 }
1895
1896 return supported;
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001897}
1898
Matthew Jackson81e601c2019-07-11 12:07:09 +01001899bool RefLayerSupport::IsStackSupported(const std::vector<const TensorInfo*>& inputs,
1900 const TensorInfo& output,
1901 const StackDescriptor& descriptor,
1902 Optional<std::string&> reasonIfUnsupported) const
1903{
Jan Eilers8eb25602020-03-09 12:13:48 +00001904 IgnoreUnused(descriptor);
Matthew Jackson81e601c2019-07-11 12:07:09 +01001905
1906 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001907 std::array<DataType,6> supportedTypes =
Matthew Jackson81e601c2019-07-11 12:07:09 +01001908 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001909 DataType::BFloat16,
Matthew Jackson81e601c2019-07-11 12:07:09 +01001910 DataType::Float32,
Matthew Jacksone69c3992019-09-09 14:31:21 +01001911 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001912 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001913 DataType::QAsymmU8,
1914 DataType::QSymmS16
Matthew Jackson81e601c2019-07-11 12:07:09 +01001915 };
1916
1917 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1918 "Reference stack: output type not supported");
1919 for (const TensorInfo* input : inputs)
1920 {
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +01001921 ARMNN_ASSERT(input != nullptr);
Matthew Jackson81e601c2019-07-11 12:07:09 +01001922 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
1923 "Reference stack: input type not supported");
1924
1925 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
1926 "Reference stack: input and output types mismatched.");
1927 }
1928
1929 return supported;
1930}
1931
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00001932bool RefLayerSupport::IsStridedSliceSupported(const TensorInfo& input,
1933 const TensorInfo& output,
1934 const StridedSliceDescriptor& descriptor,
1935 Optional<std::string&> reasonIfUnsupported) const
1936{
Jan Eilers8eb25602020-03-09 12:13:48 +00001937 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001938 bool supported = true;
1939
Sadik Armagan303980c2020-04-17 12:45:14 +01001940 std::array<DataType,5> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001941 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001942 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001943 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001944 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001945 DataType::QAsymmU8,
1946 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001947 };
1948
1949 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1950 "Reference StridedSlice: input type not supported");
1951
1952 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1953 "Reference StridedSlice: output type not supported");
1954
1955 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1956 "Reference StridedSlice: input and output types are mismatched");
1957
1958 return supported;
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00001959}
1960
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001961bool RefLayerSupport::IsSubtractionSupported(const TensorInfo& input0,
1962 const TensorInfo& input1,
1963 const TensorInfo& output,
1964 Optional<std::string&> reasonIfUnsupported) const
1965{
Sadik Armagan2999a022019-04-09 14:20:12 +01001966 bool supported = true;
1967
Sadik Armagan303980c2020-04-17 12:45:14 +01001968 std::array<DataType,6> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001969 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001970 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001971 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001972 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001973 DataType::QAsymmU8,
1974 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001975 };
1976
1977 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1978 "Reference subtraction: input 0 is not a supported type.");
1979
1980 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1981 "Reference subtraction: input 1 is not a supported type.");
1982
1983 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1984 "Reference subtraction: output is not a supported type.");
1985
1986 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1987 "Reference subtraction: input 0 and Input 1 types are mismatched");
1988
1989 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1990 "Reference subtraction: input and output types are mismatched");
1991
1992 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1993 "Reference subtraction: shapes are not suitable for implicit broadcast.");
1994
1995 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001996}
1997
Matteo Martincighab9e5252019-06-13 17:27:46 +01001998bool RefLayerSupport::IsPreluSupported(const TensorInfo& input,
1999 const TensorInfo& alpha,
2000 const TensorInfo& output,
2001 Optional<std::string&> reasonIfUnsupported) const
2002{
2003 bool supported = true;
2004
Sadik Armagan303980c2020-04-17 12:45:14 +01002005 std::array<DataType, 6> supportedTypes
Matteo Martincighab9e5252019-06-13 17:27:46 +01002006 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002007 DataType::BFloat16,
Matteo Martincighab9e5252019-06-13 17:27:46 +01002008 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01002009 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002010 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002011 DataType::QAsymmU8,
2012 DataType::QSymmS16
Matteo Martincighab9e5252019-06-13 17:27:46 +01002013 };
2014
2015 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2016 "PReLU: input is not a supported type.");
2017
2018 supported &= CheckSupportRule(TypeAnyOf(alpha, supportedTypes), reasonIfUnsupported,
2019 "PReLU: alpha is not a supported type.");
2020
2021 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2022 "PReLU: output is not a supported type.");
2023
2024 supported &= CheckSupportRule(TypesAreEqual(input, alpha, output), reasonIfUnsupported,
2025 "PReLU: input, alpha and output types are mismatched");
2026
2027 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input, alpha, output), reasonIfUnsupported,
2028 "PReLU: shapes are not suitable for implicit broadcast");
2029
2030 return supported;
2031}
2032
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002033bool RefLayerSupport::IsTransposeConvolution2dSupported(const TensorInfo& input,
2034 const TensorInfo& output,
2035 const TransposeConvolution2dDescriptor& descriptor,
2036 const TensorInfo& weights,
2037 const Optional<TensorInfo>& biases,
2038 Optional<std::string&> reasonIfUnsupported) const
2039{
Jan Eilers8eb25602020-03-09 12:13:48 +00002040 IgnoreUnused(descriptor);
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002041 bool supported = true;
2042
Sadik Armagan303980c2020-04-17 12:45:14 +01002043 std::array<DataType,7> supportedTypes =
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002044 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002045 DataType::BFloat16,
2046 DataType::Float32,
2047 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002048 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002049 DataType::QAsymmU8,
Sadik Armagan303980c2020-04-17 12:45:14 +01002050 DataType::QSymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002051 DataType::QSymmS16
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002052 };
2053
2054 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2055 "Reference TransposeConvolution2d: input is not a supported type.");
2056
2057 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2058 "Reference TransposeConvolution2d: output is not a supported type.");
2059
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002060 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2061 "Reference TransposeConvolution2d: input and output types mismatched.");
2062
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002063
2064 const DataType inputType = input.GetDataType();
Sadik Armagan303980c2020-04-17 12:45:14 +01002065 if (IsQuantized8BitType(inputType))
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002066 {
Derek Lambertid466a542020-01-22 15:37:29 +00002067 ARMNN_NO_DEPRECATE_WARN_BEGIN
Sadik Armagan303980c2020-04-17 12:45:14 +01002068 std::array<DataType, 4> supportedWeightTypes =
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002069 {
Sadik Armagan303980c2020-04-17 12:45:14 +01002070 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002071 DataType::QAsymmU8,
Derek Lambertid466a542020-01-22 15:37:29 +00002072 DataType::QSymmS8,
2073 DataType::QuantizedSymm8PerAxis //Deprecated
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002074 };
Derek Lambertid466a542020-01-22 15:37:29 +00002075 ARMNN_NO_DEPRECATE_WARN_END
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002076
2077 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
2078 "Reference TransposeConvolution2d: weights type not supported for "
2079 "quantized input.");
2080 }
2081 else
2082 {
2083 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
2084 "Reference TransposeConvolution2d: weights is not a supported type.");
2085
2086 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
2087 "Reference TransposeConvolution2d: input and weights types mismatched.");
2088 }
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002089
2090 if (biases.has_value())
2091 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002092 std::array<DataType,4> biasesSupportedTypes =
Aron Virginas-Tar651aafe2019-08-05 11:52:05 +01002093 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002094 DataType::BFloat16,
2095 DataType::Float32,
2096 DataType::Float16,
2097 DataType::Signed32
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002098 };
2099 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
2100 "Reference TransposeConvolution2d: biases is not a supported type.");
2101 }
2102
2103 return supported;
2104}
2105
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002106bool RefLayerSupport::IsTransposeSupported(const TensorInfo& input,
2107 const TensorInfo& output,
2108 const TransposeDescriptor& descriptor,
2109 Optional<std::string&> reasonIfUnsupported) const
2110{
Jan Eilers8eb25602020-03-09 12:13:48 +00002111 IgnoreUnused(descriptor);
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002112 bool supported = true;
2113
2114 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01002115 std::array<DataType, 6> supportedTypes =
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002116 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002117 DataType::BFloat16,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002118 DataType::Float32,
2119 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002120 DataType::QAsymmS8,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002121 DataType::QAsymmU8,
2122 DataType::QSymmS16
2123 };
2124
2125 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2126 "Reference transpose: input is not a supported type.");
2127
2128 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2129 "Reference transpose: output is not a supported type.");
2130
2131 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2132 "Reference transpose: input and output types are mismatched.");
2133
2134 return supported;
2135}
2136
arovir011c7c81b2018-10-08 11:34:28 +01002137} // namespace armnn