blob: d1933c90c092b1472f3203082e1788ca213bdced [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
Teresa Charlin52664732020-06-29 16:27:03 +01002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5
telsoa014fcda012018-03-09 14:13:49 +00006#include "RefLayerSupport.hpp"
David Beck3cc9a622018-10-12 10:38:31 +01007
Keith Davis0c2eeac2020-02-11 16:51:50 +00008#include <armnn/TypesUtils.hpp>
telsoa014fcda012018-03-09 14:13:49 +00009#include <armnn/Types.hpp>
Derek Lamberti50db4e82019-03-13 14:16:15 +000010#include <armnn/Descriptors.hpp>
Jan Eilers8eb25602020-03-09 12:13:48 +000011#include <armnn/utility/IgnoreUnused.hpp>
Matthew Sloyan171214c2020-09-09 09:07:37 +010012#include <armnn/utility/NumericCast.hpp>
telsoa014fcda012018-03-09 14:13:49 +000013
Matteo Martincighe011d202019-11-28 11:35:47 +000014#include <LayerSupportCommon.hpp>
Derek Lambertif674aa02019-08-01 15:56:25 +010015#include <backendsCommon/LayerSupportRules.hpp>
Matteo Martincighe011d202019-11-28 11:35:47 +000016
Derek Lamberti50db4e82019-03-13 14:16:15 +000017#include <vector>
Derek Lamberti50db4e82019-03-13 14:16:15 +000018#include <array>
19
telsoa014fcda012018-03-09 14:13:49 +000020namespace armnn
21{
22
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +010023namespace
24{
25
26template<typename Float32Func, typename Uint8Func, typename ... Params>
27bool IsSupportedForDataTypeRef(Optional<std::string&> reasonIfUnsupported,
28 DataType dataType,
29 Float32Func floatFuncPtr,
30 Uint8Func uint8FuncPtr,
31 Params&&... params)
32{
33 return IsSupportedForDataTypeGeneric(reasonIfUnsupported,
34 dataType,
35 &FalseFunc<Params...>,
36 floatFuncPtr,
37 uint8FuncPtr,
narpra01db2b1602019-01-23 15:23:11 +000038 &FalseFunc<Params...>,
kevmay012b4d88e2019-01-24 14:05:09 +000039 &FalseFunc<Params...>,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +010040 std::forward<Params>(params)...);
41}
42
43} // anonymous namespace
44
James Conroy4d1ff582019-06-10 17:06:39 +010045namespace
46{
47
48std::string CreateIncorrectDimensionsErrorMsg(unsigned int expected,
49 unsigned int actual,
50 std::string& layerStr,
51 std::string& tensorName)
52{
53 std::string errorMsg = "Reference " + layerStr + ": Expected " + std::to_string(expected) + " dimensions but got" +
54 " " + std::to_string(actual) + " dimensions instead, for the '" + tensorName + "' tensor.";
55
56 return errorMsg;
57}
58
59} // anonymous namespace
Derek Lamberti50db4e82019-03-13 14:16:15 +000060
Sadik Armagan9199e582019-09-05 17:35:31 +010061bool RefLayerSupport::IsAbsSupported(const TensorInfo& input, const TensorInfo& output,
62 Optional<std::string&> reasonIfUnsupported) const
63{
josh minor4a3c6102020-01-06 16:40:46 -060064 return IsElementwiseUnarySupported(input,
65 output,
66 ElementwiseUnaryDescriptor(UnaryOperation::Abs),
67 reasonIfUnsupported);
Sadik Armagan9199e582019-09-05 17:35:31 +010068}
69
arovir011c7c81b2018-10-08 11:34:28 +010070bool RefLayerSupport::IsActivationSupported(const TensorInfo& input,
71 const TensorInfo& output,
72 const ActivationDescriptor& descriptor,
73 Optional<std::string&> reasonIfUnsupported) const
74{
Derek Lamberti50db4e82019-03-13 14:16:15 +000075 bool supported = true;
76
77 // Define supported types.
Keith Davis0c2eeac2020-02-11 16:51:50 +000078 std::array<DataType,6> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +000079 DataType::BFloat16,
Derek Lamberti50db4e82019-03-13 14:16:15 +000080 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +010081 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +000082 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +000083 DataType::QAsymmU8,
84 DataType::QSymmS16
Derek Lamberti50db4e82019-03-13 14:16:15 +000085 };
86
87 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
88 "Reference activation: input type not supported.");
89
90 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
91 "Reference activation: output type not supported.");
92
93 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
94 "Reference activation: input and output types mismatched.");
95
96 supported &= CheckSupportRule(ShapesAreSameRank(input, output), reasonIfUnsupported,
97 "Reference activation: input and output shapes are of different rank.");
98
99
100 struct ActivationFunctionSupported : public Rule
101 {
102 ActivationFunctionSupported(const ActivationDescriptor& desc)
103 {
104 switch(desc.m_Function)
105 {
106 case ActivationFunction::Abs:
107 case ActivationFunction::BoundedReLu:
David Monahan3b3c3812020-02-25 09:03:29 +0000108 case ActivationFunction::Elu:
Colm Donelan03fbeaf2020-02-26 15:39:23 +0000109 case ActivationFunction::HardSwish:
Derek Lamberti50db4e82019-03-13 14:16:15 +0000110 case ActivationFunction::LeakyReLu:
111 case ActivationFunction::Linear:
112 case ActivationFunction::ReLu:
113 case ActivationFunction::Sigmoid:
114 case ActivationFunction::SoftReLu:
115 case ActivationFunction::Sqrt:
116 case ActivationFunction::Square:
117 case ActivationFunction::TanH:
118 {
119 m_Res = true;
120 break;
121 }
122 default:
123 {
124 m_Res = false;
125 break;
126 }
127 }
128 }
129 };
130
131 // Function is supported
132 supported &= CheckSupportRule(ActivationFunctionSupported(descriptor), reasonIfUnsupported,
133 "Reference activation: function not supported.");
134
135 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100136}
137
138bool RefLayerSupport::IsAdditionSupported(const TensorInfo& input0,
139 const TensorInfo& input1,
140 const TensorInfo& output,
141 Optional<std::string&> reasonIfUnsupported) const
142{
Derek Lamberti50db4e82019-03-13 14:16:15 +0000143 bool supported = true;
144
Teresa Charlinecb6b8e2020-05-22 18:08:23 +0100145 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000146 DataType::BFloat16,
Derek Lamberti50db4e82019-03-13 14:16:15 +0000147 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100148 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000149 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000150 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +0100151 DataType::QSymmS16,
152 DataType::Signed32
Derek Lamberti50db4e82019-03-13 14:16:15 +0000153 };
154
155 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
156 "Reference addition: input 0 is not a supported type.");
157
158 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
159 "Reference addition: input 1 is not a supported type.");
160
161 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
162 "Reference addition: output is not a supported type.");
163
164 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
165 "Reference addition: input 0 and Input 1 types are mismatched");
166
167 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
168 "Reference addition: input and output types are mismatched");
169
170 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
171 "Reference addition: shapes are not suitable for implicit broadcast.");
172
173 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100174}
175
Nikhil Raj68c2c902019-09-19 11:21:11 +0100176bool RefLayerSupport::IsArgMinMaxSupported(const armnn::TensorInfo &input, const armnn::TensorInfo &output,
177 const armnn::ArgMinMaxDescriptor &descriptor,
178 armnn::Optional<std::string &> reasonIfUnsupported) const
179{
Jan Eilers8eb25602020-03-09 12:13:48 +0000180 IgnoreUnused(descriptor);
Nikhil Raj68c2c902019-09-19 11:21:11 +0100181
Teresa Charline300b362020-05-25 10:01:03 +0100182 std::array<DataType, 7> supportedTypes =
Nikhil Raj68c2c902019-09-19 11:21:11 +0100183 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000184 DataType::BFloat16,
Teresa Charline300b362020-05-25 10:01:03 +0100185 DataType::Float16,
Nikhil Raj68c2c902019-09-19 11:21:11 +0100186 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +0100187 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000188 DataType::QAsymmU8,
189 DataType::QSymmS16,
Francis Murtagh1939df52019-11-13 15:21:09 +0000190 DataType::Signed32
Nikhil Raj68c2c902019-09-19 11:21:11 +0100191 };
192
193 bool supported = true;
194
195 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
196 "Reference ArgMinMax: input is not a supported type.");
197 supported &= CheckSupportRule(TypeIs(output, DataType::Signed32), reasonIfUnsupported,
198 "Reference ArgMinMax: output type not supported");
199
200 return supported;
201}
202
arovir011c7c81b2018-10-08 11:34:28 +0100203bool RefLayerSupport::IsBatchNormalizationSupported(const TensorInfo& input,
204 const TensorInfo& output,
205 const TensorInfo& mean,
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100206 const TensorInfo& variance,
arovir011c7c81b2018-10-08 11:34:28 +0100207 const TensorInfo& beta,
208 const TensorInfo& gamma,
209 const BatchNormalizationDescriptor& descriptor,
210 Optional<std::string&> reasonIfUnsupported) const
211{
Jan Eilers8eb25602020-03-09 12:13:48 +0000212 IgnoreUnused(descriptor);
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100213
Sadik Armagan303980c2020-04-17 12:45:14 +0100214 std::array<DataType, 6> supportedTypes =
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100215 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000216 DataType::BFloat16,
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100217 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100218 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100219 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000220 DataType::QAsymmU8,
221 DataType::QSymmS16
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100222 };
223
224 bool supported = true;
225
226 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
227 "Reference batch normalization: input is not a supported type.");
228
229 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
230 "Reference batch normalization: output is not a supported type.");
231
232 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
233 "Reference batch normalization: input and output types are mismatched");
234
235 supported &= CheckSupportRule(TypeAnyOf(mean, supportedTypes), reasonIfUnsupported,
236 "Reference batch normalization: mean is not a supported type.");
237
238 supported &= CheckSupportRule(TypeAnyOf(variance, supportedTypes), reasonIfUnsupported,
239 "Reference batch normalization: variance is not a supported type.");
240
241 supported &= CheckSupportRule(TypeAnyOf(beta, supportedTypes), reasonIfUnsupported,
242 "Reference batch normalization: beta is not a supported type.");
243
244 supported &= CheckSupportRule(TypeAnyOf(gamma, supportedTypes), reasonIfUnsupported,
245 "Reference batch normalization: gamma is not a supported type.");
246
247 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100248}
249
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000250bool RefLayerSupport::IsBatchToSpaceNdSupported(const TensorInfo& input,
251 const TensorInfo& output,
252 const BatchToSpaceNdDescriptor& descriptor,
253 Optional<std::string&> reasonIfUnsupported) const
254{
Jan Eilers8eb25602020-03-09 12:13:48 +0000255 IgnoreUnused(descriptor);
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100256
257 bool supported = true;
258
259 std::string batchToSpaceNdLayerStr = "batchToSpaceNd";
260 std::string inputTensorStr = "input";
261 std::string outputTensorStr = "output";
262
263 // Define supported types.
Sadik Armagan303980c2020-04-17 12:45:14 +0100264 std::array<DataType,6> supportedTypes =
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100265 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000266 DataType::BFloat16,
267 DataType::Float32,
268 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100269 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000270 DataType::QAsymmU8,
271 DataType::QSymmS16
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100272 };
273
274 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
275 "Reference BatchToSpaceNd: input type not supported.");
276
277 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
278 "Reference BatchToSpaceNd: output type not supported.");
279
280 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
281 "Reference BatchToSpaceNd: input and output types mismatched.");
282
283 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 4),
284 reasonIfUnsupported,
285 CreateIncorrectDimensionsErrorMsg(4,
286 output.GetNumDimensions(),
287 batchToSpaceNdLayerStr,
288 outputTensorStr).data());
289
290 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(input, 4),
291 reasonIfUnsupported,
292 CreateIncorrectDimensionsErrorMsg(4,
293 input.GetNumDimensions(),
294 batchToSpaceNdLayerStr,
295 inputTensorStr).data());
296
297 return supported;
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000298}
299
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100300bool RefLayerSupport::IsComparisonSupported(const TensorInfo& input0,
301 const TensorInfo& input1,
302 const TensorInfo& output,
303 const ComparisonDescriptor& descriptor,
304 Optional<std::string&> reasonIfUnsupported) const
305{
Jan Eilers8eb25602020-03-09 12:13:48 +0000306 IgnoreUnused(descriptor);
Sadik Armagan303980c2020-04-17 12:45:14 +0100307 std::array<DataType, 8> supportedInputTypes =
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100308 {
Sadik Armaganb60dd242020-03-19 13:53:16 +0000309 DataType::Boolean,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000310 DataType::BFloat16,
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100311 DataType::Float32,
312 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100313 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000314 DataType::QAsymmU8,
Sadik Armaganb60dd242020-03-19 13:53:16 +0000315 DataType::QSymmS16,
316 DataType::Signed32
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100317 };
318
319 bool supported = true;
320 supported &= CheckSupportRule(TypeAnyOf(input0, supportedInputTypes), reasonIfUnsupported,
321 "Reference comparison: input 0 is not a supported type");
322
323 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
324 "Reference comparison: input 0 and Input 1 types are mismatched");
325
326 supported &= CheckSupportRule(TypeIs(output, DataType::Boolean), reasonIfUnsupported,
327 "Reference comparison: output is not of type Boolean");
328
329 return supported;
330}
331
Jim Flynn906f9462019-05-10 13:55:21 +0100332bool RefLayerSupport::IsConcatSupported(const std::vector<const TensorInfo*> inputs,
333 const TensorInfo& output,
Jim Flynne242f2d2019-05-22 14:24:13 +0100334 const ConcatDescriptor& descriptor,
Jim Flynn906f9462019-05-10 13:55:21 +0100335 Optional<std::string&> reasonIfUnsupported) const
336{
Jan Eilers8eb25602020-03-09 12:13:48 +0000337 IgnoreUnused(descriptor);
Jim Flynne242f2d2019-05-22 14:24:13 +0100338
339 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000340 std::array<DataType,6> supportedTypes =
Jim Flynne242f2d2019-05-22 14:24:13 +0100341 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000342 DataType::BFloat16,
343 DataType::Float32,
344 DataType::Float16,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000345 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100346 DataType::QAsymmU8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000347 DataType::QSymmS16
Jim Flynne242f2d2019-05-22 14:24:13 +0100348 };
349
350 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
351 "Reference concatenation: output type not supported");
352 for (const TensorInfo* input : inputs)
353 {
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100354 ARMNN_ASSERT(input != nullptr);
Jim Flynne242f2d2019-05-22 14:24:13 +0100355 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
356 "Reference concatenation: input type not supported");
357
358 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
359 "Reference concatenation: input and output types mismatched.");
360 }
361
362 return supported;
Jim Flynn906f9462019-05-10 13:55:21 +0100363}
364
arovir011c7c81b2018-10-08 11:34:28 +0100365bool RefLayerSupport::IsConstantSupported(const TensorInfo& output,
366 Optional<std::string&> reasonIfUnsupported) const
367{
Teresa Charlin6fa8ce62020-05-25 16:16:44 +0100368 std::array<DataType,8> supportedTypes =
Jim Flynne242f2d2019-05-22 14:24:13 +0100369 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000370 DataType::BFloat16,
Teresa Charlin6fa8ce62020-05-25 16:16:44 +0100371 DataType::Float16,
Nina Drozd58ef2c62019-05-16 12:09:18 +0100372 DataType::Float32,
Keith Davis67e6c542020-02-19 10:08:33 +0000373 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100374 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +0000375 DataType::QSymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100376 DataType::QSymmS16,
377 DataType::Signed32
Nina Drozd58ef2c62019-05-16 12:09:18 +0100378 };
379
380 return CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
381 "Reference constant: output is not a supported type.");
arovir011c7c81b2018-10-08 11:34:28 +0100382}
383
Narumol Prangnawarat7ddbbae2020-03-13 10:26:05 +0000384bool RefLayerSupport::IsConvertBf16ToFp32Supported(const TensorInfo& input,
385 const TensorInfo& output,
386 Optional<std::string&> reasonIfUnsupported) const
387{
388 bool supported = true;
389
390 supported &= CheckSupportRule(TypeIs(input, DataType::BFloat16), reasonIfUnsupported,
391 "Reference for ConvertBf16ToFp32 layer: input type not supported");
392
393 supported &= CheckSupportRule(TypeIs(output, DataType::Float32), reasonIfUnsupported,
394 "Reference for ConvertBf16ToFp32 layer: output type not supported");
395
396 return supported;
397}
398
arovir011c7c81b2018-10-08 11:34:28 +0100399bool RefLayerSupport::IsConvertFp16ToFp32Supported(const TensorInfo& input,
400 const TensorInfo& output,
401 Optional<std::string&> reasonIfUnsupported) const
402{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100403 return (IsSupportedForDataTypeGeneric(reasonIfUnsupported,
404 input.GetDataType(),
405 &TrueFunc<>,
406 &FalseInputFuncF32<>,
narpra01db2b1602019-01-23 15:23:11 +0000407 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000408 &FalseFuncI32<>,
409 &FalseFuncU8<>) &&
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100410 IsSupportedForDataTypeGeneric(reasonIfUnsupported,
411 output.GetDataType(),
412 &FalseOutputFuncF16<>,
413 &TrueFunc<>,
narpra01db2b1602019-01-23 15:23:11 +0000414 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000415 &FalseFuncI32<>,
416 &FalseFuncU8<>));
arovir011c7c81b2018-10-08 11:34:28 +0100417}
418
Narumol Prangnawaratea54a012020-03-16 16:36:10 +0000419bool RefLayerSupport::IsConvertFp32ToBf16Supported(const TensorInfo& input,
420 const TensorInfo& output,
421 Optional<std::string&> reasonIfUnsupported) const
422{
423 bool supported = true;
424
425 supported &= CheckSupportRule(TypeIs(input, DataType::Float32), reasonIfUnsupported,
426 "Reference for ConvertFp32ToBf16 layer: input type not supported");
427
428 supported &= CheckSupportRule(TypeIs(output, DataType::BFloat16), reasonIfUnsupported,
429 "Reference for ConvertFp32ToBf16 layer: output type not supported");
430
431 return supported;
432}
433
arovir011c7c81b2018-10-08 11:34:28 +0100434bool RefLayerSupport::IsConvertFp32ToFp16Supported(const TensorInfo& input,
435 const TensorInfo& output,
436 Optional<std::string&> reasonIfUnsupported) const
437{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100438 return (IsSupportedForDataTypeGeneric(reasonIfUnsupported,
439 input.GetDataType(),
440 &FalseInputFuncF16<>,
441 &TrueFunc<>,
narpra01db2b1602019-01-23 15:23:11 +0000442 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000443 &FalseFuncI32<>,
444 &FalseFuncU8<>) &&
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100445 IsSupportedForDataTypeGeneric(reasonIfUnsupported,
446 output.GetDataType(),
447 &TrueFunc<>,
448 &FalseOutputFuncF32<>,
narpra01db2b1602019-01-23 15:23:11 +0000449 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000450 &FalseFuncI32<>,
451 &FalseFuncU8<>));
arovir011c7c81b2018-10-08 11:34:28 +0100452}
453
454bool RefLayerSupport::IsConvolution2dSupported(const TensorInfo& input,
455 const TensorInfo& output,
456 const Convolution2dDescriptor& descriptor,
457 const TensorInfo& weights,
458 const Optional<TensorInfo>& biases,
459 Optional<std::string&> reasonIfUnsupported) const
460{
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100461 bool supported = true;
462
463 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000464 std::array<DataType,7> supportedTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000465 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000466 DataType::BFloat16,
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000467 DataType::Float32,
468 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000469 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100470 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +0000471 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000472 DataType::QSymmS16
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100473 };
474
475 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000476 "Reference Convolution2d: input is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100477
478 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000479 "Reference Convolution2d: output is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100480
Narumol Prangnawarat57ef0082020-03-26 09:20:43 +0000481 // For Convolution2d, we allow to have BFloat16 input with Float32 output for optimization.
482 if (input.GetDataType() == DataType::BFloat16)
483 {
484 if (output.GetDataType() != DataType::BFloat16 && output.GetDataType() != DataType::Float32)
485 {
486 reasonIfUnsupported.value() += "Output tensor type must be BFloat16 or Float32 for BFloat16 input.\n";
487 supported = false;
488 }
489 }
490 else
491 {
492 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000493 "Reference Convolution2d: input and output types mismatched.");
Narumol Prangnawarat57ef0082020-03-26 09:20:43 +0000494 }
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100495
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000496 const DataType inputType = input.GetDataType();
Keith Davis0c2eeac2020-02-11 16:51:50 +0000497 if (IsQuantized8BitType(inputType))
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000498 {
Derek Lambertid466a542020-01-22 15:37:29 +0000499 ARMNN_NO_DEPRECATE_WARN_BEGIN
Keith Davis0c2eeac2020-02-11 16:51:50 +0000500 std::array<DataType, 4> supportedWeightTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000501 {
Sadik Armagan303980c2020-04-17 12:45:14 +0100502 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000503 DataType::QAsymmU8,
Derek Lambertid466a542020-01-22 15:37:29 +0000504 DataType::QSymmS8,
505 DataType::QuantizedSymm8PerAxis // deprecated
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000506 };
Derek Lambertid466a542020-01-22 15:37:29 +0000507 ARMNN_NO_DEPRECATE_WARN_END
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000508
509 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000510 "Reference Convolution2d: weights type not supported for quantized input.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000511 }
512 else
513 {
514 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000515 "Reference Convolution2d: weights is not a supported type.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000516
517 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000518 "Reference Convolution2d: input and weights types mismatched.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000519 }
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100520
521 if (biases.has_value())
522 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000523 std::array<DataType,4> biasesSupportedTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000524 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000525 DataType::BFloat16,
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000526 DataType::Float32,
527 DataType::Float16,
528 DataType::Signed32
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100529 };
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000530
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100531 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000532 "Reference Convolution2d: biases is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100533 }
Jan Eilers8eb25602020-03-09 12:13:48 +0000534 IgnoreUnused(descriptor);
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100535
536 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100537}
538
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000539bool RefLayerSupport::IsDebugSupported(const TensorInfo& input,
540 const TensorInfo& output,
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000541 Optional<std::string&> reasonIfUnsupported) const
542{
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100543 bool supported = true;
544
Narumol Prangnawarat403a1852020-03-12 14:24:13 +0000545 std::array<DataType, 8> supportedTypes =
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100546 {
Narumol Prangnawarat403a1852020-03-12 14:24:13 +0000547 DataType::BFloat16,
Aron Virginas-Tardb1a2832019-11-12 16:15:11 +0000548 DataType::Float16,
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100549 DataType::Float32,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000550 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100551 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +0000552 DataType::QSymmS8,
Narumol Prangnawaratd2d917d2020-01-09 10:16:39 +0000553 DataType::QSymmS16,
554 DataType::Signed32
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100555 };
556
557 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000558 "Reference for Debug layer: input type not supported");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100559
560 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000561 "Reference for Debug layer: output type not supported");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100562
563 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000564 "Reference for Debug layer: input and output types are mismatched");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100565
566 return supported;
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000567}
568
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100569bool RefLayerSupport::IsDepthToSpaceSupported(const TensorInfo& input,
570 const TensorInfo& output,
571 const DepthToSpaceDescriptor& descriptor,
572 Optional<std::string&> reasonIfUnsupported) const
573{
Jan Eilers8eb25602020-03-09 12:13:48 +0000574 IgnoreUnused(descriptor);
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100575 bool supported = true;
576
Sadik Armagan303980c2020-04-17 12:45:14 +0100577 std::array<DataType,6> supportedTypes =
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100578 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000579 DataType::BFloat16,
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100580 DataType::Float32,
581 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100582 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000583 DataType::QAsymmU8,
584 DataType::QSymmS16
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100585 };
586
587 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
588 "Reference DepthToSpace: input type not supported");
589
590 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
591 "Reference DepthToSpace: output type not supported");
592
593 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
594 "Reference DepthToSpace: input and output types are mismatched");
595
596 return supported;
597}
598
arovir011c7c81b2018-10-08 11:34:28 +0100599bool RefLayerSupport::IsDepthwiseConvolutionSupported(const TensorInfo& input,
600 const TensorInfo& output,
601 const DepthwiseConvolution2dDescriptor& descriptor,
602 const TensorInfo& weights,
603 const Optional<TensorInfo>& biases,
604 Optional<std::string&> reasonIfUnsupported) const
605{
Sadik Armagan303980c2020-04-17 12:45:14 +0100606 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100607 bool supported = true;
608
609 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000610 std::array<DataType,7> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100611 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000612 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100613 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100614 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000615 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000616 DataType::QAsymmU8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100617 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000618 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100619 };
620
621 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
622 "Reference DepthwiseConvolution2d: input is not a supported type.");
623
624 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
625 "Reference DepthwiseConvolution2d: output is not a supported type.");
626
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100627 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
628 "Reference DepthwiseConvolution2d: input and output types mismatched.");
629
Teresa Charlind8df0262019-11-11 12:28:15 +0000630 const DataType inputType = input.GetDataType();
Keith Davis0c2eeac2020-02-11 16:51:50 +0000631 if (IsQuantized8BitType(inputType))
Teresa Charlind8df0262019-11-11 12:28:15 +0000632 {
Sadik Armagan303980c2020-04-17 12:45:14 +0100633 ARMNN_NO_DEPRECATE_WARN_BEGIN
634 std::array<DataType, 4> supportedWeightTypes =
635 {
636 DataType::QAsymmS8,
637 DataType::QAsymmU8,
638 DataType::QSymmS8,
639 DataType::QuantizedSymm8PerAxis // deprecated
640 };
641 ARMNN_NO_DEPRECATE_WARN_END
Teresa Charlind8df0262019-11-11 12:28:15 +0000642
643 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
Sadik Armagan303980c2020-04-17 12:45:14 +0100644 "Reference DepthwiseConvolution2d: weights type not supported for "
645 "quantized input.");
Teresa Charlind8df0262019-11-11 12:28:15 +0000646 }
647 else
648 {
649 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
650 "Reference DepthwiseConvolution2d: weights is not a supported type.");
651
652 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
653 "Reference DepthwiseConvolution2d: input and weights types mismatched.");
654 }
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100655
656 if (biases.has_value())
657 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000658 std::array<DataType,4> biasesSupportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100659 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000660 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100661 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100662 DataType::Float16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100663 DataType::Signed32
664 };
665 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
666 "Reference DepthwiseConvolution2d: biases is not a supported type.");
667 }
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100668
669 return supported;
670
arovir011c7c81b2018-10-08 11:34:28 +0100671}
672
Nattapat Chaimanowong8a54ac02019-03-29 15:25:04 +0000673bool RefLayerSupport::IsDequantizeSupported(const TensorInfo& input,
674 const TensorInfo& output,
675 Optional<std::string&> reasonIfUnsupported) const
676{
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100677 bool supported = true;
678
Ryan OShea9add1202020-02-07 10:06:33 +0000679 std::array<DataType,4> supportedInputTypes = {
680 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000681 DataType::QAsymmU8,
Finn Williamsfd271062019-12-04 14:27:27 +0000682 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000683 DataType::QSymmS16
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100684 };
685
686 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000687 "Reference for Dequantize layer: input type not supported.");
688
689 supported &= CheckSupportRule( TypeNotPerAxisQuantized(input), reasonIfUnsupported,
690 "Reference for Dequantize layer: per-axis quantized input not support .");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100691
Derek Lambertid466a542020-01-22 15:37:29 +0000692 supported &= CheckSupportRule(TypeNotPerAxisQuantized(input), reasonIfUnsupported,
693 "Reference dequantize: per-axis quantized input not support .");
694
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000695 std::array<DataType,3> supportedOutputTypes = {
696 DataType::BFloat16,
Jan Eilersf7107932019-11-01 11:09:36 +0000697 DataType::Float32,
698 DataType::Float16
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100699 };
700
701 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000702 "Reference for Dequantize layer: output type not supported.");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100703
704 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000705 "Reference for Dequantize layer: input/output shapes have different num total "
706 "elements.");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100707
708 return supported;
Nattapat Chaimanowong8a54ac02019-03-29 15:25:04 +0000709}
710
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000711bool RefLayerSupport::IsDetectionPostProcessSupported(const TensorInfo& boxEncodings,
712 const TensorInfo& scores,
713 const TensorInfo& anchors,
714 const TensorInfo& detectionBoxes,
715 const TensorInfo& detectionClasses,
716 const TensorInfo& detectionScores,
717 const TensorInfo& numDetections,
718 const DetectionPostProcessDescriptor& descriptor,
719 Optional<std::string&> reasonIfUnsupported) const
Narumol Prangnawaratbc67cef2019-01-31 15:31:54 +0000720{
Jan Eilers8eb25602020-03-09 12:13:48 +0000721 IgnoreUnused(anchors, detectionBoxes, detectionClasses, detectionScores, numDetections, descriptor);
Derek Lamberti901ea112019-12-10 22:07:09 +0000722
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100723 bool supported = true;
724
Sadik Armaganaa41d5d2020-11-16 14:27:52 +0000725 std::array<DataType,6> supportedInputTypes =
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100726 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000727 DataType::BFloat16,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100728 DataType::Float32,
Sadik Armaganaa41d5d2020-11-16 14:27:52 +0000729 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100730 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000731 DataType::QAsymmU8,
732 DataType::QSymmS16
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100733 };
734
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000735 supported &= CheckSupportRule(TypeAnyOf(boxEncodings, supportedInputTypes), reasonIfUnsupported,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100736 "Reference DetectionPostProcess: input 0 is not a supported type.");
737
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000738 supported &= CheckSupportRule(TypeAnyOf(scores, supportedInputTypes), reasonIfUnsupported,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100739 "Reference DetectionPostProcess: input 1 is not a supported type.");
740
741 return supported;
Narumol Prangnawaratbc67cef2019-01-31 15:31:54 +0000742}
743
Pablo Tellof0bd6832019-04-26 17:58:13 +0100744bool RefLayerSupport::IsDilatedDepthwiseConvolutionSupported(const TensorInfo& input,
745 const TensorInfo& output,
746 const DepthwiseConvolution2dDescriptor& descriptor,
747 const TensorInfo& weights,
748 const Optional<TensorInfo>& biases,
749 Optional<std::string&> reasonIfUnsupported) const
750{
Aron Virginas-Taraece4ed2019-06-14 17:00:09 +0100751 return IsDepthwiseConvolutionSupported(input, output, descriptor, weights, biases, reasonIfUnsupported);
Pablo Tellof0bd6832019-04-26 17:58:13 +0100752}
753
Aron Virginas-Taraece4ed2019-06-14 17:00:09 +0100754bool RefLayerSupport::IsDivisionSupported(const TensorInfo& input0,
arovir011c7c81b2018-10-08 11:34:28 +0100755 const TensorInfo& input1,
756 const TensorInfo& output,
757 Optional<std::string&> reasonIfUnsupported) const
758{
Sadik Armagan2999a022019-04-09 14:20:12 +0100759 bool supported = true;
760
Teresa Charlinecb6b8e2020-05-22 18:08:23 +0100761 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000762 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +0100763 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100764 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100765 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000766 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +0100767 DataType::QSymmS16,
768 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +0100769 };
770
771 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
772 "Reference division: input 0 is not a supported type.");
773
774 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
775 "Reference division: input 1 is not a supported type.");
776
777 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
778 "Reference division: output is not a supported type.");
779
780 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
781 "Reference division: input 0 and Input 1 types are mismatched");
782
783 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
784 "Reference division: input and output types are mismatched");
785
786 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
787 "Reference division: shapes are not suitable for implicit broadcast.");
788
789 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100790}
791
josh minor4a3c6102020-01-06 16:40:46 -0600792bool RefLayerSupport::IsElementwiseUnarySupported(const TensorInfo& input,
793 const TensorInfo& output,
794 const ElementwiseUnaryDescriptor& descriptor,
795 Optional<std::string&> reasonIfUnsupported) const
796{
Jan Eilers8eb25602020-03-09 12:13:48 +0000797 IgnoreUnused(descriptor);
josh minor4a3c6102020-01-06 16:40:46 -0600798
Sadik Armagan303980c2020-04-17 12:45:14 +0100799 std::array<DataType, 7> supportedTypes =
josh minor4a3c6102020-01-06 16:40:46 -0600800 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000801 DataType::BFloat16,
josh minor4a3c6102020-01-06 16:40:46 -0600802 DataType::Float32,
803 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100804 DataType::QAsymmS8,
josh minor4a3c6102020-01-06 16:40:46 -0600805 DataType::QAsymmU8,
Sadik Armaganac472102020-03-24 09:54:36 +0000806 DataType::QSymmS16,
807 DataType::Signed32
josh minor4a3c6102020-01-06 16:40:46 -0600808 };
809
Narumol Prangnawarat0c95f4c2020-11-18 16:52:07 +0000810 std::array<DataType, 1> logicalSupportedTypes =
811 {
812 DataType::Boolean
813 };
814
josh minor4a3c6102020-01-06 16:40:46 -0600815 bool supported = true;
816
Narumol Prangnawarat0c95f4c2020-11-18 16:52:07 +0000817 if (descriptor.m_Operation == UnaryOperation::LogicalNot)
818 {
819 supported &= CheckSupportRule(TypeAnyOf(input, logicalSupportedTypes), reasonIfUnsupported,
820 "Reference elementwise unary: input type not supported");
josh minor4a3c6102020-01-06 16:40:46 -0600821
Narumol Prangnawarat0c95f4c2020-11-18 16:52:07 +0000822 supported &= CheckSupportRule(TypeAnyOf(output, logicalSupportedTypes), reasonIfUnsupported,
823 "Reference elementwise unary: output type not supported");
824 }
825 else
826 {
827 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
828 "Reference elementwise unary: input type not supported");
829
830 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
831 "Reference elementwise unary: output type not supported");
832 }
josh minor4a3c6102020-01-06 16:40:46 -0600833
834 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
835 "Reference elementwise unary: input and output types not matching");
836
837 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
838 "Reference elementwise unary: input and output shapes"
839 "have different number of total elements");
840
841 return supported;
842}
843
FrancisMurtagh30cdfca2018-12-18 12:57:35 +0000844bool RefLayerSupport::IsEqualSupported(const TensorInfo& input0,
845 const TensorInfo& input1,
846 const TensorInfo& output,
847 Optional<std::string&> reasonIfUnsupported) const
848{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100849 return IsComparisonSupported(input0,
850 input1,
851 output,
852 ComparisonDescriptor(ComparisonOperation::Equal),
853 reasonIfUnsupported);
FrancisMurtagh30cdfca2018-12-18 12:57:35 +0000854}
855
arovir011c7c81b2018-10-08 11:34:28 +0100856bool RefLayerSupport::IsFakeQuantizationSupported(const TensorInfo& input,
857 const FakeQuantizationDescriptor& descriptor,
858 Optional<std::string&> reasonIfUnsupported) const
859{
Jan Eilers8eb25602020-03-09 12:13:48 +0000860 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100861 bool supported = true;
862
863 std::array<DataType,1> supportedTypes =
864 {
865 DataType::Float32
866 };
867
868 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
869 "Reference fake quantization: input type not supported.");
870
871 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100872}
873
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100874bool RefLayerSupport::IsFillSupported(const TensorInfo& input,
875 const TensorInfo& output,
876 const FillDescriptor& descriptor,
877 Optional<std::string&> reasonIfUnsupported) const
878{
879 IgnoreUnused(descriptor);
880 IgnoreUnused(output);
881
882 bool supported = true;
883
Sadik Armagana792a052020-06-23 16:22:23 +0100884 std::array<DataType,3> supportedTypes =
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100885 {
886 DataType::Float32,
Sadik Armagana792a052020-06-23 16:22:23 +0100887 DataType::Float16,
888 DataType::Signed32
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100889 };
890
Teresa Charlin4b10fef2020-07-29 09:36:41 +0100891 supported &= CheckSupportRule(TypeIs(input, DataType::Signed32), reasonIfUnsupported,
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100892 "Reference Fill: input type not supported.");
893
Teresa Charlin44088502020-07-27 11:27:19 +0100894 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
895 "Reference Fill: output type not supported.");
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100896 return supported;
897}
898
arovir011c7c81b2018-10-08 11:34:28 +0100899bool RefLayerSupport::IsFloorSupported(const TensorInfo& input,
900 const TensorInfo& output,
901 Optional<std::string&> reasonIfUnsupported) const
902{
Jan Eilers8eb25602020-03-09 12:13:48 +0000903 IgnoreUnused(output);
James Conroy83735b12019-05-30 16:36:59 +0100904 bool supported = true;
905
Francis Murtaghe8ac1332020-07-30 18:03:40 +0100906 std::array<DataType,3> supportedTypes =
James Conroy83735b12019-05-30 16:36:59 +0100907 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000908 DataType::BFloat16,
James Conroyb40d7102019-06-04 12:32:09 +0100909 DataType::Float32,
Francis Murtaghe8ac1332020-07-30 18:03:40 +0100910 DataType::Float16
James Conroy83735b12019-05-30 16:36:59 +0100911 };
912
913 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
914 "Reference Floor: input type not supported.");
915
916 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
917 "Reference Floor: output type not supported.");
918
919 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100920}
921
922bool RefLayerSupport::IsFullyConnectedSupported(const TensorInfo& input,
923 const TensorInfo& output,
924 const TensorInfo& weights,
925 const TensorInfo& biases,
926 const FullyConnectedDescriptor& descriptor,
927 Optional<std::string&> reasonIfUnsupported) const
928{
Francis Murtagh46c09d02019-05-28 08:15:28 +0100929 bool supported = true;
930
931 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000932 std::array<DataType,6> supportedTypes =
Francis Murtagh46c09d02019-05-28 08:15:28 +0100933 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000934 DataType::BFloat16,
935 DataType::Float32,
936 DataType::Float16,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000937 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100938 DataType::QAsymmU8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000939 DataType::QSymmS16
Francis Murtagh46c09d02019-05-28 08:15:28 +0100940 };
941
942 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
943 "Reference Fully Connected: input type not supported.");
944
945 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
946 "Reference Fully Connected: output type not supported.");
947
Francis Murtagh46c09d02019-05-28 08:15:28 +0100948 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
949 "Reference Fully Connected: weights type not supported.");
950
Narumol Prangnawarat57ef0082020-03-26 09:20:43 +0000951 // For FullyConnected, we allow to have BFloat16 input with Float32 output for optimization.
952 if (input.GetDataType() == DataType::BFloat16)
953 {
954 if (output.GetDataType() != DataType::BFloat16 && output.GetDataType() != DataType::Float32)
955 {
956 reasonIfUnsupported.value() += "Output tensor type must be BFloat16 or Float32 for BFloat16 input.\n";
957 supported = false;
958 }
959 }
960 else
961 {
962 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
963 "Reference Fully Connected: input and output types mismatched.");
964 }
965
Jan Eilers1f45dc32020-06-15 11:43:03 +0100966 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
967 "Reference Fully Connected: weights is not a supported type.");
Francis Murtaghddb1d062020-03-10 13:51:45 +0000968
Jan Eilers1f45dc32020-06-15 11:43:03 +0100969 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
970 "Reference Fully Connected: input and weights types mismatched.");
Francis Murtagh46c09d02019-05-28 08:15:28 +0100971
972 if (descriptor.m_BiasEnabled)
973 {
974 // Defined supported types for bias
Sadik Armagandb73c982020-04-01 17:35:30 +0100975 std::array<DataType, 5>
Francis Murtagh46c09d02019-05-28 08:15:28 +0100976 supportedBiasTypes =
977 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000978 DataType::BFloat16,
Francis Murtagh46c09d02019-05-28 08:15:28 +0100979 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100980 DataType::Float16,
Sadik Armagandb73c982020-04-01 17:35:30 +0100981 DataType::Signed32,
982 DataType::QAsymmS8
Francis Murtagh46c09d02019-05-28 08:15:28 +0100983 };
984
985 supported &= CheckSupportRule(TypeAnyOf(biases, supportedBiasTypes), reasonIfUnsupported,
986 "Reference Fully Connected: bias type not supported.");
987
988 supported &= CheckSupportRule(BiasAndWeightsTypesMatch(biases, weights), reasonIfUnsupported,
989 "Reference Fully Connected: bias and weight types mismatch.");
990
991 supported &= CheckSupportRule(BiasAndWeightsTypesCompatible(weights, supportedBiasTypes), reasonIfUnsupported,
992 "Reference Fully Connected: bias type inferred from weights is incompatible.");
993
Narumol Prangnawarat366d7232020-04-29 12:58:17 +0100994 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(biases, 1U), reasonIfUnsupported,
995 "Reference Fully Connected: bias must have 1 dimension.");
996
Francis Murtagh46c09d02019-05-28 08:15:28 +0100997 }
998
999 return supported;
arovir011c7c81b2018-10-08 11:34:28 +01001000}
1001
narpra014951d842019-01-18 16:53:53 +00001002bool RefLayerSupport::IsGatherSupported(const armnn::TensorInfo& input0,
1003 const armnn::TensorInfo& input1,
1004 const armnn::TensorInfo& output,
Teresa Charlin52664732020-06-29 16:27:03 +01001005 const GatherDescriptor& descriptor,
narpra014951d842019-01-18 16:53:53 +00001006 armnn::Optional<std::string&> reasonIfUnsupported) const
1007{
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +01001008 bool supported = true;
Teresa Charlin3940d8b2020-05-29 16:47:23 +01001009 std::array<DataType,7> supportedTypes =
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +01001010 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001011 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001012 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001013 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001014 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001015 DataType::QAsymmU8,
Teresa Charlin3940d8b2020-05-29 16:47:23 +01001016 DataType::QSymmS16,
1017 DataType::Signed32
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +01001018 };
1019
Teresa Charlin52664732020-06-29 16:27:03 +01001020 if (descriptor.m_Axis != 0)
1021 {
1022 reasonIfUnsupported.value() += std::string("Reference Gather: axis not supported\n");
1023 supported &= false;
1024 }
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +01001025 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1026 "Reference Gather: input type not supported");
1027
1028 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1029 "Reference Gather: output type not supported");
1030
1031 supported &= CheckSupportRule(TypeIs(input1, DataType::Signed32), reasonIfUnsupported,
1032 "Reference Gather: indices (input1) type not supported");
1033
1034 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1035 "Reference Gather: input and output types not matching");
1036
1037 return supported;
narpra014951d842019-01-18 16:53:53 +00001038}
1039
FrancisMurtagh878f0232018-12-19 10:56:15 +00001040bool RefLayerSupport::IsGreaterSupported(const TensorInfo& input0,
1041 const TensorInfo& input1,
1042 const TensorInfo& output,
1043 Optional<std::string&> reasonIfUnsupported) const
1044{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +01001045 return IsComparisonSupported(input0,
1046 input1,
1047 output,
1048 ComparisonDescriptor(ComparisonOperation::Greater),
1049 reasonIfUnsupported);
FrancisMurtagh878f0232018-12-19 10:56:15 +00001050}
1051
Derek Lamberti901ea112019-12-10 22:07:09 +00001052bool RefLayerSupport::IsInputSupported(const TensorInfo& /*input*/,
1053 Optional<std::string&> /*reasonIfUnsupported*/) const
arovir011c7c81b2018-10-08 11:34:28 +01001054{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +01001055 return true;
arovir011c7c81b2018-10-08 11:34:28 +01001056}
1057
Kevin May09ca49c2019-10-09 12:37:34 +01001058bool RefLayerSupport::IsInstanceNormalizationSupported(const TensorInfo& input,
1059 const TensorInfo& output,
1060 const InstanceNormalizationDescriptor& descriptor,
1061 Optional<std::string&> reasonIfUnsupported) const
1062{
Jan Eilers8eb25602020-03-09 12:13:48 +00001063 IgnoreUnused(descriptor);
Kevin May09ca49c2019-10-09 12:37:34 +01001064 // Define supported types
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001065 std::array<DataType, 3> supportedTypes =
Kevin May09ca49c2019-10-09 12:37:34 +01001066 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001067 DataType::BFloat16,
Kevin May09ca49c2019-10-09 12:37:34 +01001068 DataType::Float32,
1069 DataType::Float16
1070 };
1071
1072 bool supported = true;
1073
1074 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1075 "Reference Instance Normalization: input type not supported.");
1076
1077 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1078 "Reference Instance Normalization: output type not supported.");
1079
1080 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1081 "Reference Instance Normalization: input and output types mismatched.");
1082
1083 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1084 "Reference Instance Normalization: input and output shapes have different "
1085 "num total elements.");
1086
1087 return supported;
1088}
1089
arovir011c7c81b2018-10-08 11:34:28 +01001090bool RefLayerSupport::IsL2NormalizationSupported(const TensorInfo& input,
1091 const TensorInfo& output,
1092 const L2NormalizationDescriptor& descriptor,
1093 Optional<std::string&> reasonIfUnsupported) const
1094{
Jan Eilers8eb25602020-03-09 12:13:48 +00001095 IgnoreUnused(descriptor);
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001096 // Define supported types
Sadik Armagan303980c2020-04-17 12:45:14 +01001097 std::array<DataType, 6> supportedTypes =
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001098 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001099 DataType::BFloat16,
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001100 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001101 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001102 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001103 DataType::QAsymmU8,
1104 DataType::QSymmS16
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001105 };
1106
1107 bool supported = true;
1108
1109 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1110 "Reference L2normalization: input type not supported.");
1111
1112 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1113 "Reference L2normalization: output type not supported.");
1114
1115 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1116 "Reference L2normalization: input and output types mismatched.");
1117
1118 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1119 "Reference L2normalization: input and output shapes have different "
1120 "num total elements.");
1121
1122 return supported;
arovir011c7c81b2018-10-08 11:34:28 +01001123}
1124
James Conroyaba90cd2020-11-06 16:28:18 +00001125bool RefLayerSupport::IsLogicalBinarySupported(const TensorInfo& input0,
1126 const TensorInfo& input1,
1127 const TensorInfo& output,
1128 const LogicalBinaryDescriptor& descriptor,
1129 Optional<std::string&> reasonIfUnsupported) const
1130{
1131 IgnoreUnused(descriptor);
1132
1133 std::array<DataType, 1> supportedTypes =
1134 {
1135 DataType::Boolean
1136 };
1137
1138 bool supported = true;
1139 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1140 "Reference LogicalBinary: input 0 type not supported");
1141 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1142 "Reference LogicalBinary: input 1 type not supported");
1143
1144 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1145 "Reference LogicalBinary: input and output types do not match");
1146
1147 return supported;
1148}
1149
1150bool RefLayerSupport::IsLogicalUnarySupported(const TensorInfo& input,
1151 const TensorInfo& output,
1152 const ElementwiseUnaryDescriptor& descriptor,
1153 Optional<std::string&> reasonIfUnsupported) const
1154{
1155 IgnoreUnused(descriptor);
1156
1157 std::array<DataType, 1> supportedTypes =
1158 {
1159 DataType::Boolean
1160 };
1161
1162 bool supported = true;
1163 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1164 "Reference LogicalUnary: input type not supported");
1165
1166 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1167 "Reference LogicalUnary: input and output types do not match");
1168
1169 return supported;
1170}
1171
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001172bool RefLayerSupport::IsLogSoftmaxSupported(const TensorInfo& input,
1173 const TensorInfo& output,
1174 const LogSoftmaxDescriptor& descriptor,
1175 Optional<std::string&> reasonIfUnsupported) const
1176{
Jan Eilers8eb25602020-03-09 12:13:48 +00001177 IgnoreUnused(descriptor);
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001178
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001179 std::array<DataType, 3> supportedTypes =
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001180 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001181 DataType::BFloat16,
1182 DataType::Float32,
1183 DataType::Float16
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001184 };
1185
1186 bool supported = true;
1187 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1188 "Reference LogSoftmax: input type not supported");
1189
1190 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1191 "Reference LogSoftmax: output type not supported");
1192
1193 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1194 "Reference LogSoftmax: input and output types do not match");
1195
1196 return supported;
1197}
1198
arovir011c7c81b2018-10-08 11:34:28 +01001199bool RefLayerSupport::IsLstmSupported(const TensorInfo& input,
1200 const TensorInfo& outputStateIn,
1201 const TensorInfo& cellStateIn,
1202 const TensorInfo& scratchBuffer,
1203 const TensorInfo& outputStateOut,
1204 const TensorInfo& cellStateOut,
1205 const TensorInfo& output,
1206 const LstmDescriptor& descriptor,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001207 const LstmInputParamsInfo& paramsInfo,
1208 Optional<std::string&> reasonIfUnsupported) const
arovir011c7c81b2018-10-08 11:34:28 +01001209{
Jan Eilers8eb25602020-03-09 12:13:48 +00001210 IgnoreUnused(descriptor);
1211 IgnoreUnused(paramsInfo);
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001212
1213 bool supported = true;
1214
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001215 std::array<DataType,3> supportedTypes = {
1216 DataType::BFloat16,
Conor Kennedyb9971c92019-05-07 07:14:23 +01001217 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001218 DataType::QSymmS16
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001219 };
1220
Jan Eilersd01a83c2019-07-03 18:20:40 +01001221 // check inputs and outputs
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001222 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1223 "Reference Lstm: input is not a supported type.");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001224 supported &= CheckSupportRule(TypesAreEqual(input, outputStateIn), reasonIfUnsupported,
1225 "Reference Lstm: input and outputStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001226 supported &= CheckSupportRule(TypesAreEqual(input, cellStateIn), reasonIfUnsupported,
1227 "Reference Lstm: input and cellStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001228 supported &= CheckSupportRule(TypesAreEqual(input, scratchBuffer), reasonIfUnsupported,
1229 "Reference Lstm: input and scratchBuffer types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001230 supported &= CheckSupportRule(TypesAreEqual(input, outputStateOut), reasonIfUnsupported,
1231 "Reference Lstm: input and outputStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001232 supported &= CheckSupportRule(TypesAreEqual(input, cellStateOut), reasonIfUnsupported,
1233 "Reference Lstm: input and cellStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001234 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1235 "Reference Lstm: input and output types are mismatched");
Jan Eilersd01a83c2019-07-03 18:20:40 +01001236 // check layer parameters
Francis Murtaghbb590b42019-08-14 09:51:36 +01001237 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001238 "Reference Lstm: input and InputToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001239 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001240 "Reference Lstm: input and InputToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001241 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001242 "Reference Lstm: input and InputToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001243 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001244 "Reference Lstm: input and RecurrentToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001245 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001246 "Reference Lstm: input and RecurrentToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001247 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001248 "Reference Lstm: input and RecurrentToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001249 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001250 "Reference Lstm: input and ForgetGateBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001251 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001252 "Reference Lstm: input and CellBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001253 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001254 "Reference Lstm: input and OutputGateBias types are mismatched");
1255 if (!descriptor.m_CifgEnabled)
1256 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001257 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToInputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001258 "Reference Lstm: input and InputToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001259 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001260 reasonIfUnsupported,
1261 "Reference Lstm: input and RecurrentToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001262 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001263 "Reference Lstm: input and InputGateBias types are mismatched");
1264 if (descriptor.m_PeepholeEnabled)
1265 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001266 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001267 reasonIfUnsupported,
1268 "Reference Lstm: input and CellToInputWeights types are mismatched");
1269 }
1270 }
1271 if (descriptor.m_PeepholeEnabled)
1272 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001273 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001274 "Reference Lstm: input and CellToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001275 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001276 "Reference Lstm: input and CellToOutputWeights types are mismatched");
1277 }
1278 if (descriptor.m_ProjectionEnabled)
1279 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001280 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001281 "Reference Lstm: input and mProjectionWeights types are mismatched");
1282 if (paramsInfo.m_ProjectionBias != nullptr)
1283 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001284 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001285 "Reference Lstm: input and ProjectionBias types are mismatched");
1286 }
1287 }
1288 if (descriptor.m_LayerNormEnabled)
1289 {
1290 if (!descriptor.m_CifgEnabled)
1291 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001292 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001293 reasonIfUnsupported,
1294 "Reference Lstm: input and InputLayerNormWeights types are mismatched");
1295 }
Francis Murtaghbb590b42019-08-14 09:51:36 +01001296 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001297 reasonIfUnsupported,
1298 "Reference Lstm: input and ForgetLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001299 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001300 reasonIfUnsupported,
1301 "Reference Lstm: input and CellLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001302 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001303 reasonIfUnsupported,
1304 "Reference Lstm: input and OutputLayerNormWeights types are mismatched");
1305 }
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001306
1307 return supported;
telsoa01c577f2c2018-08-31 09:22:23 +01001308}
1309
saoste012df12b32018-11-28 16:57:20 +00001310bool RefLayerSupport::IsMaximumSupported(const TensorInfo& input0,
1311 const TensorInfo& input1,
1312 const TensorInfo& output,
1313 Optional<std::string&> reasonIfUnsupported) const
1314{
Sadik Armagan2999a022019-04-09 14:20:12 +01001315 bool supported = true;
1316
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001317 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001318 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001319 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001320 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001321 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001322 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001323 DataType::QSymmS16,
1324 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01001325 };
1326
1327 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1328 "Reference maximum: input 0 is not a supported type.");
1329
1330 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1331 "Reference maximum: input 1 is not a supported type.");
1332
1333 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1334 "Reference maximum: output is not a supported type.");
1335
1336 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1337 "Reference maximum: input 0 and Input 1 types are mismatched");
1338
1339 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1340 "Reference maximum: input and output types are mismatched");
1341
1342 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1343 "Reference maximum: shapes are not suitable for implicit broadcast.");
1344
1345 return supported;
saoste012df12b32018-11-28 16:57:20 +00001346}
1347
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001348bool RefLayerSupport::IsMeanSupported(const TensorInfo& input,
1349 const TensorInfo& output,
1350 const MeanDescriptor& descriptor,
1351 Optional<std::string&> reasonIfUnsupported) const
narpra0132b90462018-09-13 11:07:48 +01001352{
James Conroy4d1ff582019-06-10 17:06:39 +01001353 bool supported = true;
1354 std::string meanLayerStr = "Mean";
1355 std::string outputTensorStr = "output";
1356
Sadik Armagan303980c2020-04-17 12:45:14 +01001357 std::array<DataType,6> supportedTypes =
James Conroy4d1ff582019-06-10 17:06:39 +01001358 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001359 DataType::BFloat16,
James Conroy4d1ff582019-06-10 17:06:39 +01001360 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001361 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001362 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001363 DataType::QAsymmU8,
1364 DataType::QSymmS16
James Conroy4d1ff582019-06-10 17:06:39 +01001365 };
1366
1367 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1368 "Reference Mean: input type not supported.");
1369
1370 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1371 "Reference Mean: input and output types are mismatched");
1372
1373 if (descriptor.m_KeepDims)
1374 {
1375 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, input.GetNumDimensions()),
1376 reasonIfUnsupported,
1377 CreateIncorrectDimensionsErrorMsg(input.GetNumDimensions(),
1378 output.GetNumDimensions(),
1379 meanLayerStr, outputTensorStr).data());
1380 }
1381 else if (descriptor.m_Axis.empty())
1382 {
1383 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1384 reasonIfUnsupported,
1385 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1386 meanLayerStr, outputTensorStr).data());
1387 }
1388 else
1389 {
Matthew Sloyan171214c2020-09-09 09:07:37 +01001390 auto outputDim = input.GetNumDimensions() - armnn::numeric_cast<unsigned int>(descriptor.m_Axis.size());
James Conroy4d1ff582019-06-10 17:06:39 +01001391
1392 if (outputDim > 0)
1393 {
1394 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, outputDim),
1395 reasonIfUnsupported,
1396 CreateIncorrectDimensionsErrorMsg(outputDim, output.GetNumDimensions(),
1397 meanLayerStr, outputTensorStr).data());
1398 }
1399 else
1400 {
1401 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1402 reasonIfUnsupported,
1403 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1404 meanLayerStr, outputTensorStr).data());
1405 }
1406 }
1407
1408 return supported;
narpra0132b90462018-09-13 11:07:48 +01001409}
1410
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001411bool RefLayerSupport::IsMergerSupported(const std::vector<const TensorInfo*> inputs,
Nikhil Raj8599a412018-11-19 14:51:07 +00001412 const TensorInfo& output,
Jim Flynne242f2d2019-05-22 14:24:13 +01001413 const MergerDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001414 Optional<std::string&> reasonIfUnsupported) const
1415{
Jim Flynne242f2d2019-05-22 14:24:13 +01001416 return IsConcatSupported(inputs, output, descriptor, reasonIfUnsupported);
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001417}
1418
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001419bool RefLayerSupport::IsMemCopySupported(const TensorInfo &input,
1420 const TensorInfo &output,
1421 Optional<std::string &> reasonIfUnsupported) const
1422{
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001423 bool supported = true;
1424
Sadik Armagan303980c2020-04-17 12:45:14 +01001425 std::array<DataType,7> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001426 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001427 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001428 DataType::Float32,
1429 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001430 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001431 DataType::QAsymmU8,
1432 DataType::QSymmS16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001433 DataType::Boolean
1434 };
1435
1436 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1437 "Reference MemCopy: input type not supported");
1438
1439 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1440 "Reference MemCopy: output type not supported");
1441
1442 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1443 "Reference MemCopy: input and output types are mismatched");
1444
1445 return supported;
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001446}
1447
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001448bool RefLayerSupport::IsMinimumSupported(const TensorInfo& input0,
1449 const TensorInfo& input1,
1450 const TensorInfo& output,
1451 Optional<std::string&> reasonIfUnsupported) const
1452{
Sadik Armagan2999a022019-04-09 14:20:12 +01001453 bool supported = true;
1454
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001455 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001456 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001457 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001458 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001459 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001460 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001461 DataType::QSymmS16,
1462 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01001463 };
1464
1465 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1466 "Reference minimum: input 0 is not a supported type.");
1467
1468 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1469 "Reference minimum: input 1 is not a supported type.");
1470
1471 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1472 "Reference minimum: output is not a supported type.");
1473
1474 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1475 "Reference minimum: input 0 and Input 1 types are mismatched");
1476
1477 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1478 "Reference minimum: input and output types are mismatched");
1479
1480 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1481 "Reference minimum: shapes are not suitable for implicit broadcast.");
1482
1483 return supported;
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001484}
1485
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001486bool RefLayerSupport::IsMultiplicationSupported(const TensorInfo& input0,
1487 const TensorInfo& input1,
1488 const TensorInfo& output,
1489 Optional<std::string&> reasonIfUnsupported) const
1490{
Sadik Armagan2999a022019-04-09 14:20:12 +01001491 bool supported = true;
1492
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001493 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001494 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001495 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001496 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001497 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001498 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001499 DataType::QSymmS16,
1500 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01001501 };
1502
1503 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1504 "Reference multiplication: input 0 is not a supported type.");
1505
1506 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1507 "Reference multiplication: input 1 is not a supported type.");
1508
1509 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1510 "Reference multiplication: output is not a supported type.");
1511
1512 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1513 "Reference multiplication: input 0 and Input 1 types are mismatched");
1514
1515 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1516 "Reference multiplication: input and output types are mismatched");
1517
1518 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1519 "Reference multiplication: shapes are not suitable for implicit broadcast.");
1520
1521 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001522}
1523
1524bool RefLayerSupport::IsNormalizationSupported(const TensorInfo& input,
1525 const TensorInfo& output,
1526 const NormalizationDescriptor& descriptor,
1527 Optional<std::string&> reasonIfUnsupported) const
Nina Drozd661dfa72018-10-02 11:14:17 +01001528{
Jan Eilers8eb25602020-03-09 12:13:48 +00001529 IgnoreUnused(descriptor);
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001530
1531 // Define supported types
Sadik Armagan303980c2020-04-17 12:45:14 +01001532 std::array<DataType, 6> supportedTypes =
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001533 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001534 DataType::BFloat16,
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001535 DataType::Float16,
1536 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001537 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001538 DataType::QAsymmU8,
1539 DataType::QSymmS16
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001540 };
1541
1542 bool supported = true;
1543
1544 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1545 "Reference normalization: input type not supported.");
1546
1547 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1548 "Reference normalization: output type not supported.");
1549
1550 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1551 "Reference normalization: input and output shapes have different "
1552 "num total elements.");
1553
1554 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001555}
1556
Derek Lamberti901ea112019-12-10 22:07:09 +00001557bool RefLayerSupport::IsOutputSupported(const TensorInfo& /*output*/,
1558 Optional<std::string&> /*reasonIfUnsupported*/) const
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001559{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +01001560 return true;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001561}
1562
1563bool RefLayerSupport::IsPadSupported(const TensorInfo& input,
1564 const TensorInfo& output,
1565 const PadDescriptor& descriptor,
1566 Optional<std::string&> reasonIfUnsupported) const
1567{
Jan Eilers8eb25602020-03-09 12:13:48 +00001568 IgnoreUnused(descriptor);
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001569 bool supported = true;
1570
1571 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01001572 std::array<DataType,6> supportedTypes =
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001573 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001574 DataType::BFloat16,
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001575 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001576 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001577 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001578 DataType::QAsymmU8,
1579 DataType::QSymmS16
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001580 };
1581
1582 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1583 "Reference pad: input is not a supported type.");
1584
1585 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1586 "Reference pad: output is not a supported type.");
1587
1588 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1589 "Reference pad: input and output types are mismatched.");
1590
1591 return supported;
Nina Drozd661dfa72018-10-02 11:14:17 +01001592}
1593
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001594bool RefLayerSupport::IsPermuteSupported(const TensorInfo& input,
1595 const TensorInfo& output,
1596 const PermuteDescriptor& descriptor,
1597 Optional<std::string&> reasonIfUnsupported) const
1598{
Jan Eilers8eb25602020-03-09 12:13:48 +00001599 IgnoreUnused(descriptor);
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001600 bool supported = true;
1601
1602 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01001603 std::array<DataType, 6> supportedTypes =
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001604 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001605 DataType::BFloat16,
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001606 DataType::Float32,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00001607 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001608 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001609 DataType::QAsymmU8,
1610 DataType::QSymmS16
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001611 };
1612
1613 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1614 "Reference permute: input is not a supported type.");
1615
1616 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1617 "Reference permute: output is not a supported type.");
1618
1619 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1620 "Reference permute: input and output types are mismatched.");
1621
1622 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001623}
1624
1625bool RefLayerSupport::IsPooling2dSupported(const TensorInfo& input,
1626 const TensorInfo& output,
1627 const Pooling2dDescriptor& descriptor,
1628 Optional<std::string&> reasonIfUnsupported) const
1629{
Jan Eilers8eb25602020-03-09 12:13:48 +00001630 IgnoreUnused(descriptor);
Teresa Charlina3b20472019-06-06 11:12:32 +01001631 bool supported = true;
1632
1633 // Define supported output and inputs types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001634 std::array<DataType,6> supportedTypes =
Teresa Charlina3b20472019-06-06 11:12:32 +01001635 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001636 DataType::BFloat16,
Teresa Charlina3b20472019-06-06 11:12:32 +01001637 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001638 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001639 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001640 DataType::QAsymmU8,
1641 DataType::QSymmS16
Teresa Charlina3b20472019-06-06 11:12:32 +01001642 };
1643
1644 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1645 "Reference poolind2d: input is not a supported type.");
1646
1647 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1648 "Reference poolind2d: output is not a supported type.");
1649
1650 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1651 "Reference poolind2d: input and output types are mismatched.");
1652
1653 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001654}
1655
James Conroy4f1f8992020-04-29 20:01:10 +01001656bool RefLayerSupport::IsQLstmSupported(const TensorInfo& input,
1657 const TensorInfo& previousOutputIn,
1658 const TensorInfo& previousCellStateIn,
1659 const TensorInfo& outputStateOut,
1660 const TensorInfo& cellStateOut,
1661 const TensorInfo& output,
1662 const QLstmDescriptor& descriptor,
1663 const LstmInputParamsInfo& paramsInfo,
1664 Optional<std::string&> reasonIfUnsupported) const
1665{
1666 IgnoreUnused(input);
1667 IgnoreUnused(previousOutputIn);
1668 IgnoreUnused(previousCellStateIn);
1669 IgnoreUnused(outputStateOut);
1670 IgnoreUnused(cellStateOut);
1671 IgnoreUnused(output);
1672 IgnoreUnused(descriptor);
1673 IgnoreUnused(paramsInfo);
1674
1675 IgnoreUnused(reasonIfUnsupported);
1676
1677 return true;
1678}
1679
Derek Lamberti5f400d62019-03-25 15:41:58 +00001680bool RefLayerSupport::IsQuantizeSupported(const TensorInfo& input,
1681 const TensorInfo& output,
1682 Optional<std::string&> reasonIfUnsupported) const
1683{
1684 bool supported = true;
1685
Finn Williamsfd271062019-12-04 14:27:27 +00001686 // Define supported input types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001687 std::array<DataType,7> supportedInputTypes = {
1688 DataType::BFloat16,
Keith Davis5e51cd82020-01-29 16:52:59 +00001689 DataType::Float32,
Keith Davis3d8bc972020-02-04 09:31:47 +00001690 DataType::Float16,
Ryan OShea9add1202020-02-07 10:06:33 +00001691 DataType::QAsymmS8,
Keith Davis5e51cd82020-01-29 16:52:59 +00001692 DataType::QAsymmU8,
1693 DataType::QSymmS8,
1694 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001695 };
1696
1697 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
1698 "Reference quantize: input type not supported.");
1699
1700 // Define supported output types.
Ryan OShea9add1202020-02-07 10:06:33 +00001701 std::array<DataType,4> supportedOutputTypes = {
Ryan OShea9add1202020-02-07 10:06:33 +00001702 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001703 DataType::QAsymmU8,
Finn Williamsfd271062019-12-04 14:27:27 +00001704 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001705 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001706 };
1707 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
1708 "Reference quantize: output type not supported.");
1709
1710 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1711 "Reference quantize: input and output shapes have different num total elements.");
1712
1713 return supported;
1714}
1715
Finn Williams2605b232020-06-10 15:53:46 +01001716bool RefLayerSupport::IsRankSupported(const TensorInfo& input,
1717 const TensorInfo& output,
1718 Optional<std::string&> reasonIfUnsupported) const
1719{
1720 IgnoreUnused(input);
1721 // Define supported output types.
1722 std::array<DataType,1> supportedOutputTypes =
1723 {
1724 DataType::Signed32,
1725 };
1726
1727 return CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
1728 "Reference rank: input type not supported.");
1729}
1730
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001731bool RefLayerSupport::IsReshapeSupported(const TensorInfo& input,
Kevin Maya023c402019-12-12 17:28:05 +00001732 const TensorInfo& output,
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001733 const ReshapeDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001734 Optional<std::string&> reasonIfUnsupported) const
1735{
Jan Eilers8eb25602020-03-09 12:13:48 +00001736 IgnoreUnused(output);
1737 IgnoreUnused(descriptor);
Nina Drozd2f2778f2019-05-27 10:37:05 +01001738 // Define supported output types.
Narumol Prangnawarat0c95f4c2020-11-18 16:52:07 +00001739 std::array<DataType,8> supportedOutputTypes =
Nina Drozd2f2778f2019-05-27 10:37:05 +01001740 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001741 DataType::BFloat16,
Nina Drozd2f2778f2019-05-27 10:37:05 +01001742 DataType::Float32,
1743 DataType::Float16,
Narumol Prangnawarat0718ee92019-09-13 16:53:38 +01001744 DataType::Signed32,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001745 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001746 DataType::QAsymmU8,
Narumol Prangnawarat0c95f4c2020-11-18 16:52:07 +00001747 DataType::QSymmS16,
1748 DataType::Boolean
Nina Drozd2f2778f2019-05-27 10:37:05 +01001749 };
Keith Davis0c2eeac2020-02-11 16:51:50 +00001750
Nina Drozd2f2778f2019-05-27 10:37:05 +01001751 return CheckSupportRule(TypeAnyOf(input, supportedOutputTypes), reasonIfUnsupported,
1752 "Reference reshape: input type not supported.");
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001753}
1754
1755bool RefLayerSupport::IsResizeBilinearSupported(const TensorInfo& input,
Sadik Armaganc625f002018-12-17 11:32:16 +00001756 const TensorInfo& output,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001757 Optional<std::string&> reasonIfUnsupported) const
1758{
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001759 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001760 std::array<DataType,6> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001761 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001762 DataType::BFloat16,
Teresa Charlin970f43b2019-07-01 13:51:07 +01001763 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001764 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001765 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001766 DataType::QAsymmU8,
1767 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001768 };
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001769
1770 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1771 "Reference ResizeBilinear: input type not supported");
1772
1773 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1774 "Reference ResizeBilinear: output type not supported");
1775
1776 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1777 "Reference ResizeBilinear: input and output types not matching");
1778
1779 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001780}
1781
Teresa Charlin970f43b2019-07-01 13:51:07 +01001782bool RefLayerSupport::IsResizeSupported(const TensorInfo& input,
1783 const TensorInfo& output,
1784 const ResizeDescriptor& descriptor,
1785 Optional<std::string&> reasonIfUnsupported) const
1786{
Jan Eilers8eb25602020-03-09 12:13:48 +00001787 IgnoreUnused(descriptor);
Teresa Charlin970f43b2019-07-01 13:51:07 +01001788 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001789 std::array<DataType,6> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001790 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001791 DataType::BFloat16,
Teresa Charlin970f43b2019-07-01 13:51:07 +01001792 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001793 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001794 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001795 DataType::QAsymmU8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001796 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001797 };
1798
1799 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1800 "Reference Resize: input type not supported");
1801
1802 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1803 "Reference Resize: output type not supported");
1804
1805 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1806 "Reference Resize: input and output types not matching");
1807
1808 return supported;
1809}
1810
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001811bool RefLayerSupport::IsRsqrtSupported(const TensorInfo& input,
1812 const TensorInfo& output,
1813 Optional<std::string&> reasonIfUnsupported) const
1814{
josh minor4a3c6102020-01-06 16:40:46 -06001815 return IsElementwiseUnarySupported(input,
1816 output,
1817 ElementwiseUnaryDescriptor(UnaryOperation::Rsqrt),
1818 reasonIfUnsupported);
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001819}
1820
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001821bool RefLayerSupport::IsSliceSupported(const TensorInfo& input,
1822 const TensorInfo& output,
1823 const SliceDescriptor& descriptor,
1824 Optional<std::string&> reasonIfUnsupported) const
1825{
Jan Eilers8eb25602020-03-09 12:13:48 +00001826 IgnoreUnused(descriptor);
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001827 bool supported = true;
1828
Sadik Armagan303980c2020-04-17 12:45:14 +01001829 std::array<DataType, 5> supportedTypes =
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001830 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001831 DataType::BFloat16,
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001832 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001833 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001834 DataType::QAsymmU8,
1835 DataType::QSymmS16
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001836 };
1837
1838 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1839 "Reference Slice: input type not supported");
1840
1841 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1842 "Reference Slice: output type not supported");
1843
1844 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1845 "Reference Slice: input and output types are mismatched");
1846
1847 return supported;
1848}
1849
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001850bool RefLayerSupport::IsSoftmaxSupported(const TensorInfo& input,
1851 const TensorInfo& output,
1852 const SoftmaxDescriptor& descriptor,
1853 Optional<std::string&> reasonIfUnsupported) const
1854{
Jan Eilers8eb25602020-03-09 12:13:48 +00001855 IgnoreUnused(descriptor);
nikraj01248683f2019-05-29 16:46:50 +01001856 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001857 std::array<DataType,7> supportedTypes =
nikraj01248683f2019-05-29 16:46:50 +01001858 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001859 DataType::BFloat16,
1860 DataType::Float32,
1861 DataType::Float16,
1862 DataType::QSymmS8,
1863 DataType::QAsymmS8,
1864 DataType::QAsymmU8,
1865 DataType::QSymmS16
nikraj01248683f2019-05-29 16:46:50 +01001866 };
1867
1868 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001869 "Reference Softmax: output type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001870
1871 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001872 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001873
1874 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001875 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001876
1877 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001878}
1879
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001880bool RefLayerSupport::IsSpaceToBatchNdSupported(const TensorInfo& input,
1881 const TensorInfo& output,
1882 const SpaceToBatchNdDescriptor& descriptor,
1883 Optional<std::string&> reasonIfUnsupported) const
1884{
Jan Eilers8eb25602020-03-09 12:13:48 +00001885 IgnoreUnused(descriptor);
nikraj01120522a2019-05-31 11:33:07 +01001886 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001887 std::array<DataType,6> supportedTypes =
nikraj01120522a2019-05-31 11:33:07 +01001888 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001889 DataType::BFloat16,
1890 DataType::Float32,
1891 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001892 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001893 DataType::QAsymmU8,
1894 DataType::QSymmS16
nikraj01120522a2019-05-31 11:33:07 +01001895 };
1896
1897 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1898 "Reference SpaceToBatchNd: input type not supported");
1899
1900 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1901 "Reference SpaceToBatchNd: output type not supported");
1902
1903 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1904 "Reference SpaceToBatchNd: input and output types are mismatched");
1905
1906 return supported;
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001907}
1908
Keith Davisa57eccb2019-06-14 17:33:22 +01001909bool RefLayerSupport::IsSpaceToDepthSupported(const TensorInfo& input,
Keith Davis51910332019-06-26 15:28:43 +01001910 const TensorInfo& output,
1911 const SpaceToDepthDescriptor& descriptor,
1912 Optional<std::string&> reasonIfUnsupported) const
Keith Davisa57eccb2019-06-14 17:33:22 +01001913{
1914
Jan Eilers8eb25602020-03-09 12:13:48 +00001915 IgnoreUnused(descriptor);
Keith Davisa57eccb2019-06-14 17:33:22 +01001916 bool supported = true;
1917
Sadik Armagan303980c2020-04-17 12:45:14 +01001918 std::array<DataType,6> supportedTypes =
Keith Davisa57eccb2019-06-14 17:33:22 +01001919 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001920 DataType::BFloat16,
Keith Davisa57eccb2019-06-14 17:33:22 +01001921 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001922 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001923 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001924 DataType::QAsymmU8,
1925 DataType::QSymmS16
Keith Davisa57eccb2019-06-14 17:33:22 +01001926 };
1927
1928 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1929 "Reference SpaceToDepth: input type not supported");
1930
1931 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1932 "Reference SpaceToDepth: output type not supported");
1933
1934 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1935 "Reference SpaceToDepth: input and output types are mismatched");
1936
1937 return supported;
1938}
1939
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001940bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1941 const ViewsDescriptor& descriptor,
1942 Optional<std::string&> reasonIfUnsupported) const
1943{
Jan Eilers8eb25602020-03-09 12:13:48 +00001944 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001945 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001946 std::array<DataType,6> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001947 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001948 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001949 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001950 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001951 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001952 DataType::QAsymmU8,
1953 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001954 };
1955
1956 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1957 "Reference splitter: input type not supported");
1958
1959 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001960}
1961
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001962bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1963 const std::vector<std::reference_wrapper<TensorInfo>>& outputs,
1964 const ViewsDescriptor& descriptor,
1965 Optional<std::string&> reasonIfUnsupported) const
1966{
Jan Eilers8eb25602020-03-09 12:13:48 +00001967 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001968 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001969 std::array<DataType,6> 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,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001973 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001974 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001975 DataType::QAsymmU8,
1976 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001977 };
1978
1979 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1980 "Reference splitter: output type not supported");
Derek Lambertieac4adb2020-08-25 13:05:59 +01001981 for (const TensorInfo& output : outputs)
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001982 {
1983 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1984 "Reference splitter: input type not supported");
1985
1986 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1987 "Reference splitter: input and output types mismatched.");
1988 }
1989
1990 return supported;
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001991}
1992
Matthew Jackson81e601c2019-07-11 12:07:09 +01001993bool RefLayerSupport::IsStackSupported(const std::vector<const TensorInfo*>& inputs,
1994 const TensorInfo& output,
1995 const StackDescriptor& descriptor,
1996 Optional<std::string&> reasonIfUnsupported) const
1997{
Jan Eilers8eb25602020-03-09 12:13:48 +00001998 IgnoreUnused(descriptor);
Matthew Jackson81e601c2019-07-11 12:07:09 +01001999
2000 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01002001 std::array<DataType,6> supportedTypes =
Matthew Jackson81e601c2019-07-11 12:07:09 +01002002 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002003 DataType::BFloat16,
Matthew Jackson81e601c2019-07-11 12:07:09 +01002004 DataType::Float32,
Matthew Jacksone69c3992019-09-09 14:31:21 +01002005 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002006 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002007 DataType::QAsymmU8,
2008 DataType::QSymmS16
Matthew Jackson81e601c2019-07-11 12:07:09 +01002009 };
2010
2011 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2012 "Reference stack: output type not supported");
2013 for (const TensorInfo* input : inputs)
2014 {
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +01002015 ARMNN_ASSERT(input != nullptr);
Matthew Jackson81e601c2019-07-11 12:07:09 +01002016 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
2017 "Reference stack: input type not supported");
2018
2019 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
2020 "Reference stack: input and output types mismatched.");
2021 }
2022
2023 return supported;
2024}
2025
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00002026bool RefLayerSupport::IsStridedSliceSupported(const TensorInfo& input,
2027 const TensorInfo& output,
2028 const StridedSliceDescriptor& descriptor,
2029 Optional<std::string&> reasonIfUnsupported) const
2030{
Jan Eilers8eb25602020-03-09 12:13:48 +00002031 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01002032 bool supported = true;
2033
Sadik Armagan303980c2020-04-17 12:45:14 +01002034 std::array<DataType,5> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01002035 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002036 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01002037 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01002038 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002039 DataType::QAsymmU8,
2040 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01002041 };
2042
2043 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2044 "Reference StridedSlice: input type not supported");
2045
2046 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2047 "Reference StridedSlice: output type not supported");
2048
2049 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2050 "Reference StridedSlice: input and output types are mismatched");
2051
2052 return supported;
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00002053}
2054
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01002055bool RefLayerSupport::IsSubtractionSupported(const TensorInfo& input0,
2056 const TensorInfo& input1,
2057 const TensorInfo& output,
2058 Optional<std::string&> reasonIfUnsupported) const
2059{
Sadik Armagan2999a022019-04-09 14:20:12 +01002060 bool supported = true;
2061
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01002062 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002063 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01002064 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01002065 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002066 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002067 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01002068 DataType::QSymmS16,
2069 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01002070 };
2071
2072 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
2073 "Reference subtraction: input 0 is not a supported type.");
2074
2075 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
2076 "Reference subtraction: input 1 is not a supported type.");
2077
2078 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2079 "Reference subtraction: output is not a supported type.");
2080
2081 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
2082 "Reference subtraction: input 0 and Input 1 types are mismatched");
2083
2084 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
2085 "Reference subtraction: input and output types are mismatched");
2086
2087 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
2088 "Reference subtraction: shapes are not suitable for implicit broadcast.");
2089
2090 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01002091}
2092
Matteo Martincighab9e5252019-06-13 17:27:46 +01002093bool RefLayerSupport::IsPreluSupported(const TensorInfo& input,
2094 const TensorInfo& alpha,
2095 const TensorInfo& output,
2096 Optional<std::string&> reasonIfUnsupported) const
2097{
2098 bool supported = true;
2099
Teresa Charlin3940d8b2020-05-29 16:47:23 +01002100 std::array<DataType, 6> supportedTypes
Matteo Martincighab9e5252019-06-13 17:27:46 +01002101 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002102 DataType::BFloat16,
Matteo Martincighab9e5252019-06-13 17:27:46 +01002103 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01002104 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002105 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002106 DataType::QAsymmU8,
Teresa Charlin3940d8b2020-05-29 16:47:23 +01002107 DataType::QSymmS16
Matteo Martincighab9e5252019-06-13 17:27:46 +01002108 };
2109
2110 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2111 "PReLU: input is not a supported type.");
2112
2113 supported &= CheckSupportRule(TypeAnyOf(alpha, supportedTypes), reasonIfUnsupported,
2114 "PReLU: alpha is not a supported type.");
2115
2116 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2117 "PReLU: output is not a supported type.");
2118
2119 supported &= CheckSupportRule(TypesAreEqual(input, alpha, output), reasonIfUnsupported,
2120 "PReLU: input, alpha and output types are mismatched");
2121
2122 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input, alpha, output), reasonIfUnsupported,
2123 "PReLU: shapes are not suitable for implicit broadcast");
2124
2125 return supported;
2126}
2127
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002128bool RefLayerSupport::IsTransposeConvolution2dSupported(const TensorInfo& input,
2129 const TensorInfo& output,
2130 const TransposeConvolution2dDescriptor& descriptor,
2131 const TensorInfo& weights,
2132 const Optional<TensorInfo>& biases,
2133 Optional<std::string&> reasonIfUnsupported) const
2134{
Jan Eilers8eb25602020-03-09 12:13:48 +00002135 IgnoreUnused(descriptor);
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002136 bool supported = true;
2137
Sadik Armagan303980c2020-04-17 12:45:14 +01002138 std::array<DataType,7> supportedTypes =
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002139 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002140 DataType::BFloat16,
2141 DataType::Float32,
2142 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002143 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002144 DataType::QAsymmU8,
Sadik Armagan303980c2020-04-17 12:45:14 +01002145 DataType::QSymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002146 DataType::QSymmS16
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002147 };
2148
2149 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2150 "Reference TransposeConvolution2d: input is not a supported type.");
2151
2152 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2153 "Reference TransposeConvolution2d: output is not a supported type.");
2154
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002155 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2156 "Reference TransposeConvolution2d: input and output types mismatched.");
2157
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002158
2159 const DataType inputType = input.GetDataType();
Sadik Armagan303980c2020-04-17 12:45:14 +01002160 if (IsQuantized8BitType(inputType))
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002161 {
Derek Lambertid466a542020-01-22 15:37:29 +00002162 ARMNN_NO_DEPRECATE_WARN_BEGIN
Sadik Armagan303980c2020-04-17 12:45:14 +01002163 std::array<DataType, 4> supportedWeightTypes =
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002164 {
Sadik Armagan303980c2020-04-17 12:45:14 +01002165 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002166 DataType::QAsymmU8,
Derek Lambertid466a542020-01-22 15:37:29 +00002167 DataType::QSymmS8,
2168 DataType::QuantizedSymm8PerAxis //Deprecated
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002169 };
Derek Lambertid466a542020-01-22 15:37:29 +00002170 ARMNN_NO_DEPRECATE_WARN_END
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002171
2172 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
2173 "Reference TransposeConvolution2d: weights type not supported for "
2174 "quantized input.");
2175 }
2176 else
2177 {
2178 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
2179 "Reference TransposeConvolution2d: weights is not a supported type.");
2180
2181 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
2182 "Reference TransposeConvolution2d: input and weights types mismatched.");
2183 }
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002184
2185 if (biases.has_value())
2186 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002187 std::array<DataType,4> biasesSupportedTypes =
Aron Virginas-Tar651aafe2019-08-05 11:52:05 +01002188 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002189 DataType::BFloat16,
2190 DataType::Float32,
2191 DataType::Float16,
2192 DataType::Signed32
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002193 };
2194 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
2195 "Reference TransposeConvolution2d: biases is not a supported type.");
2196 }
2197
2198 return supported;
2199}
2200
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002201bool RefLayerSupport::IsTransposeSupported(const TensorInfo& input,
2202 const TensorInfo& output,
2203 const TransposeDescriptor& descriptor,
2204 Optional<std::string&> reasonIfUnsupported) const
2205{
Jan Eilers8eb25602020-03-09 12:13:48 +00002206 IgnoreUnused(descriptor);
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002207 bool supported = true;
2208
2209 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01002210 std::array<DataType, 6> supportedTypes =
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002211 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002212 DataType::BFloat16,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002213 DataType::Float32,
2214 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002215 DataType::QAsymmS8,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002216 DataType::QAsymmU8,
2217 DataType::QSymmS16
2218 };
2219
2220 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2221 "Reference transpose: input is not a supported type.");
2222
2223 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2224 "Reference transpose: output is not a supported type.");
2225
2226 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2227 "Reference transpose: input and output types are mismatched.");
2228
2229 return supported;
2230}
2231
arovir011c7c81b2018-10-08 11:34:28 +01002232} // namespace armnn