blob: 52c079fae488c1f8a13ef9fdd4848932f2b121f4 [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 Armagan303980c2020-04-17 12:45:14 +0100725 std::array<DataType,5> supportedInputTypes =
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100726 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000727 DataType::BFloat16,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100728 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +0100729 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000730 DataType::QAsymmU8,
731 DataType::QSymmS16
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100732 };
733
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000734 supported &= CheckSupportRule(TypeAnyOf(boxEncodings, supportedInputTypes), reasonIfUnsupported,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100735 "Reference DetectionPostProcess: input 0 is not a supported type.");
736
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000737 supported &= CheckSupportRule(TypeAnyOf(scores, supportedInputTypes), reasonIfUnsupported,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100738 "Reference DetectionPostProcess: input 1 is not a supported type.");
739
740 return supported;
Narumol Prangnawaratbc67cef2019-01-31 15:31:54 +0000741}
742
Pablo Tellof0bd6832019-04-26 17:58:13 +0100743bool RefLayerSupport::IsDilatedDepthwiseConvolutionSupported(const TensorInfo& input,
744 const TensorInfo& output,
745 const DepthwiseConvolution2dDescriptor& descriptor,
746 const TensorInfo& weights,
747 const Optional<TensorInfo>& biases,
748 Optional<std::string&> reasonIfUnsupported) const
749{
Aron Virginas-Taraece4ed2019-06-14 17:00:09 +0100750 return IsDepthwiseConvolutionSupported(input, output, descriptor, weights, biases, reasonIfUnsupported);
Pablo Tellof0bd6832019-04-26 17:58:13 +0100751}
752
Aron Virginas-Taraece4ed2019-06-14 17:00:09 +0100753bool RefLayerSupport::IsDivisionSupported(const TensorInfo& input0,
arovir011c7c81b2018-10-08 11:34:28 +0100754 const TensorInfo& input1,
755 const TensorInfo& output,
756 Optional<std::string&> reasonIfUnsupported) const
757{
Sadik Armagan2999a022019-04-09 14:20:12 +0100758 bool supported = true;
759
Teresa Charlinecb6b8e2020-05-22 18:08:23 +0100760 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000761 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +0100762 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100763 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100764 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000765 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +0100766 DataType::QSymmS16,
767 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +0100768 };
769
770 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
771 "Reference division: input 0 is not a supported type.");
772
773 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
774 "Reference division: input 1 is not a supported type.");
775
776 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
777 "Reference division: output is not a supported type.");
778
779 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
780 "Reference division: input 0 and Input 1 types are mismatched");
781
782 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
783 "Reference division: input and output types are mismatched");
784
785 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
786 "Reference division: shapes are not suitable for implicit broadcast.");
787
788 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100789}
790
josh minor4a3c6102020-01-06 16:40:46 -0600791bool RefLayerSupport::IsElementwiseUnarySupported(const TensorInfo& input,
792 const TensorInfo& output,
793 const ElementwiseUnaryDescriptor& descriptor,
794 Optional<std::string&> reasonIfUnsupported) const
795{
Jan Eilers8eb25602020-03-09 12:13:48 +0000796 IgnoreUnused(descriptor);
josh minor4a3c6102020-01-06 16:40:46 -0600797
Sadik Armagan303980c2020-04-17 12:45:14 +0100798 std::array<DataType, 7> supportedTypes =
josh minor4a3c6102020-01-06 16:40:46 -0600799 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000800 DataType::BFloat16,
josh minor4a3c6102020-01-06 16:40:46 -0600801 DataType::Float32,
802 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100803 DataType::QAsymmS8,
josh minor4a3c6102020-01-06 16:40:46 -0600804 DataType::QAsymmU8,
Sadik Armaganac472102020-03-24 09:54:36 +0000805 DataType::QSymmS16,
806 DataType::Signed32
josh minor4a3c6102020-01-06 16:40:46 -0600807 };
808
809 bool supported = true;
810
811 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
812 "Reference elementwise unary: input type not supported");
813
814 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
815 "Reference elementwise unary: output type not supported");
816
817 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
818 "Reference elementwise unary: input and output types not matching");
819
820 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
821 "Reference elementwise unary: input and output shapes"
822 "have different number of total elements");
823
824 return supported;
825}
826
FrancisMurtagh30cdfca2018-12-18 12:57:35 +0000827bool RefLayerSupport::IsEqualSupported(const TensorInfo& input0,
828 const TensorInfo& input1,
829 const TensorInfo& output,
830 Optional<std::string&> reasonIfUnsupported) const
831{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100832 return IsComparisonSupported(input0,
833 input1,
834 output,
835 ComparisonDescriptor(ComparisonOperation::Equal),
836 reasonIfUnsupported);
FrancisMurtagh30cdfca2018-12-18 12:57:35 +0000837}
838
arovir011c7c81b2018-10-08 11:34:28 +0100839bool RefLayerSupport::IsFakeQuantizationSupported(const TensorInfo& input,
840 const FakeQuantizationDescriptor& descriptor,
841 Optional<std::string&> reasonIfUnsupported) const
842{
Jan Eilers8eb25602020-03-09 12:13:48 +0000843 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100844 bool supported = true;
845
846 std::array<DataType,1> supportedTypes =
847 {
848 DataType::Float32
849 };
850
851 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
852 "Reference fake quantization: input type not supported.");
853
854 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100855}
856
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100857bool RefLayerSupport::IsFillSupported(const TensorInfo& input,
858 const TensorInfo& output,
859 const FillDescriptor& descriptor,
860 Optional<std::string&> reasonIfUnsupported) const
861{
862 IgnoreUnused(descriptor);
863 IgnoreUnused(output);
864
865 bool supported = true;
866
Sadik Armagana792a052020-06-23 16:22:23 +0100867 std::array<DataType,3> supportedTypes =
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100868 {
869 DataType::Float32,
Sadik Armagana792a052020-06-23 16:22:23 +0100870 DataType::Float16,
871 DataType::Signed32
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100872 };
873
Teresa Charlin4b10fef2020-07-29 09:36:41 +0100874 supported &= CheckSupportRule(TypeIs(input, DataType::Signed32), reasonIfUnsupported,
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100875 "Reference Fill: input type not supported.");
876
Teresa Charlin44088502020-07-27 11:27:19 +0100877 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
878 "Reference Fill: output type not supported.");
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100879 return supported;
880}
881
arovir011c7c81b2018-10-08 11:34:28 +0100882bool RefLayerSupport::IsFloorSupported(const TensorInfo& input,
883 const TensorInfo& output,
884 Optional<std::string&> reasonIfUnsupported) const
885{
Jan Eilers8eb25602020-03-09 12:13:48 +0000886 IgnoreUnused(output);
James Conroy83735b12019-05-30 16:36:59 +0100887 bool supported = true;
888
Francis Murtaghe8ac1332020-07-30 18:03:40 +0100889 std::array<DataType,3> supportedTypes =
James Conroy83735b12019-05-30 16:36:59 +0100890 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000891 DataType::BFloat16,
James Conroyb40d7102019-06-04 12:32:09 +0100892 DataType::Float32,
Francis Murtaghe8ac1332020-07-30 18:03:40 +0100893 DataType::Float16
James Conroy83735b12019-05-30 16:36:59 +0100894 };
895
896 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
897 "Reference Floor: input type not supported.");
898
899 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
900 "Reference Floor: output type not supported.");
901
902 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100903}
904
905bool RefLayerSupport::IsFullyConnectedSupported(const TensorInfo& input,
906 const TensorInfo& output,
907 const TensorInfo& weights,
908 const TensorInfo& biases,
909 const FullyConnectedDescriptor& descriptor,
910 Optional<std::string&> reasonIfUnsupported) const
911{
Francis Murtagh46c09d02019-05-28 08:15:28 +0100912 bool supported = true;
913
914 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000915 std::array<DataType,6> supportedTypes =
Francis Murtagh46c09d02019-05-28 08:15:28 +0100916 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000917 DataType::BFloat16,
918 DataType::Float32,
919 DataType::Float16,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000920 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100921 DataType::QAsymmU8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000922 DataType::QSymmS16
Francis Murtagh46c09d02019-05-28 08:15:28 +0100923 };
924
925 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
926 "Reference Fully Connected: input type not supported.");
927
928 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
929 "Reference Fully Connected: output type not supported.");
930
Francis Murtagh46c09d02019-05-28 08:15:28 +0100931 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
932 "Reference Fully Connected: weights type not supported.");
933
Narumol Prangnawarat57ef0082020-03-26 09:20:43 +0000934 // For FullyConnected, we allow to have BFloat16 input with Float32 output for optimization.
935 if (input.GetDataType() == DataType::BFloat16)
936 {
937 if (output.GetDataType() != DataType::BFloat16 && output.GetDataType() != DataType::Float32)
938 {
939 reasonIfUnsupported.value() += "Output tensor type must be BFloat16 or Float32 for BFloat16 input.\n";
940 supported = false;
941 }
942 }
943 else
944 {
945 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
946 "Reference Fully Connected: input and output types mismatched.");
947 }
948
Jan Eilers1f45dc32020-06-15 11:43:03 +0100949 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
950 "Reference Fully Connected: weights is not a supported type.");
Francis Murtaghddb1d062020-03-10 13:51:45 +0000951
Jan Eilers1f45dc32020-06-15 11:43:03 +0100952 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
953 "Reference Fully Connected: input and weights types mismatched.");
Francis Murtagh46c09d02019-05-28 08:15:28 +0100954
955 if (descriptor.m_BiasEnabled)
956 {
957 // Defined supported types for bias
Sadik Armagandb73c982020-04-01 17:35:30 +0100958 std::array<DataType, 5>
Francis Murtagh46c09d02019-05-28 08:15:28 +0100959 supportedBiasTypes =
960 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000961 DataType::BFloat16,
Francis Murtagh46c09d02019-05-28 08:15:28 +0100962 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100963 DataType::Float16,
Sadik Armagandb73c982020-04-01 17:35:30 +0100964 DataType::Signed32,
965 DataType::QAsymmS8
Francis Murtagh46c09d02019-05-28 08:15:28 +0100966 };
967
968 supported &= CheckSupportRule(TypeAnyOf(biases, supportedBiasTypes), reasonIfUnsupported,
969 "Reference Fully Connected: bias type not supported.");
970
971 supported &= CheckSupportRule(BiasAndWeightsTypesMatch(biases, weights), reasonIfUnsupported,
972 "Reference Fully Connected: bias and weight types mismatch.");
973
974 supported &= CheckSupportRule(BiasAndWeightsTypesCompatible(weights, supportedBiasTypes), reasonIfUnsupported,
975 "Reference Fully Connected: bias type inferred from weights is incompatible.");
976
Narumol Prangnawarat366d7232020-04-29 12:58:17 +0100977 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(biases, 1U), reasonIfUnsupported,
978 "Reference Fully Connected: bias must have 1 dimension.");
979
Francis Murtagh46c09d02019-05-28 08:15:28 +0100980 }
981
982 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100983}
984
narpra014951d842019-01-18 16:53:53 +0000985bool RefLayerSupport::IsGatherSupported(const armnn::TensorInfo& input0,
986 const armnn::TensorInfo& input1,
987 const armnn::TensorInfo& output,
Teresa Charlin52664732020-06-29 16:27:03 +0100988 const GatherDescriptor& descriptor,
narpra014951d842019-01-18 16:53:53 +0000989 armnn::Optional<std::string&> reasonIfUnsupported) const
990{
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100991 bool supported = true;
Teresa Charlin3940d8b2020-05-29 16:47:23 +0100992 std::array<DataType,7> supportedTypes =
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100993 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000994 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100995 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100996 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100997 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000998 DataType::QAsymmU8,
Teresa Charlin3940d8b2020-05-29 16:47:23 +0100999 DataType::QSymmS16,
1000 DataType::Signed32
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +01001001 };
1002
Teresa Charlin52664732020-06-29 16:27:03 +01001003 if (descriptor.m_Axis != 0)
1004 {
1005 reasonIfUnsupported.value() += std::string("Reference Gather: axis not supported\n");
1006 supported &= false;
1007 }
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +01001008 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1009 "Reference Gather: input type not supported");
1010
1011 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1012 "Reference Gather: output type not supported");
1013
1014 supported &= CheckSupportRule(TypeIs(input1, DataType::Signed32), reasonIfUnsupported,
1015 "Reference Gather: indices (input1) type not supported");
1016
1017 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1018 "Reference Gather: input and output types not matching");
1019
1020 return supported;
narpra014951d842019-01-18 16:53:53 +00001021}
1022
FrancisMurtagh878f0232018-12-19 10:56:15 +00001023bool RefLayerSupport::IsGreaterSupported(const TensorInfo& input0,
1024 const TensorInfo& input1,
1025 const TensorInfo& output,
1026 Optional<std::string&> reasonIfUnsupported) const
1027{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +01001028 return IsComparisonSupported(input0,
1029 input1,
1030 output,
1031 ComparisonDescriptor(ComparisonOperation::Greater),
1032 reasonIfUnsupported);
FrancisMurtagh878f0232018-12-19 10:56:15 +00001033}
1034
Derek Lamberti901ea112019-12-10 22:07:09 +00001035bool RefLayerSupport::IsInputSupported(const TensorInfo& /*input*/,
1036 Optional<std::string&> /*reasonIfUnsupported*/) const
arovir011c7c81b2018-10-08 11:34:28 +01001037{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +01001038 return true;
arovir011c7c81b2018-10-08 11:34:28 +01001039}
1040
Kevin May09ca49c2019-10-09 12:37:34 +01001041bool RefLayerSupport::IsInstanceNormalizationSupported(const TensorInfo& input,
1042 const TensorInfo& output,
1043 const InstanceNormalizationDescriptor& descriptor,
1044 Optional<std::string&> reasonIfUnsupported) const
1045{
Jan Eilers8eb25602020-03-09 12:13:48 +00001046 IgnoreUnused(descriptor);
Kevin May09ca49c2019-10-09 12:37:34 +01001047 // Define supported types
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001048 std::array<DataType, 3> supportedTypes =
Kevin May09ca49c2019-10-09 12:37:34 +01001049 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001050 DataType::BFloat16,
Kevin May09ca49c2019-10-09 12:37:34 +01001051 DataType::Float32,
1052 DataType::Float16
1053 };
1054
1055 bool supported = true;
1056
1057 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1058 "Reference Instance Normalization: input type not supported.");
1059
1060 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1061 "Reference Instance Normalization: output type not supported.");
1062
1063 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1064 "Reference Instance Normalization: input and output types mismatched.");
1065
1066 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1067 "Reference Instance Normalization: input and output shapes have different "
1068 "num total elements.");
1069
1070 return supported;
1071}
1072
arovir011c7c81b2018-10-08 11:34:28 +01001073bool RefLayerSupport::IsL2NormalizationSupported(const TensorInfo& input,
1074 const TensorInfo& output,
1075 const L2NormalizationDescriptor& descriptor,
1076 Optional<std::string&> reasonIfUnsupported) const
1077{
Jan Eilers8eb25602020-03-09 12:13:48 +00001078 IgnoreUnused(descriptor);
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001079 // Define supported types
Sadik Armagan303980c2020-04-17 12:45:14 +01001080 std::array<DataType, 6> supportedTypes =
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001081 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001082 DataType::BFloat16,
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001083 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001084 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001085 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001086 DataType::QAsymmU8,
1087 DataType::QSymmS16
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001088 };
1089
1090 bool supported = true;
1091
1092 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1093 "Reference L2normalization: input type not supported.");
1094
1095 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1096 "Reference L2normalization: output type not supported.");
1097
1098 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1099 "Reference L2normalization: input and output types mismatched.");
1100
1101 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1102 "Reference L2normalization: input and output shapes have different "
1103 "num total elements.");
1104
1105 return supported;
arovir011c7c81b2018-10-08 11:34:28 +01001106}
1107
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001108bool RefLayerSupport::IsLogSoftmaxSupported(const TensorInfo& input,
1109 const TensorInfo& output,
1110 const LogSoftmaxDescriptor& descriptor,
1111 Optional<std::string&> reasonIfUnsupported) const
1112{
Jan Eilers8eb25602020-03-09 12:13:48 +00001113 IgnoreUnused(descriptor);
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001114
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001115 std::array<DataType, 3> supportedTypes =
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001116 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001117 DataType::BFloat16,
1118 DataType::Float32,
1119 DataType::Float16
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001120 };
1121
1122 bool supported = true;
1123 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1124 "Reference LogSoftmax: input type not supported");
1125
1126 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1127 "Reference LogSoftmax: output type not supported");
1128
1129 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1130 "Reference LogSoftmax: input and output types do not match");
1131
1132 return supported;
1133}
1134
arovir011c7c81b2018-10-08 11:34:28 +01001135bool RefLayerSupport::IsLstmSupported(const TensorInfo& input,
1136 const TensorInfo& outputStateIn,
1137 const TensorInfo& cellStateIn,
1138 const TensorInfo& scratchBuffer,
1139 const TensorInfo& outputStateOut,
1140 const TensorInfo& cellStateOut,
1141 const TensorInfo& output,
1142 const LstmDescriptor& descriptor,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001143 const LstmInputParamsInfo& paramsInfo,
1144 Optional<std::string&> reasonIfUnsupported) const
arovir011c7c81b2018-10-08 11:34:28 +01001145{
Jan Eilers8eb25602020-03-09 12:13:48 +00001146 IgnoreUnused(descriptor);
1147 IgnoreUnused(paramsInfo);
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001148
1149 bool supported = true;
1150
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001151 std::array<DataType,3> supportedTypes = {
1152 DataType::BFloat16,
Conor Kennedyb9971c92019-05-07 07:14:23 +01001153 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001154 DataType::QSymmS16
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001155 };
1156
Jan Eilersd01a83c2019-07-03 18:20:40 +01001157 // check inputs and outputs
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001158 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1159 "Reference Lstm: input is not a supported type.");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001160 supported &= CheckSupportRule(TypesAreEqual(input, outputStateIn), reasonIfUnsupported,
1161 "Reference Lstm: input and outputStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001162 supported &= CheckSupportRule(TypesAreEqual(input, cellStateIn), reasonIfUnsupported,
1163 "Reference Lstm: input and cellStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001164 supported &= CheckSupportRule(TypesAreEqual(input, scratchBuffer), reasonIfUnsupported,
1165 "Reference Lstm: input and scratchBuffer types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001166 supported &= CheckSupportRule(TypesAreEqual(input, outputStateOut), reasonIfUnsupported,
1167 "Reference Lstm: input and outputStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001168 supported &= CheckSupportRule(TypesAreEqual(input, cellStateOut), reasonIfUnsupported,
1169 "Reference Lstm: input and cellStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001170 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1171 "Reference Lstm: input and output types are mismatched");
Jan Eilersd01a83c2019-07-03 18:20:40 +01001172 // check layer parameters
Francis Murtaghbb590b42019-08-14 09:51:36 +01001173 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001174 "Reference Lstm: input and InputToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001175 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001176 "Reference Lstm: input and InputToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001177 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001178 "Reference Lstm: input and InputToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001179 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001180 "Reference Lstm: input and RecurrentToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001181 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001182 "Reference Lstm: input and RecurrentToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001183 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001184 "Reference Lstm: input and RecurrentToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001185 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001186 "Reference Lstm: input and ForgetGateBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001187 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001188 "Reference Lstm: input and CellBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001189 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001190 "Reference Lstm: input and OutputGateBias types are mismatched");
1191 if (!descriptor.m_CifgEnabled)
1192 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001193 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToInputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001194 "Reference Lstm: input and InputToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001195 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001196 reasonIfUnsupported,
1197 "Reference Lstm: input and RecurrentToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001198 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001199 "Reference Lstm: input and InputGateBias types are mismatched");
1200 if (descriptor.m_PeepholeEnabled)
1201 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001202 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001203 reasonIfUnsupported,
1204 "Reference Lstm: input and CellToInputWeights types are mismatched");
1205 }
1206 }
1207 if (descriptor.m_PeepholeEnabled)
1208 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001209 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001210 "Reference Lstm: input and CellToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001211 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001212 "Reference Lstm: input and CellToOutputWeights types are mismatched");
1213 }
1214 if (descriptor.m_ProjectionEnabled)
1215 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001216 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001217 "Reference Lstm: input and mProjectionWeights types are mismatched");
1218 if (paramsInfo.m_ProjectionBias != nullptr)
1219 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001220 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001221 "Reference Lstm: input and ProjectionBias types are mismatched");
1222 }
1223 }
1224 if (descriptor.m_LayerNormEnabled)
1225 {
1226 if (!descriptor.m_CifgEnabled)
1227 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001228 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001229 reasonIfUnsupported,
1230 "Reference Lstm: input and InputLayerNormWeights types are mismatched");
1231 }
Francis Murtaghbb590b42019-08-14 09:51:36 +01001232 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001233 reasonIfUnsupported,
1234 "Reference Lstm: input and ForgetLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001235 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001236 reasonIfUnsupported,
1237 "Reference Lstm: input and CellLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001238 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001239 reasonIfUnsupported,
1240 "Reference Lstm: input and OutputLayerNormWeights types are mismatched");
1241 }
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001242
1243 return supported;
telsoa01c577f2c2018-08-31 09:22:23 +01001244}
1245
saoste012df12b32018-11-28 16:57:20 +00001246bool RefLayerSupport::IsMaximumSupported(const TensorInfo& input0,
1247 const TensorInfo& input1,
1248 const TensorInfo& output,
1249 Optional<std::string&> reasonIfUnsupported) const
1250{
Sadik Armagan2999a022019-04-09 14:20:12 +01001251 bool supported = true;
1252
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001253 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001254 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001255 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001256 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001257 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001258 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001259 DataType::QSymmS16,
1260 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01001261 };
1262
1263 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1264 "Reference maximum: input 0 is not a supported type.");
1265
1266 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1267 "Reference maximum: input 1 is not a supported type.");
1268
1269 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1270 "Reference maximum: output is not a supported type.");
1271
1272 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1273 "Reference maximum: input 0 and Input 1 types are mismatched");
1274
1275 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1276 "Reference maximum: input and output types are mismatched");
1277
1278 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1279 "Reference maximum: shapes are not suitable for implicit broadcast.");
1280
1281 return supported;
saoste012df12b32018-11-28 16:57:20 +00001282}
1283
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001284bool RefLayerSupport::IsMeanSupported(const TensorInfo& input,
1285 const TensorInfo& output,
1286 const MeanDescriptor& descriptor,
1287 Optional<std::string&> reasonIfUnsupported) const
narpra0132b90462018-09-13 11:07:48 +01001288{
James Conroy4d1ff582019-06-10 17:06:39 +01001289 bool supported = true;
1290 std::string meanLayerStr = "Mean";
1291 std::string outputTensorStr = "output";
1292
Sadik Armagan303980c2020-04-17 12:45:14 +01001293 std::array<DataType,6> supportedTypes =
James Conroy4d1ff582019-06-10 17:06:39 +01001294 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001295 DataType::BFloat16,
James Conroy4d1ff582019-06-10 17:06:39 +01001296 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001297 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001298 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001299 DataType::QAsymmU8,
1300 DataType::QSymmS16
James Conroy4d1ff582019-06-10 17:06:39 +01001301 };
1302
1303 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1304 "Reference Mean: input type not supported.");
1305
1306 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1307 "Reference Mean: input and output types are mismatched");
1308
1309 if (descriptor.m_KeepDims)
1310 {
1311 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, input.GetNumDimensions()),
1312 reasonIfUnsupported,
1313 CreateIncorrectDimensionsErrorMsg(input.GetNumDimensions(),
1314 output.GetNumDimensions(),
1315 meanLayerStr, outputTensorStr).data());
1316 }
1317 else if (descriptor.m_Axis.empty())
1318 {
1319 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1320 reasonIfUnsupported,
1321 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1322 meanLayerStr, outputTensorStr).data());
1323 }
1324 else
1325 {
Matthew Sloyan171214c2020-09-09 09:07:37 +01001326 auto outputDim = input.GetNumDimensions() - armnn::numeric_cast<unsigned int>(descriptor.m_Axis.size());
James Conroy4d1ff582019-06-10 17:06:39 +01001327
1328 if (outputDim > 0)
1329 {
1330 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, outputDim),
1331 reasonIfUnsupported,
1332 CreateIncorrectDimensionsErrorMsg(outputDim, output.GetNumDimensions(),
1333 meanLayerStr, outputTensorStr).data());
1334 }
1335 else
1336 {
1337 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1338 reasonIfUnsupported,
1339 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1340 meanLayerStr, outputTensorStr).data());
1341 }
1342 }
1343
1344 return supported;
narpra0132b90462018-09-13 11:07:48 +01001345}
1346
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001347bool RefLayerSupport::IsMergerSupported(const std::vector<const TensorInfo*> inputs,
Nikhil Raj8599a412018-11-19 14:51:07 +00001348 const TensorInfo& output,
Jim Flynne242f2d2019-05-22 14:24:13 +01001349 const MergerDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001350 Optional<std::string&> reasonIfUnsupported) const
1351{
Jim Flynne242f2d2019-05-22 14:24:13 +01001352 return IsConcatSupported(inputs, output, descriptor, reasonIfUnsupported);
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001353}
1354
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001355bool RefLayerSupport::IsMemCopySupported(const TensorInfo &input,
1356 const TensorInfo &output,
1357 Optional<std::string &> reasonIfUnsupported) const
1358{
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001359 bool supported = true;
1360
Sadik Armagan303980c2020-04-17 12:45:14 +01001361 std::array<DataType,7> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001362 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001363 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001364 DataType::Float32,
1365 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001366 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001367 DataType::QAsymmU8,
1368 DataType::QSymmS16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001369 DataType::Boolean
1370 };
1371
1372 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1373 "Reference MemCopy: input type not supported");
1374
1375 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1376 "Reference MemCopy: output type not supported");
1377
1378 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1379 "Reference MemCopy: input and output types are mismatched");
1380
1381 return supported;
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001382}
1383
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001384bool RefLayerSupport::IsMinimumSupported(const TensorInfo& input0,
1385 const TensorInfo& input1,
1386 const TensorInfo& output,
1387 Optional<std::string&> reasonIfUnsupported) const
1388{
Sadik Armagan2999a022019-04-09 14:20:12 +01001389 bool supported = true;
1390
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001391 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001392 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001393 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001394 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001395 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001396 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001397 DataType::QSymmS16,
1398 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01001399 };
1400
1401 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1402 "Reference minimum: input 0 is not a supported type.");
1403
1404 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1405 "Reference minimum: input 1 is not a supported type.");
1406
1407 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1408 "Reference minimum: output is not a supported type.");
1409
1410 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1411 "Reference minimum: input 0 and Input 1 types are mismatched");
1412
1413 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1414 "Reference minimum: input and output types are mismatched");
1415
1416 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1417 "Reference minimum: shapes are not suitable for implicit broadcast.");
1418
1419 return supported;
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001420}
1421
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001422bool RefLayerSupport::IsMultiplicationSupported(const TensorInfo& input0,
1423 const TensorInfo& input1,
1424 const TensorInfo& output,
1425 Optional<std::string&> reasonIfUnsupported) const
1426{
Sadik Armagan2999a022019-04-09 14:20:12 +01001427 bool supported = true;
1428
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001429 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001430 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001431 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001432 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001433 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001434 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001435 DataType::QSymmS16,
1436 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01001437 };
1438
1439 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1440 "Reference multiplication: input 0 is not a supported type.");
1441
1442 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1443 "Reference multiplication: input 1 is not a supported type.");
1444
1445 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1446 "Reference multiplication: output is not a supported type.");
1447
1448 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1449 "Reference multiplication: input 0 and Input 1 types are mismatched");
1450
1451 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1452 "Reference multiplication: input and output types are mismatched");
1453
1454 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1455 "Reference multiplication: shapes are not suitable for implicit broadcast.");
1456
1457 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001458}
1459
1460bool RefLayerSupport::IsNormalizationSupported(const TensorInfo& input,
1461 const TensorInfo& output,
1462 const NormalizationDescriptor& descriptor,
1463 Optional<std::string&> reasonIfUnsupported) const
Nina Drozd661dfa72018-10-02 11:14:17 +01001464{
Jan Eilers8eb25602020-03-09 12:13:48 +00001465 IgnoreUnused(descriptor);
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001466
1467 // Define supported types
Sadik Armagan303980c2020-04-17 12:45:14 +01001468 std::array<DataType, 6> supportedTypes =
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001469 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001470 DataType::BFloat16,
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001471 DataType::Float16,
1472 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001473 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001474 DataType::QAsymmU8,
1475 DataType::QSymmS16
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001476 };
1477
1478 bool supported = true;
1479
1480 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1481 "Reference normalization: input type not supported.");
1482
1483 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1484 "Reference normalization: output type not supported.");
1485
1486 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1487 "Reference normalization: input and output shapes have different "
1488 "num total elements.");
1489
1490 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001491}
1492
Derek Lamberti901ea112019-12-10 22:07:09 +00001493bool RefLayerSupport::IsOutputSupported(const TensorInfo& /*output*/,
1494 Optional<std::string&> /*reasonIfUnsupported*/) const
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001495{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +01001496 return true;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001497}
1498
1499bool RefLayerSupport::IsPadSupported(const TensorInfo& input,
1500 const TensorInfo& output,
1501 const PadDescriptor& descriptor,
1502 Optional<std::string&> reasonIfUnsupported) const
1503{
Jan Eilers8eb25602020-03-09 12:13:48 +00001504 IgnoreUnused(descriptor);
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001505 bool supported = true;
1506
1507 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01001508 std::array<DataType,6> supportedTypes =
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001509 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001510 DataType::BFloat16,
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001511 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001512 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001513 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001514 DataType::QAsymmU8,
1515 DataType::QSymmS16
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001516 };
1517
1518 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1519 "Reference pad: input is not a supported type.");
1520
1521 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1522 "Reference pad: output is not a supported type.");
1523
1524 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1525 "Reference pad: input and output types are mismatched.");
1526
1527 return supported;
Nina Drozd661dfa72018-10-02 11:14:17 +01001528}
1529
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001530bool RefLayerSupport::IsPermuteSupported(const TensorInfo& input,
1531 const TensorInfo& output,
1532 const PermuteDescriptor& descriptor,
1533 Optional<std::string&> reasonIfUnsupported) const
1534{
Jan Eilers8eb25602020-03-09 12:13:48 +00001535 IgnoreUnused(descriptor);
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001536 bool supported = true;
1537
1538 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01001539 std::array<DataType, 6> supportedTypes =
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001540 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001541 DataType::BFloat16,
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001542 DataType::Float32,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00001543 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001544 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001545 DataType::QAsymmU8,
1546 DataType::QSymmS16
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001547 };
1548
1549 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1550 "Reference permute: input is not a supported type.");
1551
1552 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1553 "Reference permute: output is not a supported type.");
1554
1555 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1556 "Reference permute: input and output types are mismatched.");
1557
1558 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001559}
1560
1561bool RefLayerSupport::IsPooling2dSupported(const TensorInfo& input,
1562 const TensorInfo& output,
1563 const Pooling2dDescriptor& descriptor,
1564 Optional<std::string&> reasonIfUnsupported) const
1565{
Jan Eilers8eb25602020-03-09 12:13:48 +00001566 IgnoreUnused(descriptor);
Teresa Charlina3b20472019-06-06 11:12:32 +01001567 bool supported = true;
1568
1569 // Define supported output and inputs types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001570 std::array<DataType,6> supportedTypes =
Teresa Charlina3b20472019-06-06 11:12:32 +01001571 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001572 DataType::BFloat16,
Teresa Charlina3b20472019-06-06 11:12:32 +01001573 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001574 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001575 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001576 DataType::QAsymmU8,
1577 DataType::QSymmS16
Teresa Charlina3b20472019-06-06 11:12:32 +01001578 };
1579
1580 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1581 "Reference poolind2d: input is not a supported type.");
1582
1583 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1584 "Reference poolind2d: output is not a supported type.");
1585
1586 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1587 "Reference poolind2d: input and output types are mismatched.");
1588
1589 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001590}
1591
James Conroy4f1f8992020-04-29 20:01:10 +01001592bool RefLayerSupport::IsQLstmSupported(const TensorInfo& input,
1593 const TensorInfo& previousOutputIn,
1594 const TensorInfo& previousCellStateIn,
1595 const TensorInfo& outputStateOut,
1596 const TensorInfo& cellStateOut,
1597 const TensorInfo& output,
1598 const QLstmDescriptor& descriptor,
1599 const LstmInputParamsInfo& paramsInfo,
1600 Optional<std::string&> reasonIfUnsupported) const
1601{
1602 IgnoreUnused(input);
1603 IgnoreUnused(previousOutputIn);
1604 IgnoreUnused(previousCellStateIn);
1605 IgnoreUnused(outputStateOut);
1606 IgnoreUnused(cellStateOut);
1607 IgnoreUnused(output);
1608 IgnoreUnused(descriptor);
1609 IgnoreUnused(paramsInfo);
1610
1611 IgnoreUnused(reasonIfUnsupported);
1612
1613 return true;
1614}
1615
Derek Lamberti5f400d62019-03-25 15:41:58 +00001616bool RefLayerSupport::IsQuantizeSupported(const TensorInfo& input,
1617 const TensorInfo& output,
1618 Optional<std::string&> reasonIfUnsupported) const
1619{
1620 bool supported = true;
1621
Finn Williamsfd271062019-12-04 14:27:27 +00001622 // Define supported input types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001623 std::array<DataType,7> supportedInputTypes = {
1624 DataType::BFloat16,
Keith Davis5e51cd82020-01-29 16:52:59 +00001625 DataType::Float32,
Keith Davis3d8bc972020-02-04 09:31:47 +00001626 DataType::Float16,
Ryan OShea9add1202020-02-07 10:06:33 +00001627 DataType::QAsymmS8,
Keith Davis5e51cd82020-01-29 16:52:59 +00001628 DataType::QAsymmU8,
1629 DataType::QSymmS8,
1630 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001631 };
1632
1633 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
1634 "Reference quantize: input type not supported.");
1635
1636 // Define supported output types.
Ryan OShea9add1202020-02-07 10:06:33 +00001637 std::array<DataType,4> supportedOutputTypes = {
Ryan OShea9add1202020-02-07 10:06:33 +00001638 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001639 DataType::QAsymmU8,
Finn Williamsfd271062019-12-04 14:27:27 +00001640 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001641 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001642 };
1643 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
1644 "Reference quantize: output type not supported.");
1645
1646 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1647 "Reference quantize: input and output shapes have different num total elements.");
1648
1649 return supported;
1650}
1651
Finn Williams2605b232020-06-10 15:53:46 +01001652bool RefLayerSupport::IsRankSupported(const TensorInfo& input,
1653 const TensorInfo& output,
1654 Optional<std::string&> reasonIfUnsupported) const
1655{
1656 IgnoreUnused(input);
1657 // Define supported output types.
1658 std::array<DataType,1> supportedOutputTypes =
1659 {
1660 DataType::Signed32,
1661 };
1662
1663 return CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
1664 "Reference rank: input type not supported.");
1665}
1666
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001667bool RefLayerSupport::IsReshapeSupported(const TensorInfo& input,
Kevin Maya023c402019-12-12 17:28:05 +00001668 const TensorInfo& output,
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001669 const ReshapeDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001670 Optional<std::string&> reasonIfUnsupported) const
1671{
Jan Eilers8eb25602020-03-09 12:13:48 +00001672 IgnoreUnused(output);
1673 IgnoreUnused(descriptor);
Nina Drozd2f2778f2019-05-27 10:37:05 +01001674 // Define supported output types.
Keith Davis0c2eeac2020-02-11 16:51:50 +00001675 std::array<DataType,7> supportedOutputTypes =
Nina Drozd2f2778f2019-05-27 10:37:05 +01001676 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001677 DataType::BFloat16,
Nina Drozd2f2778f2019-05-27 10:37:05 +01001678 DataType::Float32,
1679 DataType::Float16,
Narumol Prangnawarat0718ee92019-09-13 16:53:38 +01001680 DataType::Signed32,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001681 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001682 DataType::QAsymmU8,
1683 DataType::QSymmS16
Nina Drozd2f2778f2019-05-27 10:37:05 +01001684 };
Keith Davis0c2eeac2020-02-11 16:51:50 +00001685
Nina Drozd2f2778f2019-05-27 10:37:05 +01001686 return CheckSupportRule(TypeAnyOf(input, supportedOutputTypes), reasonIfUnsupported,
1687 "Reference reshape: input type not supported.");
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001688}
1689
1690bool RefLayerSupport::IsResizeBilinearSupported(const TensorInfo& input,
Sadik Armaganc625f002018-12-17 11:32:16 +00001691 const TensorInfo& output,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001692 Optional<std::string&> reasonIfUnsupported) const
1693{
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001694 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001695 std::array<DataType,6> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001696 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001697 DataType::BFloat16,
Teresa Charlin970f43b2019-07-01 13:51:07 +01001698 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001699 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001700 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001701 DataType::QAsymmU8,
1702 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001703 };
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001704
1705 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1706 "Reference ResizeBilinear: input type not supported");
1707
1708 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1709 "Reference ResizeBilinear: output type not supported");
1710
1711 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1712 "Reference ResizeBilinear: input and output types not matching");
1713
1714 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001715}
1716
Teresa Charlin970f43b2019-07-01 13:51:07 +01001717bool RefLayerSupport::IsResizeSupported(const TensorInfo& input,
1718 const TensorInfo& output,
1719 const ResizeDescriptor& descriptor,
1720 Optional<std::string&> reasonIfUnsupported) const
1721{
Jan Eilers8eb25602020-03-09 12:13:48 +00001722 IgnoreUnused(descriptor);
Teresa Charlin970f43b2019-07-01 13:51:07 +01001723 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001724 std::array<DataType,6> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001725 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001726 DataType::BFloat16,
Teresa Charlin970f43b2019-07-01 13:51:07 +01001727 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001728 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001729 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001730 DataType::QAsymmU8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001731 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001732 };
1733
1734 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1735 "Reference Resize: input type not supported");
1736
1737 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1738 "Reference Resize: output type not supported");
1739
1740 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1741 "Reference Resize: input and output types not matching");
1742
1743 return supported;
1744}
1745
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001746bool RefLayerSupport::IsRsqrtSupported(const TensorInfo& input,
1747 const TensorInfo& output,
1748 Optional<std::string&> reasonIfUnsupported) const
1749{
josh minor4a3c6102020-01-06 16:40:46 -06001750 return IsElementwiseUnarySupported(input,
1751 output,
1752 ElementwiseUnaryDescriptor(UnaryOperation::Rsqrt),
1753 reasonIfUnsupported);
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001754}
1755
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001756bool RefLayerSupport::IsSliceSupported(const TensorInfo& input,
1757 const TensorInfo& output,
1758 const SliceDescriptor& descriptor,
1759 Optional<std::string&> reasonIfUnsupported) const
1760{
Jan Eilers8eb25602020-03-09 12:13:48 +00001761 IgnoreUnused(descriptor);
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001762 bool supported = true;
1763
Sadik Armagan303980c2020-04-17 12:45:14 +01001764 std::array<DataType, 5> supportedTypes =
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001765 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001766 DataType::BFloat16,
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001767 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001768 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001769 DataType::QAsymmU8,
1770 DataType::QSymmS16
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001771 };
1772
1773 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1774 "Reference Slice: input type not supported");
1775
1776 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1777 "Reference Slice: output type not supported");
1778
1779 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1780 "Reference Slice: input and output types are mismatched");
1781
1782 return supported;
1783}
1784
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001785bool RefLayerSupport::IsSoftmaxSupported(const TensorInfo& input,
1786 const TensorInfo& output,
1787 const SoftmaxDescriptor& descriptor,
1788 Optional<std::string&> reasonIfUnsupported) const
1789{
Jan Eilers8eb25602020-03-09 12:13:48 +00001790 IgnoreUnused(descriptor);
nikraj01248683f2019-05-29 16:46:50 +01001791 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001792 std::array<DataType,7> supportedTypes =
nikraj01248683f2019-05-29 16:46:50 +01001793 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001794 DataType::BFloat16,
1795 DataType::Float32,
1796 DataType::Float16,
1797 DataType::QSymmS8,
1798 DataType::QAsymmS8,
1799 DataType::QAsymmU8,
1800 DataType::QSymmS16
nikraj01248683f2019-05-29 16:46:50 +01001801 };
1802
1803 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001804 "Reference Softmax: output type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001805
1806 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001807 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001808
1809 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001810 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001811
1812 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001813}
1814
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001815bool RefLayerSupport::IsSpaceToBatchNdSupported(const TensorInfo& input,
1816 const TensorInfo& output,
1817 const SpaceToBatchNdDescriptor& descriptor,
1818 Optional<std::string&> reasonIfUnsupported) const
1819{
Jan Eilers8eb25602020-03-09 12:13:48 +00001820 IgnoreUnused(descriptor);
nikraj01120522a2019-05-31 11:33:07 +01001821 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001822 std::array<DataType,6> supportedTypes =
nikraj01120522a2019-05-31 11:33:07 +01001823 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001824 DataType::BFloat16,
1825 DataType::Float32,
1826 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001827 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001828 DataType::QAsymmU8,
1829 DataType::QSymmS16
nikraj01120522a2019-05-31 11:33:07 +01001830 };
1831
1832 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1833 "Reference SpaceToBatchNd: input type not supported");
1834
1835 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1836 "Reference SpaceToBatchNd: output type not supported");
1837
1838 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1839 "Reference SpaceToBatchNd: input and output types are mismatched");
1840
1841 return supported;
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001842}
1843
Keith Davisa57eccb2019-06-14 17:33:22 +01001844bool RefLayerSupport::IsSpaceToDepthSupported(const TensorInfo& input,
Keith Davis51910332019-06-26 15:28:43 +01001845 const TensorInfo& output,
1846 const SpaceToDepthDescriptor& descriptor,
1847 Optional<std::string&> reasonIfUnsupported) const
Keith Davisa57eccb2019-06-14 17:33:22 +01001848{
1849
Jan Eilers8eb25602020-03-09 12:13:48 +00001850 IgnoreUnused(descriptor);
Keith Davisa57eccb2019-06-14 17:33:22 +01001851 bool supported = true;
1852
Sadik Armagan303980c2020-04-17 12:45:14 +01001853 std::array<DataType,6> supportedTypes =
Keith Davisa57eccb2019-06-14 17:33:22 +01001854 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001855 DataType::BFloat16,
Keith Davisa57eccb2019-06-14 17:33:22 +01001856 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001857 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001858 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001859 DataType::QAsymmU8,
1860 DataType::QSymmS16
Keith Davisa57eccb2019-06-14 17:33:22 +01001861 };
1862
1863 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1864 "Reference SpaceToDepth: input type not supported");
1865
1866 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1867 "Reference SpaceToDepth: output type not supported");
1868
1869 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1870 "Reference SpaceToDepth: input and output types are mismatched");
1871
1872 return supported;
1873}
1874
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001875bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1876 const ViewsDescriptor& descriptor,
1877 Optional<std::string&> reasonIfUnsupported) const
1878{
Jan Eilers8eb25602020-03-09 12:13:48 +00001879 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001880 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001881 std::array<DataType,6> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001882 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001883 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001884 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001885 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001886 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001887 DataType::QAsymmU8,
1888 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001889 };
1890
1891 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1892 "Reference splitter: input type not supported");
1893
1894 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001895}
1896
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001897bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1898 const std::vector<std::reference_wrapper<TensorInfo>>& outputs,
1899 const ViewsDescriptor& descriptor,
1900 Optional<std::string&> reasonIfUnsupported) const
1901{
Jan Eilers8eb25602020-03-09 12:13:48 +00001902 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001903 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001904 std::array<DataType,6> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001905 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001906 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001907 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001908 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001909 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001910 DataType::QAsymmU8,
1911 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001912 };
1913
1914 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1915 "Reference splitter: output type not supported");
Derek Lambertieac4adb2020-08-25 13:05:59 +01001916 for (const TensorInfo& output : outputs)
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001917 {
1918 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1919 "Reference splitter: input type not supported");
1920
1921 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1922 "Reference splitter: input and output types mismatched.");
1923 }
1924
1925 return supported;
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001926}
1927
Matthew Jackson81e601c2019-07-11 12:07:09 +01001928bool RefLayerSupport::IsStackSupported(const std::vector<const TensorInfo*>& inputs,
1929 const TensorInfo& output,
1930 const StackDescriptor& descriptor,
1931 Optional<std::string&> reasonIfUnsupported) const
1932{
Jan Eilers8eb25602020-03-09 12:13:48 +00001933 IgnoreUnused(descriptor);
Matthew Jackson81e601c2019-07-11 12:07:09 +01001934
1935 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001936 std::array<DataType,6> supportedTypes =
Matthew Jackson81e601c2019-07-11 12:07:09 +01001937 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001938 DataType::BFloat16,
Matthew Jackson81e601c2019-07-11 12:07:09 +01001939 DataType::Float32,
Matthew Jacksone69c3992019-09-09 14:31:21 +01001940 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001941 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001942 DataType::QAsymmU8,
1943 DataType::QSymmS16
Matthew Jackson81e601c2019-07-11 12:07:09 +01001944 };
1945
1946 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1947 "Reference stack: output type not supported");
1948 for (const TensorInfo* input : inputs)
1949 {
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +01001950 ARMNN_ASSERT(input != nullptr);
Matthew Jackson81e601c2019-07-11 12:07:09 +01001951 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
1952 "Reference stack: input type not supported");
1953
1954 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
1955 "Reference stack: input and output types mismatched.");
1956 }
1957
1958 return supported;
1959}
1960
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00001961bool RefLayerSupport::IsStridedSliceSupported(const TensorInfo& input,
1962 const TensorInfo& output,
1963 const StridedSliceDescriptor& descriptor,
1964 Optional<std::string&> reasonIfUnsupported) const
1965{
Jan Eilers8eb25602020-03-09 12:13:48 +00001966 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001967 bool supported = true;
1968
Sadik Armagan303980c2020-04-17 12:45:14 +01001969 std::array<DataType,5> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001970 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001971 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001972 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001973 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001974 DataType::QAsymmU8,
1975 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001976 };
1977
1978 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1979 "Reference StridedSlice: input type not supported");
1980
1981 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1982 "Reference StridedSlice: output type not supported");
1983
1984 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1985 "Reference StridedSlice: input and output types are mismatched");
1986
1987 return supported;
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00001988}
1989
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001990bool RefLayerSupport::IsSubtractionSupported(const TensorInfo& input0,
1991 const TensorInfo& input1,
1992 const TensorInfo& output,
1993 Optional<std::string&> reasonIfUnsupported) const
1994{
Sadik Armagan2999a022019-04-09 14:20:12 +01001995 bool supported = true;
1996
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001997 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001998 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001999 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01002000 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002001 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002002 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01002003 DataType::QSymmS16,
2004 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01002005 };
2006
2007 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
2008 "Reference subtraction: input 0 is not a supported type.");
2009
2010 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
2011 "Reference subtraction: input 1 is not a supported type.");
2012
2013 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2014 "Reference subtraction: output is not a supported type.");
2015
2016 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
2017 "Reference subtraction: input 0 and Input 1 types are mismatched");
2018
2019 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
2020 "Reference subtraction: input and output types are mismatched");
2021
2022 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
2023 "Reference subtraction: shapes are not suitable for implicit broadcast.");
2024
2025 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01002026}
2027
Matteo Martincighab9e5252019-06-13 17:27:46 +01002028bool RefLayerSupport::IsPreluSupported(const TensorInfo& input,
2029 const TensorInfo& alpha,
2030 const TensorInfo& output,
2031 Optional<std::string&> reasonIfUnsupported) const
2032{
2033 bool supported = true;
2034
Teresa Charlin3940d8b2020-05-29 16:47:23 +01002035 std::array<DataType, 6> supportedTypes
Matteo Martincighab9e5252019-06-13 17:27:46 +01002036 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002037 DataType::BFloat16,
Matteo Martincighab9e5252019-06-13 17:27:46 +01002038 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01002039 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002040 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002041 DataType::QAsymmU8,
Teresa Charlin3940d8b2020-05-29 16:47:23 +01002042 DataType::QSymmS16
Matteo Martincighab9e5252019-06-13 17:27:46 +01002043 };
2044
2045 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2046 "PReLU: input is not a supported type.");
2047
2048 supported &= CheckSupportRule(TypeAnyOf(alpha, supportedTypes), reasonIfUnsupported,
2049 "PReLU: alpha is not a supported type.");
2050
2051 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2052 "PReLU: output is not a supported type.");
2053
2054 supported &= CheckSupportRule(TypesAreEqual(input, alpha, output), reasonIfUnsupported,
2055 "PReLU: input, alpha and output types are mismatched");
2056
2057 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input, alpha, output), reasonIfUnsupported,
2058 "PReLU: shapes are not suitable for implicit broadcast");
2059
2060 return supported;
2061}
2062
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002063bool RefLayerSupport::IsTransposeConvolution2dSupported(const TensorInfo& input,
2064 const TensorInfo& output,
2065 const TransposeConvolution2dDescriptor& descriptor,
2066 const TensorInfo& weights,
2067 const Optional<TensorInfo>& biases,
2068 Optional<std::string&> reasonIfUnsupported) const
2069{
Jan Eilers8eb25602020-03-09 12:13:48 +00002070 IgnoreUnused(descriptor);
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002071 bool supported = true;
2072
Sadik Armagan303980c2020-04-17 12:45:14 +01002073 std::array<DataType,7> supportedTypes =
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002074 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002075 DataType::BFloat16,
2076 DataType::Float32,
2077 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002078 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002079 DataType::QAsymmU8,
Sadik Armagan303980c2020-04-17 12:45:14 +01002080 DataType::QSymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002081 DataType::QSymmS16
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002082 };
2083
2084 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2085 "Reference TransposeConvolution2d: input is not a supported type.");
2086
2087 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2088 "Reference TransposeConvolution2d: output is not a supported type.");
2089
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002090 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2091 "Reference TransposeConvolution2d: input and output types mismatched.");
2092
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002093
2094 const DataType inputType = input.GetDataType();
Sadik Armagan303980c2020-04-17 12:45:14 +01002095 if (IsQuantized8BitType(inputType))
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002096 {
Derek Lambertid466a542020-01-22 15:37:29 +00002097 ARMNN_NO_DEPRECATE_WARN_BEGIN
Sadik Armagan303980c2020-04-17 12:45:14 +01002098 std::array<DataType, 4> supportedWeightTypes =
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002099 {
Sadik Armagan303980c2020-04-17 12:45:14 +01002100 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002101 DataType::QAsymmU8,
Derek Lambertid466a542020-01-22 15:37:29 +00002102 DataType::QSymmS8,
2103 DataType::QuantizedSymm8PerAxis //Deprecated
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002104 };
Derek Lambertid466a542020-01-22 15:37:29 +00002105 ARMNN_NO_DEPRECATE_WARN_END
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002106
2107 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
2108 "Reference TransposeConvolution2d: weights type not supported for "
2109 "quantized input.");
2110 }
2111 else
2112 {
2113 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
2114 "Reference TransposeConvolution2d: weights is not a supported type.");
2115
2116 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
2117 "Reference TransposeConvolution2d: input and weights types mismatched.");
2118 }
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002119
2120 if (biases.has_value())
2121 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002122 std::array<DataType,4> biasesSupportedTypes =
Aron Virginas-Tar651aafe2019-08-05 11:52:05 +01002123 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002124 DataType::BFloat16,
2125 DataType::Float32,
2126 DataType::Float16,
2127 DataType::Signed32
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002128 };
2129 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
2130 "Reference TransposeConvolution2d: biases is not a supported type.");
2131 }
2132
2133 return supported;
2134}
2135
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002136bool RefLayerSupport::IsTransposeSupported(const TensorInfo& input,
2137 const TensorInfo& output,
2138 const TransposeDescriptor& descriptor,
2139 Optional<std::string&> reasonIfUnsupported) const
2140{
Jan Eilers8eb25602020-03-09 12:13:48 +00002141 IgnoreUnused(descriptor);
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002142 bool supported = true;
2143
2144 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01002145 std::array<DataType, 6> supportedTypes =
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002146 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002147 DataType::BFloat16,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002148 DataType::Float32,
2149 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002150 DataType::QAsymmS8,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002151 DataType::QAsymmU8,
2152 DataType::QSymmS16
2153 };
2154
2155 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2156 "Reference transpose: input is not a supported type.");
2157
2158 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2159 "Reference transpose: output is not a supported type.");
2160
2161 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2162 "Reference transpose: input and output types are mismatched.");
2163
2164 return supported;
2165}
2166
arovir011c7c81b2018-10-08 11:34:28 +01002167} // namespace armnn