blob: 2e0a8f2faab88a662500421422cf189b881e1c93 [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
Mike Kelly1f140f72021-04-06 12:25:55 +0100182 std::array<DataType, 8> supportedInputTypes =
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,
Mike Kelly1f140f72021-04-06 12:25:55 +0100190 DataType::Signed32,
191 DataType::Signed64
192 };
193
194 std::array<DataType,2> supportedOutputTypes = {
195 DataType::Signed32,
196 DataType::Signed64
Nikhil Raj68c2c902019-09-19 11:21:11 +0100197 };
198
199 bool supported = true;
200
Mike Kelly1f140f72021-04-06 12:25:55 +0100201 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
Nikhil Raj68c2c902019-09-19 11:21:11 +0100202 "Reference ArgMinMax: input is not a supported type.");
Mike Kelly1f140f72021-04-06 12:25:55 +0100203 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
Nikhil Raj68c2c902019-09-19 11:21:11 +0100204 "Reference ArgMinMax: output type not supported");
205
206 return supported;
207}
208
arovir011c7c81b2018-10-08 11:34:28 +0100209bool RefLayerSupport::IsBatchNormalizationSupported(const TensorInfo& input,
210 const TensorInfo& output,
211 const TensorInfo& mean,
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100212 const TensorInfo& variance,
arovir011c7c81b2018-10-08 11:34:28 +0100213 const TensorInfo& beta,
214 const TensorInfo& gamma,
215 const BatchNormalizationDescriptor& descriptor,
216 Optional<std::string&> reasonIfUnsupported) const
217{
Jan Eilers8eb25602020-03-09 12:13:48 +0000218 IgnoreUnused(descriptor);
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100219
Sadik Armagan303980c2020-04-17 12:45:14 +0100220 std::array<DataType, 6> supportedTypes =
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100221 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000222 DataType::BFloat16,
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100223 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100224 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100225 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000226 DataType::QAsymmU8,
227 DataType::QSymmS16
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100228 };
229
230 bool supported = true;
231
232 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
233 "Reference batch normalization: input is not a supported type.");
234
235 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
236 "Reference batch normalization: output is not a supported type.");
237
238 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
239 "Reference batch normalization: input and output types are mismatched");
240
241 supported &= CheckSupportRule(TypeAnyOf(mean, supportedTypes), reasonIfUnsupported,
242 "Reference batch normalization: mean is not a supported type.");
243
244 supported &= CheckSupportRule(TypeAnyOf(variance, supportedTypes), reasonIfUnsupported,
245 "Reference batch normalization: variance is not a supported type.");
246
247 supported &= CheckSupportRule(TypeAnyOf(beta, supportedTypes), reasonIfUnsupported,
248 "Reference batch normalization: beta is not a supported type.");
249
250 supported &= CheckSupportRule(TypeAnyOf(gamma, supportedTypes), reasonIfUnsupported,
251 "Reference batch normalization: gamma is not a supported type.");
252
253 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100254}
255
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000256bool RefLayerSupport::IsBatchToSpaceNdSupported(const TensorInfo& input,
257 const TensorInfo& output,
258 const BatchToSpaceNdDescriptor& descriptor,
259 Optional<std::string&> reasonIfUnsupported) const
260{
Jan Eilers8eb25602020-03-09 12:13:48 +0000261 IgnoreUnused(descriptor);
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100262
263 bool supported = true;
264
265 std::string batchToSpaceNdLayerStr = "batchToSpaceNd";
266 std::string inputTensorStr = "input";
267 std::string outputTensorStr = "output";
268
269 // Define supported types.
Sadik Armagan303980c2020-04-17 12:45:14 +0100270 std::array<DataType,6> supportedTypes =
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100271 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000272 DataType::BFloat16,
273 DataType::Float32,
274 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100275 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000276 DataType::QAsymmU8,
277 DataType::QSymmS16
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100278 };
279
280 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
281 "Reference BatchToSpaceNd: input type not supported.");
282
283 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
284 "Reference BatchToSpaceNd: output type not supported.");
285
286 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
287 "Reference BatchToSpaceNd: input and output types mismatched.");
288
289 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 4),
290 reasonIfUnsupported,
291 CreateIncorrectDimensionsErrorMsg(4,
292 output.GetNumDimensions(),
293 batchToSpaceNdLayerStr,
294 outputTensorStr).data());
295
296 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(input, 4),
297 reasonIfUnsupported,
298 CreateIncorrectDimensionsErrorMsg(4,
299 input.GetNumDimensions(),
300 batchToSpaceNdLayerStr,
301 inputTensorStr).data());
302
303 return supported;
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000304}
305
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100306bool RefLayerSupport::IsComparisonSupported(const TensorInfo& input0,
307 const TensorInfo& input1,
308 const TensorInfo& output,
309 const ComparisonDescriptor& descriptor,
310 Optional<std::string&> reasonIfUnsupported) const
311{
Jan Eilers8eb25602020-03-09 12:13:48 +0000312 IgnoreUnused(descriptor);
Sadik Armagan303980c2020-04-17 12:45:14 +0100313 std::array<DataType, 8> supportedInputTypes =
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100314 {
Sadik Armaganb60dd242020-03-19 13:53:16 +0000315 DataType::Boolean,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000316 DataType::BFloat16,
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100317 DataType::Float32,
318 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100319 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000320 DataType::QAsymmU8,
Sadik Armaganb60dd242020-03-19 13:53:16 +0000321 DataType::QSymmS16,
322 DataType::Signed32
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100323 };
324
325 bool supported = true;
326 supported &= CheckSupportRule(TypeAnyOf(input0, supportedInputTypes), reasonIfUnsupported,
327 "Reference comparison: input 0 is not a supported type");
328
329 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
330 "Reference comparison: input 0 and Input 1 types are mismatched");
331
332 supported &= CheckSupportRule(TypeIs(output, DataType::Boolean), reasonIfUnsupported,
333 "Reference comparison: output is not of type Boolean");
334
335 return supported;
336}
337
Jim Flynn906f9462019-05-10 13:55:21 +0100338bool RefLayerSupport::IsConcatSupported(const std::vector<const TensorInfo*> inputs,
339 const TensorInfo& output,
Jim Flynne242f2d2019-05-22 14:24:13 +0100340 const ConcatDescriptor& descriptor,
Jim Flynn906f9462019-05-10 13:55:21 +0100341 Optional<std::string&> reasonIfUnsupported) const
342{
Jan Eilers8eb25602020-03-09 12:13:48 +0000343 IgnoreUnused(descriptor);
Jim Flynne242f2d2019-05-22 14:24:13 +0100344
345 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000346 std::array<DataType,6> supportedTypes =
Jim Flynne242f2d2019-05-22 14:24:13 +0100347 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000348 DataType::BFloat16,
349 DataType::Float32,
350 DataType::Float16,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000351 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100352 DataType::QAsymmU8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000353 DataType::QSymmS16
Jim Flynne242f2d2019-05-22 14:24:13 +0100354 };
355
356 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
357 "Reference concatenation: output type not supported");
358 for (const TensorInfo* input : inputs)
359 {
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100360 ARMNN_ASSERT(input != nullptr);
Jim Flynne242f2d2019-05-22 14:24:13 +0100361 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
362 "Reference concatenation: input type not supported");
363
364 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
365 "Reference concatenation: input and output types mismatched.");
366 }
367
368 return supported;
Jim Flynn906f9462019-05-10 13:55:21 +0100369}
370
arovir011c7c81b2018-10-08 11:34:28 +0100371bool RefLayerSupport::IsConstantSupported(const TensorInfo& output,
372 Optional<std::string&> reasonIfUnsupported) const
373{
Teresa Charlin6fa8ce62020-05-25 16:16:44 +0100374 std::array<DataType,8> supportedTypes =
Jim Flynne242f2d2019-05-22 14:24:13 +0100375 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000376 DataType::BFloat16,
Teresa Charlin6fa8ce62020-05-25 16:16:44 +0100377 DataType::Float16,
Nina Drozd58ef2c62019-05-16 12:09:18 +0100378 DataType::Float32,
Keith Davis67e6c542020-02-19 10:08:33 +0000379 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100380 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +0000381 DataType::QSymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100382 DataType::QSymmS16,
383 DataType::Signed32
Nina Drozd58ef2c62019-05-16 12:09:18 +0100384 };
385
386 return CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
387 "Reference constant: output is not a supported type.");
arovir011c7c81b2018-10-08 11:34:28 +0100388}
389
Narumol Prangnawarat7ddbbae2020-03-13 10:26:05 +0000390bool RefLayerSupport::IsConvertBf16ToFp32Supported(const TensorInfo& input,
391 const TensorInfo& output,
392 Optional<std::string&> reasonIfUnsupported) const
393{
394 bool supported = true;
395
396 supported &= CheckSupportRule(TypeIs(input, DataType::BFloat16), reasonIfUnsupported,
397 "Reference for ConvertBf16ToFp32 layer: input type not supported");
398
399 supported &= CheckSupportRule(TypeIs(output, DataType::Float32), reasonIfUnsupported,
400 "Reference for ConvertBf16ToFp32 layer: output type not supported");
401
402 return supported;
403}
404
arovir011c7c81b2018-10-08 11:34:28 +0100405bool RefLayerSupport::IsConvertFp16ToFp32Supported(const TensorInfo& input,
406 const TensorInfo& output,
407 Optional<std::string&> reasonIfUnsupported) const
408{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100409 return (IsSupportedForDataTypeGeneric(reasonIfUnsupported,
410 input.GetDataType(),
411 &TrueFunc<>,
412 &FalseInputFuncF32<>,
narpra01db2b1602019-01-23 15:23:11 +0000413 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000414 &FalseFuncI32<>,
415 &FalseFuncU8<>) &&
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100416 IsSupportedForDataTypeGeneric(reasonIfUnsupported,
417 output.GetDataType(),
418 &FalseOutputFuncF16<>,
419 &TrueFunc<>,
narpra01db2b1602019-01-23 15:23:11 +0000420 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000421 &FalseFuncI32<>,
422 &FalseFuncU8<>));
arovir011c7c81b2018-10-08 11:34:28 +0100423}
424
Narumol Prangnawaratea54a012020-03-16 16:36:10 +0000425bool RefLayerSupport::IsConvertFp32ToBf16Supported(const TensorInfo& input,
426 const TensorInfo& output,
427 Optional<std::string&> reasonIfUnsupported) const
428{
429 bool supported = true;
430
431 supported &= CheckSupportRule(TypeIs(input, DataType::Float32), reasonIfUnsupported,
432 "Reference for ConvertFp32ToBf16 layer: input type not supported");
433
434 supported &= CheckSupportRule(TypeIs(output, DataType::BFloat16), reasonIfUnsupported,
435 "Reference for ConvertFp32ToBf16 layer: output type not supported");
436
437 return supported;
438}
439
arovir011c7c81b2018-10-08 11:34:28 +0100440bool RefLayerSupport::IsConvertFp32ToFp16Supported(const TensorInfo& input,
441 const TensorInfo& output,
442 Optional<std::string&> reasonIfUnsupported) const
443{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100444 return (IsSupportedForDataTypeGeneric(reasonIfUnsupported,
445 input.GetDataType(),
446 &FalseInputFuncF16<>,
447 &TrueFunc<>,
narpra01db2b1602019-01-23 15:23:11 +0000448 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000449 &FalseFuncI32<>,
450 &FalseFuncU8<>) &&
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100451 IsSupportedForDataTypeGeneric(reasonIfUnsupported,
452 output.GetDataType(),
453 &TrueFunc<>,
454 &FalseOutputFuncF32<>,
narpra01db2b1602019-01-23 15:23:11 +0000455 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000456 &FalseFuncI32<>,
457 &FalseFuncU8<>));
arovir011c7c81b2018-10-08 11:34:28 +0100458}
459
460bool RefLayerSupport::IsConvolution2dSupported(const TensorInfo& input,
461 const TensorInfo& output,
462 const Convolution2dDescriptor& descriptor,
463 const TensorInfo& weights,
464 const Optional<TensorInfo>& biases,
465 Optional<std::string&> reasonIfUnsupported) const
466{
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100467 bool supported = true;
468
469 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000470 std::array<DataType,7> supportedTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000471 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000472 DataType::BFloat16,
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000473 DataType::Float32,
474 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000475 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100476 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +0000477 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000478 DataType::QSymmS16
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100479 };
480
481 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000482 "Reference Convolution2d: input is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100483
484 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000485 "Reference Convolution2d: output is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100486
Narumol Prangnawarat57ef0082020-03-26 09:20:43 +0000487 // For Convolution2d, we allow to have BFloat16 input with Float32 output for optimization.
488 if (input.GetDataType() == DataType::BFloat16)
489 {
490 if (output.GetDataType() != DataType::BFloat16 && output.GetDataType() != DataType::Float32)
491 {
492 reasonIfUnsupported.value() += "Output tensor type must be BFloat16 or Float32 for BFloat16 input.\n";
493 supported = false;
494 }
495 }
496 else
497 {
498 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000499 "Reference Convolution2d: input and output types mismatched.");
Narumol Prangnawarat57ef0082020-03-26 09:20:43 +0000500 }
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100501
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000502 const DataType inputType = input.GetDataType();
Keith Davis0c2eeac2020-02-11 16:51:50 +0000503 if (IsQuantized8BitType(inputType))
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000504 {
Derek Lambertid466a542020-01-22 15:37:29 +0000505 ARMNN_NO_DEPRECATE_WARN_BEGIN
Keith Davis0c2eeac2020-02-11 16:51:50 +0000506 std::array<DataType, 4> supportedWeightTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000507 {
Sadik Armagan303980c2020-04-17 12:45:14 +0100508 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000509 DataType::QAsymmU8,
Derek Lambertid466a542020-01-22 15:37:29 +0000510 DataType::QSymmS8,
511 DataType::QuantizedSymm8PerAxis // deprecated
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000512 };
Derek Lambertid466a542020-01-22 15:37:29 +0000513 ARMNN_NO_DEPRECATE_WARN_END
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000514
515 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000516 "Reference Convolution2d: weights type not supported for quantized input.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000517 }
518 else
519 {
520 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000521 "Reference Convolution2d: weights is not a supported type.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000522
523 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000524 "Reference Convolution2d: input and weights types mismatched.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000525 }
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100526
527 if (biases.has_value())
528 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000529 std::array<DataType,4> biasesSupportedTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000530 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000531 DataType::BFloat16,
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000532 DataType::Float32,
533 DataType::Float16,
534 DataType::Signed32
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100535 };
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000536
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100537 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000538 "Reference Convolution2d: biases is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100539 }
Jan Eilers8eb25602020-03-09 12:13:48 +0000540 IgnoreUnused(descriptor);
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100541
542 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100543}
544
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000545bool RefLayerSupport::IsDebugSupported(const TensorInfo& input,
546 const TensorInfo& output,
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000547 Optional<std::string&> reasonIfUnsupported) const
548{
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100549 bool supported = true;
550
Narumol Prangnawarat403a1852020-03-12 14:24:13 +0000551 std::array<DataType, 8> supportedTypes =
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100552 {
Narumol Prangnawarat403a1852020-03-12 14:24:13 +0000553 DataType::BFloat16,
Aron Virginas-Tardb1a2832019-11-12 16:15:11 +0000554 DataType::Float16,
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100555 DataType::Float32,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000556 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100557 DataType::QAsymmU8,
Keith Davis5204aa82020-01-27 15:24:59 +0000558 DataType::QSymmS8,
Narumol Prangnawaratd2d917d2020-01-09 10:16:39 +0000559 DataType::QSymmS16,
560 DataType::Signed32
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100561 };
562
563 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000564 "Reference for Debug layer: input type not supported");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100565
566 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000567 "Reference for Debug layer: output type not supported");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100568
569 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000570 "Reference for Debug layer: input and output types are mismatched");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100571
572 return supported;
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000573}
574
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100575bool RefLayerSupport::IsDepthToSpaceSupported(const TensorInfo& input,
576 const TensorInfo& output,
577 const DepthToSpaceDescriptor& descriptor,
578 Optional<std::string&> reasonIfUnsupported) const
579{
Jan Eilers8eb25602020-03-09 12:13:48 +0000580 IgnoreUnused(descriptor);
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100581 bool supported = true;
582
Sadik Armagan303980c2020-04-17 12:45:14 +0100583 std::array<DataType,6> supportedTypes =
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100584 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000585 DataType::BFloat16,
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100586 DataType::Float32,
587 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100588 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000589 DataType::QAsymmU8,
590 DataType::QSymmS16
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100591 };
592
593 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
594 "Reference DepthToSpace: input type not supported");
595
596 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
597 "Reference DepthToSpace: output type not supported");
598
599 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
600 "Reference DepthToSpace: input and output types are mismatched");
601
602 return supported;
603}
604
arovir011c7c81b2018-10-08 11:34:28 +0100605bool RefLayerSupport::IsDepthwiseConvolutionSupported(const TensorInfo& input,
606 const TensorInfo& output,
607 const DepthwiseConvolution2dDescriptor& descriptor,
608 const TensorInfo& weights,
609 const Optional<TensorInfo>& biases,
610 Optional<std::string&> reasonIfUnsupported) const
611{
Sadik Armagan303980c2020-04-17 12:45:14 +0100612 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100613 bool supported = true;
614
615 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000616 std::array<DataType,7> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100617 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000618 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100619 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100620 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000621 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000622 DataType::QAsymmU8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100623 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000624 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100625 };
626
627 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
628 "Reference DepthwiseConvolution2d: input is not a supported type.");
629
630 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
631 "Reference DepthwiseConvolution2d: output is not a supported type.");
632
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100633 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
634 "Reference DepthwiseConvolution2d: input and output types mismatched.");
635
Teresa Charlind8df0262019-11-11 12:28:15 +0000636 const DataType inputType = input.GetDataType();
Keith Davis0c2eeac2020-02-11 16:51:50 +0000637 if (IsQuantized8BitType(inputType))
Teresa Charlind8df0262019-11-11 12:28:15 +0000638 {
Sadik Armagan303980c2020-04-17 12:45:14 +0100639 ARMNN_NO_DEPRECATE_WARN_BEGIN
640 std::array<DataType, 4> supportedWeightTypes =
641 {
642 DataType::QAsymmS8,
643 DataType::QAsymmU8,
644 DataType::QSymmS8,
645 DataType::QuantizedSymm8PerAxis // deprecated
646 };
647 ARMNN_NO_DEPRECATE_WARN_END
Teresa Charlind8df0262019-11-11 12:28:15 +0000648
649 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
Sadik Armagan303980c2020-04-17 12:45:14 +0100650 "Reference DepthwiseConvolution2d: weights type not supported for "
651 "quantized input.");
Teresa Charlind8df0262019-11-11 12:28:15 +0000652 }
653 else
654 {
655 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
656 "Reference DepthwiseConvolution2d: weights is not a supported type.");
657
658 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
659 "Reference DepthwiseConvolution2d: input and weights types mismatched.");
660 }
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100661
662 if (biases.has_value())
663 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000664 std::array<DataType,4> biasesSupportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100665 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000666 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100667 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100668 DataType::Float16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100669 DataType::Signed32
670 };
671 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
672 "Reference DepthwiseConvolution2d: biases is not a supported type.");
673 }
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100674
675 return supported;
676
arovir011c7c81b2018-10-08 11:34:28 +0100677}
678
Nattapat Chaimanowong8a54ac02019-03-29 15:25:04 +0000679bool RefLayerSupport::IsDequantizeSupported(const TensorInfo& input,
680 const TensorInfo& output,
681 Optional<std::string&> reasonIfUnsupported) const
682{
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100683 bool supported = true;
684
Ryan OShea9add1202020-02-07 10:06:33 +0000685 std::array<DataType,4> supportedInputTypes = {
686 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000687 DataType::QAsymmU8,
Finn Williamsfd271062019-12-04 14:27:27 +0000688 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000689 DataType::QSymmS16
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100690 };
691
692 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000693 "Reference for Dequantize layer: input type not supported.");
694
695 supported &= CheckSupportRule( TypeNotPerAxisQuantized(input), reasonIfUnsupported,
696 "Reference for Dequantize layer: per-axis quantized input not support .");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100697
Derek Lambertid466a542020-01-22 15:37:29 +0000698 supported &= CheckSupportRule(TypeNotPerAxisQuantized(input), reasonIfUnsupported,
699 "Reference dequantize: per-axis quantized input not support .");
700
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000701 std::array<DataType,3> supportedOutputTypes = {
702 DataType::BFloat16,
Jan Eilersf7107932019-11-01 11:09:36 +0000703 DataType::Float32,
704 DataType::Float16
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100705 };
706
707 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000708 "Reference for Dequantize layer: output type not supported.");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100709
710 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000711 "Reference for Dequantize layer: input/output shapes have different num total "
712 "elements.");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100713
714 return supported;
Nattapat Chaimanowong8a54ac02019-03-29 15:25:04 +0000715}
716
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000717bool RefLayerSupport::IsDetectionPostProcessSupported(const TensorInfo& boxEncodings,
718 const TensorInfo& scores,
719 const TensorInfo& anchors,
720 const TensorInfo& detectionBoxes,
721 const TensorInfo& detectionClasses,
722 const TensorInfo& detectionScores,
723 const TensorInfo& numDetections,
724 const DetectionPostProcessDescriptor& descriptor,
725 Optional<std::string&> reasonIfUnsupported) const
Narumol Prangnawaratbc67cef2019-01-31 15:31:54 +0000726{
Jan Eilers8eb25602020-03-09 12:13:48 +0000727 IgnoreUnused(anchors, detectionBoxes, detectionClasses, detectionScores, numDetections, descriptor);
Derek Lamberti901ea112019-12-10 22:07:09 +0000728
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100729 bool supported = true;
730
Sadik Armaganaa41d5d2020-11-16 14:27:52 +0000731 std::array<DataType,6> supportedInputTypes =
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100732 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000733 DataType::BFloat16,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100734 DataType::Float32,
Sadik Armaganaa41d5d2020-11-16 14:27:52 +0000735 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100736 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000737 DataType::QAsymmU8,
738 DataType::QSymmS16
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100739 };
740
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000741 supported &= CheckSupportRule(TypeAnyOf(boxEncodings, supportedInputTypes), reasonIfUnsupported,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100742 "Reference DetectionPostProcess: input 0 is not a supported type.");
743
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000744 supported &= CheckSupportRule(TypeAnyOf(scores, supportedInputTypes), reasonIfUnsupported,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100745 "Reference DetectionPostProcess: input 1 is not a supported type.");
746
747 return supported;
Narumol Prangnawaratbc67cef2019-01-31 15:31:54 +0000748}
749
Pablo Tellof0bd6832019-04-26 17:58:13 +0100750bool RefLayerSupport::IsDilatedDepthwiseConvolutionSupported(const TensorInfo& input,
751 const TensorInfo& output,
752 const DepthwiseConvolution2dDescriptor& descriptor,
753 const TensorInfo& weights,
754 const Optional<TensorInfo>& biases,
755 Optional<std::string&> reasonIfUnsupported) const
756{
Aron Virginas-Taraece4ed2019-06-14 17:00:09 +0100757 return IsDepthwiseConvolutionSupported(input, output, descriptor, weights, biases, reasonIfUnsupported);
Pablo Tellof0bd6832019-04-26 17:58:13 +0100758}
759
Aron Virginas-Taraece4ed2019-06-14 17:00:09 +0100760bool RefLayerSupport::IsDivisionSupported(const TensorInfo& input0,
arovir011c7c81b2018-10-08 11:34:28 +0100761 const TensorInfo& input1,
762 const TensorInfo& output,
763 Optional<std::string&> reasonIfUnsupported) const
764{
Sadik Armagan2999a022019-04-09 14:20:12 +0100765 bool supported = true;
766
Teresa Charlinecb6b8e2020-05-22 18:08:23 +0100767 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000768 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +0100769 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100770 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100771 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000772 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +0100773 DataType::QSymmS16,
774 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +0100775 };
776
777 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
778 "Reference division: input 0 is not a supported type.");
779
780 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
781 "Reference division: input 1 is not a supported type.");
782
783 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
784 "Reference division: output is not a supported type.");
785
786 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
787 "Reference division: input 0 and Input 1 types are mismatched");
788
789 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
790 "Reference division: input and output types are mismatched");
791
792 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
793 "Reference division: shapes are not suitable for implicit broadcast.");
794
795 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100796}
797
josh minor4a3c6102020-01-06 16:40:46 -0600798bool RefLayerSupport::IsElementwiseUnarySupported(const TensorInfo& input,
799 const TensorInfo& output,
800 const ElementwiseUnaryDescriptor& descriptor,
801 Optional<std::string&> reasonIfUnsupported) const
802{
Jan Eilers8eb25602020-03-09 12:13:48 +0000803 IgnoreUnused(descriptor);
josh minor4a3c6102020-01-06 16:40:46 -0600804
Sadik Armagan303980c2020-04-17 12:45:14 +0100805 std::array<DataType, 7> supportedTypes =
josh minor4a3c6102020-01-06 16:40:46 -0600806 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000807 DataType::BFloat16,
josh minor4a3c6102020-01-06 16:40:46 -0600808 DataType::Float32,
809 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +0100810 DataType::QAsymmS8,
josh minor4a3c6102020-01-06 16:40:46 -0600811 DataType::QAsymmU8,
Sadik Armaganac472102020-03-24 09:54:36 +0000812 DataType::QSymmS16,
813 DataType::Signed32
josh minor4a3c6102020-01-06 16:40:46 -0600814 };
815
Narumol Prangnawarat0c95f4c2020-11-18 16:52:07 +0000816 std::array<DataType, 1> logicalSupportedTypes =
817 {
818 DataType::Boolean
819 };
820
josh minor4a3c6102020-01-06 16:40:46 -0600821 bool supported = true;
822
Narumol Prangnawarat0c95f4c2020-11-18 16:52:07 +0000823 if (descriptor.m_Operation == UnaryOperation::LogicalNot)
824 {
825 supported &= CheckSupportRule(TypeAnyOf(input, logicalSupportedTypes), reasonIfUnsupported,
826 "Reference elementwise unary: input type not supported");
josh minor4a3c6102020-01-06 16:40:46 -0600827
Narumol Prangnawarat0c95f4c2020-11-18 16:52:07 +0000828 supported &= CheckSupportRule(TypeAnyOf(output, logicalSupportedTypes), reasonIfUnsupported,
829 "Reference elementwise unary: output type not supported");
830 }
831 else
832 {
833 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
834 "Reference elementwise unary: input type not supported");
835
836 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
837 "Reference elementwise unary: output type not supported");
838 }
josh minor4a3c6102020-01-06 16:40:46 -0600839
840 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
841 "Reference elementwise unary: input and output types not matching");
842
843 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
844 "Reference elementwise unary: input and output shapes"
845 "have different number of total elements");
846
847 return supported;
848}
849
FrancisMurtagh30cdfca2018-12-18 12:57:35 +0000850bool RefLayerSupport::IsEqualSupported(const TensorInfo& input0,
851 const TensorInfo& input1,
852 const TensorInfo& output,
853 Optional<std::string&> reasonIfUnsupported) const
854{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100855 return IsComparisonSupported(input0,
856 input1,
857 output,
858 ComparisonDescriptor(ComparisonOperation::Equal),
859 reasonIfUnsupported);
FrancisMurtagh30cdfca2018-12-18 12:57:35 +0000860}
861
arovir011c7c81b2018-10-08 11:34:28 +0100862bool RefLayerSupport::IsFakeQuantizationSupported(const TensorInfo& input,
863 const FakeQuantizationDescriptor& descriptor,
864 Optional<std::string&> reasonIfUnsupported) const
865{
Jan Eilers8eb25602020-03-09 12:13:48 +0000866 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100867 bool supported = true;
868
869 std::array<DataType,1> supportedTypes =
870 {
871 DataType::Float32
872 };
873
874 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
875 "Reference fake quantization: input type not supported.");
876
877 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100878}
879
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100880bool RefLayerSupport::IsFillSupported(const TensorInfo& input,
881 const TensorInfo& output,
882 const FillDescriptor& descriptor,
883 Optional<std::string&> reasonIfUnsupported) const
884{
885 IgnoreUnused(descriptor);
886 IgnoreUnused(output);
887
888 bool supported = true;
889
Sadik Armagana792a052020-06-23 16:22:23 +0100890 std::array<DataType,3> supportedTypes =
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100891 {
892 DataType::Float32,
Sadik Armagana792a052020-06-23 16:22:23 +0100893 DataType::Float16,
894 DataType::Signed32
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100895 };
896
Teresa Charlin4b10fef2020-07-29 09:36:41 +0100897 supported &= CheckSupportRule(TypeIs(input, DataType::Signed32), reasonIfUnsupported,
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100898 "Reference Fill: input type not supported.");
899
Teresa Charlin44088502020-07-27 11:27:19 +0100900 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
901 "Reference Fill: output type not supported.");
Ryan OSheaf4bfa6a2020-06-10 11:33:37 +0100902 return supported;
903}
904
arovir011c7c81b2018-10-08 11:34:28 +0100905bool RefLayerSupport::IsFloorSupported(const TensorInfo& input,
906 const TensorInfo& output,
907 Optional<std::string&> reasonIfUnsupported) const
908{
Jan Eilers8eb25602020-03-09 12:13:48 +0000909 IgnoreUnused(output);
James Conroy83735b12019-05-30 16:36:59 +0100910 bool supported = true;
911
Francis Murtaghe8ac1332020-07-30 18:03:40 +0100912 std::array<DataType,3> supportedTypes =
James Conroy83735b12019-05-30 16:36:59 +0100913 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000914 DataType::BFloat16,
James Conroyb40d7102019-06-04 12:32:09 +0100915 DataType::Float32,
Francis Murtaghe8ac1332020-07-30 18:03:40 +0100916 DataType::Float16
James Conroy83735b12019-05-30 16:36:59 +0100917 };
918
919 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
920 "Reference Floor: input type not supported.");
921
922 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
923 "Reference Floor: output type not supported.");
924
925 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100926}
927
928bool RefLayerSupport::IsFullyConnectedSupported(const TensorInfo& input,
929 const TensorInfo& output,
930 const TensorInfo& weights,
931 const TensorInfo& biases,
932 const FullyConnectedDescriptor& descriptor,
933 Optional<std::string&> reasonIfUnsupported) const
934{
Francis Murtagh46c09d02019-05-28 08:15:28 +0100935 bool supported = true;
936
937 // Define supported types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000938 std::array<DataType,6> supportedTypes =
Francis Murtagh46c09d02019-05-28 08:15:28 +0100939 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000940 DataType::BFloat16,
941 DataType::Float32,
942 DataType::Float16,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000943 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +0100944 DataType::QAsymmU8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000945 DataType::QSymmS16
Francis Murtagh46c09d02019-05-28 08:15:28 +0100946 };
947
948 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
949 "Reference Fully Connected: input type not supported.");
950
951 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
952 "Reference Fully Connected: output type not supported.");
953
Francis Murtagh46c09d02019-05-28 08:15:28 +0100954 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
955 "Reference Fully Connected: weights type not supported.");
956
Narumol Prangnawarat57ef0082020-03-26 09:20:43 +0000957 // For FullyConnected, we allow to have BFloat16 input with Float32 output for optimization.
958 if (input.GetDataType() == DataType::BFloat16)
959 {
960 if (output.GetDataType() != DataType::BFloat16 && output.GetDataType() != DataType::Float32)
961 {
962 reasonIfUnsupported.value() += "Output tensor type must be BFloat16 or Float32 for BFloat16 input.\n";
963 supported = false;
964 }
965 }
966 else
967 {
968 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
969 "Reference Fully Connected: input and output types mismatched.");
970 }
971
Jan Eilers1f45dc32020-06-15 11:43:03 +0100972 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
973 "Reference Fully Connected: weights is not a supported type.");
Francis Murtaghddb1d062020-03-10 13:51:45 +0000974
Jan Eilers1f45dc32020-06-15 11:43:03 +0100975 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
976 "Reference Fully Connected: input and weights types mismatched.");
Francis Murtagh46c09d02019-05-28 08:15:28 +0100977
978 if (descriptor.m_BiasEnabled)
979 {
980 // Defined supported types for bias
Sadik Armagandb73c982020-04-01 17:35:30 +0100981 std::array<DataType, 5>
Francis Murtagh46c09d02019-05-28 08:15:28 +0100982 supportedBiasTypes =
983 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +0000984 DataType::BFloat16,
Francis Murtagh46c09d02019-05-28 08:15:28 +0100985 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100986 DataType::Float16,
Sadik Armagandb73c982020-04-01 17:35:30 +0100987 DataType::Signed32,
988 DataType::QAsymmS8
Francis Murtagh46c09d02019-05-28 08:15:28 +0100989 };
990
991 supported &= CheckSupportRule(TypeAnyOf(biases, supportedBiasTypes), reasonIfUnsupported,
992 "Reference Fully Connected: bias type not supported.");
993
994 supported &= CheckSupportRule(BiasAndWeightsTypesMatch(biases, weights), reasonIfUnsupported,
995 "Reference Fully Connected: bias and weight types mismatch.");
996
997 supported &= CheckSupportRule(BiasAndWeightsTypesCompatible(weights, supportedBiasTypes), reasonIfUnsupported,
998 "Reference Fully Connected: bias type inferred from weights is incompatible.");
999
Narumol Prangnawarat366d7232020-04-29 12:58:17 +01001000 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(biases, 1U), reasonIfUnsupported,
1001 "Reference Fully Connected: bias must have 1 dimension.");
1002
Francis Murtagh46c09d02019-05-28 08:15:28 +01001003 }
1004
1005 return supported;
arovir011c7c81b2018-10-08 11:34:28 +01001006}
1007
narpra014951d842019-01-18 16:53:53 +00001008bool RefLayerSupport::IsGatherSupported(const armnn::TensorInfo& input0,
1009 const armnn::TensorInfo& input1,
1010 const armnn::TensorInfo& output,
Teresa Charlin52664732020-06-29 16:27:03 +01001011 const GatherDescriptor& descriptor,
narpra014951d842019-01-18 16:53:53 +00001012 armnn::Optional<std::string&> reasonIfUnsupported) const
1013{
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +01001014 bool supported = true;
Teresa Charlin3940d8b2020-05-29 16:47:23 +01001015 std::array<DataType,7> supportedTypes =
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +01001016 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001017 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001018 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001019 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001020 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001021 DataType::QAsymmU8,
Teresa Charlin3940d8b2020-05-29 16:47:23 +01001022 DataType::QSymmS16,
1023 DataType::Signed32
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +01001024 };
1025
Teresa Charlin52664732020-06-29 16:27:03 +01001026 if (descriptor.m_Axis != 0)
1027 {
1028 reasonIfUnsupported.value() += std::string("Reference Gather: axis not supported\n");
1029 supported &= false;
1030 }
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +01001031 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1032 "Reference Gather: input type not supported");
1033
1034 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1035 "Reference Gather: output type not supported");
1036
1037 supported &= CheckSupportRule(TypeIs(input1, DataType::Signed32), reasonIfUnsupported,
1038 "Reference Gather: indices (input1) type not supported");
1039
1040 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1041 "Reference Gather: input and output types not matching");
1042
1043 return supported;
narpra014951d842019-01-18 16:53:53 +00001044}
1045
FrancisMurtagh878f0232018-12-19 10:56:15 +00001046bool RefLayerSupport::IsGreaterSupported(const TensorInfo& input0,
1047 const TensorInfo& input1,
1048 const TensorInfo& output,
1049 Optional<std::string&> reasonIfUnsupported) const
1050{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +01001051 return IsComparisonSupported(input0,
1052 input1,
1053 output,
1054 ComparisonDescriptor(ComparisonOperation::Greater),
1055 reasonIfUnsupported);
FrancisMurtagh878f0232018-12-19 10:56:15 +00001056}
1057
Derek Lamberti901ea112019-12-10 22:07:09 +00001058bool RefLayerSupport::IsInputSupported(const TensorInfo& /*input*/,
1059 Optional<std::string&> /*reasonIfUnsupported*/) const
arovir011c7c81b2018-10-08 11:34:28 +01001060{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +01001061 return true;
arovir011c7c81b2018-10-08 11:34:28 +01001062}
1063
Kevin May09ca49c2019-10-09 12:37:34 +01001064bool RefLayerSupport::IsInstanceNormalizationSupported(const TensorInfo& input,
1065 const TensorInfo& output,
1066 const InstanceNormalizationDescriptor& descriptor,
1067 Optional<std::string&> reasonIfUnsupported) const
1068{
Jan Eilers8eb25602020-03-09 12:13:48 +00001069 IgnoreUnused(descriptor);
Kevin May09ca49c2019-10-09 12:37:34 +01001070 // Define supported types
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001071 std::array<DataType, 3> supportedTypes =
Kevin May09ca49c2019-10-09 12:37:34 +01001072 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001073 DataType::BFloat16,
Kevin May09ca49c2019-10-09 12:37:34 +01001074 DataType::Float32,
1075 DataType::Float16
1076 };
1077
1078 bool supported = true;
1079
1080 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1081 "Reference Instance Normalization: input type not supported.");
1082
1083 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1084 "Reference Instance Normalization: output type not supported.");
1085
1086 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1087 "Reference Instance Normalization: input and output types mismatched.");
1088
1089 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1090 "Reference Instance Normalization: input and output shapes have different "
1091 "num total elements.");
1092
1093 return supported;
1094}
1095
arovir011c7c81b2018-10-08 11:34:28 +01001096bool RefLayerSupport::IsL2NormalizationSupported(const TensorInfo& input,
1097 const TensorInfo& output,
1098 const L2NormalizationDescriptor& descriptor,
1099 Optional<std::string&> reasonIfUnsupported) const
1100{
Jan Eilers8eb25602020-03-09 12:13:48 +00001101 IgnoreUnused(descriptor);
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001102 // Define supported types
Sadik Armagan303980c2020-04-17 12:45:14 +01001103 std::array<DataType, 6> supportedTypes =
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001104 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001105 DataType::BFloat16,
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001106 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001107 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001108 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001109 DataType::QAsymmU8,
1110 DataType::QSymmS16
Ferran Balaguerd73d14f2019-06-10 10:29:54 +01001111 };
1112
1113 bool supported = true;
1114
1115 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1116 "Reference L2normalization: input type not supported.");
1117
1118 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1119 "Reference L2normalization: output type not supported.");
1120
1121 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1122 "Reference L2normalization: input and output types mismatched.");
1123
1124 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1125 "Reference L2normalization: input and output shapes have different "
1126 "num total elements.");
1127
1128 return supported;
arovir011c7c81b2018-10-08 11:34:28 +01001129}
1130
James Conroyaba90cd2020-11-06 16:28:18 +00001131bool RefLayerSupport::IsLogicalBinarySupported(const TensorInfo& input0,
1132 const TensorInfo& input1,
1133 const TensorInfo& output,
1134 const LogicalBinaryDescriptor& descriptor,
1135 Optional<std::string&> reasonIfUnsupported) const
1136{
1137 IgnoreUnused(descriptor);
1138
1139 std::array<DataType, 1> supportedTypes =
1140 {
1141 DataType::Boolean
1142 };
1143
1144 bool supported = true;
1145 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1146 "Reference LogicalBinary: input 0 type not supported");
1147 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1148 "Reference LogicalBinary: input 1 type not supported");
1149
1150 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1151 "Reference LogicalBinary: input and output types do not match");
1152
1153 return supported;
1154}
1155
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001156bool RefLayerSupport::IsLogSoftmaxSupported(const TensorInfo& input,
1157 const TensorInfo& output,
1158 const LogSoftmaxDescriptor& descriptor,
1159 Optional<std::string&> reasonIfUnsupported) const
1160{
Jan Eilers8eb25602020-03-09 12:13:48 +00001161 IgnoreUnused(descriptor);
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001162
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001163 std::array<DataType, 3> supportedTypes =
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001164 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001165 DataType::BFloat16,
1166 DataType::Float32,
1167 DataType::Float16
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001168 };
1169
1170 bool supported = true;
1171 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1172 "Reference LogSoftmax: input type not supported");
1173
1174 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1175 "Reference LogSoftmax: output type not supported");
1176
1177 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1178 "Reference LogSoftmax: input and output types do not match");
1179
1180 return supported;
1181}
1182
arovir011c7c81b2018-10-08 11:34:28 +01001183bool RefLayerSupport::IsLstmSupported(const TensorInfo& input,
1184 const TensorInfo& outputStateIn,
1185 const TensorInfo& cellStateIn,
1186 const TensorInfo& scratchBuffer,
1187 const TensorInfo& outputStateOut,
1188 const TensorInfo& cellStateOut,
1189 const TensorInfo& output,
1190 const LstmDescriptor& descriptor,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001191 const LstmInputParamsInfo& paramsInfo,
1192 Optional<std::string&> reasonIfUnsupported) const
arovir011c7c81b2018-10-08 11:34:28 +01001193{
Jan Eilers8eb25602020-03-09 12:13:48 +00001194 IgnoreUnused(descriptor);
1195 IgnoreUnused(paramsInfo);
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001196
1197 bool supported = true;
1198
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001199 std::array<DataType,3> supportedTypes = {
1200 DataType::BFloat16,
Conor Kennedyb9971c92019-05-07 07:14:23 +01001201 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001202 DataType::QSymmS16
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001203 };
1204
Jan Eilersd01a83c2019-07-03 18:20:40 +01001205 // check inputs and outputs
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001206 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1207 "Reference Lstm: input is not a supported type.");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001208 supported &= CheckSupportRule(TypesAreEqual(input, outputStateIn), reasonIfUnsupported,
1209 "Reference Lstm: input and outputStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001210 supported &= CheckSupportRule(TypesAreEqual(input, cellStateIn), reasonIfUnsupported,
1211 "Reference Lstm: input and cellStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001212 supported &= CheckSupportRule(TypesAreEqual(input, scratchBuffer), reasonIfUnsupported,
1213 "Reference Lstm: input and scratchBuffer types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001214 supported &= CheckSupportRule(TypesAreEqual(input, outputStateOut), reasonIfUnsupported,
1215 "Reference Lstm: input and outputStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001216 supported &= CheckSupportRule(TypesAreEqual(input, cellStateOut), reasonIfUnsupported,
1217 "Reference Lstm: input and cellStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001218 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1219 "Reference Lstm: input and output types are mismatched");
Jan Eilersd01a83c2019-07-03 18:20:40 +01001220 // check layer parameters
Francis Murtaghbb590b42019-08-14 09:51:36 +01001221 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001222 "Reference Lstm: input and InputToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001223 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001224 "Reference Lstm: input and InputToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001225 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001226 "Reference Lstm: input and InputToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001227 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001228 "Reference Lstm: input and RecurrentToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001229 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001230 "Reference Lstm: input and RecurrentToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001231 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001232 "Reference Lstm: input and RecurrentToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001233 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001234 "Reference Lstm: input and ForgetGateBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001235 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001236 "Reference Lstm: input and CellBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001237 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001238 "Reference Lstm: input and OutputGateBias types are mismatched");
1239 if (!descriptor.m_CifgEnabled)
1240 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001241 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToInputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001242 "Reference Lstm: input and InputToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001243 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001244 reasonIfUnsupported,
1245 "Reference Lstm: input and RecurrentToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001246 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001247 "Reference Lstm: input and InputGateBias types are mismatched");
1248 if (descriptor.m_PeepholeEnabled)
1249 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001250 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001251 reasonIfUnsupported,
1252 "Reference Lstm: input and CellToInputWeights types are mismatched");
1253 }
1254 }
1255 if (descriptor.m_PeepholeEnabled)
1256 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001257 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001258 "Reference Lstm: input and CellToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001259 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001260 "Reference Lstm: input and CellToOutputWeights types are mismatched");
1261 }
1262 if (descriptor.m_ProjectionEnabled)
1263 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001264 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001265 "Reference Lstm: input and mProjectionWeights types are mismatched");
1266 if (paramsInfo.m_ProjectionBias != nullptr)
1267 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001268 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001269 "Reference Lstm: input and ProjectionBias types are mismatched");
1270 }
1271 }
1272 if (descriptor.m_LayerNormEnabled)
1273 {
1274 if (!descriptor.m_CifgEnabled)
1275 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001276 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001277 reasonIfUnsupported,
1278 "Reference Lstm: input and InputLayerNormWeights types are mismatched");
1279 }
Francis Murtaghbb590b42019-08-14 09:51:36 +01001280 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001281 reasonIfUnsupported,
1282 "Reference Lstm: input and ForgetLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001283 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001284 reasonIfUnsupported,
1285 "Reference Lstm: input and CellLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001286 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001287 reasonIfUnsupported,
1288 "Reference Lstm: input and OutputLayerNormWeights types are mismatched");
1289 }
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001290
1291 return supported;
telsoa01c577f2c2018-08-31 09:22:23 +01001292}
1293
saoste012df12b32018-11-28 16:57:20 +00001294bool RefLayerSupport::IsMaximumSupported(const TensorInfo& input0,
1295 const TensorInfo& input1,
1296 const TensorInfo& output,
1297 Optional<std::string&> reasonIfUnsupported) const
1298{
Sadik Armagan2999a022019-04-09 14:20:12 +01001299 bool supported = true;
1300
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001301 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001302 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001303 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001304 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001305 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001306 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001307 DataType::QSymmS16,
1308 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01001309 };
1310
1311 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1312 "Reference maximum: input 0 is not a supported type.");
1313
1314 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1315 "Reference maximum: input 1 is not a supported type.");
1316
1317 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1318 "Reference maximum: output is not a supported type.");
1319
1320 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1321 "Reference maximum: input 0 and Input 1 types are mismatched");
1322
1323 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1324 "Reference maximum: input and output types are mismatched");
1325
1326 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1327 "Reference maximum: shapes are not suitable for implicit broadcast.");
1328
1329 return supported;
saoste012df12b32018-11-28 16:57:20 +00001330}
1331
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001332bool RefLayerSupport::IsMeanSupported(const TensorInfo& input,
1333 const TensorInfo& output,
1334 const MeanDescriptor& descriptor,
1335 Optional<std::string&> reasonIfUnsupported) const
narpra0132b90462018-09-13 11:07:48 +01001336{
James Conroy4d1ff582019-06-10 17:06:39 +01001337 bool supported = true;
1338 std::string meanLayerStr = "Mean";
1339 std::string outputTensorStr = "output";
1340
Sadik Armagan303980c2020-04-17 12:45:14 +01001341 std::array<DataType,6> supportedTypes =
James Conroy4d1ff582019-06-10 17:06:39 +01001342 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001343 DataType::BFloat16,
James Conroy4d1ff582019-06-10 17:06:39 +01001344 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001345 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001346 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001347 DataType::QAsymmU8,
1348 DataType::QSymmS16
James Conroy4d1ff582019-06-10 17:06:39 +01001349 };
1350
1351 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1352 "Reference Mean: input type not supported.");
1353
1354 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1355 "Reference Mean: input and output types are mismatched");
1356
1357 if (descriptor.m_KeepDims)
1358 {
1359 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, input.GetNumDimensions()),
1360 reasonIfUnsupported,
1361 CreateIncorrectDimensionsErrorMsg(input.GetNumDimensions(),
1362 output.GetNumDimensions(),
1363 meanLayerStr, outputTensorStr).data());
1364 }
1365 else if (descriptor.m_Axis.empty())
1366 {
1367 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1368 reasonIfUnsupported,
1369 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1370 meanLayerStr, outputTensorStr).data());
1371 }
1372 else
1373 {
Matthew Sloyan171214c2020-09-09 09:07:37 +01001374 auto outputDim = input.GetNumDimensions() - armnn::numeric_cast<unsigned int>(descriptor.m_Axis.size());
James Conroy4d1ff582019-06-10 17:06:39 +01001375
1376 if (outputDim > 0)
1377 {
1378 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, outputDim),
1379 reasonIfUnsupported,
1380 CreateIncorrectDimensionsErrorMsg(outputDim, output.GetNumDimensions(),
1381 meanLayerStr, outputTensorStr).data());
1382 }
1383 else
1384 {
1385 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1386 reasonIfUnsupported,
1387 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1388 meanLayerStr, outputTensorStr).data());
1389 }
1390 }
1391
1392 return supported;
narpra0132b90462018-09-13 11:07:48 +01001393}
1394
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001395bool RefLayerSupport::IsMergerSupported(const std::vector<const TensorInfo*> inputs,
Nikhil Raj8599a412018-11-19 14:51:07 +00001396 const TensorInfo& output,
Jim Flynne242f2d2019-05-22 14:24:13 +01001397 const MergerDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001398 Optional<std::string&> reasonIfUnsupported) const
1399{
Jim Flynne242f2d2019-05-22 14:24:13 +01001400 return IsConcatSupported(inputs, output, descriptor, reasonIfUnsupported);
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001401}
1402
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001403bool RefLayerSupport::IsMemCopySupported(const TensorInfo &input,
1404 const TensorInfo &output,
1405 Optional<std::string &> reasonIfUnsupported) const
1406{
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001407 bool supported = true;
1408
Sadik Armagan303980c2020-04-17 12:45:14 +01001409 std::array<DataType,7> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001410 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001411 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001412 DataType::Float32,
1413 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001414 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001415 DataType::QAsymmU8,
1416 DataType::QSymmS16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001417 DataType::Boolean
1418 };
1419
1420 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1421 "Reference MemCopy: input type not supported");
1422
1423 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1424 "Reference MemCopy: output type not supported");
1425
1426 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1427 "Reference MemCopy: input and output types are mismatched");
1428
1429 return supported;
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001430}
1431
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001432bool RefLayerSupport::IsMinimumSupported(const TensorInfo& input0,
1433 const TensorInfo& input1,
1434 const TensorInfo& output,
1435 Optional<std::string&> reasonIfUnsupported) const
1436{
Sadik Armagan2999a022019-04-09 14:20:12 +01001437 bool supported = true;
1438
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001439 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001440 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001441 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001442 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001443 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001444 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001445 DataType::QSymmS16,
1446 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01001447 };
1448
1449 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1450 "Reference minimum: input 0 is not a supported type.");
1451
1452 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1453 "Reference minimum: input 1 is not a supported type.");
1454
1455 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1456 "Reference minimum: output is not a supported type.");
1457
1458 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1459 "Reference minimum: input 0 and Input 1 types are mismatched");
1460
1461 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1462 "Reference minimum: input and output types are mismatched");
1463
1464 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1465 "Reference minimum: shapes are not suitable for implicit broadcast.");
1466
1467 return supported;
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001468}
1469
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001470bool RefLayerSupport::IsMultiplicationSupported(const TensorInfo& input0,
1471 const TensorInfo& input1,
1472 const TensorInfo& output,
1473 Optional<std::string&> reasonIfUnsupported) const
1474{
Sadik Armagan2999a022019-04-09 14:20:12 +01001475 bool supported = true;
1476
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001477 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001478 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01001479 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001480 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001481 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001482 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01001483 DataType::QSymmS16,
1484 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01001485 };
1486
1487 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1488 "Reference multiplication: input 0 is not a supported type.");
1489
1490 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1491 "Reference multiplication: input 1 is not a supported type.");
1492
1493 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1494 "Reference multiplication: output is not a supported type.");
1495
1496 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1497 "Reference multiplication: input 0 and Input 1 types are mismatched");
1498
1499 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1500 "Reference multiplication: input and output types are mismatched");
1501
1502 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1503 "Reference multiplication: shapes are not suitable for implicit broadcast.");
1504
1505 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001506}
1507
1508bool RefLayerSupport::IsNormalizationSupported(const TensorInfo& input,
1509 const TensorInfo& output,
1510 const NormalizationDescriptor& descriptor,
1511 Optional<std::string&> reasonIfUnsupported) const
Nina Drozd661dfa72018-10-02 11:14:17 +01001512{
Jan Eilers8eb25602020-03-09 12:13:48 +00001513 IgnoreUnused(descriptor);
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001514
1515 // Define supported types
Sadik Armagan303980c2020-04-17 12:45:14 +01001516 std::array<DataType, 6> supportedTypes =
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001517 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001518 DataType::BFloat16,
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001519 DataType::Float16,
1520 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001521 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001522 DataType::QAsymmU8,
1523 DataType::QSymmS16
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001524 };
1525
1526 bool supported = true;
1527
1528 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1529 "Reference normalization: input type not supported.");
1530
1531 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1532 "Reference normalization: output type not supported.");
1533
1534 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1535 "Reference normalization: input and output shapes have different "
1536 "num total elements.");
1537
1538 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001539}
1540
Derek Lamberti901ea112019-12-10 22:07:09 +00001541bool RefLayerSupport::IsOutputSupported(const TensorInfo& /*output*/,
1542 Optional<std::string&> /*reasonIfUnsupported*/) const
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001543{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +01001544 return true;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001545}
1546
1547bool RefLayerSupport::IsPadSupported(const TensorInfo& input,
1548 const TensorInfo& output,
1549 const PadDescriptor& descriptor,
1550 Optional<std::string&> reasonIfUnsupported) const
1551{
Jan Eilers8eb25602020-03-09 12:13:48 +00001552 IgnoreUnused(descriptor);
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001553 bool supported = true;
1554
1555 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01001556 std::array<DataType,6> supportedTypes =
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001557 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001558 DataType::BFloat16,
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001559 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001560 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001561 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001562 DataType::QAsymmU8,
1563 DataType::QSymmS16
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001564 };
1565
1566 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1567 "Reference pad: input is not a supported type.");
1568
1569 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1570 "Reference pad: output is not a supported type.");
1571
1572 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1573 "Reference pad: input and output types are mismatched.");
1574
1575 return supported;
Nina Drozd661dfa72018-10-02 11:14:17 +01001576}
1577
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001578bool RefLayerSupport::IsPermuteSupported(const TensorInfo& input,
1579 const TensorInfo& output,
1580 const PermuteDescriptor& descriptor,
1581 Optional<std::string&> reasonIfUnsupported) const
1582{
Jan Eilers8eb25602020-03-09 12:13:48 +00001583 IgnoreUnused(descriptor);
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001584 bool supported = true;
1585
1586 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01001587 std::array<DataType, 6> supportedTypes =
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001588 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001589 DataType::BFloat16,
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001590 DataType::Float32,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00001591 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001592 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001593 DataType::QAsymmU8,
1594 DataType::QSymmS16
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001595 };
1596
1597 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1598 "Reference permute: input is not a supported type.");
1599
1600 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1601 "Reference permute: output is not a supported type.");
1602
1603 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1604 "Reference permute: input and output types are mismatched.");
1605
1606 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001607}
1608
1609bool RefLayerSupport::IsPooling2dSupported(const TensorInfo& input,
1610 const TensorInfo& output,
1611 const Pooling2dDescriptor& descriptor,
1612 Optional<std::string&> reasonIfUnsupported) const
1613{
Jan Eilers8eb25602020-03-09 12:13:48 +00001614 IgnoreUnused(descriptor);
Teresa Charlina3b20472019-06-06 11:12:32 +01001615 bool supported = true;
1616
1617 // Define supported output and inputs types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001618 std::array<DataType,6> supportedTypes =
Teresa Charlina3b20472019-06-06 11:12:32 +01001619 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001620 DataType::BFloat16,
Teresa Charlina3b20472019-06-06 11:12:32 +01001621 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001622 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001623 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001624 DataType::QAsymmU8,
1625 DataType::QSymmS16
Teresa Charlina3b20472019-06-06 11:12:32 +01001626 };
1627
1628 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1629 "Reference poolind2d: input is not a supported type.");
1630
1631 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1632 "Reference poolind2d: output is not a supported type.");
1633
1634 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1635 "Reference poolind2d: input and output types are mismatched.");
1636
1637 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001638}
1639
James Conroy4f1f8992020-04-29 20:01:10 +01001640bool RefLayerSupport::IsQLstmSupported(const TensorInfo& input,
1641 const TensorInfo& previousOutputIn,
1642 const TensorInfo& previousCellStateIn,
1643 const TensorInfo& outputStateOut,
1644 const TensorInfo& cellStateOut,
1645 const TensorInfo& output,
1646 const QLstmDescriptor& descriptor,
1647 const LstmInputParamsInfo& paramsInfo,
1648 Optional<std::string&> reasonIfUnsupported) const
1649{
1650 IgnoreUnused(input);
1651 IgnoreUnused(previousOutputIn);
1652 IgnoreUnused(previousCellStateIn);
1653 IgnoreUnused(outputStateOut);
1654 IgnoreUnused(cellStateOut);
1655 IgnoreUnused(output);
1656 IgnoreUnused(descriptor);
1657 IgnoreUnused(paramsInfo);
1658
1659 IgnoreUnused(reasonIfUnsupported);
1660
1661 return true;
1662}
1663
Derek Lamberti5f400d62019-03-25 15:41:58 +00001664bool RefLayerSupport::IsQuantizeSupported(const TensorInfo& input,
1665 const TensorInfo& output,
1666 Optional<std::string&> reasonIfUnsupported) const
1667{
1668 bool supported = true;
1669
Finn Williamsfd271062019-12-04 14:27:27 +00001670 // Define supported input types.
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001671 std::array<DataType,7> supportedInputTypes = {
1672 DataType::BFloat16,
Keith Davis5e51cd82020-01-29 16:52:59 +00001673 DataType::Float32,
Keith Davis3d8bc972020-02-04 09:31:47 +00001674 DataType::Float16,
Ryan OShea9add1202020-02-07 10:06:33 +00001675 DataType::QAsymmS8,
Keith Davis5e51cd82020-01-29 16:52:59 +00001676 DataType::QAsymmU8,
1677 DataType::QSymmS8,
1678 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001679 };
1680
1681 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
1682 "Reference quantize: input type not supported.");
1683
1684 // Define supported output types.
Ryan OShea9add1202020-02-07 10:06:33 +00001685 std::array<DataType,4> supportedOutputTypes = {
Ryan OShea9add1202020-02-07 10:06:33 +00001686 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001687 DataType::QAsymmU8,
Finn Williamsfd271062019-12-04 14:27:27 +00001688 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001689 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001690 };
1691 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
1692 "Reference quantize: output type not supported.");
1693
1694 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1695 "Reference quantize: input and output shapes have different num total elements.");
1696
1697 return supported;
1698}
1699
Finn Williams2605b232020-06-10 15:53:46 +01001700bool RefLayerSupport::IsRankSupported(const TensorInfo& input,
1701 const TensorInfo& output,
1702 Optional<std::string&> reasonIfUnsupported) const
1703{
1704 IgnoreUnused(input);
1705 // Define supported output types.
1706 std::array<DataType,1> supportedOutputTypes =
1707 {
1708 DataType::Signed32,
1709 };
1710
1711 return CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
1712 "Reference rank: input type not supported.");
1713}
1714
Sadik Armagan0c3ea5b2021-02-03 09:29:30 +00001715bool RefLayerSupport::IsReduceSupported(const TensorInfo& input,
1716 const TensorInfo& output,
1717 const ReduceDescriptor& descriptor,
1718 Optional<std::string&> reasonIfUnsupported) const
1719{
1720 IgnoreUnused(descriptor);
1721 bool supported = true;
1722 std::array<DataType,7> supportedTypes =
1723 {
1724 DataType::BFloat16,
1725 DataType::Float32,
1726 DataType::Float16,
1727 DataType::QAsymmS8,
1728 DataType::QAsymmU8,
1729 DataType::QSymmS16,
1730 DataType::Signed32
1731 };
1732
1733 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1734 "Reference Reduce: input type not supported");
1735
1736 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1737 "Reference Reduce: output type not supported");
1738
1739 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1740 "Reference Reduce: input and output types not matching");
1741
1742 return supported;
1743}
1744
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001745bool RefLayerSupport::IsReshapeSupported(const TensorInfo& input,
Kevin Maya023c402019-12-12 17:28:05 +00001746 const TensorInfo& output,
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001747 const ReshapeDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001748 Optional<std::string&> reasonIfUnsupported) const
1749{
Jan Eilers8eb25602020-03-09 12:13:48 +00001750 IgnoreUnused(output);
1751 IgnoreUnused(descriptor);
Nina Drozd2f2778f2019-05-27 10:37:05 +01001752 // Define supported output types.
Narumol Prangnawarat0c95f4c2020-11-18 16:52:07 +00001753 std::array<DataType,8> supportedOutputTypes =
Nina Drozd2f2778f2019-05-27 10:37:05 +01001754 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001755 DataType::BFloat16,
Nina Drozd2f2778f2019-05-27 10:37:05 +01001756 DataType::Float32,
1757 DataType::Float16,
Narumol Prangnawarat0718ee92019-09-13 16:53:38 +01001758 DataType::Signed32,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001759 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001760 DataType::QAsymmU8,
Narumol Prangnawarat0c95f4c2020-11-18 16:52:07 +00001761 DataType::QSymmS16,
1762 DataType::Boolean
Nina Drozd2f2778f2019-05-27 10:37:05 +01001763 };
Keith Davis0c2eeac2020-02-11 16:51:50 +00001764
Nina Drozd2f2778f2019-05-27 10:37:05 +01001765 return CheckSupportRule(TypeAnyOf(input, supportedOutputTypes), reasonIfUnsupported,
1766 "Reference reshape: input type not supported.");
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001767}
1768
1769bool RefLayerSupport::IsResizeBilinearSupported(const TensorInfo& input,
Sadik Armaganc625f002018-12-17 11:32:16 +00001770 const TensorInfo& output,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001771 Optional<std::string&> reasonIfUnsupported) const
1772{
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001773 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001774 std::array<DataType,6> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001775 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001776 DataType::BFloat16,
Teresa Charlin970f43b2019-07-01 13:51:07 +01001777 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001778 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001779 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001780 DataType::QAsymmU8,
1781 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001782 };
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001783
1784 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1785 "Reference ResizeBilinear: input type not supported");
1786
1787 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1788 "Reference ResizeBilinear: output type not supported");
1789
1790 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1791 "Reference ResizeBilinear: input and output types not matching");
1792
1793 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001794}
1795
Teresa Charlin970f43b2019-07-01 13:51:07 +01001796bool RefLayerSupport::IsResizeSupported(const TensorInfo& input,
1797 const TensorInfo& output,
1798 const ResizeDescriptor& descriptor,
1799 Optional<std::string&> reasonIfUnsupported) const
1800{
Jan Eilers8eb25602020-03-09 12:13:48 +00001801 IgnoreUnused(descriptor);
Teresa Charlin970f43b2019-07-01 13:51:07 +01001802 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001803 std::array<DataType,6> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001804 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001805 DataType::BFloat16,
Teresa Charlin970f43b2019-07-01 13:51:07 +01001806 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001807 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001808 DataType::QAsymmS8,
Sadik Armagan303980c2020-04-17 12:45:14 +01001809 DataType::QAsymmU8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001810 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001811 };
1812
1813 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1814 "Reference Resize: input type not supported");
1815
1816 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1817 "Reference Resize: output type not supported");
1818
1819 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1820 "Reference Resize: input and output types not matching");
1821
1822 return supported;
1823}
1824
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001825bool RefLayerSupport::IsRsqrtSupported(const TensorInfo& input,
1826 const TensorInfo& output,
1827 Optional<std::string&> reasonIfUnsupported) const
1828{
josh minor4a3c6102020-01-06 16:40:46 -06001829 return IsElementwiseUnarySupported(input,
1830 output,
1831 ElementwiseUnaryDescriptor(UnaryOperation::Rsqrt),
1832 reasonIfUnsupported);
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001833}
1834
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001835bool RefLayerSupport::IsSliceSupported(const TensorInfo& input,
1836 const TensorInfo& output,
1837 const SliceDescriptor& descriptor,
1838 Optional<std::string&> reasonIfUnsupported) const
1839{
Jan Eilers8eb25602020-03-09 12:13:48 +00001840 IgnoreUnused(descriptor);
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001841 bool supported = true;
1842
Sadik Armagan303980c2020-04-17 12:45:14 +01001843 std::array<DataType, 5> supportedTypes =
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001844 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001845 DataType::BFloat16,
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001846 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01001847 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001848 DataType::QAsymmU8,
1849 DataType::QSymmS16
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001850 };
1851
1852 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1853 "Reference Slice: input type not supported");
1854
1855 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1856 "Reference Slice: output type not supported");
1857
1858 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1859 "Reference Slice: input and output types are mismatched");
1860
1861 return supported;
1862}
1863
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001864bool RefLayerSupport::IsSoftmaxSupported(const TensorInfo& input,
1865 const TensorInfo& output,
1866 const SoftmaxDescriptor& descriptor,
1867 Optional<std::string&> reasonIfUnsupported) const
1868{
Jan Eilers8eb25602020-03-09 12:13:48 +00001869 IgnoreUnused(descriptor);
nikraj01248683f2019-05-29 16:46:50 +01001870 bool supported = true;
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001871 std::array<DataType,7> supportedTypes =
nikraj01248683f2019-05-29 16:46:50 +01001872 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001873 DataType::BFloat16,
1874 DataType::Float32,
1875 DataType::Float16,
1876 DataType::QSymmS8,
1877 DataType::QAsymmS8,
1878 DataType::QAsymmU8,
1879 DataType::QSymmS16
nikraj01248683f2019-05-29 16:46:50 +01001880 };
1881
1882 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001883 "Reference Softmax: output type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001884
1885 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001886 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001887
1888 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001889 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001890
1891 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001892}
1893
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001894bool RefLayerSupport::IsSpaceToBatchNdSupported(const TensorInfo& input,
1895 const TensorInfo& output,
1896 const SpaceToBatchNdDescriptor& descriptor,
1897 Optional<std::string&> reasonIfUnsupported) const
1898{
Jan Eilers8eb25602020-03-09 12:13:48 +00001899 IgnoreUnused(descriptor);
nikraj01120522a2019-05-31 11:33:07 +01001900 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001901 std::array<DataType,6> supportedTypes =
nikraj01120522a2019-05-31 11:33:07 +01001902 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001903 DataType::BFloat16,
1904 DataType::Float32,
1905 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001906 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001907 DataType::QAsymmU8,
1908 DataType::QSymmS16
nikraj01120522a2019-05-31 11:33:07 +01001909 };
1910
1911 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1912 "Reference SpaceToBatchNd: input type not supported");
1913
1914 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1915 "Reference SpaceToBatchNd: output type not supported");
1916
1917 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1918 "Reference SpaceToBatchNd: input and output types are mismatched");
1919
1920 return supported;
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001921}
1922
Keith Davisa57eccb2019-06-14 17:33:22 +01001923bool RefLayerSupport::IsSpaceToDepthSupported(const TensorInfo& input,
Keith Davis51910332019-06-26 15:28:43 +01001924 const TensorInfo& output,
1925 const SpaceToDepthDescriptor& descriptor,
1926 Optional<std::string&> reasonIfUnsupported) const
Keith Davisa57eccb2019-06-14 17:33:22 +01001927{
1928
Jan Eilers8eb25602020-03-09 12:13:48 +00001929 IgnoreUnused(descriptor);
Keith Davisa57eccb2019-06-14 17:33:22 +01001930 bool supported = true;
1931
Sadik Armagan303980c2020-04-17 12:45:14 +01001932 std::array<DataType,6> supportedTypes =
Keith Davisa57eccb2019-06-14 17:33:22 +01001933 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001934 DataType::BFloat16,
Keith Davisa57eccb2019-06-14 17:33:22 +01001935 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001936 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001937 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001938 DataType::QAsymmU8,
1939 DataType::QSymmS16
Keith Davisa57eccb2019-06-14 17:33:22 +01001940 };
1941
1942 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1943 "Reference SpaceToDepth: input type not supported");
1944
1945 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1946 "Reference SpaceToDepth: output type not supported");
1947
1948 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1949 "Reference SpaceToDepth: input and output types are mismatched");
1950
1951 return supported;
1952}
1953
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001954bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1955 const ViewsDescriptor& descriptor,
1956 Optional<std::string&> reasonIfUnsupported) const
1957{
Jan Eilers8eb25602020-03-09 12:13:48 +00001958 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001959 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001960 std::array<DataType,6> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001961 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001962 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001963 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001964 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001965 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001966 DataType::QAsymmU8,
1967 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001968 };
1969
1970 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1971 "Reference splitter: input type not supported");
1972
1973 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001974}
1975
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001976bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1977 const std::vector<std::reference_wrapper<TensorInfo>>& outputs,
1978 const ViewsDescriptor& descriptor,
1979 Optional<std::string&> reasonIfUnsupported) const
1980{
Jan Eilers8eb25602020-03-09 12:13:48 +00001981 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001982 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01001983 std::array<DataType,6> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001984 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00001985 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001986 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001987 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01001988 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001989 DataType::QAsymmU8,
1990 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001991 };
1992
1993 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1994 "Reference splitter: output type not supported");
Derek Lambertieac4adb2020-08-25 13:05:59 +01001995 for (const TensorInfo& output : outputs)
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001996 {
1997 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1998 "Reference splitter: input type not supported");
1999
2000 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2001 "Reference splitter: input and output types mismatched.");
2002 }
2003
2004 return supported;
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01002005}
2006
Matthew Jackson81e601c2019-07-11 12:07:09 +01002007bool RefLayerSupport::IsStackSupported(const std::vector<const TensorInfo*>& inputs,
2008 const TensorInfo& output,
2009 const StackDescriptor& descriptor,
2010 Optional<std::string&> reasonIfUnsupported) const
2011{
Jan Eilers8eb25602020-03-09 12:13:48 +00002012 IgnoreUnused(descriptor);
Matthew Jackson81e601c2019-07-11 12:07:09 +01002013
2014 bool supported = true;
Sadik Armagan303980c2020-04-17 12:45:14 +01002015 std::array<DataType,6> supportedTypes =
Matthew Jackson81e601c2019-07-11 12:07:09 +01002016 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002017 DataType::BFloat16,
Matthew Jackson81e601c2019-07-11 12:07:09 +01002018 DataType::Float32,
Matthew Jacksone69c3992019-09-09 14:31:21 +01002019 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002020 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002021 DataType::QAsymmU8,
2022 DataType::QSymmS16
Matthew Jackson81e601c2019-07-11 12:07:09 +01002023 };
2024
2025 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2026 "Reference stack: output type not supported");
2027 for (const TensorInfo* input : inputs)
2028 {
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +01002029 ARMNN_ASSERT(input != nullptr);
Matthew Jackson81e601c2019-07-11 12:07:09 +01002030 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
2031 "Reference stack: input type not supported");
2032
2033 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
2034 "Reference stack: input and output types mismatched.");
2035 }
2036
2037 return supported;
2038}
2039
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00002040bool RefLayerSupport::IsStridedSliceSupported(const TensorInfo& input,
2041 const TensorInfo& output,
2042 const StridedSliceDescriptor& descriptor,
2043 Optional<std::string&> reasonIfUnsupported) const
2044{
Jan Eilers8eb25602020-03-09 12:13:48 +00002045 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01002046 bool supported = true;
2047
Sadik Armagan303980c2020-04-17 12:45:14 +01002048 std::array<DataType,5> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01002049 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002050 DataType::BFloat16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01002051 DataType::Float32,
Sadik Armagan303980c2020-04-17 12:45:14 +01002052 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002053 DataType::QAsymmU8,
2054 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01002055 };
2056
2057 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2058 "Reference StridedSlice: input type not supported");
2059
2060 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2061 "Reference StridedSlice: output type not supported");
2062
2063 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2064 "Reference StridedSlice: input and output types are mismatched");
2065
2066 return supported;
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00002067}
2068
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01002069bool RefLayerSupport::IsSubtractionSupported(const TensorInfo& input0,
2070 const TensorInfo& input1,
2071 const TensorInfo& output,
2072 Optional<std::string&> reasonIfUnsupported) const
2073{
Sadik Armagan2999a022019-04-09 14:20:12 +01002074 bool supported = true;
2075
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01002076 std::array<DataType,7> supportedTypes = {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002077 DataType::BFloat16,
Sadik Armagan2999a022019-04-09 14:20:12 +01002078 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01002079 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002080 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002081 DataType::QAsymmU8,
Teresa Charlinecb6b8e2020-05-22 18:08:23 +01002082 DataType::QSymmS16,
2083 DataType::Signed32
Sadik Armagan2999a022019-04-09 14:20:12 +01002084 };
2085
2086 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
2087 "Reference subtraction: input 0 is not a supported type.");
2088
2089 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
2090 "Reference subtraction: input 1 is not a supported type.");
2091
2092 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2093 "Reference subtraction: output is not a supported type.");
2094
2095 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
2096 "Reference subtraction: input 0 and Input 1 types are mismatched");
2097
2098 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
2099 "Reference subtraction: input and output types are mismatched");
2100
2101 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
2102 "Reference subtraction: shapes are not suitable for implicit broadcast.");
2103
2104 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01002105}
2106
Matteo Martincighab9e5252019-06-13 17:27:46 +01002107bool RefLayerSupport::IsPreluSupported(const TensorInfo& input,
2108 const TensorInfo& alpha,
2109 const TensorInfo& output,
2110 Optional<std::string&> reasonIfUnsupported) const
2111{
2112 bool supported = true;
2113
Teresa Charlin3940d8b2020-05-29 16:47:23 +01002114 std::array<DataType, 6> supportedTypes
Matteo Martincighab9e5252019-06-13 17:27:46 +01002115 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002116 DataType::BFloat16,
Matteo Martincighab9e5252019-06-13 17:27:46 +01002117 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01002118 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002119 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002120 DataType::QAsymmU8,
Teresa Charlin3940d8b2020-05-29 16:47:23 +01002121 DataType::QSymmS16
Matteo Martincighab9e5252019-06-13 17:27:46 +01002122 };
2123
2124 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2125 "PReLU: input is not a supported type.");
2126
2127 supported &= CheckSupportRule(TypeAnyOf(alpha, supportedTypes), reasonIfUnsupported,
2128 "PReLU: alpha is not a supported type.");
2129
2130 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2131 "PReLU: output is not a supported type.");
2132
2133 supported &= CheckSupportRule(TypesAreEqual(input, alpha, output), reasonIfUnsupported,
2134 "PReLU: input, alpha and output types are mismatched");
2135
2136 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input, alpha, output), reasonIfUnsupported,
2137 "PReLU: shapes are not suitable for implicit broadcast");
2138
2139 return supported;
2140}
2141
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002142bool RefLayerSupport::IsTransposeConvolution2dSupported(const TensorInfo& input,
2143 const TensorInfo& output,
2144 const TransposeConvolution2dDescriptor& descriptor,
2145 const TensorInfo& weights,
2146 const Optional<TensorInfo>& biases,
2147 Optional<std::string&> reasonIfUnsupported) const
2148{
Jan Eilers8eb25602020-03-09 12:13:48 +00002149 IgnoreUnused(descriptor);
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002150 bool supported = true;
2151
Sadik Armagan303980c2020-04-17 12:45:14 +01002152 std::array<DataType,7> supportedTypes =
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002153 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002154 DataType::BFloat16,
2155 DataType::Float32,
2156 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002157 DataType::QAsymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002158 DataType::QAsymmU8,
Sadik Armagan303980c2020-04-17 12:45:14 +01002159 DataType::QSymmS8,
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002160 DataType::QSymmS16
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002161 };
2162
2163 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2164 "Reference TransposeConvolution2d: input is not a supported type.");
2165
2166 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2167 "Reference TransposeConvolution2d: output is not a supported type.");
2168
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002169 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2170 "Reference TransposeConvolution2d: input and output types mismatched.");
2171
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002172
2173 const DataType inputType = input.GetDataType();
Sadik Armagan303980c2020-04-17 12:45:14 +01002174 if (IsQuantized8BitType(inputType))
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002175 {
Derek Lambertid466a542020-01-22 15:37:29 +00002176 ARMNN_NO_DEPRECATE_WARN_BEGIN
Sadik Armagan303980c2020-04-17 12:45:14 +01002177 std::array<DataType, 4> supportedWeightTypes =
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002178 {
Sadik Armagan303980c2020-04-17 12:45:14 +01002179 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00002180 DataType::QAsymmU8,
Derek Lambertid466a542020-01-22 15:37:29 +00002181 DataType::QSymmS8,
2182 DataType::QuantizedSymm8PerAxis //Deprecated
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002183 };
Derek Lambertid466a542020-01-22 15:37:29 +00002184 ARMNN_NO_DEPRECATE_WARN_END
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00002185
2186 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
2187 "Reference TransposeConvolution2d: weights type not supported for "
2188 "quantized input.");
2189 }
2190 else
2191 {
2192 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
2193 "Reference TransposeConvolution2d: weights is not a supported type.");
2194
2195 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
2196 "Reference TransposeConvolution2d: input and weights types mismatched.");
2197 }
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002198
2199 if (biases.has_value())
2200 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002201 std::array<DataType,4> biasesSupportedTypes =
Aron Virginas-Tar651aafe2019-08-05 11:52:05 +01002202 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002203 DataType::BFloat16,
2204 DataType::Float32,
2205 DataType::Float16,
2206 DataType::Signed32
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01002207 };
2208 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
2209 "Reference TransposeConvolution2d: biases is not a supported type.");
2210 }
2211
2212 return supported;
2213}
2214
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002215bool RefLayerSupport::IsTransposeSupported(const TensorInfo& input,
2216 const TensorInfo& output,
2217 const TransposeDescriptor& descriptor,
2218 Optional<std::string&> reasonIfUnsupported) const
2219{
Jan Eilers8eb25602020-03-09 12:13:48 +00002220 IgnoreUnused(descriptor);
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002221 bool supported = true;
2222
2223 // Define supported output and inputs types.
Sadik Armagan303980c2020-04-17 12:45:14 +01002224 std::array<DataType, 6> supportedTypes =
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002225 {
Narumol Prangnawarat44179c32020-03-11 14:51:27 +00002226 DataType::BFloat16,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002227 DataType::Float32,
2228 DataType::Float16,
Sadik Armagan303980c2020-04-17 12:45:14 +01002229 DataType::QAsymmS8,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00002230 DataType::QAsymmU8,
2231 DataType::QSymmS16
2232 };
2233
2234 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
2235 "Reference transpose: input is not a supported type.");
2236
2237 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
2238 "Reference transpose: output is not a supported type.");
2239
2240 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
2241 "Reference transpose: input and output types are mismatched.");
2242
2243 return supported;
2244}
2245
arovir011c7c81b2018-10-08 11:34:28 +01002246} // namespace armnn