blob: b3feae6713118f042401d8babc4f357b8624d580 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
Teresa Charlin52664732020-06-29 16:27:03 +01002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5
telsoa014fcda012018-03-09 14:13:49 +00006#include "RefLayerSupport.hpp"
David Beck3cc9a622018-10-12 10:38:31 +01007
Keith Davis0c2eeac2020-02-11 16:51:50 +00008#include <armnn/TypesUtils.hpp>
telsoa014fcda012018-03-09 14:13:49 +00009#include <armnn/Types.hpp>
Derek Lamberti50db4e82019-03-13 14:16:15 +000010#include <armnn/Descriptors.hpp>
Jan Eilers8eb25602020-03-09 12:13:48 +000011#include <armnn/utility/IgnoreUnused.hpp>
Matthew Sloyan171214c2020-09-09 09:07:37 +010012#include <armnn/utility/NumericCast.hpp>
telsoa014fcda012018-03-09 14:13:49 +000013
Matteo Martincighe011d202019-11-28 11:35:47 +000014#include <LayerSupportCommon.hpp>
Derek Lambertif674aa02019-08-01 15:56:25 +010015#include <backendsCommon/LayerSupportRules.hpp>
Matteo Martincighe011d202019-11-28 11:35:47 +000016
Derek Lamberti50db4e82019-03-13 14:16:15 +000017#include <vector>
Derek Lamberti50db4e82019-03-13 14:16:15 +000018#include <array>
19
telsoa014fcda012018-03-09 14:13:49 +000020namespace armnn
21{
22
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +010023namespace
24{
25
26template<typename Float32Func, typename Uint8Func, typename ... Params>
27bool IsSupportedForDataTypeRef(Optional<std::string&> reasonIfUnsupported,
28 DataType dataType,
29 Float32Func floatFuncPtr,
30 Uint8Func uint8FuncPtr,
31 Params&&... params)
32{
33 return IsSupportedForDataTypeGeneric(reasonIfUnsupported,
34 dataType,
35 &FalseFunc<Params...>,
36 floatFuncPtr,
37 uint8FuncPtr,
narpra01db2b1602019-01-23 15:23:11 +000038 &FalseFunc<Params...>,
kevmay012b4d88e2019-01-24 14:05:09 +000039 &FalseFunc<Params...>,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +010040 std::forward<Params>(params)...);
41}
42
43} // anonymous namespace
44
James Conroy4d1ff582019-06-10 17:06:39 +010045namespace
46{
47
48std::string CreateIncorrectDimensionsErrorMsg(unsigned int expected,
49 unsigned int actual,
50 std::string& layerStr,
51 std::string& tensorName)
52{
53 std::string errorMsg = "Reference " + layerStr + ": Expected " + std::to_string(expected) + " dimensions but got" +
54 " " + std::to_string(actual) + " dimensions instead, for the '" + tensorName + "' tensor.";
55
56 return errorMsg;
57}
58
59} // anonymous namespace
Derek Lamberti50db4e82019-03-13 14:16:15 +000060
Sadik Armagan9199e582019-09-05 17:35:31 +010061bool RefLayerSupport::IsAbsSupported(const TensorInfo& input, const TensorInfo& output,
62 Optional<std::string&> reasonIfUnsupported) const
63{
josh minor4a3c6102020-01-06 16:40:46 -060064 return IsElementwiseUnarySupported(input,
65 output,
66 ElementwiseUnaryDescriptor(UnaryOperation::Abs),
67 reasonIfUnsupported);
Sadik Armagan9199e582019-09-05 17:35:31 +010068}
69
arovir011c7c81b2018-10-08 11:34:28 +010070bool RefLayerSupport::IsActivationSupported(const TensorInfo& input,
71 const TensorInfo& output,
72 const ActivationDescriptor& descriptor,
73 Optional<std::string&> reasonIfUnsupported) const
74{
Derek Lamberti50db4e82019-03-13 14:16:15 +000075 bool supported = true;
76
77 // Define supported types.
Keith Davis0c2eeac2020-02-11 16:51:50 +000078 std::array<DataType,6> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +000079 DataType::BFloat16,
Derek Lamberti50db4e82019-03-13 14:16:15 +000080 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +010081 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +000082 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +000083 DataType::QAsymmU8,
84 DataType::QSymmS16
Derek Lamberti50db4e82019-03-13 14:16:15 +000085 };
86
87 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
88 "Reference activation: input type not supported.");
89
90 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
91 "Reference activation: output type not supported.");
92
93 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
94 "Reference activation: input and output types mismatched.");
95
96 supported &= CheckSupportRule(ShapesAreSameRank(input, output), reasonIfUnsupported,
97 "Reference activation: input and output shapes are of different rank.");
98
99
100 struct ActivationFunctionSupported : public Rule
101 {
102 ActivationFunctionSupported(const ActivationDescriptor& desc)
103 {
104 switch(desc.m_Function)
105 {
106 case ActivationFunction::Abs:
107 case ActivationFunction::BoundedReLu:
David Monahan3b3c3812020-02-25 09:03:29 +0000108 case ActivationFunction::Elu:
Colm Donelan03fbeaf2020-02-26 15:39:23 +0000109 case ActivationFunction::HardSwish:
Derek Lamberti50db4e82019-03-13 14:16:15 +0000110 case ActivationFunction::LeakyReLu:
111 case ActivationFunction::Linear:
112 case ActivationFunction::ReLu:
113 case ActivationFunction::Sigmoid:
114 case ActivationFunction::SoftReLu:
115 case ActivationFunction::Sqrt:
116 case ActivationFunction::Square:
117 case ActivationFunction::TanH:
118 {
119 m_Res = true;
120 break;
121 }
122 default:
123 {
124 m_Res = false;
125 break;
126 }
127 }
128 }
129 };
130
131 // Function is supported
132 supported &= CheckSupportRule(ActivationFunctionSupported(descriptor), reasonIfUnsupported,
133 "Reference activation: function not supported.");
134
135 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100136}
137
138bool RefLayerSupport::IsAdditionSupported(const TensorInfo& input0,
139 const TensorInfo& input1,
140 const TensorInfo& output,
141 Optional<std::string&> reasonIfUnsupported) const
142{
Derek Lamberti50db4e82019-03-13 14:16:15 +0000143 bool supported = true;
144
Teresa Charlinecb6b8e2020-05-22 18:08:23 +0100145 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000146 DataType::BFloat16,
Derek Lamberti50db4e82019-03-13 14:16:15 +0000147 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100148 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000149 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000150 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +0100151 DataType::QSymmS16,
152 DataType::Signed32
Derek Lamberti50db4e82019-03-13 14:16:15 +0000153 };
154
155 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
156 "Reference addition: input 0 is not a supported type.");
157
158 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
159 "Reference addition: input 1 is not a supported type.");
160
161 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
162 "Reference addition: output is not a supported type.");
163
164 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
165 "Reference addition: input 0 and Input 1 types are mismatched");
166
167 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
168 "Reference addition: input and output types are mismatched");
169
170 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
171 "Reference addition: shapes are not suitable for implicit broadcast.");
172
173 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100174}
175
Nikhil Raj68c2c902019-09-19 11:21:11 +0100176bool RefLayerSupport::IsArgMinMaxSupported(const armnn::TensorInfo &input, const armnn::TensorInfo &output,
177 const armnn::ArgMinMaxDescriptor &descriptor,
178 armnn::Optional<std::string &> reasonIfUnsupported) const
179{
Jan Eilers8eb25602020-03-09 12:13:48 +0000180 IgnoreUnused(descriptor);
Nikhil Raj68c2c902019-09-19 11:21:11 +0100181
Teresa Charline300b362020-05-25 10:01:03 +0100182 std::array<DataType, 7> supportedTypes =
Nikhil Raj68c2c902019-09-19 11:21:11 +0100183 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000184 DataType::BFloat16,
Teresa Charline300b362020-05-25 10:01:03 +0100185 DataType::Float16,
Nikhil Raj68c2c902019-09-19 11:21:11 +0100186 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +0100187 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000188 DataType::QAsymmU8,
189 DataType::QSymmS16,
Francis Murtagh1939df52019-11-13 15:21:09 +0000190 DataType::Signed32
Nikhil Raj68c2c902019-09-19 11:21:11 +0100191 };
192
193 bool supported = true;
194
195 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
196 "Reference ArgMinMax: input is not a supported type.");
197 supported &= CheckSupportRule(TypeIs(output, DataType::Signed32), reasonIfUnsupported,
198 "Reference ArgMinMax: output type not supported");
199
200 return supported;
201}
202
arovir011c7c81b2018-10-08 11:34:28 +0100203bool RefLayerSupport::IsBatchNormalizationSupported(const TensorInfo& input,
204 const TensorInfo& output,
205 const TensorInfo& mean,
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100206 const TensorInfo& variance,
arovir011c7c81b2018-10-08 11:34:28 +0100207 const TensorInfo& beta,
208 const TensorInfo& gamma,
209 const BatchNormalizationDescriptor& descriptor,
210 Optional<std::string&> reasonIfUnsupported) const
211{
Jan Eilers8eb25602020-03-09 12:13:48 +0000212 IgnoreUnused(descriptor);
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100213
Sadik Armagan303980c2020-04-17 12:45:14 +0100214 std::array<DataType, 6> supportedTypes =
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100215 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000216 DataType::BFloat16,
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100217 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100218 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100219 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000220 DataType::QAsymmU8,
221 DataType::QSymmS16
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100222 };
223
224 bool supported = true;
225
226 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
227 "Reference batch normalization: input is not a supported type.");
228
229 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
230 "Reference batch normalization: output is not a supported type.");
231
232 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
233 "Reference batch normalization: input and output types are mismatched");
234
235 supported &= CheckSupportRule(TypeAnyOf(mean, supportedTypes), reasonIfUnsupported,
236 "Reference batch normalization: mean is not a supported type.");
237
238 supported &= CheckSupportRule(TypeAnyOf(variance, supportedTypes), reasonIfUnsupported,
239 "Reference batch normalization: variance is not a supported type.");
240
241 supported &= CheckSupportRule(TypeAnyOf(beta, supportedTypes), reasonIfUnsupported,
242 "Reference batch normalization: beta is not a supported type.");
243
244 supported &= CheckSupportRule(TypeAnyOf(gamma, supportedTypes), reasonIfUnsupported,
245 "Reference batch normalization: gamma is not a supported type.");
246
247 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100248}
249
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000250bool RefLayerSupport::IsBatchToSpaceNdSupported(const TensorInfo& input,
251 const TensorInfo& output,
252 const BatchToSpaceNdDescriptor& descriptor,
253 Optional<std::string&> reasonIfUnsupported) const
254{
Jan Eilers8eb25602020-03-09 12:13:48 +0000255 IgnoreUnused(descriptor);
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100256
257 bool supported = true;
258
259 std::string batchToSpaceNdLayerStr = "batchToSpaceNd";
260 std::string inputTensorStr = "input";
261 std::string outputTensorStr = "output";
262
263 // Define supported types.
Sadik Armagan303980c2020-04-17 12:45:14 +0100264 std::array<DataType,6> supportedTypes =
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100265 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000266 DataType::BFloat16,
267 DataType::Float32,
268 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100269 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000270 DataType::QAsymmU8,
271 DataType::QSymmS16
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100272 };
273
274 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
275 "Reference BatchToSpaceNd: input type not supported.");
276
277 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
278 "Reference BatchToSpaceNd: output type not supported.");
279
280 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
281 "Reference BatchToSpaceNd: input and output types mismatched.");
282
283 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 4),
284 reasonIfUnsupported,
285 CreateIncorrectDimensionsErrorMsg(4,
286 output.GetNumDimensions(),
287 batchToSpaceNdLayerStr,
288 outputTensorStr).data());
289
290 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(input, 4),
291 reasonIfUnsupported,
292 CreateIncorrectDimensionsErrorMsg(4,
293 input.GetNumDimensions(),
294 batchToSpaceNdLayerStr,
295 inputTensorStr).data());
296
297 return supported;
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000298}
299
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100300bool RefLayerSupport::IsComparisonSupported(const TensorInfo& input0,
301 const TensorInfo& input1,
302 const TensorInfo& output,
303 const ComparisonDescriptor& descriptor,
304 Optional<std::string&> reasonIfUnsupported) const
305{
Jan Eilers8eb25602020-03-09 12:13:48 +0000306 IgnoreUnused(descriptor);
Sadik Armagan303980c2020-04-17 12:45:14 +0100307 std::array<DataType, 8> supportedInputTypes =
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100308 {
Sadik Armaganb60dd242020-03-19 13:53:16 +0000309 DataType::Boolean,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000310 DataType::BFloat16,
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100311 DataType::Float32,
312 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100313 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000314 DataType::QAsymmU8,
Sadik Armaganb60dd242020-03-19 13:53:16 +0000315 DataType::QSymmS16,
316 DataType::Signed32
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100317 };
318
319 bool supported = true;
320 supported &= CheckSupportRule(TypeAnyOf(input0, supportedInputTypes), reasonIfUnsupported,
321 "Reference comparison: input 0 is not a supported type");
322
323 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
324 "Reference comparison: input 0 and Input 1 types are mismatched");
325
326 supported &= CheckSupportRule(TypeIs(output, DataType::Boolean), reasonIfUnsupported,
327 "Reference comparison: output is not of type Boolean");
328
329 return supported;
330}
331
Jim Flynn906f9462019-05-10 13:55:21 +0100332bool RefLayerSupport::IsConcatSupported(const std::vector<const TensorInfo*> inputs,
333 const TensorInfo& output,
Jim Flynne242f2d2019-05-22 14:24:13 +0100334 const ConcatDescriptor& descriptor,
Jim Flynn906f9462019-05-10 13:55:21 +0100335 Optional<std::string&> reasonIfUnsupported) const
336{
Jan Eilers8eb25602020-03-09 12:13:48 +0000337 IgnoreUnused(descriptor);
Jim Flynne242f2d2019-05-22 14:24:13 +0100338
339 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000340 std::array<DataType,6> supportedTypes =
Jim Flynne242f2d2019-05-22 14:24:13 +0100341 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000342 DataType::BFloat16,
343 DataType::Float32,
344 DataType::Float16,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000345 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100346 DataType::QAsymmU8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000347 DataType::QSymmS16
Jim Flynne242f2d2019-05-22 14:24:13 +0100348 };
349
350 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
351 "Reference concatenation: output type not supported");
352 for (const TensorInfo* input : inputs)
353 {
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100354 ARMNN_ASSERT(input != nullptr);
Jim Flynne242f2d2019-05-22 14:24:13 +0100355 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
356 "Reference concatenation: input type not supported");
357
358 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
359 "Reference concatenation: input and output types mismatched.");
360 }
361
362 return supported;
Jim Flynn906f9462019-05-10 13:55:21 +0100363}
364
arovir011c7c81b2018-10-08 11:34:28 +0100365bool RefLayerSupport::IsConstantSupported(const TensorInfo& output,
366 Optional<std::string&> reasonIfUnsupported) const
367{
Teresa Charlin6fa8ce62020-05-25 16:16:44 +0100368 std::array<DataType,8> supportedTypes =
Jim Flynne242f2d2019-05-22 14:24:13 +0100369 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000370 DataType::BFloat16,
Teresa Charlin6fa8ce62020-05-25 16:16:44 +0100371 DataType::Float16,
Nina Drozd58ef2c62019-05-16 12:09:18 +0100372 DataType::Float32,
Keith Davis67e6c542020-02-19 10:08:33 +0000373 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100374 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +0000375 DataType::QSymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100376 DataType::QSymmS16,
377 DataType::Signed32
Nina Drozd58ef2c62019-05-16 12:09:18 +0100378 };
379
380 return CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
381 "Reference constant: output is not a supported type.");
arovir011c7c81b2018-10-08 11:34:28 +0100382}
383
Narumol Prangnawarat7ddbbae2020-03-13 10:26:05 +0000384bool RefLayerSupport::IsConvertBf16ToFp32Supported(const TensorInfo& input,
385 const TensorInfo& output,
386 Optional<std::string&> reasonIfUnsupported) const
387{
388 bool supported = true;
389
390 supported &= CheckSupportRule(TypeIs(input, DataType::BFloat16), reasonIfUnsupported,
391 "Reference for ConvertBf16ToFp32 layer: input type not supported");
392
393 supported &= CheckSupportRule(TypeIs(output, DataType::Float32), reasonIfUnsupported,
394 "Reference for ConvertBf16ToFp32 layer: output type not supported");
395
396 return supported;
397}
398
arovir011c7c81b2018-10-08 11:34:28 +0100399bool RefLayerSupport::IsConvertFp16ToFp32Supported(const TensorInfo& input,
400 const TensorInfo& output,
401 Optional<std::string&> reasonIfUnsupported) const
402{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100403 return (IsSupportedForDataTypeGeneric(reasonIfUnsupported,
404 input.GetDataType(),
405 &TrueFunc<>,
406 &FalseInputFuncF32<>,
narpra01db2b1602019-01-23 15:23:11 +0000407 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000408 &FalseFuncI32<>,
409 &FalseFuncU8<>) &&
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100410 IsSupportedForDataTypeGeneric(reasonIfUnsupported,
411 output.GetDataType(),
412 &FalseOutputFuncF16<>,
413 &TrueFunc<>,
narpra01db2b1602019-01-23 15:23:11 +0000414 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000415 &FalseFuncI32<>,
416 &FalseFuncU8<>));
arovir011c7c81b2018-10-08 11:34:28 +0100417}
418
Narumol Prangnawaratea54a012020-03-16 16:36:10 +0000419bool RefLayerSupport::IsConvertFp32ToBf16Supported(const TensorInfo& input,
420 const TensorInfo& output,
421 Optional<std::string&> reasonIfUnsupported) const
422{
423 bool supported = true;
424
425 supported &= CheckSupportRule(TypeIs(input, DataType::Float32), reasonIfUnsupported,
426 "Reference for ConvertFp32ToBf16 layer: input type not supported");
427
428 supported &= CheckSupportRule(TypeIs(output, DataType::BFloat16), reasonIfUnsupported,
429 "Reference for ConvertFp32ToBf16 layer: output type not supported");
430
431 return supported;
432}
433
arovir011c7c81b2018-10-08 11:34:28 +0100434bool RefLayerSupport::IsConvertFp32ToFp16Supported(const TensorInfo& input,
435 const TensorInfo& output,
436 Optional<std::string&> reasonIfUnsupported) const
437{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100438 return (IsSupportedForDataTypeGeneric(reasonIfUnsupported,
439 input.GetDataType(),
440 &FalseInputFuncF16<>,
441 &TrueFunc<>,
narpra01db2b1602019-01-23 15:23:11 +0000442 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000443 &FalseFuncI32<>,
444 &FalseFuncU8<>) &&
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100445 IsSupportedForDataTypeGeneric(reasonIfUnsupported,
446 output.GetDataType(),
447 &TrueFunc<>,
448 &FalseOutputFuncF32<>,
narpra01db2b1602019-01-23 15:23:11 +0000449 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000450 &FalseFuncI32<>,
451 &FalseFuncU8<>));
arovir011c7c81b2018-10-08 11:34:28 +0100452}
453
454bool RefLayerSupport::IsConvolution2dSupported(const TensorInfo& input,
455 const TensorInfo& output,
456 const Convolution2dDescriptor& descriptor,
457 const TensorInfo& weights,
458 const Optional<TensorInfo>& biases,
459 Optional<std::string&> reasonIfUnsupported) const
460{
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100461 bool supported = true;
462
463 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000464 std::array<DataType,7> supportedTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000465 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000466 DataType::BFloat16,
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000467 DataType::Float32,
468 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000469 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100470 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +0000471 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000472 DataType::QSymmS16
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100473 };
474
475 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000476 "Reference Convolution2d: input is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100477
478 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000479 "Reference Convolution2d: output is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100480
Narumol Prangnawarat57ef0082020-03-26 09:20:43 +0000481 // For Convolution2d, we allow to have BFloat16 input with Float32 output for optimization.
482 if (input.GetDataType() == DataType::BFloat16)
483 {
484 if (output.GetDataType() != DataType::BFloat16 && output.GetDataType() != DataType::Float32)
485 {
486 reasonIfUnsupported.value() += "Output tensor type must be BFloat16 or Float32 for BFloat16 input.\n";
487 supported = false;
488 }
489 }
490 else
491 {
492 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000493 "Reference Convolution2d: input and output types mismatched.");
Narumol Prangnawarat57ef0082020-03-26 09:20:43 +0000494 }
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100495
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000496 const DataType inputType = input.GetDataType();
Keith Davis0c2eeac2020-02-11 16:51:50 +0000497 if (IsQuantized8BitType(inputType))
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000498 {
Derek Lambertid466a542020-01-22 15:37:29 +0000499 ARMNN_NO_DEPRECATE_WARN_BEGIN
Keith Davis0c2eeac2020-02-11 16:51:50 +0000500 std::array<DataType, 4> supportedWeightTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000501 {
Sadik Armagan303980c2020-04-17 12:45:14 +0100502 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000503 DataType::QAsymmU8,
Derek Lambertid466a542020-01-22 15:37:29 +0000504 DataType::QSymmS8,
505 DataType::QuantizedSymm8PerAxis // deprecated
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000506 };
Derek Lambertid466a542020-01-22 15:37:29 +0000507 ARMNN_NO_DEPRECATE_WARN_END
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000508
509 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000510 "Reference Convolution2d: weights type not supported for quantized input.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000511 }
512 else
513 {
514 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000515 "Reference Convolution2d: weights is not a supported type.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000516
517 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000518 "Reference Convolution2d: input and weights types mismatched.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000519 }
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100520
521 if (biases.has_value())
522 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000523 std::array<DataType,4> biasesSupportedTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000524 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000525 DataType::BFloat16,
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000526 DataType::Float32,
527 DataType::Float16,
528 DataType::Signed32
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100529 };
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000530
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100531 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000532 "Reference Convolution2d: biases is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100533 }
Jan Eilers8eb25602020-03-09 12:13:48 +0000534 IgnoreUnused(descriptor);
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100535
536 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100537}
538
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000539bool RefLayerSupport::IsDebugSupported(const TensorInfo& input,
540 const TensorInfo& output,
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000541 Optional<std::string&> reasonIfUnsupported) const
542{
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100543 bool supported = true;
544
Narumol Prangnawarat403a1852020-03-12 14:24:13 +0000545 std::array<DataType, 8> supportedTypes =
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100546 {
Narumol Prangnawarat403a1852020-03-12 14:24:13 +0000547 DataType::BFloat16,
Aron Virginas-Tardb1a2832019-11-12 16:15:11 +0000548 DataType::Float16,
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100549 DataType::Float32,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000550 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100551 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +0000552 DataType::QSymmS8,
Narumol Prangnawaratd2d917d2020-01-09 10:16:39 +0000553 DataType::QSymmS16,
554 DataType::Signed32
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100555 };
556
557 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000558 "Reference for Debug layer: input type not supported");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100559
560 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000561 "Reference for Debug layer: output type not supported");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100562
563 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000564 "Reference for Debug layer: input and output types are mismatched");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100565
566 return supported;
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000567}
568
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100569bool RefLayerSupport::IsDepthToSpaceSupported(const TensorInfo& input,
570 const TensorInfo& output,
571 const DepthToSpaceDescriptor& descriptor,
572 Optional<std::string&> reasonIfUnsupported) const
573{
Jan Eilers8eb25602020-03-09 12:13:48 +0000574 IgnoreUnused(descriptor);
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100575 bool supported = true;
576
Sadik Armagan303980c2020-04-17 12:45:14 +0100577 std::array<DataType,6> supportedTypes =
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100578 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000579 DataType::BFloat16,
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100580 DataType::Float32,
581 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100582 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000583 DataType::QAsymmU8,
584 DataType::QSymmS16
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100585 };
586
587 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
588 "Reference DepthToSpace: input type not supported");
589
590 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
591 "Reference DepthToSpace: output type not supported");
592
593 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
594 "Reference DepthToSpace: input and output types are mismatched");
595
596 return supported;
597}
598
arovir011c7c81b2018-10-08 11:34:28 +0100599bool RefLayerSupport::IsDepthwiseConvolutionSupported(const TensorInfo& input,
600 const TensorInfo& output,
601 const DepthwiseConvolution2dDescriptor& descriptor,
602 const TensorInfo& weights,
603 const Optional<TensorInfo>& biases,
604 Optional<std::string&> reasonIfUnsupported) const
605{
Sadik Armagan303980c2020-04-17 12:45:14 +0100606 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100607 bool supported = true;
608
609 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000610 std::array<DataType,7> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100611 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000612 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100613 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100614 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000615 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000616 DataType::QAsymmU8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100617 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000618 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100619 };
620
621 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
622 "Reference DepthwiseConvolution2d: input is not a supported type.");
623
624 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
625 "Reference DepthwiseConvolution2d: output is not a supported type.");
626
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100627 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
628 "Reference DepthwiseConvolution2d: input and output types mismatched.");
629
Teresa Charlind8df0262019-11-11 12:28:15 +0000630 const DataType inputType = input.GetDataType();
Keith Davis0c2eeac2020-02-11 16:51:50 +0000631 if (IsQuantized8BitType(inputType))
Teresa Charlind8df0262019-11-11 12:28:15 +0000632 {
Sadik Armagan303980c2020-04-17 12:45:14 +0100633 ARMNN_NO_DEPRECATE_WARN_BEGIN
634 std::array<DataType, 4> supportedWeightTypes =
635 {
636 DataType::QAsymmS8,
637 DataType::QAsymmU8,
638 DataType::QSymmS8,
639 DataType::QuantizedSymm8PerAxis // deprecated
640 };
641 ARMNN_NO_DEPRECATE_WARN_END
Teresa Charlind8df0262019-11-11 12:28:15 +0000642
643 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
Sadik Armagan303980c2020-04-17 12:45:14 +0100644 "Reference DepthwiseConvolution2d: weights type not supported for "
645 "quantized input.");
Teresa Charlind8df0262019-11-11 12:28:15 +0000646 }
647 else
648 {
649 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
650 "Reference DepthwiseConvolution2d: weights is not a supported type.");
651
652 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
653 "Reference DepthwiseConvolution2d: input and weights types mismatched.");
654 }
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100655
656 if (biases.has_value())
657 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000658 std::array<DataType,4> biasesSupportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100659 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000660 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100661 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100662 DataType::Float16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100663 DataType::Signed32
664 };
665 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
666 "Reference DepthwiseConvolution2d: biases is not a supported type.");
667 }
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100668
669 return supported;
670
arovir011c7c81b2018-10-08 11:34:28 +0100671}
672
Nattapat Chaimanowong8a54ac02019-03-29 15:25:04 +0000673bool RefLayerSupport::IsDequantizeSupported(const TensorInfo& input,
674 const TensorInfo& output,
675 Optional<std::string&> reasonIfUnsupported) const
676{
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100677 bool supported = true;
678
Ryan OShea9add1202020-02-07 10:06:33 +0000679 std::array<DataType,4> supportedInputTypes = {
680 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000681 DataType::QAsymmU8,
Finn Williamsfd271062019-12-04 14:27:27 +0000682 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000683 DataType::QSymmS16
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100684 };
685
686 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000687 "Reference for Dequantize layer: input type not supported.");
688
689 supported &= CheckSupportRule( TypeNotPerAxisQuantized(input), reasonIfUnsupported,
690 "Reference for Dequantize layer: per-axis quantized input not support .");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100691
Derek Lambertid466a542020-01-22 15:37:29 +0000692 supported &= CheckSupportRule(TypeNotPerAxisQuantized(input), reasonIfUnsupported,
693 "Reference dequantize: per-axis quantized input not support .");
694
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000695 std::array<DataType,3> supportedOutputTypes = {
696 DataType::BFloat16,
Jan Eilersf7107932019-11-01 11:09:36 +0000697 DataType::Float32,
698 DataType::Float16
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100699 };
700
701 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000702 "Reference for Dequantize layer: output type not supported.");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100703
704 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000705 "Reference for Dequantize layer: input/output shapes have different num total "
706 "elements.");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100707
708 return supported;
Nattapat Chaimanowong8a54ac02019-03-29 15:25:04 +0000709}
710
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000711bool RefLayerSupport::IsDetectionPostProcessSupported(const TensorInfo& boxEncodings,
712 const TensorInfo& scores,
713 const TensorInfo& anchors,
714 const TensorInfo& detectionBoxes,
715 const TensorInfo& detectionClasses,
716 const TensorInfo& detectionScores,
717 const TensorInfo& numDetections,
718 const DetectionPostProcessDescriptor& descriptor,
719 Optional<std::string&> reasonIfUnsupported) const
Narumol Prangnawaratbc67cef2019-01-31 15:31:54 +0000720{
Jan Eilers8eb25602020-03-09 12:13:48 +0000721 IgnoreUnused(anchors, detectionBoxes, detectionClasses, detectionScores, numDetections, descriptor);
Derek Lamberti901ea112019-12-10 22:07:09 +0000722
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100723 bool supported = true;
724
Sadik Armaganaa41d5d2020-11-16 14:27:52 +0000725 std::array<DataType,6> supportedInputTypes =
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100726 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000727 DataType::BFloat16,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100728 DataType::Float32,
Sadik Armaganaa41d5d2020-11-16 14:27:52 +0000729 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100730 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000731 DataType::QAsymmU8,
732 DataType::QSymmS16
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100733 };
734
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000735 supported &= CheckSupportRule(TypeAnyOf(boxEncodings, supportedInputTypes), reasonIfUnsupported,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100736 "Reference DetectionPostProcess: input 0 is not a supported type.");
737
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000738 supported &= CheckSupportRule(TypeAnyOf(scores, supportedInputTypes), reasonIfUnsupported,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100739 "Reference DetectionPostProcess: input 1 is not a supported type.");
740
741 return supported;
Narumol Prangnawaratbc67cef2019-01-31 15:31:54 +0000742}
743
Pablo Tellof0bd6832019-04-26 17:58:13 +0100744bool RefLayerSupport::IsDilatedDepthwiseConvolutionSupported(const TensorInfo& input,
745 const TensorInfo& output,
746 const DepthwiseConvolution2dDescriptor& descriptor,
747 const TensorInfo& weights,
748 const Optional<TensorInfo>& biases,
749 Optional<std::string&> reasonIfUnsupported) const
750{
Aron Virginas-Taraece4ed2019-06-14 17:00:09 +0100751 return IsDepthwiseConvolutionSupported(input, output, descriptor, weights, biases, reasonIfUnsupported);
Pablo Tellof0bd6832019-04-26 17:58:13 +0100752}
753
Aron Virginas-Taraece4ed2019-06-14 17:00:09 +0100754bool RefLayerSupport::IsDivisionSupported(const TensorInfo& input0,
arovir011c7c81b2018-10-08 11:34:28 +0100755 const TensorInfo& input1,
756 const TensorInfo& output,
757 Optional<std::string&> reasonIfUnsupported) const
758{
Sadik Armagan2999a022019-04-09 14:20:12 +0100759 bool supported = true;
760
Teresa Charlinecb6b8e2020-05-22 18:08:23 +0100761 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000762 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +0100763 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100764 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100765 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000766 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +0100767 DataType::QSymmS16,
768 DataType::Signed32
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
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100858bool RefLayerSupport::IsFillSupported(const TensorInfo& input,
859 const TensorInfo& output,
860 const FillDescriptor& descriptor,
861 Optional<std::string&> reasonIfUnsupported) const
862{
863 IgnoreUnused(descriptor);
864 IgnoreUnused(output);
865
866 bool supported = true;
867
Sadik Armagana792a052020-06-23 16:22:23 +0100868 std::array<DataType,3> supportedTypes =
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100869 {
870 DataType::Float32,
Sadik Armagana792a052020-06-23 16:22:23 +0100871 DataType::Float16,
872 DataType::Signed32
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100873 };
874
Teresa Charlin4b10fef2020-07-29 09:36:41 +0100875 supported &= CheckSupportRule(TypeIs(input, DataType::Signed32), reasonIfUnsupported,
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100876 "Reference Fill: input type not supported.");
877
Teresa Charlin44088502020-07-27 11:27:19 +0100878 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
879 "Reference Fill: output type not supported.");
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100880 return supported;
881}
882
arovir011c7c81b2018-10-08 11:34:28 +0100883bool RefLayerSupport::IsFloorSupported(const TensorInfo& input,
884 const TensorInfo& output,
885 Optional<std::string&> reasonIfUnsupported) const
886{
Jan Eilers8eb25602020-03-09 12:13:48 +0000887 IgnoreUnused(output);
James Conroy83735b12019-05-30 16:36:59 +0100888 bool supported = true;
889
Francis Murtaghe8ac1332020-07-30 18:03:40 +0100890 std::array<DataType,3> supportedTypes =
James Conroy83735b12019-05-30 16:36:59 +0100891 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000892 DataType::BFloat16,
James Conroyb40d7102019-06-04 12:32:09 +0100893 DataType::Float32,
Francis Murtaghe8ac1332020-07-30 18:03:40 +0100894 DataType::Float16
James Conroy83735b12019-05-30 16:36:59 +0100895 };
896
897 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
898 "Reference Floor: input type not supported.");
899
900 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
901 "Reference Floor: output type not supported.");
902
903 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100904}
905
906bool RefLayerSupport::IsFullyConnectedSupported(const TensorInfo& input,
907 const TensorInfo& output,
908 const TensorInfo& weights,
909 const TensorInfo& biases,
910 const FullyConnectedDescriptor& descriptor,
911 Optional<std::string&> reasonIfUnsupported) const
912{
Francis Murtagh46c09d02019-05-28 08:15:28 +0100913 bool supported = true;
914
915 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000916 std::array<DataType,6> supportedTypes =
Francis Murtagh46c09d02019-05-28 08:15:28 +0100917 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000918 DataType::BFloat16,
919 DataType::Float32,
920 DataType::Float16,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000921 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100922 DataType::QAsymmU8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000923 DataType::QSymmS16
Francis Murtagh46c09d02019-05-28 08:15:28 +0100924 };
925
926 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
927 "Reference Fully Connected: input type not supported.");
928
929 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
930 "Reference Fully Connected: output type not supported.");
931
Francis Murtagh46c09d02019-05-28 08:15:28 +0100932 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
933 "Reference Fully Connected: weights type not supported.");
934
Narumol Prangnawarat57ef0082020-03-26 09:20:43 +0000935 // For FullyConnected, we allow to have BFloat16 input with Float32 output for optimization.
936 if (input.GetDataType() == DataType::BFloat16)
937 {
938 if (output.GetDataType() != DataType::BFloat16 && output.GetDataType() != DataType::Float32)
939 {
940 reasonIfUnsupported.value() += "Output tensor type must be BFloat16 or Float32 for BFloat16 input.\n";
941 supported = false;
942 }
943 }
944 else
945 {
946 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
947 "Reference Fully Connected: input and output types mismatched.");
948 }
949
Jan Eilers1f45dc32020-06-15 11:43:03 +0100950 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
951 "Reference Fully Connected: weights is not a supported type.");
Francis Murtaghddb1d062020-03-10 13:51:45 +0000952
Jan Eilers1f45dc32020-06-15 11:43:03 +0100953 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
954 "Reference Fully Connected: input and weights types mismatched.");
Francis Murtagh46c09d02019-05-28 08:15:28 +0100955
956 if (descriptor.m_BiasEnabled)
957 {
958 // Defined supported types for bias
Sadik Armagandb73c982020-04-01 17:35:30 +0100959 std::array<DataType, 5>
Francis Murtagh46c09d02019-05-28 08:15:28 +0100960 supportedBiasTypes =
961 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000962 DataType::BFloat16,
Francis Murtagh46c09d02019-05-28 08:15:28 +0100963 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100964 DataType::Float16,
Sadik Armagandb73c982020-04-01 17:35:30 +0100965 DataType::Signed32,
966 DataType::QAsymmS8
Francis Murtagh46c09d02019-05-28 08:15:28 +0100967 };
968
969 supported &= CheckSupportRule(TypeAnyOf(biases, supportedBiasTypes), reasonIfUnsupported,
970 "Reference Fully Connected: bias type not supported.");
971
972 supported &= CheckSupportRule(BiasAndWeightsTypesMatch(biases, weights), reasonIfUnsupported,
973 "Reference Fully Connected: bias and weight types mismatch.");
974
975 supported &= CheckSupportRule(BiasAndWeightsTypesCompatible(weights, supportedBiasTypes), reasonIfUnsupported,
976 "Reference Fully Connected: bias type inferred from weights is incompatible.");
977
Narumol Prangnawarat366d7232020-04-29 12:58:17 +0100978 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(biases, 1U), reasonIfUnsupported,
979 "Reference Fully Connected: bias must have 1 dimension.");
980
Francis Murtagh46c09d02019-05-28 08:15:28 +0100981 }
982
983 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100984}
985
narpra014951d842019-01-18 16:53:53 +0000986bool RefLayerSupport::IsGatherSupported(const armnn::TensorInfo& input0,
987 const armnn::TensorInfo& input1,
988 const armnn::TensorInfo& output,
Teresa Charlin52664732020-06-29 16:27:03 +0100989 const GatherDescriptor& descriptor,
narpra014951d842019-01-18 16:53:53 +0000990 armnn::Optional<std::string&> reasonIfUnsupported) const
991{
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100992 bool supported = true;
Teresa Charlin3940d8b2020-05-29 16:47:23 +0100993 std::array<DataType,7> supportedTypes =
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100994 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000995 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100996 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100997 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100998 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000999 DataType::QAsymmU8,
Teresa Charlin3940d8b2020-05-29 16:47:23 +01001000 DataType::QSymmS16,
1001 DataType::Signed32
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +01001002 };
1003
Teresa Charlin52664732020-06-29 16:27:03 +01001004 if (descriptor.m_Axis != 0)
1005 {
1006 reasonIfUnsupported.value() += std::string("Reference Gather: axis not supported\n");
1007 supported &= false;
1008 }
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +01001009 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1010 "Reference Gather: input type not supported");
1011
1012 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1013 "Reference Gather: output type not supported");
1014
1015 supported &= CheckSupportRule(TypeIs(input1, DataType::Signed32), reasonIfUnsupported,
1016 "Reference Gather: indices (input1) type not supported");
1017
1018 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1019 "Reference Gather: input and output types not matching");
1020
1021 return supported;
narpra014951d842019-01-18 16:53:53 +00001022}
1023
FrancisMurtagh878f0232018-12-19 10:56:15 +00001024bool RefLayerSupport::IsGreaterSupported(const TensorInfo& input0,
1025 const TensorInfo& input1,
1026 const TensorInfo& output,
1027 Optional<std::string&> reasonIfUnsupported) const
1028{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +01001029 return IsComparisonSupported(input0,
1030 input1,
1031 output,
1032 ComparisonDescriptor(ComparisonOperation::Greater),
1033 reasonIfUnsupported);
FrancisMurtagh878f0232018-12-19 10:56:15 +00001034}
1035
Derek Lamberti901ea112019-12-10 22:07:09 +00001036bool RefLayerSupport::IsInputSupported(const TensorInfo& /*input*/,
1037 Optional<std::string&> /*reasonIfUnsupported*/) const
arovir011c7c81b2018-10-08 11:34:28 +01001038{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +01001039 return true;
arovir011c7c81b2018-10-08 11:34:28 +01001040}
1041
Kevin May09ca49c2019-10-09 12:37:34 +01001042bool RefLayerSupport::IsInstanceNormalizationSupported(const TensorInfo& input,
1043 const TensorInfo& output,
1044 const InstanceNormalizationDescriptor& descriptor,
1045 Optional<std::string&> reasonIfUnsupported) const
1046{
Jan Eilers8eb25602020-03-09 12:13:48 +00001047 IgnoreUnused(descriptor);
Kevin May09ca49c2019-10-09 12:37:34 +01001048 // Define supported types
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001049 std::array<DataType, 3> supportedTypes =
Kevin May09ca49c2019-10-09 12:37:34 +01001050 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001051 DataType::BFloat16,
Kevin May09ca49c2019-10-09 12:37:34 +01001052 DataType::Float32,
1053 DataType::Float16
1054 };
1055
1056 bool supported = true;
1057
1058 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1059 "Reference Instance Normalization: input type not supported.");
1060
1061 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1062 "Reference Instance Normalization: output type not supported.");
1063
1064 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1065 "Reference Instance Normalization: input and output types mismatched.");
1066
1067 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1068 "Reference Instance Normalization: input and output shapes have different "
1069 "num total elements.");
1070
1071 return supported;
1072}
1073
arovir011c7c81b2018-10-08 11:34:28 +01001074bool RefLayerSupport::IsL2NormalizationSupported(const TensorInfo& input,
1075 const TensorInfo& output,
1076 const L2NormalizationDescriptor& descriptor,
1077 Optional<std::string&> reasonIfUnsupported) const
1078{
Jan Eilers8eb25602020-03-09 12:13:48 +00001079 IgnoreUnused(descriptor);
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001080 // Define supported types
Sadik Armagan303980c2020-04-17 12:45:14 +01001081 std::array<DataType, 6> supportedTypes =
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001082 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001083 DataType::BFloat16,
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001084 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001085 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001086 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001087 DataType::QAsymmU8,
1088 DataType::QSymmS16
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001089 };
1090
1091 bool supported = true;
1092
1093 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1094 "Reference L2normalization: input type not supported.");
1095
1096 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1097 "Reference L2normalization: output type not supported.");
1098
1099 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1100 "Reference L2normalization: input and output types mismatched.");
1101
1102 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1103 "Reference L2normalization: input and output shapes have different "
1104 "num total elements.");
1105
1106 return supported;
arovir011c7c81b2018-10-08 11:34:28 +01001107}
1108
James Conroyaba90cd2020-11-06 16:28:18 +00001109bool RefLayerSupport::IsLogicalBinarySupported(const TensorInfo& input0,
1110 const TensorInfo& input1,
1111 const TensorInfo& output,
1112 const LogicalBinaryDescriptor& descriptor,
1113 Optional<std::string&> reasonIfUnsupported) const
1114{
1115 IgnoreUnused(descriptor);
1116
1117 std::array<DataType, 1> supportedTypes =
1118 {
1119 DataType::Boolean
1120 };
1121
1122 bool supported = true;
1123 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1124 "Reference LogicalBinary: input 0 type not supported");
1125 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1126 "Reference LogicalBinary: input 1 type not supported");
1127
1128 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1129 "Reference LogicalBinary: input and output types do not match");
1130
1131 return supported;
1132}
1133
1134bool RefLayerSupport::IsLogicalUnarySupported(const TensorInfo& input,
1135 const TensorInfo& output,
1136 const ElementwiseUnaryDescriptor& descriptor,
1137 Optional<std::string&> reasonIfUnsupported) const
1138{
1139 IgnoreUnused(descriptor);
1140
1141 std::array<DataType, 1> supportedTypes =
1142 {
1143 DataType::Boolean
1144 };
1145
1146 bool supported = true;
1147 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1148 "Reference LogicalUnary: input type not supported");
1149
1150 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1151 "Reference LogicalUnary: input and output types do not match");
1152
1153 return supported;
1154}
1155
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001156bool RefLayerSupport::IsLogSoftmaxSupported(const TensorInfo& input,
1157 const TensorInfo& output,
1158 const LogSoftmaxDescriptor& descriptor,
1159 Optional<std::string&> reasonIfUnsupported) const
1160{
Jan Eilers8eb25602020-03-09 12:13:48 +00001161 IgnoreUnused(descriptor);
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001162
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001163 std::array<DataType, 3> supportedTypes =
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001164 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001165 DataType::BFloat16,
1166 DataType::Float32,
1167 DataType::Float16
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001168 };
1169
1170 bool supported = true;
1171 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1172 "Reference LogSoftmax: input type not supported");
1173
1174 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1175 "Reference LogSoftmax: output type not supported");
1176
1177 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1178 "Reference LogSoftmax: input and output types do not match");
1179
1180 return supported;
1181}
1182
arovir011c7c81b2018-10-08 11:34:28 +01001183bool RefLayerSupport::IsLstmSupported(const TensorInfo& input,
1184 const TensorInfo& outputStateIn,
1185 const TensorInfo& cellStateIn,
1186 const TensorInfo& scratchBuffer,
1187 const TensorInfo& outputStateOut,
1188 const TensorInfo& cellStateOut,
1189 const TensorInfo& output,
1190 const LstmDescriptor& descriptor,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001191 const LstmInputParamsInfo& paramsInfo,
1192 Optional<std::string&> reasonIfUnsupported) const
arovir011c7c81b2018-10-08 11:34:28 +01001193{
Jan Eilers8eb25602020-03-09 12:13:48 +00001194 IgnoreUnused(descriptor);
1195 IgnoreUnused(paramsInfo);
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001196
1197 bool supported = true;
1198
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001199 std::array<DataType,3> supportedTypes = {
1200 DataType::BFloat16,
Conor Kennedyb9971c92019-05-07 07:14:23 +01001201 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001202 DataType::QSymmS16
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001203 };
1204
Jan Eilersd01a83c2019-07-03 18:20:40 +01001205 // check inputs and outputs
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001206 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1207 "Reference Lstm: input is not a supported type.");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001208 supported &= CheckSupportRule(TypesAreEqual(input, outputStateIn), reasonIfUnsupported,
1209 "Reference Lstm: input and outputStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001210 supported &= CheckSupportRule(TypesAreEqual(input, cellStateIn), reasonIfUnsupported,
1211 "Reference Lstm: input and cellStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001212 supported &= CheckSupportRule(TypesAreEqual(input, scratchBuffer), reasonIfUnsupported,
1213 "Reference Lstm: input and scratchBuffer types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001214 supported &= CheckSupportRule(TypesAreEqual(input, outputStateOut), reasonIfUnsupported,
1215 "Reference Lstm: input and outputStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001216 supported &= CheckSupportRule(TypesAreEqual(input, cellStateOut), reasonIfUnsupported,
1217 "Reference Lstm: input and cellStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001218 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1219 "Reference Lstm: input and output types are mismatched");
Jan Eilersd01a83c2019-07-03 18:20:40 +01001220 // check layer parameters
Francis Murtaghbb590b42019-08-14 09:51:36 +01001221 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001222 "Reference Lstm: input and InputToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001223 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001224 "Reference Lstm: input and InputToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001225 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001226 "Reference Lstm: input and InputToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001227 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001228 "Reference Lstm: input and RecurrentToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001229 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001230 "Reference Lstm: input and RecurrentToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001231 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001232 "Reference Lstm: input and RecurrentToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001233 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001234 "Reference Lstm: input and ForgetGateBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001235 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001236 "Reference Lstm: input and CellBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001237 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001238 "Reference Lstm: input and OutputGateBias types are mismatched");
1239 if (!descriptor.m_CifgEnabled)
1240 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001241 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToInputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001242 "Reference Lstm: input and InputToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001243 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001244 reasonIfUnsupported,
1245 "Reference Lstm: input and RecurrentToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001246 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001247 "Reference Lstm: input and InputGateBias types are mismatched");
1248 if (descriptor.m_PeepholeEnabled)
1249 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001250 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001251 reasonIfUnsupported,
1252 "Reference Lstm: input and CellToInputWeights types are mismatched");
1253 }
1254 }
1255 if (descriptor.m_PeepholeEnabled)
1256 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001257 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001258 "Reference Lstm: input and CellToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001259 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001260 "Reference Lstm: input and CellToOutputWeights types are mismatched");
1261 }
1262 if (descriptor.m_ProjectionEnabled)
1263 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001264 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001265 "Reference Lstm: input and mProjectionWeights types are mismatched");
1266 if (paramsInfo.m_ProjectionBias != nullptr)
1267 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001268 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001269 "Reference Lstm: input and ProjectionBias types are mismatched");
1270 }
1271 }
1272 if (descriptor.m_LayerNormEnabled)
1273 {
1274 if (!descriptor.m_CifgEnabled)
1275 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001276 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001277 reasonIfUnsupported,
1278 "Reference Lstm: input and InputLayerNormWeights types are mismatched");
1279 }
Francis Murtaghbb590b42019-08-14 09:51:36 +01001280 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001281 reasonIfUnsupported,
1282 "Reference Lstm: input and ForgetLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001283 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001284 reasonIfUnsupported,
1285 "Reference Lstm: input and CellLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001286 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001287 reasonIfUnsupported,
1288 "Reference Lstm: input and OutputLayerNormWeights types are mismatched");
1289 }
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001290
1291 return supported;
telsoa01c577f2c2018-08-31 09:22:23 +01001292}
1293
saoste012df12b32018-11-28 16:57:20 +00001294bool RefLayerSupport::IsMaximumSupported(const TensorInfo& input0,
1295 const TensorInfo& input1,
1296 const TensorInfo& output,
1297 Optional<std::string&> reasonIfUnsupported) const
1298{
Sadik Armagan2999a022019-04-09 14:20:12 +01001299 bool supported = true;
1300
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001301 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001302 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001303 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001304 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001305 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001306 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001307 DataType::QSymmS16,
1308 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01001309 };
1310
1311 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1312 "Reference maximum: input 0 is not a supported type.");
1313
1314 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1315 "Reference maximum: input 1 is not a supported type.");
1316
1317 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1318 "Reference maximum: output is not a supported type.");
1319
1320 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1321 "Reference maximum: input 0 and Input 1 types are mismatched");
1322
1323 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1324 "Reference maximum: input and output types are mismatched");
1325
1326 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1327 "Reference maximum: shapes are not suitable for implicit broadcast.");
1328
1329 return supported;
saoste012df12b32018-11-28 16:57:20 +00001330}
1331
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001332bool RefLayerSupport::IsMeanSupported(const TensorInfo& input,
1333 const TensorInfo& output,
1334 const MeanDescriptor& descriptor,
1335 Optional<std::string&> reasonIfUnsupported) const
narpra0132b90462018-09-13 11:07:48 +01001336{
James Conroy4d1ff582019-06-10 17:06:39 +01001337 bool supported = true;
1338 std::string meanLayerStr = "Mean";
1339 std::string outputTensorStr = "output";
1340
Sadik Armagan303980c2020-04-17 12:45:14 +01001341 std::array<DataType,6> supportedTypes =
James Conroy4d1ff582019-06-10 17:06:39 +01001342 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001343 DataType::BFloat16,
James Conroy4d1ff582019-06-10 17:06:39 +01001344 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001345 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001346 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001347 DataType::QAsymmU8,
1348 DataType::QSymmS16
James Conroy4d1ff582019-06-10 17:06:39 +01001349 };
1350
1351 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1352 "Reference Mean: input type not supported.");
1353
1354 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1355 "Reference Mean: input and output types are mismatched");
1356
1357 if (descriptor.m_KeepDims)
1358 {
1359 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, input.GetNumDimensions()),
1360 reasonIfUnsupported,
1361 CreateIncorrectDimensionsErrorMsg(input.GetNumDimensions(),
1362 output.GetNumDimensions(),
1363 meanLayerStr, outputTensorStr).data());
1364 }
1365 else if (descriptor.m_Axis.empty())
1366 {
1367 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1368 reasonIfUnsupported,
1369 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1370 meanLayerStr, outputTensorStr).data());
1371 }
1372 else
1373 {
Matthew Sloyan171214c2020-09-09 09:07:37 +01001374 auto outputDim = input.GetNumDimensions() - armnn::numeric_cast<unsigned int>(descriptor.m_Axis.size());
James Conroy4d1ff582019-06-10 17:06:39 +01001375
1376 if (outputDim > 0)
1377 {
1378 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, outputDim),
1379 reasonIfUnsupported,
1380 CreateIncorrectDimensionsErrorMsg(outputDim, output.GetNumDimensions(),
1381 meanLayerStr, outputTensorStr).data());
1382 }
1383 else
1384 {
1385 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1386 reasonIfUnsupported,
1387 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1388 meanLayerStr, outputTensorStr).data());
1389 }
1390 }
1391
1392 return supported;
narpra0132b90462018-09-13 11:07:48 +01001393}
1394
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001395bool RefLayerSupport::IsMergerSupported(const std::vector<const TensorInfo*> inputs,
Nikhil Raj8599a412018-11-19 14:51:07 +00001396 const TensorInfo& output,
Jim Flynne242f2d2019-05-22 14:24:13 +01001397 const MergerDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001398 Optional<std::string&> reasonIfUnsupported) const
1399{
Jim Flynne242f2d2019-05-22 14:24:13 +01001400 return IsConcatSupported(inputs, output, descriptor, reasonIfUnsupported);
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001401}
1402
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001403bool RefLayerSupport::IsMemCopySupported(const TensorInfo &input,
1404 const TensorInfo &output,
1405 Optional<std::string &> reasonIfUnsupported) const
1406{
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001407 bool supported = true;
1408
Sadik Armagan303980c2020-04-17 12:45:14 +01001409 std::array<DataType,7> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001410 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001411 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001412 DataType::Float32,
1413 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001414 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001415 DataType::QAsymmU8,
1416 DataType::QSymmS16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001417 DataType::Boolean
1418 };
1419
1420 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1421 "Reference MemCopy: input type not supported");
1422
1423 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1424 "Reference MemCopy: output type not supported");
1425
1426 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1427 "Reference MemCopy: input and output types are mismatched");
1428
1429 return supported;
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001430}
1431
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001432bool RefLayerSupport::IsMinimumSupported(const TensorInfo& input0,
1433 const TensorInfo& input1,
1434 const TensorInfo& output,
1435 Optional<std::string&> reasonIfUnsupported) const
1436{
Sadik Armagan2999a022019-04-09 14:20:12 +01001437 bool supported = true;
1438
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001439 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001440 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001441 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001442 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001443 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001444 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001445 DataType::QSymmS16,
1446 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01001447 };
1448
1449 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1450 "Reference minimum: input 0 is not a supported type.");
1451
1452 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1453 "Reference minimum: input 1 is not a supported type.");
1454
1455 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1456 "Reference minimum: output is not a supported type.");
1457
1458 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1459 "Reference minimum: input 0 and Input 1 types are mismatched");
1460
1461 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1462 "Reference minimum: input and output types are mismatched");
1463
1464 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1465 "Reference minimum: shapes are not suitable for implicit broadcast.");
1466
1467 return supported;
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001468}
1469
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001470bool RefLayerSupport::IsMultiplicationSupported(const TensorInfo& input0,
1471 const TensorInfo& input1,
1472 const TensorInfo& output,
1473 Optional<std::string&> reasonIfUnsupported) const
1474{
Sadik Armagan2999a022019-04-09 14:20:12 +01001475 bool supported = true;
1476
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001477 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001478 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001479 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001480 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001481 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001482 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001483 DataType::QSymmS16,
1484 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01001485 };
1486
1487 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1488 "Reference multiplication: input 0 is not a supported type.");
1489
1490 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1491 "Reference multiplication: input 1 is not a supported type.");
1492
1493 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1494 "Reference multiplication: output is not a supported type.");
1495
1496 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1497 "Reference multiplication: input 0 and Input 1 types are mismatched");
1498
1499 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1500 "Reference multiplication: input and output types are mismatched");
1501
1502 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1503 "Reference multiplication: shapes are not suitable for implicit broadcast.");
1504
1505 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001506}
1507
1508bool RefLayerSupport::IsNormalizationSupported(const TensorInfo& input,
1509 const TensorInfo& output,
1510 const NormalizationDescriptor& descriptor,
1511 Optional<std::string&> reasonIfUnsupported) const
Nina Drozd661dfa72018-10-02 11:14:17 +01001512{
Jan Eilers8eb25602020-03-09 12:13:48 +00001513 IgnoreUnused(descriptor);
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001514
1515 // Define supported types
Sadik Armagan303980c2020-04-17 12:45:14 +01001516 std::array<DataType, 6> supportedTypes =
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001517 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001518 DataType::BFloat16,
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001519 DataType::Float16,
1520 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001521 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001522 DataType::QAsymmU8,
1523 DataType::QSymmS16
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001524 };
1525
1526 bool supported = true;
1527
1528 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1529 "Reference normalization: input type not supported.");
1530
1531 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1532 "Reference normalization: output type not supported.");
1533
1534 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1535 "Reference normalization: input and output shapes have different "
1536 "num total elements.");
1537
1538 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001539}
1540
Derek Lamberti901ea112019-12-10 22:07:09 +00001541bool RefLayerSupport::IsOutputSupported(const TensorInfo& /*output*/,
1542 Optional<std::string&> /*reasonIfUnsupported*/) const
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001543{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +01001544 return true;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001545}
1546
1547bool RefLayerSupport::IsPadSupported(const TensorInfo& input,
1548 const TensorInfo& output,
1549 const PadDescriptor& descriptor,
1550 Optional<std::string&> reasonIfUnsupported) const
1551{
Jan Eilers8eb25602020-03-09 12:13:48 +00001552 IgnoreUnused(descriptor);
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001553 bool supported = true;
1554
1555 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01001556 std::array<DataType,6> supportedTypes =
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001557 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001558 DataType::BFloat16,
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001559 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001560 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001561 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001562 DataType::QAsymmU8,
1563 DataType::QSymmS16
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001564 };
1565
1566 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1567 "Reference pad: input is not a supported type.");
1568
1569 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1570 "Reference pad: output is not a supported type.");
1571
1572 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1573 "Reference pad: input and output types are mismatched.");
1574
1575 return supported;
Nina Drozd661dfa72018-10-02 11:14:17 +01001576}
1577
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001578bool RefLayerSupport::IsPermuteSupported(const TensorInfo& input,
1579 const TensorInfo& output,
1580 const PermuteDescriptor& descriptor,
1581 Optional<std::string&> reasonIfUnsupported) const
1582{
Jan Eilers8eb25602020-03-09 12:13:48 +00001583 IgnoreUnused(descriptor);
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001584 bool supported = true;
1585
1586 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01001587 std::array<DataType, 6> supportedTypes =
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001588 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001589 DataType::BFloat16,
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001590 DataType::Float32,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00001591 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001592 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001593 DataType::QAsymmU8,
1594 DataType::QSymmS16
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001595 };
1596
1597 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1598 "Reference permute: input is not a supported type.");
1599
1600 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1601 "Reference permute: output is not a supported type.");
1602
1603 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1604 "Reference permute: input and output types are mismatched.");
1605
1606 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001607}
1608
1609bool RefLayerSupport::IsPooling2dSupported(const TensorInfo& input,
1610 const TensorInfo& output,
1611 const Pooling2dDescriptor& descriptor,
1612 Optional<std::string&> reasonIfUnsupported) const
1613{
Jan Eilers8eb25602020-03-09 12:13:48 +00001614 IgnoreUnused(descriptor);
Teresa Charlina3b20472019-06-06 11:12:32 +01001615 bool supported = true;
1616
1617 // Define supported output and inputs types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001618 std::array<DataType,6> supportedTypes =
Teresa Charlina3b20472019-06-06 11:12:32 +01001619 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001620 DataType::BFloat16,
Teresa Charlina3b20472019-06-06 11:12:32 +01001621 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001622 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001623 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001624 DataType::QAsymmU8,
1625 DataType::QSymmS16
Teresa Charlina3b20472019-06-06 11:12:32 +01001626 };
1627
1628 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1629 "Reference poolind2d: input is not a supported type.");
1630
1631 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1632 "Reference poolind2d: output is not a supported type.");
1633
1634 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1635 "Reference poolind2d: input and output types are mismatched.");
1636
1637 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001638}
1639
James Conroy4f1f8992020-04-29 20:01:10 +01001640bool RefLayerSupport::IsQLstmSupported(const TensorInfo& input,
1641 const TensorInfo& previousOutputIn,
1642 const TensorInfo& previousCellStateIn,
1643 const TensorInfo& outputStateOut,
1644 const TensorInfo& cellStateOut,
1645 const TensorInfo& output,
1646 const QLstmDescriptor& descriptor,
1647 const LstmInputParamsInfo& paramsInfo,
1648 Optional<std::string&> reasonIfUnsupported) const
1649{
1650 IgnoreUnused(input);
1651 IgnoreUnused(previousOutputIn);
1652 IgnoreUnused(previousCellStateIn);
1653 IgnoreUnused(outputStateOut);
1654 IgnoreUnused(cellStateOut);
1655 IgnoreUnused(output);
1656 IgnoreUnused(descriptor);
1657 IgnoreUnused(paramsInfo);
1658
1659 IgnoreUnused(reasonIfUnsupported);
1660
1661 return true;
1662}
1663
Derek Lamberti5f400d62019-03-25 15:41:58 +00001664bool RefLayerSupport::IsQuantizeSupported(const TensorInfo& input,
1665 const TensorInfo& output,
1666 Optional<std::string&> reasonIfUnsupported) const
1667{
1668 bool supported = true;
1669
Finn Williamsfd271062019-12-04 14:27:27 +00001670 // Define supported input types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001671 std::array<DataType,7> supportedInputTypes = {
1672 DataType::BFloat16,
Keith Davis5e51cd82020-01-29 16:52:59 +00001673 DataType::Float32,
Keith Davis3d8bc972020-02-04 09:31:47 +00001674 DataType::Float16,
Ryan OShea9add1202020-02-07 10:06:33 +00001675 DataType::QAsymmS8,
Keith Davis5e51cd82020-01-29 16:52:59 +00001676 DataType::QAsymmU8,
1677 DataType::QSymmS8,
1678 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001679 };
1680
1681 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
1682 "Reference quantize: input type not supported.");
1683
1684 // Define supported output types.
Ryan OShea9add1202020-02-07 10:06:33 +00001685 std::array<DataType,4> supportedOutputTypes = {
Ryan OShea9add1202020-02-07 10:06:33 +00001686 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001687 DataType::QAsymmU8,
Finn Williamsfd271062019-12-04 14:27:27 +00001688 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001689 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001690 };
1691 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
1692 "Reference quantize: output type not supported.");
1693
1694 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1695 "Reference quantize: input and output shapes have different num total elements.");
1696
1697 return supported;
1698}
1699
Finn Williams2605b232020-06-10 15:53:46 +01001700bool RefLayerSupport::IsRankSupported(const TensorInfo& input,
1701 const TensorInfo& output,
1702 Optional<std::string&> reasonIfUnsupported) const
1703{
1704 IgnoreUnused(input);
1705 // Define supported output types.
1706 std::array<DataType,1> supportedOutputTypes =
1707 {
1708 DataType::Signed32,
1709 };
1710
1711 return CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
1712 "Reference rank: input type not supported.");
1713}
1714
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001715bool RefLayerSupport::IsReshapeSupported(const TensorInfo& input,
Kevin Maya023c402019-12-12 17:28:05 +00001716 const TensorInfo& output,
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001717 const ReshapeDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001718 Optional<std::string&> reasonIfUnsupported) const
1719{
Jan Eilers8eb25602020-03-09 12:13:48 +00001720 IgnoreUnused(output);
1721 IgnoreUnused(descriptor);
Nina Drozd2f2778f2019-05-27 10:37:05 +01001722 // Define supported output types.
Keith Davis0c2eeac2020-02-11 16:51:50 +00001723 std::array<DataType,7> supportedOutputTypes =
Nina Drozd2f2778f2019-05-27 10:37:05 +01001724 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001725 DataType::BFloat16,
Nina Drozd2f2778f2019-05-27 10:37:05 +01001726 DataType::Float32,
1727 DataType::Float16,
Narumol Prangnawarat0718ee92019-09-13 16:53:38 +01001728 DataType::Signed32,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001729 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001730 DataType::QAsymmU8,
1731 DataType::QSymmS16
Nina Drozd2f2778f2019-05-27 10:37:05 +01001732 };
Keith Davis0c2eeac2020-02-11 16:51:50 +00001733
Nina Drozd2f2778f2019-05-27 10:37:05 +01001734 return CheckSupportRule(TypeAnyOf(input, supportedOutputTypes), reasonIfUnsupported,
1735 "Reference reshape: input type not supported.");
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001736}
1737
1738bool RefLayerSupport::IsResizeBilinearSupported(const TensorInfo& input,
Sadik Armaganc625f002018-12-17 11:32:16 +00001739 const TensorInfo& output,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001740 Optional<std::string&> reasonIfUnsupported) const
1741{
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001742 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001743 std::array<DataType,6> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001744 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001745 DataType::BFloat16,
Teresa Charlin970f43b2019-07-01 13:51:07 +01001746 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001747 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001748 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001749 DataType::QAsymmU8,
1750 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001751 };
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001752
1753 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1754 "Reference ResizeBilinear: input type not supported");
1755
1756 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1757 "Reference ResizeBilinear: output type not supported");
1758
1759 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1760 "Reference ResizeBilinear: input and output types not matching");
1761
1762 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001763}
1764
Teresa Charlin970f43b2019-07-01 13:51:07 +01001765bool RefLayerSupport::IsResizeSupported(const TensorInfo& input,
1766 const TensorInfo& output,
1767 const ResizeDescriptor& descriptor,
1768 Optional<std::string&> reasonIfUnsupported) const
1769{
Jan Eilers8eb25602020-03-09 12:13:48 +00001770 IgnoreUnused(descriptor);
Teresa Charlin970f43b2019-07-01 13:51:07 +01001771 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001772 std::array<DataType,6> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001773 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001774 DataType::BFloat16,
Teresa Charlin970f43b2019-07-01 13:51:07 +01001775 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001776 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001777 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001778 DataType::QAsymmU8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001779 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001780 };
1781
1782 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1783 "Reference Resize: input type not supported");
1784
1785 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1786 "Reference Resize: output type not supported");
1787
1788 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1789 "Reference Resize: input and output types not matching");
1790
1791 return supported;
1792}
1793
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001794bool RefLayerSupport::IsRsqrtSupported(const TensorInfo& input,
1795 const TensorInfo& output,
1796 Optional<std::string&> reasonIfUnsupported) const
1797{
josh minor4a3c6102020-01-06 16:40:46 -06001798 return IsElementwiseUnarySupported(input,
1799 output,
1800 ElementwiseUnaryDescriptor(UnaryOperation::Rsqrt),
1801 reasonIfUnsupported);
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001802}
1803
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001804bool RefLayerSupport::IsSliceSupported(const TensorInfo& input,
1805 const TensorInfo& output,
1806 const SliceDescriptor& descriptor,
1807 Optional<std::string&> reasonIfUnsupported) const
1808{
Jan Eilers8eb25602020-03-09 12:13:48 +00001809 IgnoreUnused(descriptor);
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001810 bool supported = true;
1811
Sadik Armagan303980c2020-04-17 12:45:14 +01001812 std::array<DataType, 5> supportedTypes =
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001813 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001814 DataType::BFloat16,
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001815 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001816 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001817 DataType::QAsymmU8,
1818 DataType::QSymmS16
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001819 };
1820
1821 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1822 "Reference Slice: input type not supported");
1823
1824 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1825 "Reference Slice: output type not supported");
1826
1827 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1828 "Reference Slice: input and output types are mismatched");
1829
1830 return supported;
1831}
1832
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001833bool RefLayerSupport::IsSoftmaxSupported(const TensorInfo& input,
1834 const TensorInfo& output,
1835 const SoftmaxDescriptor& descriptor,
1836 Optional<std::string&> reasonIfUnsupported) const
1837{
Jan Eilers8eb25602020-03-09 12:13:48 +00001838 IgnoreUnused(descriptor);
nikraj01248683f2019-05-29 16:46:50 +01001839 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001840 std::array<DataType,7> supportedTypes =
nikraj01248683f2019-05-29 16:46:50 +01001841 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001842 DataType::BFloat16,
1843 DataType::Float32,
1844 DataType::Float16,
1845 DataType::QSymmS8,
1846 DataType::QAsymmS8,
1847 DataType::QAsymmU8,
1848 DataType::QSymmS16
nikraj01248683f2019-05-29 16:46:50 +01001849 };
1850
1851 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001852 "Reference Softmax: output type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001853
1854 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001855 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001856
1857 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001858 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001859
1860 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001861}
1862
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001863bool RefLayerSupport::IsSpaceToBatchNdSupported(const TensorInfo& input,
1864 const TensorInfo& output,
1865 const SpaceToBatchNdDescriptor& descriptor,
1866 Optional<std::string&> reasonIfUnsupported) const
1867{
Jan Eilers8eb25602020-03-09 12:13:48 +00001868 IgnoreUnused(descriptor);
nikraj01120522a2019-05-31 11:33:07 +01001869 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001870 std::array<DataType,6> supportedTypes =
nikraj01120522a2019-05-31 11:33:07 +01001871 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001872 DataType::BFloat16,
1873 DataType::Float32,
1874 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001875 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001876 DataType::QAsymmU8,
1877 DataType::QSymmS16
nikraj01120522a2019-05-31 11:33:07 +01001878 };
1879
1880 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1881 "Reference SpaceToBatchNd: input type not supported");
1882
1883 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1884 "Reference SpaceToBatchNd: output type not supported");
1885
1886 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1887 "Reference SpaceToBatchNd: input and output types are mismatched");
1888
1889 return supported;
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001890}
1891
Keith Davisa57eccb2019-06-14 17:33:22 +01001892bool RefLayerSupport::IsSpaceToDepthSupported(const TensorInfo& input,
Keith Davis51910332019-06-26 15:28:43 +01001893 const TensorInfo& output,
1894 const SpaceToDepthDescriptor& descriptor,
1895 Optional<std::string&> reasonIfUnsupported) const
Keith Davisa57eccb2019-06-14 17:33:22 +01001896{
1897
Jan Eilers8eb25602020-03-09 12:13:48 +00001898 IgnoreUnused(descriptor);
Keith Davisa57eccb2019-06-14 17:33:22 +01001899 bool supported = true;
1900
Sadik Armagan303980c2020-04-17 12:45:14 +01001901 std::array<DataType,6> supportedTypes =
Keith Davisa57eccb2019-06-14 17:33:22 +01001902 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001903 DataType::BFloat16,
Keith Davisa57eccb2019-06-14 17:33:22 +01001904 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001905 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001906 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001907 DataType::QAsymmU8,
1908 DataType::QSymmS16
Keith Davisa57eccb2019-06-14 17:33:22 +01001909 };
1910
1911 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1912 "Reference SpaceToDepth: input type not supported");
1913
1914 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1915 "Reference SpaceToDepth: output type not supported");
1916
1917 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1918 "Reference SpaceToDepth: input and output types are mismatched");
1919
1920 return supported;
1921}
1922
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001923bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1924 const ViewsDescriptor& descriptor,
1925 Optional<std::string&> reasonIfUnsupported) const
1926{
Jan Eilers8eb25602020-03-09 12:13:48 +00001927 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001928 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001929 std::array<DataType,6> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001930 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001931 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001932 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001933 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001934 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001935 DataType::QAsymmU8,
1936 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001937 };
1938
1939 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1940 "Reference splitter: input type not supported");
1941
1942 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001943}
1944
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001945bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1946 const std::vector<std::reference_wrapper<TensorInfo>>& outputs,
1947 const ViewsDescriptor& descriptor,
1948 Optional<std::string&> reasonIfUnsupported) const
1949{
Jan Eilers8eb25602020-03-09 12:13:48 +00001950 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001951 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001952 std::array<DataType,6> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001953 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001954 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001955 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001956 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001957 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001958 DataType::QAsymmU8,
1959 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001960 };
1961
1962 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1963 "Reference splitter: output type not supported");
Derek Lambertieac4adb2020-08-25 13:05:59 +01001964 for (const TensorInfo& output : outputs)
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001965 {
1966 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1967 "Reference splitter: input type not supported");
1968
1969 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1970 "Reference splitter: input and output types mismatched.");
1971 }
1972
1973 return supported;
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001974}
1975
Matthew Jackson81e601c2019-07-11 12:07:09 +01001976bool RefLayerSupport::IsStackSupported(const std::vector<const TensorInfo*>& inputs,
1977 const TensorInfo& output,
1978 const StackDescriptor& descriptor,
1979 Optional<std::string&> reasonIfUnsupported) const
1980{
Jan Eilers8eb25602020-03-09 12:13:48 +00001981 IgnoreUnused(descriptor);
Matthew Jackson81e601c2019-07-11 12:07:09 +01001982
1983 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001984 std::array<DataType,6> supportedTypes =
Matthew Jackson81e601c2019-07-11 12:07:09 +01001985 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001986 DataType::BFloat16,
Matthew Jackson81e601c2019-07-11 12:07:09 +01001987 DataType::Float32,
Matthew Jacksone69c3992019-09-09 14:31:21 +01001988 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001989 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001990 DataType::QAsymmU8,
1991 DataType::QSymmS16
Matthew Jackson81e601c2019-07-11 12:07:09 +01001992 };
1993
1994 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1995 "Reference stack: output type not supported");
1996 for (const TensorInfo* input : inputs)
1997 {
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +01001998 ARMNN_ASSERT(input != nullptr);
Matthew Jackson81e601c2019-07-11 12:07:09 +01001999 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
2000 "Reference stack: input type not supported");
2001
2002 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
2003 "Reference stack: input and output types mismatched.");
2004 }
2005
2006 return supported;
2007}
2008
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00002009bool RefLayerSupport::IsStridedSliceSupported(const TensorInfo& input,
2010 const TensorInfo& output,
2011 const StridedSliceDescriptor& descriptor,
2012 Optional<std::string&> reasonIfUnsupported) const
2013{
Jan Eilers8eb25602020-03-09 12:13:48 +00002014 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01002015 bool supported = true;
2016
Sadik Armagan303980c2020-04-17 12:45:14 +01002017 std::array<DataType,5> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01002018 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002019 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01002020 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01002021 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002022 DataType::QAsymmU8,
2023 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01002024 };
2025
2026 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2027 "Reference StridedSlice: input type not supported");
2028
2029 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2030 "Reference StridedSlice: output type not supported");
2031
2032 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2033 "Reference StridedSlice: input and output types are mismatched");
2034
2035 return supported;
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00002036}
2037
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01002038bool RefLayerSupport::IsSubtractionSupported(const TensorInfo& input0,
2039 const TensorInfo& input1,
2040 const TensorInfo& output,
2041 Optional<std::string&> reasonIfUnsupported) const
2042{
Sadik Armagan2999a022019-04-09 14:20:12 +01002043 bool supported = true;
2044
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01002045 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002046 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01002047 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01002048 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002049 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002050 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01002051 DataType::QSymmS16,
2052 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01002053 };
2054
2055 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
2056 "Reference subtraction: input 0 is not a supported type.");
2057
2058 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
2059 "Reference subtraction: input 1 is not a supported type.");
2060
2061 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2062 "Reference subtraction: output is not a supported type.");
2063
2064 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
2065 "Reference subtraction: input 0 and Input 1 types are mismatched");
2066
2067 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
2068 "Reference subtraction: input and output types are mismatched");
2069
2070 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
2071 "Reference subtraction: shapes are not suitable for implicit broadcast.");
2072
2073 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01002074}
2075
Matteo Martincighab9e5252019-06-13 17:27:46 +01002076bool RefLayerSupport::IsPreluSupported(const TensorInfo& input,
2077 const TensorInfo& alpha,
2078 const TensorInfo& output,
2079 Optional<std::string&> reasonIfUnsupported) const
2080{
2081 bool supported = true;
2082
Teresa Charlin3940d8b2020-05-29 16:47:23 +01002083 std::array<DataType, 6> supportedTypes
Matteo Martincighab9e5252019-06-13 17:27:46 +01002084 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002085 DataType::BFloat16,
Matteo Martincighab9e5252019-06-13 17:27:46 +01002086 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01002087 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002088 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002089 DataType::QAsymmU8,
Teresa Charlin3940d8b2020-05-29 16:47:23 +01002090 DataType::QSymmS16
Matteo Martincighab9e5252019-06-13 17:27:46 +01002091 };
2092
2093 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2094 "PReLU: input is not a supported type.");
2095
2096 supported &= CheckSupportRule(TypeAnyOf(alpha, supportedTypes), reasonIfUnsupported,
2097 "PReLU: alpha is not a supported type.");
2098
2099 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2100 "PReLU: output is not a supported type.");
2101
2102 supported &= CheckSupportRule(TypesAreEqual(input, alpha, output), reasonIfUnsupported,
2103 "PReLU: input, alpha and output types are mismatched");
2104
2105 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input, alpha, output), reasonIfUnsupported,
2106 "PReLU: shapes are not suitable for implicit broadcast");
2107
2108 return supported;
2109}
2110
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002111bool RefLayerSupport::IsTransposeConvolution2dSupported(const TensorInfo& input,
2112 const TensorInfo& output,
2113 const TransposeConvolution2dDescriptor& descriptor,
2114 const TensorInfo& weights,
2115 const Optional<TensorInfo>& biases,
2116 Optional<std::string&> reasonIfUnsupported) const
2117{
Jan Eilers8eb25602020-03-09 12:13:48 +00002118 IgnoreUnused(descriptor);
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002119 bool supported = true;
2120
Sadik Armagan303980c2020-04-17 12:45:14 +01002121 std::array<DataType,7> supportedTypes =
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002122 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002123 DataType::BFloat16,
2124 DataType::Float32,
2125 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002126 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002127 DataType::QAsymmU8,
Sadik Armagan303980c2020-04-17 12:45:14 +01002128 DataType::QSymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002129 DataType::QSymmS16
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002130 };
2131
2132 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2133 "Reference TransposeConvolution2d: input is not a supported type.");
2134
2135 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2136 "Reference TransposeConvolution2d: output is not a supported type.");
2137
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002138 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2139 "Reference TransposeConvolution2d: input and output types mismatched.");
2140
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002141
2142 const DataType inputType = input.GetDataType();
Sadik Armagan303980c2020-04-17 12:45:14 +01002143 if (IsQuantized8BitType(inputType))
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002144 {
Derek Lambertid466a542020-01-22 15:37:29 +00002145 ARMNN_NO_DEPRECATE_WARN_BEGIN
Sadik Armagan303980c2020-04-17 12:45:14 +01002146 std::array<DataType, 4> supportedWeightTypes =
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002147 {
Sadik Armagan303980c2020-04-17 12:45:14 +01002148 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002149 DataType::QAsymmU8,
Derek Lambertid466a542020-01-22 15:37:29 +00002150 DataType::QSymmS8,
2151 DataType::QuantizedSymm8PerAxis //Deprecated
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002152 };
Derek Lambertid466a542020-01-22 15:37:29 +00002153 ARMNN_NO_DEPRECATE_WARN_END
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002154
2155 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
2156 "Reference TransposeConvolution2d: weights type not supported for "
2157 "quantized input.");
2158 }
2159 else
2160 {
2161 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
2162 "Reference TransposeConvolution2d: weights is not a supported type.");
2163
2164 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
2165 "Reference TransposeConvolution2d: input and weights types mismatched.");
2166 }
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002167
2168 if (biases.has_value())
2169 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002170 std::array<DataType,4> biasesSupportedTypes =
Aron Virginas-Tar651aafe2019-08-05 11:52:05 +01002171 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002172 DataType::BFloat16,
2173 DataType::Float32,
2174 DataType::Float16,
2175 DataType::Signed32
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002176 };
2177 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
2178 "Reference TransposeConvolution2d: biases is not a supported type.");
2179 }
2180
2181 return supported;
2182}
2183
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002184bool RefLayerSupport::IsTransposeSupported(const TensorInfo& input,
2185 const TensorInfo& output,
2186 const TransposeDescriptor& descriptor,
2187 Optional<std::string&> reasonIfUnsupported) const
2188{
Jan Eilers8eb25602020-03-09 12:13:48 +00002189 IgnoreUnused(descriptor);
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002190 bool supported = true;
2191
2192 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01002193 std::array<DataType, 6> supportedTypes =
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002194 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002195 DataType::BFloat16,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002196 DataType::Float32,
2197 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002198 DataType::QAsymmS8,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002199 DataType::QAsymmU8,
2200 DataType::QSymmS16
2201 };
2202
2203 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2204 "Reference transpose: input is not a supported type.");
2205
2206 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2207 "Reference transpose: output is not a supported type.");
2208
2209 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2210 "Reference transpose: input and output types are mismatched.");
2211
2212 return supported;
2213}
2214
arovir011c7c81b2018-10-08 11:34:28 +01002215} // namespace armnn