blob: 992ae71f97c4541f79e0f904b7e4987f97553f26 [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
Narumol Prangnawarat0c95f4c2020-11-18 16:52:07 +0000810 std::array<DataType, 1> logicalSupportedTypes =
811 {
812 DataType::Boolean
813 };
814
josh minor4a3c6102020-01-06 16:40:46 -0600815 bool supported = true;
816
Narumol Prangnawarat0c95f4c2020-11-18 16:52:07 +0000817 if (descriptor.m_Operation == UnaryOperation::LogicalNot)
818 {
819 supported &= CheckSupportRule(TypeAnyOf(input, logicalSupportedTypes), reasonIfUnsupported,
820 "Reference elementwise unary: input type not supported");
josh minor4a3c6102020-01-06 16:40:46 -0600821
Narumol Prangnawarat0c95f4c2020-11-18 16:52:07 +0000822 supported &= CheckSupportRule(TypeAnyOf(output, logicalSupportedTypes), reasonIfUnsupported,
823 "Reference elementwise unary: output type not supported");
824 }
825 else
826 {
827 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
828 "Reference elementwise unary: input type not supported");
829
830 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
831 "Reference elementwise unary: output type not supported");
832 }
josh minor4a3c6102020-01-06 16:40:46 -0600833
834 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
835 "Reference elementwise unary: input and output types not matching");
836
837 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
838 "Reference elementwise unary: input and output shapes"
839 "have different number of total elements");
840
841 return supported;
842}
843
FrancisMurtagh30cdfca2018-12-18 12:57:35 +0000844bool RefLayerSupport::IsEqualSupported(const TensorInfo& input0,
845 const TensorInfo& input1,
846 const TensorInfo& output,
847 Optional<std::string&> reasonIfUnsupported) const
848{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100849 return IsComparisonSupported(input0,
850 input1,
851 output,
852 ComparisonDescriptor(ComparisonOperation::Equal),
853 reasonIfUnsupported);
FrancisMurtagh30cdfca2018-12-18 12:57:35 +0000854}
855
arovir011c7c81b2018-10-08 11:34:28 +0100856bool RefLayerSupport::IsFakeQuantizationSupported(const TensorInfo& input,
857 const FakeQuantizationDescriptor& descriptor,
858 Optional<std::string&> reasonIfUnsupported) const
859{
Jan Eilers8eb25602020-03-09 12:13:48 +0000860 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100861 bool supported = true;
862
863 std::array<DataType,1> supportedTypes =
864 {
865 DataType::Float32
866 };
867
868 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
869 "Reference fake quantization: input type not supported.");
870
871 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100872}
873
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100874bool RefLayerSupport::IsFillSupported(const TensorInfo& input,
875 const TensorInfo& output,
876 const FillDescriptor& descriptor,
877 Optional<std::string&> reasonIfUnsupported) const
878{
879 IgnoreUnused(descriptor);
880 IgnoreUnused(output);
881
882 bool supported = true;
883
Sadik Armagana792a052020-06-23 16:22:23 +0100884 std::array<DataType,3> supportedTypes =
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100885 {
886 DataType::Float32,
Sadik Armagana792a052020-06-23 16:22:23 +0100887 DataType::Float16,
888 DataType::Signed32
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100889 };
890
Teresa Charlin4b10fef2020-07-29 09:36:41 +0100891 supported &= CheckSupportRule(TypeIs(input, DataType::Signed32), reasonIfUnsupported,
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100892 "Reference Fill: input type not supported.");
893
Teresa Charlin44088502020-07-27 11:27:19 +0100894 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
895 "Reference Fill: output type not supported.");
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100896 return supported;
897}
898
arovir011c7c81b2018-10-08 11:34:28 +0100899bool RefLayerSupport::IsFloorSupported(const TensorInfo& input,
900 const TensorInfo& output,
901 Optional<std::string&> reasonIfUnsupported) const
902{
Jan Eilers8eb25602020-03-09 12:13:48 +0000903 IgnoreUnused(output);
James Conroy83735b12019-05-30 16:36:59 +0100904 bool supported = true;
905
Francis Murtaghe8ac1332020-07-30 18:03:40 +0100906 std::array<DataType,3> supportedTypes =
James Conroy83735b12019-05-30 16:36:59 +0100907 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000908 DataType::BFloat16,
James Conroyb40d7102019-06-04 12:32:09 +0100909 DataType::Float32,
Francis Murtaghe8ac1332020-07-30 18:03:40 +0100910 DataType::Float16
James Conroy83735b12019-05-30 16:36:59 +0100911 };
912
913 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
914 "Reference Floor: input type not supported.");
915
916 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
917 "Reference Floor: output type not supported.");
918
919 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100920}
921
922bool RefLayerSupport::IsFullyConnectedSupported(const TensorInfo& input,
923 const TensorInfo& output,
924 const TensorInfo& weights,
925 const TensorInfo& biases,
926 const FullyConnectedDescriptor& descriptor,
927 Optional<std::string&> reasonIfUnsupported) const
928{
Francis Murtagh46c09d02019-05-28 08:15:28 +0100929 bool supported = true;
930
931 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000932 std::array<DataType,6> supportedTypes =
Francis Murtagh46c09d02019-05-28 08:15:28 +0100933 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000934 DataType::BFloat16,
935 DataType::Float32,
936 DataType::Float16,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000937 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100938 DataType::QAsymmU8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000939 DataType::QSymmS16
Francis Murtagh46c09d02019-05-28 08:15:28 +0100940 };
941
942 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
943 "Reference Fully Connected: input type not supported.");
944
945 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
946 "Reference Fully Connected: output type not supported.");
947
Francis Murtagh46c09d02019-05-28 08:15:28 +0100948 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
949 "Reference Fully Connected: weights type not supported.");
950
Narumol Prangnawarat57ef0082020-03-26 09:20:43 +0000951 // For FullyConnected, we allow to have BFloat16 input with Float32 output for optimization.
952 if (input.GetDataType() == DataType::BFloat16)
953 {
954 if (output.GetDataType() != DataType::BFloat16 && output.GetDataType() != DataType::Float32)
955 {
956 reasonIfUnsupported.value() += "Output tensor type must be BFloat16 or Float32 for BFloat16 input.\n";
957 supported = false;
958 }
959 }
960 else
961 {
962 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
963 "Reference Fully Connected: input and output types mismatched.");
964 }
965
Jan Eilers1f45dc32020-06-15 11:43:03 +0100966 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
967 "Reference Fully Connected: weights is not a supported type.");
Francis Murtaghddb1d062020-03-10 13:51:45 +0000968
Jan Eilers1f45dc32020-06-15 11:43:03 +0100969 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
970 "Reference Fully Connected: input and weights types mismatched.");
Francis Murtagh46c09d02019-05-28 08:15:28 +0100971
972 if (descriptor.m_BiasEnabled)
973 {
974 // Defined supported types for bias
Sadik Armagandb73c982020-04-01 17:35:30 +0100975 std::array<DataType, 5>
Francis Murtagh46c09d02019-05-28 08:15:28 +0100976 supportedBiasTypes =
977 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000978 DataType::BFloat16,
Francis Murtagh46c09d02019-05-28 08:15:28 +0100979 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100980 DataType::Float16,
Sadik Armagandb73c982020-04-01 17:35:30 +0100981 DataType::Signed32,
982 DataType::QAsymmS8
Francis Murtagh46c09d02019-05-28 08:15:28 +0100983 };
984
985 supported &= CheckSupportRule(TypeAnyOf(biases, supportedBiasTypes), reasonIfUnsupported,
986 "Reference Fully Connected: bias type not supported.");
987
988 supported &= CheckSupportRule(BiasAndWeightsTypesMatch(biases, weights), reasonIfUnsupported,
989 "Reference Fully Connected: bias and weight types mismatch.");
990
991 supported &= CheckSupportRule(BiasAndWeightsTypesCompatible(weights, supportedBiasTypes), reasonIfUnsupported,
992 "Reference Fully Connected: bias type inferred from weights is incompatible.");
993
Narumol Prangnawarat366d7232020-04-29 12:58:17 +0100994 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(biases, 1U), reasonIfUnsupported,
995 "Reference Fully Connected: bias must have 1 dimension.");
996
Francis Murtagh46c09d02019-05-28 08:15:28 +0100997 }
998
999 return supported;
arovir011c7c81b2018-10-08 11:34:28 +01001000}
1001
narpra014951d842019-01-18 16:53:53 +00001002bool RefLayerSupport::IsGatherSupported(const armnn::TensorInfo& input0,
1003 const armnn::TensorInfo& input1,
1004 const armnn::TensorInfo& output,
Teresa Charlin52664732020-06-29 16:27:03 +01001005 const GatherDescriptor& descriptor,
narpra014951d842019-01-18 16:53:53 +00001006 armnn::Optional<std::string&> reasonIfUnsupported) const
1007{
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +01001008 bool supported = true;
Teresa Charlin3940d8b2020-05-29 16:47:23 +01001009 std::array<DataType,7> supportedTypes =
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +01001010 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001011 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001012 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001013 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001014 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001015 DataType::QAsymmU8,
Teresa Charlin3940d8b2020-05-29 16:47:23 +01001016 DataType::QSymmS16,
1017 DataType::Signed32
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +01001018 };
1019
Teresa Charlin52664732020-06-29 16:27:03 +01001020 if (descriptor.m_Axis != 0)
1021 {
1022 reasonIfUnsupported.value() += std::string("Reference Gather: axis not supported\n");
1023 supported &= false;
1024 }
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +01001025 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1026 "Reference Gather: input type not supported");
1027
1028 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1029 "Reference Gather: output type not supported");
1030
1031 supported &= CheckSupportRule(TypeIs(input1, DataType::Signed32), reasonIfUnsupported,
1032 "Reference Gather: indices (input1) type not supported");
1033
1034 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1035 "Reference Gather: input and output types not matching");
1036
1037 return supported;
narpra014951d842019-01-18 16:53:53 +00001038}
1039
FrancisMurtagh878f0232018-12-19 10:56:15 +00001040bool RefLayerSupport::IsGreaterSupported(const TensorInfo& input0,
1041 const TensorInfo& input1,
1042 const TensorInfo& output,
1043 Optional<std::string&> reasonIfUnsupported) const
1044{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +01001045 return IsComparisonSupported(input0,
1046 input1,
1047 output,
1048 ComparisonDescriptor(ComparisonOperation::Greater),
1049 reasonIfUnsupported);
FrancisMurtagh878f0232018-12-19 10:56:15 +00001050}
1051
Derek Lamberti901ea112019-12-10 22:07:09 +00001052bool RefLayerSupport::IsInputSupported(const TensorInfo& /*input*/,
1053 Optional<std::string&> /*reasonIfUnsupported*/) const
arovir011c7c81b2018-10-08 11:34:28 +01001054{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +01001055 return true;
arovir011c7c81b2018-10-08 11:34:28 +01001056}
1057
Kevin May09ca49c2019-10-09 12:37:34 +01001058bool RefLayerSupport::IsInstanceNormalizationSupported(const TensorInfo& input,
1059 const TensorInfo& output,
1060 const InstanceNormalizationDescriptor& descriptor,
1061 Optional<std::string&> reasonIfUnsupported) const
1062{
Jan Eilers8eb25602020-03-09 12:13:48 +00001063 IgnoreUnused(descriptor);
Kevin May09ca49c2019-10-09 12:37:34 +01001064 // Define supported types
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001065 std::array<DataType, 3> supportedTypes =
Kevin May09ca49c2019-10-09 12:37:34 +01001066 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001067 DataType::BFloat16,
Kevin May09ca49c2019-10-09 12:37:34 +01001068 DataType::Float32,
1069 DataType::Float16
1070 };
1071
1072 bool supported = true;
1073
1074 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1075 "Reference Instance Normalization: input type not supported.");
1076
1077 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1078 "Reference Instance Normalization: output type not supported.");
1079
1080 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1081 "Reference Instance Normalization: input and output types mismatched.");
1082
1083 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1084 "Reference Instance Normalization: input and output shapes have different "
1085 "num total elements.");
1086
1087 return supported;
1088}
1089
arovir011c7c81b2018-10-08 11:34:28 +01001090bool RefLayerSupport::IsL2NormalizationSupported(const TensorInfo& input,
1091 const TensorInfo& output,
1092 const L2NormalizationDescriptor& descriptor,
1093 Optional<std::string&> reasonIfUnsupported) const
1094{
Jan Eilers8eb25602020-03-09 12:13:48 +00001095 IgnoreUnused(descriptor);
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001096 // Define supported types
Sadik Armagan303980c2020-04-17 12:45:14 +01001097 std::array<DataType, 6> supportedTypes =
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001098 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001099 DataType::BFloat16,
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001100 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001101 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001102 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001103 DataType::QAsymmU8,
1104 DataType::QSymmS16
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001105 };
1106
1107 bool supported = true;
1108
1109 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1110 "Reference L2normalization: input type not supported.");
1111
1112 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1113 "Reference L2normalization: output type not supported.");
1114
1115 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1116 "Reference L2normalization: input and output types mismatched.");
1117
1118 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1119 "Reference L2normalization: input and output shapes have different "
1120 "num total elements.");
1121
1122 return supported;
arovir011c7c81b2018-10-08 11:34:28 +01001123}
1124
James Conroyaba90cd2020-11-06 16:28:18 +00001125bool RefLayerSupport::IsLogicalBinarySupported(const TensorInfo& input0,
1126 const TensorInfo& input1,
1127 const TensorInfo& output,
1128 const LogicalBinaryDescriptor& descriptor,
1129 Optional<std::string&> reasonIfUnsupported) const
1130{
1131 IgnoreUnused(descriptor);
1132
1133 std::array<DataType, 1> supportedTypes =
1134 {
1135 DataType::Boolean
1136 };
1137
1138 bool supported = true;
1139 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1140 "Reference LogicalBinary: input 0 type not supported");
1141 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1142 "Reference LogicalBinary: input 1 type not supported");
1143
1144 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1145 "Reference LogicalBinary: input and output types do not match");
1146
1147 return supported;
1148}
1149
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001150bool RefLayerSupport::IsLogSoftmaxSupported(const TensorInfo& input,
1151 const TensorInfo& output,
1152 const LogSoftmaxDescriptor& descriptor,
1153 Optional<std::string&> reasonIfUnsupported) const
1154{
Jan Eilers8eb25602020-03-09 12:13:48 +00001155 IgnoreUnused(descriptor);
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001156
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001157 std::array<DataType, 3> supportedTypes =
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001158 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001159 DataType::BFloat16,
1160 DataType::Float32,
1161 DataType::Float16
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001162 };
1163
1164 bool supported = true;
1165 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1166 "Reference LogSoftmax: input type not supported");
1167
1168 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1169 "Reference LogSoftmax: output type not supported");
1170
1171 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1172 "Reference LogSoftmax: input and output types do not match");
1173
1174 return supported;
1175}
1176
arovir011c7c81b2018-10-08 11:34:28 +01001177bool RefLayerSupport::IsLstmSupported(const TensorInfo& input,
1178 const TensorInfo& outputStateIn,
1179 const TensorInfo& cellStateIn,
1180 const TensorInfo& scratchBuffer,
1181 const TensorInfo& outputStateOut,
1182 const TensorInfo& cellStateOut,
1183 const TensorInfo& output,
1184 const LstmDescriptor& descriptor,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001185 const LstmInputParamsInfo& paramsInfo,
1186 Optional<std::string&> reasonIfUnsupported) const
arovir011c7c81b2018-10-08 11:34:28 +01001187{
Jan Eilers8eb25602020-03-09 12:13:48 +00001188 IgnoreUnused(descriptor);
1189 IgnoreUnused(paramsInfo);
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001190
1191 bool supported = true;
1192
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001193 std::array<DataType,3> supportedTypes = {
1194 DataType::BFloat16,
Conor Kennedyb9971c92019-05-07 07:14:23 +01001195 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001196 DataType::QSymmS16
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001197 };
1198
Jan Eilersd01a83c2019-07-03 18:20:40 +01001199 // check inputs and outputs
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001200 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1201 "Reference Lstm: input is not a supported type.");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001202 supported &= CheckSupportRule(TypesAreEqual(input, outputStateIn), reasonIfUnsupported,
1203 "Reference Lstm: input and outputStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001204 supported &= CheckSupportRule(TypesAreEqual(input, cellStateIn), reasonIfUnsupported,
1205 "Reference Lstm: input and cellStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001206 supported &= CheckSupportRule(TypesAreEqual(input, scratchBuffer), reasonIfUnsupported,
1207 "Reference Lstm: input and scratchBuffer types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001208 supported &= CheckSupportRule(TypesAreEqual(input, outputStateOut), reasonIfUnsupported,
1209 "Reference Lstm: input and outputStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001210 supported &= CheckSupportRule(TypesAreEqual(input, cellStateOut), reasonIfUnsupported,
1211 "Reference Lstm: input and cellStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001212 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1213 "Reference Lstm: input and output types are mismatched");
Jan Eilersd01a83c2019-07-03 18:20:40 +01001214 // check layer parameters
Francis Murtaghbb590b42019-08-14 09:51:36 +01001215 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001216 "Reference Lstm: input and InputToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001217 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001218 "Reference Lstm: input and InputToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001219 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001220 "Reference Lstm: input and InputToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001221 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001222 "Reference Lstm: input and RecurrentToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001223 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001224 "Reference Lstm: input and RecurrentToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001225 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001226 "Reference Lstm: input and RecurrentToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001227 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001228 "Reference Lstm: input and ForgetGateBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001229 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001230 "Reference Lstm: input and CellBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001231 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001232 "Reference Lstm: input and OutputGateBias types are mismatched");
1233 if (!descriptor.m_CifgEnabled)
1234 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001235 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToInputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001236 "Reference Lstm: input and InputToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001237 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001238 reasonIfUnsupported,
1239 "Reference Lstm: input and RecurrentToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001240 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001241 "Reference Lstm: input and InputGateBias types are mismatched");
1242 if (descriptor.m_PeepholeEnabled)
1243 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001244 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001245 reasonIfUnsupported,
1246 "Reference Lstm: input and CellToInputWeights types are mismatched");
1247 }
1248 }
1249 if (descriptor.m_PeepholeEnabled)
1250 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001251 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001252 "Reference Lstm: input and CellToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001253 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001254 "Reference Lstm: input and CellToOutputWeights types are mismatched");
1255 }
1256 if (descriptor.m_ProjectionEnabled)
1257 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001258 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001259 "Reference Lstm: input and mProjectionWeights types are mismatched");
1260 if (paramsInfo.m_ProjectionBias != nullptr)
1261 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001262 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001263 "Reference Lstm: input and ProjectionBias types are mismatched");
1264 }
1265 }
1266 if (descriptor.m_LayerNormEnabled)
1267 {
1268 if (!descriptor.m_CifgEnabled)
1269 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001270 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001271 reasonIfUnsupported,
1272 "Reference Lstm: input and InputLayerNormWeights types are mismatched");
1273 }
Francis Murtaghbb590b42019-08-14 09:51:36 +01001274 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001275 reasonIfUnsupported,
1276 "Reference Lstm: input and ForgetLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001277 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001278 reasonIfUnsupported,
1279 "Reference Lstm: input and CellLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001280 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001281 reasonIfUnsupported,
1282 "Reference Lstm: input and OutputLayerNormWeights types are mismatched");
1283 }
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001284
1285 return supported;
telsoa01c577f2c2018-08-31 09:22:23 +01001286}
1287
saoste012df12b32018-11-28 16:57:20 +00001288bool RefLayerSupport::IsMaximumSupported(const TensorInfo& input0,
1289 const TensorInfo& input1,
1290 const TensorInfo& output,
1291 Optional<std::string&> reasonIfUnsupported) const
1292{
Sadik Armagan2999a022019-04-09 14:20:12 +01001293 bool supported = true;
1294
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001295 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001296 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001297 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001298 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001299 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001300 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001301 DataType::QSymmS16,
1302 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01001303 };
1304
1305 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1306 "Reference maximum: input 0 is not a supported type.");
1307
1308 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1309 "Reference maximum: input 1 is not a supported type.");
1310
1311 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1312 "Reference maximum: output is not a supported type.");
1313
1314 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1315 "Reference maximum: input 0 and Input 1 types are mismatched");
1316
1317 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1318 "Reference maximum: input and output types are mismatched");
1319
1320 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1321 "Reference maximum: shapes are not suitable for implicit broadcast.");
1322
1323 return supported;
saoste012df12b32018-11-28 16:57:20 +00001324}
1325
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001326bool RefLayerSupport::IsMeanSupported(const TensorInfo& input,
1327 const TensorInfo& output,
1328 const MeanDescriptor& descriptor,
1329 Optional<std::string&> reasonIfUnsupported) const
narpra0132b90462018-09-13 11:07:48 +01001330{
James Conroy4d1ff582019-06-10 17:06:39 +01001331 bool supported = true;
1332 std::string meanLayerStr = "Mean";
1333 std::string outputTensorStr = "output";
1334
Sadik Armagan303980c2020-04-17 12:45:14 +01001335 std::array<DataType,6> supportedTypes =
James Conroy4d1ff582019-06-10 17:06:39 +01001336 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001337 DataType::BFloat16,
James Conroy4d1ff582019-06-10 17:06:39 +01001338 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001339 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001340 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001341 DataType::QAsymmU8,
1342 DataType::QSymmS16
James Conroy4d1ff582019-06-10 17:06:39 +01001343 };
1344
1345 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1346 "Reference Mean: input type not supported.");
1347
1348 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1349 "Reference Mean: input and output types are mismatched");
1350
1351 if (descriptor.m_KeepDims)
1352 {
1353 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, input.GetNumDimensions()),
1354 reasonIfUnsupported,
1355 CreateIncorrectDimensionsErrorMsg(input.GetNumDimensions(),
1356 output.GetNumDimensions(),
1357 meanLayerStr, outputTensorStr).data());
1358 }
1359 else if (descriptor.m_Axis.empty())
1360 {
1361 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1362 reasonIfUnsupported,
1363 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1364 meanLayerStr, outputTensorStr).data());
1365 }
1366 else
1367 {
Matthew Sloyan171214c2020-09-09 09:07:37 +01001368 auto outputDim = input.GetNumDimensions() - armnn::numeric_cast<unsigned int>(descriptor.m_Axis.size());
James Conroy4d1ff582019-06-10 17:06:39 +01001369
1370 if (outputDim > 0)
1371 {
1372 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, outputDim),
1373 reasonIfUnsupported,
1374 CreateIncorrectDimensionsErrorMsg(outputDim, output.GetNumDimensions(),
1375 meanLayerStr, outputTensorStr).data());
1376 }
1377 else
1378 {
1379 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1380 reasonIfUnsupported,
1381 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1382 meanLayerStr, outputTensorStr).data());
1383 }
1384 }
1385
1386 return supported;
narpra0132b90462018-09-13 11:07:48 +01001387}
1388
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001389bool RefLayerSupport::IsMergerSupported(const std::vector<const TensorInfo*> inputs,
Nikhil Raj8599a412018-11-19 14:51:07 +00001390 const TensorInfo& output,
Jim Flynne242f2d2019-05-22 14:24:13 +01001391 const MergerDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001392 Optional<std::string&> reasonIfUnsupported) const
1393{
Jim Flynne242f2d2019-05-22 14:24:13 +01001394 return IsConcatSupported(inputs, output, descriptor, reasonIfUnsupported);
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001395}
1396
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001397bool RefLayerSupport::IsMemCopySupported(const TensorInfo &input,
1398 const TensorInfo &output,
1399 Optional<std::string &> reasonIfUnsupported) const
1400{
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001401 bool supported = true;
1402
Sadik Armagan303980c2020-04-17 12:45:14 +01001403 std::array<DataType,7> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001404 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001405 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001406 DataType::Float32,
1407 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001408 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001409 DataType::QAsymmU8,
1410 DataType::QSymmS16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001411 DataType::Boolean
1412 };
1413
1414 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1415 "Reference MemCopy: input type not supported");
1416
1417 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1418 "Reference MemCopy: output type not supported");
1419
1420 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1421 "Reference MemCopy: input and output types are mismatched");
1422
1423 return supported;
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001424}
1425
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001426bool RefLayerSupport::IsMinimumSupported(const TensorInfo& input0,
1427 const TensorInfo& input1,
1428 const TensorInfo& output,
1429 Optional<std::string&> reasonIfUnsupported) const
1430{
Sadik Armagan2999a022019-04-09 14:20:12 +01001431 bool supported = true;
1432
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001433 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001434 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001435 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001436 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001437 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001438 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001439 DataType::QSymmS16,
1440 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01001441 };
1442
1443 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1444 "Reference minimum: input 0 is not a supported type.");
1445
1446 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1447 "Reference minimum: input 1 is not a supported type.");
1448
1449 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1450 "Reference minimum: output is not a supported type.");
1451
1452 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1453 "Reference minimum: input 0 and Input 1 types are mismatched");
1454
1455 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1456 "Reference minimum: input and output types are mismatched");
1457
1458 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1459 "Reference minimum: shapes are not suitable for implicit broadcast.");
1460
1461 return supported;
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001462}
1463
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001464bool RefLayerSupport::IsMultiplicationSupported(const TensorInfo& input0,
1465 const TensorInfo& input1,
1466 const TensorInfo& output,
1467 Optional<std::string&> reasonIfUnsupported) const
1468{
Sadik Armagan2999a022019-04-09 14:20:12 +01001469 bool supported = true;
1470
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001471 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001472 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001473 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001474 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001475 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001476 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001477 DataType::QSymmS16,
1478 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01001479 };
1480
1481 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1482 "Reference multiplication: input 0 is not a supported type.");
1483
1484 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1485 "Reference multiplication: input 1 is not a supported type.");
1486
1487 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1488 "Reference multiplication: output is not a supported type.");
1489
1490 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1491 "Reference multiplication: input 0 and Input 1 types are mismatched");
1492
1493 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1494 "Reference multiplication: input and output types are mismatched");
1495
1496 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1497 "Reference multiplication: shapes are not suitable for implicit broadcast.");
1498
1499 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001500}
1501
1502bool RefLayerSupport::IsNormalizationSupported(const TensorInfo& input,
1503 const TensorInfo& output,
1504 const NormalizationDescriptor& descriptor,
1505 Optional<std::string&> reasonIfUnsupported) const
Nina Drozd661dfa72018-10-02 11:14:17 +01001506{
Jan Eilers8eb25602020-03-09 12:13:48 +00001507 IgnoreUnused(descriptor);
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001508
1509 // Define supported types
Sadik Armagan303980c2020-04-17 12:45:14 +01001510 std::array<DataType, 6> supportedTypes =
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001511 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001512 DataType::BFloat16,
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001513 DataType::Float16,
1514 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001515 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001516 DataType::QAsymmU8,
1517 DataType::QSymmS16
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001518 };
1519
1520 bool supported = true;
1521
1522 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1523 "Reference normalization: input type not supported.");
1524
1525 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1526 "Reference normalization: output type not supported.");
1527
1528 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1529 "Reference normalization: input and output shapes have different "
1530 "num total elements.");
1531
1532 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001533}
1534
Derek Lamberti901ea112019-12-10 22:07:09 +00001535bool RefLayerSupport::IsOutputSupported(const TensorInfo& /*output*/,
1536 Optional<std::string&> /*reasonIfUnsupported*/) const
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001537{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +01001538 return true;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001539}
1540
1541bool RefLayerSupport::IsPadSupported(const TensorInfo& input,
1542 const TensorInfo& output,
1543 const PadDescriptor& descriptor,
1544 Optional<std::string&> reasonIfUnsupported) const
1545{
Jan Eilers8eb25602020-03-09 12:13:48 +00001546 IgnoreUnused(descriptor);
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001547 bool supported = true;
1548
1549 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01001550 std::array<DataType,6> supportedTypes =
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001551 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001552 DataType::BFloat16,
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001553 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001554 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001555 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001556 DataType::QAsymmU8,
1557 DataType::QSymmS16
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001558 };
1559
1560 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1561 "Reference pad: input is not a supported type.");
1562
1563 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1564 "Reference pad: output is not a supported type.");
1565
1566 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1567 "Reference pad: input and output types are mismatched.");
1568
1569 return supported;
Nina Drozd661dfa72018-10-02 11:14:17 +01001570}
1571
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001572bool RefLayerSupport::IsPermuteSupported(const TensorInfo& input,
1573 const TensorInfo& output,
1574 const PermuteDescriptor& descriptor,
1575 Optional<std::string&> reasonIfUnsupported) const
1576{
Jan Eilers8eb25602020-03-09 12:13:48 +00001577 IgnoreUnused(descriptor);
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001578 bool supported = true;
1579
1580 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01001581 std::array<DataType, 6> supportedTypes =
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001582 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001583 DataType::BFloat16,
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001584 DataType::Float32,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00001585 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001586 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001587 DataType::QAsymmU8,
1588 DataType::QSymmS16
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001589 };
1590
1591 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1592 "Reference permute: input is not a supported type.");
1593
1594 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1595 "Reference permute: output is not a supported type.");
1596
1597 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1598 "Reference permute: input and output types are mismatched.");
1599
1600 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001601}
1602
1603bool RefLayerSupport::IsPooling2dSupported(const TensorInfo& input,
1604 const TensorInfo& output,
1605 const Pooling2dDescriptor& descriptor,
1606 Optional<std::string&> reasonIfUnsupported) const
1607{
Jan Eilers8eb25602020-03-09 12:13:48 +00001608 IgnoreUnused(descriptor);
Teresa Charlina3b20472019-06-06 11:12:32 +01001609 bool supported = true;
1610
1611 // Define supported output and inputs types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001612 std::array<DataType,6> supportedTypes =
Teresa Charlina3b20472019-06-06 11:12:32 +01001613 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001614 DataType::BFloat16,
Teresa Charlina3b20472019-06-06 11:12:32 +01001615 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001616 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001617 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001618 DataType::QAsymmU8,
1619 DataType::QSymmS16
Teresa Charlina3b20472019-06-06 11:12:32 +01001620 };
1621
1622 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1623 "Reference poolind2d: input is not a supported type.");
1624
1625 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1626 "Reference poolind2d: output is not a supported type.");
1627
1628 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1629 "Reference poolind2d: input and output types are mismatched.");
1630
1631 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001632}
1633
James Conroy4f1f8992020-04-29 20:01:10 +01001634bool RefLayerSupport::IsQLstmSupported(const TensorInfo& input,
1635 const TensorInfo& previousOutputIn,
1636 const TensorInfo& previousCellStateIn,
1637 const TensorInfo& outputStateOut,
1638 const TensorInfo& cellStateOut,
1639 const TensorInfo& output,
1640 const QLstmDescriptor& descriptor,
1641 const LstmInputParamsInfo& paramsInfo,
1642 Optional<std::string&> reasonIfUnsupported) const
1643{
1644 IgnoreUnused(input);
1645 IgnoreUnused(previousOutputIn);
1646 IgnoreUnused(previousCellStateIn);
1647 IgnoreUnused(outputStateOut);
1648 IgnoreUnused(cellStateOut);
1649 IgnoreUnused(output);
1650 IgnoreUnused(descriptor);
1651 IgnoreUnused(paramsInfo);
1652
1653 IgnoreUnused(reasonIfUnsupported);
1654
1655 return true;
1656}
1657
Derek Lamberti5f400d62019-03-25 15:41:58 +00001658bool RefLayerSupport::IsQuantizeSupported(const TensorInfo& input,
1659 const TensorInfo& output,
1660 Optional<std::string&> reasonIfUnsupported) const
1661{
1662 bool supported = true;
1663
Finn Williamsfd271062019-12-04 14:27:27 +00001664 // Define supported input types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001665 std::array<DataType,7> supportedInputTypes = {
1666 DataType::BFloat16,
Keith Davis5e51cd82020-01-29 16:52:59 +00001667 DataType::Float32,
Keith Davis3d8bc972020-02-04 09:31:47 +00001668 DataType::Float16,
Ryan OShea9add1202020-02-07 10:06:33 +00001669 DataType::QAsymmS8,
Keith Davis5e51cd82020-01-29 16:52:59 +00001670 DataType::QAsymmU8,
1671 DataType::QSymmS8,
1672 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001673 };
1674
1675 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
1676 "Reference quantize: input type not supported.");
1677
1678 // Define supported output types.
Ryan OShea9add1202020-02-07 10:06:33 +00001679 std::array<DataType,4> supportedOutputTypes = {
Ryan OShea9add1202020-02-07 10:06:33 +00001680 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001681 DataType::QAsymmU8,
Finn Williamsfd271062019-12-04 14:27:27 +00001682 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001683 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001684 };
1685 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
1686 "Reference quantize: output type not supported.");
1687
1688 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1689 "Reference quantize: input and output shapes have different num total elements.");
1690
1691 return supported;
1692}
1693
Finn Williams2605b232020-06-10 15:53:46 +01001694bool RefLayerSupport::IsRankSupported(const TensorInfo& input,
1695 const TensorInfo& output,
1696 Optional<std::string&> reasonIfUnsupported) const
1697{
1698 IgnoreUnused(input);
1699 // Define supported output types.
1700 std::array<DataType,1> supportedOutputTypes =
1701 {
1702 DataType::Signed32,
1703 };
1704
1705 return CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
1706 "Reference rank: input type not supported.");
1707}
1708
Sadik Armagan0c3ea5b2021-02-03 09:29:30 +00001709bool RefLayerSupport::IsReduceSupported(const TensorInfo& input,
1710 const TensorInfo& output,
1711 const ReduceDescriptor& descriptor,
1712 Optional<std::string&> reasonIfUnsupported) const
1713{
1714 IgnoreUnused(descriptor);
1715 bool supported = true;
1716 std::array<DataType,7> supportedTypes =
1717 {
1718 DataType::BFloat16,
1719 DataType::Float32,
1720 DataType::Float16,
1721 DataType::QAsymmS8,
1722 DataType::QAsymmU8,
1723 DataType::QSymmS16,
1724 DataType::Signed32
1725 };
1726
1727 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1728 "Reference Reduce: input type not supported");
1729
1730 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1731 "Reference Reduce: output type not supported");
1732
1733 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1734 "Reference Reduce: input and output types not matching");
1735
1736 return supported;
1737}
1738
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001739bool RefLayerSupport::IsReshapeSupported(const TensorInfo& input,
Kevin Maya023c402019-12-12 17:28:05 +00001740 const TensorInfo& output,
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001741 const ReshapeDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001742 Optional<std::string&> reasonIfUnsupported) const
1743{
Jan Eilers8eb25602020-03-09 12:13:48 +00001744 IgnoreUnused(output);
1745 IgnoreUnused(descriptor);
Nina Drozd2f2778f2019-05-27 10:37:05 +01001746 // Define supported output types.
Narumol Prangnawarat0c95f4c2020-11-18 16:52:07 +00001747 std::array<DataType,8> supportedOutputTypes =
Nina Drozd2f2778f2019-05-27 10:37:05 +01001748 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001749 DataType::BFloat16,
Nina Drozd2f2778f2019-05-27 10:37:05 +01001750 DataType::Float32,
1751 DataType::Float16,
Narumol Prangnawarat0718ee92019-09-13 16:53:38 +01001752 DataType::Signed32,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001753 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001754 DataType::QAsymmU8,
Narumol Prangnawarat0c95f4c2020-11-18 16:52:07 +00001755 DataType::QSymmS16,
1756 DataType::Boolean
Nina Drozd2f2778f2019-05-27 10:37:05 +01001757 };
Keith Davis0c2eeac2020-02-11 16:51:50 +00001758
Nina Drozd2f2778f2019-05-27 10:37:05 +01001759 return CheckSupportRule(TypeAnyOf(input, supportedOutputTypes), reasonIfUnsupported,
1760 "Reference reshape: input type not supported.");
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001761}
1762
1763bool RefLayerSupport::IsResizeBilinearSupported(const TensorInfo& input,
Sadik Armaganc625f002018-12-17 11:32:16 +00001764 const TensorInfo& output,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001765 Optional<std::string&> reasonIfUnsupported) const
1766{
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001767 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001768 std::array<DataType,6> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001769 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001770 DataType::BFloat16,
Teresa Charlin970f43b2019-07-01 13:51:07 +01001771 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001772 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001773 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001774 DataType::QAsymmU8,
1775 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001776 };
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001777
1778 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1779 "Reference ResizeBilinear: input type not supported");
1780
1781 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1782 "Reference ResizeBilinear: output type not supported");
1783
1784 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1785 "Reference ResizeBilinear: input and output types not matching");
1786
1787 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001788}
1789
Teresa Charlin970f43b2019-07-01 13:51:07 +01001790bool RefLayerSupport::IsResizeSupported(const TensorInfo& input,
1791 const TensorInfo& output,
1792 const ResizeDescriptor& descriptor,
1793 Optional<std::string&> reasonIfUnsupported) const
1794{
Jan Eilers8eb25602020-03-09 12:13:48 +00001795 IgnoreUnused(descriptor);
Teresa Charlin970f43b2019-07-01 13:51:07 +01001796 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001797 std::array<DataType,6> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001798 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001799 DataType::BFloat16,
Teresa Charlin970f43b2019-07-01 13:51:07 +01001800 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001801 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001802 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001803 DataType::QAsymmU8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001804 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001805 };
1806
1807 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1808 "Reference Resize: input type not supported");
1809
1810 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1811 "Reference Resize: output type not supported");
1812
1813 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1814 "Reference Resize: input and output types not matching");
1815
1816 return supported;
1817}
1818
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001819bool RefLayerSupport::IsRsqrtSupported(const TensorInfo& input,
1820 const TensorInfo& output,
1821 Optional<std::string&> reasonIfUnsupported) const
1822{
josh minor4a3c6102020-01-06 16:40:46 -06001823 return IsElementwiseUnarySupported(input,
1824 output,
1825 ElementwiseUnaryDescriptor(UnaryOperation::Rsqrt),
1826 reasonIfUnsupported);
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001827}
1828
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001829bool RefLayerSupport::IsSliceSupported(const TensorInfo& input,
1830 const TensorInfo& output,
1831 const SliceDescriptor& descriptor,
1832 Optional<std::string&> reasonIfUnsupported) const
1833{
Jan Eilers8eb25602020-03-09 12:13:48 +00001834 IgnoreUnused(descriptor);
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001835 bool supported = true;
1836
Sadik Armagan303980c2020-04-17 12:45:14 +01001837 std::array<DataType, 5> supportedTypes =
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001838 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001839 DataType::BFloat16,
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001840 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001841 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001842 DataType::QAsymmU8,
1843 DataType::QSymmS16
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001844 };
1845
1846 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1847 "Reference Slice: input type not supported");
1848
1849 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1850 "Reference Slice: output type not supported");
1851
1852 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1853 "Reference Slice: input and output types are mismatched");
1854
1855 return supported;
1856}
1857
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001858bool RefLayerSupport::IsSoftmaxSupported(const TensorInfo& input,
1859 const TensorInfo& output,
1860 const SoftmaxDescriptor& descriptor,
1861 Optional<std::string&> reasonIfUnsupported) const
1862{
Jan Eilers8eb25602020-03-09 12:13:48 +00001863 IgnoreUnused(descriptor);
nikraj01248683f2019-05-29 16:46:50 +01001864 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001865 std::array<DataType,7> supportedTypes =
nikraj01248683f2019-05-29 16:46:50 +01001866 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001867 DataType::BFloat16,
1868 DataType::Float32,
1869 DataType::Float16,
1870 DataType::QSymmS8,
1871 DataType::QAsymmS8,
1872 DataType::QAsymmU8,
1873 DataType::QSymmS16
nikraj01248683f2019-05-29 16:46:50 +01001874 };
1875
1876 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001877 "Reference Softmax: output type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001878
1879 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001880 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001881
1882 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001883 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001884
1885 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001886}
1887
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001888bool RefLayerSupport::IsSpaceToBatchNdSupported(const TensorInfo& input,
1889 const TensorInfo& output,
1890 const SpaceToBatchNdDescriptor& descriptor,
1891 Optional<std::string&> reasonIfUnsupported) const
1892{
Jan Eilers8eb25602020-03-09 12:13:48 +00001893 IgnoreUnused(descriptor);
nikraj01120522a2019-05-31 11:33:07 +01001894 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001895 std::array<DataType,6> supportedTypes =
nikraj01120522a2019-05-31 11:33:07 +01001896 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001897 DataType::BFloat16,
1898 DataType::Float32,
1899 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001900 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001901 DataType::QAsymmU8,
1902 DataType::QSymmS16
nikraj01120522a2019-05-31 11:33:07 +01001903 };
1904
1905 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1906 "Reference SpaceToBatchNd: input type not supported");
1907
1908 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1909 "Reference SpaceToBatchNd: output type not supported");
1910
1911 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1912 "Reference SpaceToBatchNd: input and output types are mismatched");
1913
1914 return supported;
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001915}
1916
Keith Davisa57eccb2019-06-14 17:33:22 +01001917bool RefLayerSupport::IsSpaceToDepthSupported(const TensorInfo& input,
Keith Davis51910332019-06-26 15:28:43 +01001918 const TensorInfo& output,
1919 const SpaceToDepthDescriptor& descriptor,
1920 Optional<std::string&> reasonIfUnsupported) const
Keith Davisa57eccb2019-06-14 17:33:22 +01001921{
1922
Jan Eilers8eb25602020-03-09 12:13:48 +00001923 IgnoreUnused(descriptor);
Keith Davisa57eccb2019-06-14 17:33:22 +01001924 bool supported = true;
1925
Sadik Armagan303980c2020-04-17 12:45:14 +01001926 std::array<DataType,6> supportedTypes =
Keith Davisa57eccb2019-06-14 17:33:22 +01001927 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001928 DataType::BFloat16,
Keith Davisa57eccb2019-06-14 17:33:22 +01001929 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001930 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001931 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001932 DataType::QAsymmU8,
1933 DataType::QSymmS16
Keith Davisa57eccb2019-06-14 17:33:22 +01001934 };
1935
1936 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1937 "Reference SpaceToDepth: input type not supported");
1938
1939 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1940 "Reference SpaceToDepth: output type not supported");
1941
1942 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1943 "Reference SpaceToDepth: input and output types are mismatched");
1944
1945 return supported;
1946}
1947
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001948bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1949 const ViewsDescriptor& descriptor,
1950 Optional<std::string&> reasonIfUnsupported) const
1951{
Jan Eilers8eb25602020-03-09 12:13:48 +00001952 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001953 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001954 std::array<DataType,6> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001955 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001956 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001957 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001958 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001959 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001960 DataType::QAsymmU8,
1961 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001962 };
1963
1964 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1965 "Reference splitter: input type not supported");
1966
1967 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001968}
1969
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001970bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1971 const std::vector<std::reference_wrapper<TensorInfo>>& outputs,
1972 const ViewsDescriptor& descriptor,
1973 Optional<std::string&> reasonIfUnsupported) const
1974{
Jan Eilers8eb25602020-03-09 12:13:48 +00001975 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001976 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001977 std::array<DataType,6> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001978 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001979 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001980 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001981 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001982 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001983 DataType::QAsymmU8,
1984 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001985 };
1986
1987 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1988 "Reference splitter: output type not supported");
Derek Lambertieac4adb2020-08-25 13:05:59 +01001989 for (const TensorInfo& output : outputs)
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001990 {
1991 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1992 "Reference splitter: input type not supported");
1993
1994 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1995 "Reference splitter: input and output types mismatched.");
1996 }
1997
1998 return supported;
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001999}
2000
Matthew Jackson81e601c2019-07-11 12:07:09 +01002001bool RefLayerSupport::IsStackSupported(const std::vector<const TensorInfo*>& inputs,
2002 const TensorInfo& output,
2003 const StackDescriptor& descriptor,
2004 Optional<std::string&> reasonIfUnsupported) const
2005{
Jan Eilers8eb25602020-03-09 12:13:48 +00002006 IgnoreUnused(descriptor);
Matthew Jackson81e601c2019-07-11 12:07:09 +01002007
2008 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01002009 std::array<DataType,6> supportedTypes =
Matthew Jackson81e601c2019-07-11 12:07:09 +01002010 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002011 DataType::BFloat16,
Matthew Jackson81e601c2019-07-11 12:07:09 +01002012 DataType::Float32,
Matthew Jacksone69c3992019-09-09 14:31:21 +01002013 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002014 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002015 DataType::QAsymmU8,
2016 DataType::QSymmS16
Matthew Jackson81e601c2019-07-11 12:07:09 +01002017 };
2018
2019 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2020 "Reference stack: output type not supported");
2021 for (const TensorInfo* input : inputs)
2022 {
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +01002023 ARMNN_ASSERT(input != nullptr);
Matthew Jackson81e601c2019-07-11 12:07:09 +01002024 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
2025 "Reference stack: input type not supported");
2026
2027 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
2028 "Reference stack: input and output types mismatched.");
2029 }
2030
2031 return supported;
2032}
2033
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00002034bool RefLayerSupport::IsStridedSliceSupported(const TensorInfo& input,
2035 const TensorInfo& output,
2036 const StridedSliceDescriptor& descriptor,
2037 Optional<std::string&> reasonIfUnsupported) const
2038{
Jan Eilers8eb25602020-03-09 12:13:48 +00002039 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01002040 bool supported = true;
2041
Sadik Armagan303980c2020-04-17 12:45:14 +01002042 std::array<DataType,5> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01002043 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002044 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01002045 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01002046 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002047 DataType::QAsymmU8,
2048 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01002049 };
2050
2051 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2052 "Reference StridedSlice: input type not supported");
2053
2054 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2055 "Reference StridedSlice: output type not supported");
2056
2057 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2058 "Reference StridedSlice: input and output types are mismatched");
2059
2060 return supported;
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00002061}
2062
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01002063bool RefLayerSupport::IsSubtractionSupported(const TensorInfo& input0,
2064 const TensorInfo& input1,
2065 const TensorInfo& output,
2066 Optional<std::string&> reasonIfUnsupported) const
2067{
Sadik Armagan2999a022019-04-09 14:20:12 +01002068 bool supported = true;
2069
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01002070 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002071 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01002072 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01002073 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002074 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002075 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01002076 DataType::QSymmS16,
2077 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01002078 };
2079
2080 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
2081 "Reference subtraction: input 0 is not a supported type.");
2082
2083 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
2084 "Reference subtraction: input 1 is not a supported type.");
2085
2086 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2087 "Reference subtraction: output is not a supported type.");
2088
2089 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
2090 "Reference subtraction: input 0 and Input 1 types are mismatched");
2091
2092 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
2093 "Reference subtraction: input and output types are mismatched");
2094
2095 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
2096 "Reference subtraction: shapes are not suitable for implicit broadcast.");
2097
2098 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01002099}
2100
Matteo Martincighab9e5252019-06-13 17:27:46 +01002101bool RefLayerSupport::IsPreluSupported(const TensorInfo& input,
2102 const TensorInfo& alpha,
2103 const TensorInfo& output,
2104 Optional<std::string&> reasonIfUnsupported) const
2105{
2106 bool supported = true;
2107
Teresa Charlin3940d8b2020-05-29 16:47:23 +01002108 std::array<DataType, 6> supportedTypes
Matteo Martincighab9e5252019-06-13 17:27:46 +01002109 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002110 DataType::BFloat16,
Matteo Martincighab9e5252019-06-13 17:27:46 +01002111 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01002112 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002113 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002114 DataType::QAsymmU8,
Teresa Charlin3940d8b2020-05-29 16:47:23 +01002115 DataType::QSymmS16
Matteo Martincighab9e5252019-06-13 17:27:46 +01002116 };
2117
2118 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2119 "PReLU: input is not a supported type.");
2120
2121 supported &= CheckSupportRule(TypeAnyOf(alpha, supportedTypes), reasonIfUnsupported,
2122 "PReLU: alpha is not a supported type.");
2123
2124 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2125 "PReLU: output is not a supported type.");
2126
2127 supported &= CheckSupportRule(TypesAreEqual(input, alpha, output), reasonIfUnsupported,
2128 "PReLU: input, alpha and output types are mismatched");
2129
2130 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input, alpha, output), reasonIfUnsupported,
2131 "PReLU: shapes are not suitable for implicit broadcast");
2132
2133 return supported;
2134}
2135
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002136bool RefLayerSupport::IsTransposeConvolution2dSupported(const TensorInfo& input,
2137 const TensorInfo& output,
2138 const TransposeConvolution2dDescriptor& descriptor,
2139 const TensorInfo& weights,
2140 const Optional<TensorInfo>& biases,
2141 Optional<std::string&> reasonIfUnsupported) const
2142{
Jan Eilers8eb25602020-03-09 12:13:48 +00002143 IgnoreUnused(descriptor);
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002144 bool supported = true;
2145
Sadik Armagan303980c2020-04-17 12:45:14 +01002146 std::array<DataType,7> supportedTypes =
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002147 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002148 DataType::BFloat16,
2149 DataType::Float32,
2150 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002151 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002152 DataType::QAsymmU8,
Sadik Armagan303980c2020-04-17 12:45:14 +01002153 DataType::QSymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002154 DataType::QSymmS16
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002155 };
2156
2157 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2158 "Reference TransposeConvolution2d: input is not a supported type.");
2159
2160 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2161 "Reference TransposeConvolution2d: output is not a supported type.");
2162
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002163 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2164 "Reference TransposeConvolution2d: input and output types mismatched.");
2165
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002166
2167 const DataType inputType = input.GetDataType();
Sadik Armagan303980c2020-04-17 12:45:14 +01002168 if (IsQuantized8BitType(inputType))
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002169 {
Derek Lambertid466a542020-01-22 15:37:29 +00002170 ARMNN_NO_DEPRECATE_WARN_BEGIN
Sadik Armagan303980c2020-04-17 12:45:14 +01002171 std::array<DataType, 4> supportedWeightTypes =
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002172 {
Sadik Armagan303980c2020-04-17 12:45:14 +01002173 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002174 DataType::QAsymmU8,
Derek Lambertid466a542020-01-22 15:37:29 +00002175 DataType::QSymmS8,
2176 DataType::QuantizedSymm8PerAxis //Deprecated
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002177 };
Derek Lambertid466a542020-01-22 15:37:29 +00002178 ARMNN_NO_DEPRECATE_WARN_END
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002179
2180 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
2181 "Reference TransposeConvolution2d: weights type not supported for "
2182 "quantized input.");
2183 }
2184 else
2185 {
2186 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
2187 "Reference TransposeConvolution2d: weights is not a supported type.");
2188
2189 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
2190 "Reference TransposeConvolution2d: input and weights types mismatched.");
2191 }
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002192
2193 if (biases.has_value())
2194 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002195 std::array<DataType,4> biasesSupportedTypes =
Aron Virginas-Tar651aafe2019-08-05 11:52:05 +01002196 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002197 DataType::BFloat16,
2198 DataType::Float32,
2199 DataType::Float16,
2200 DataType::Signed32
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002201 };
2202 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
2203 "Reference TransposeConvolution2d: biases is not a supported type.");
2204 }
2205
2206 return supported;
2207}
2208
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002209bool RefLayerSupport::IsTransposeSupported(const TensorInfo& input,
2210 const TensorInfo& output,
2211 const TransposeDescriptor& descriptor,
2212 Optional<std::string&> reasonIfUnsupported) const
2213{
Jan Eilers8eb25602020-03-09 12:13:48 +00002214 IgnoreUnused(descriptor);
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002215 bool supported = true;
2216
2217 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01002218 std::array<DataType, 6> supportedTypes =
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002219 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002220 DataType::BFloat16,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002221 DataType::Float32,
2222 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002223 DataType::QAsymmS8,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002224 DataType::QAsymmU8,
2225 DataType::QSymmS16
2226 };
2227
2228 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2229 "Reference transpose: input is not a supported type.");
2230
2231 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2232 "Reference transpose: output is not a supported type.");
2233
2234 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2235 "Reference transpose: input and output types are mismatched.");
2236
2237 return supported;
2238}
2239
arovir011c7c81b2018-10-08 11:34:28 +01002240} // namespace armnn