blob: cb94955e7aa621af221b4ed9108916bf9e313385 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
2// Copyright © 2017 Arm Ltd. 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>
telsoa014fcda012018-03-09 14:13:49 +000012
Matteo Martincighe011d202019-11-28 11:35:47 +000013#include <LayerSupportCommon.hpp>
Derek Lambertif674aa02019-08-01 15:56:25 +010014#include <backendsCommon/LayerSupportRules.hpp>
Matteo Martincighe011d202019-11-28 11:35:47 +000015
Matteo Martincighe011d202019-11-28 11:35:47 +000016#include <boost/cast.hpp>
telsoa014fcda012018-03-09 14:13:49 +000017
Derek Lamberti50db4e82019-03-13 14:16:15 +000018#include <vector>
Derek Lamberti50db4e82019-03-13 14:16:15 +000019#include <array>
20
telsoa014fcda012018-03-09 14:13:49 +000021using namespace boost;
22
23namespace armnn
24{
25
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +010026namespace
27{
28
29template<typename Float32Func, typename Uint8Func, typename ... Params>
30bool IsSupportedForDataTypeRef(Optional<std::string&> reasonIfUnsupported,
31 DataType dataType,
32 Float32Func floatFuncPtr,
33 Uint8Func uint8FuncPtr,
34 Params&&... params)
35{
36 return IsSupportedForDataTypeGeneric(reasonIfUnsupported,
37 dataType,
38 &FalseFunc<Params...>,
39 floatFuncPtr,
40 uint8FuncPtr,
narpra01db2b1602019-01-23 15:23:11 +000041 &FalseFunc<Params...>,
kevmay012b4d88e2019-01-24 14:05:09 +000042 &FalseFunc<Params...>,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +010043 std::forward<Params>(params)...);
44}
45
46} // anonymous namespace
47
James Conroy4d1ff582019-06-10 17:06:39 +010048namespace
49{
50
51std::string CreateIncorrectDimensionsErrorMsg(unsigned int expected,
52 unsigned int actual,
53 std::string& layerStr,
54 std::string& tensorName)
55{
56 std::string errorMsg = "Reference " + layerStr + ": Expected " + std::to_string(expected) + " dimensions but got" +
57 " " + std::to_string(actual) + " dimensions instead, for the '" + tensorName + "' tensor.";
58
59 return errorMsg;
60}
61
62} // anonymous namespace
Derek Lamberti50db4e82019-03-13 14:16:15 +000063
Sadik Armagan9199e582019-09-05 17:35:31 +010064bool RefLayerSupport::IsAbsSupported(const TensorInfo& input, const TensorInfo& output,
65 Optional<std::string&> reasonIfUnsupported) const
66{
josh minor4a3c6102020-01-06 16:40:46 -060067 return IsElementwiseUnarySupported(input,
68 output,
69 ElementwiseUnaryDescriptor(UnaryOperation::Abs),
70 reasonIfUnsupported);
Sadik Armagan9199e582019-09-05 17:35:31 +010071}
72
arovir011c7c81b2018-10-08 11:34:28 +010073bool RefLayerSupport::IsActivationSupported(const TensorInfo& input,
74 const TensorInfo& output,
75 const ActivationDescriptor& descriptor,
76 Optional<std::string&> reasonIfUnsupported) const
77{
Derek Lamberti50db4e82019-03-13 14:16:15 +000078 bool supported = true;
79
80 // Define supported types.
Keith Davis0c2eeac2020-02-11 16:51:50 +000081 std::array<DataType,6> supportedTypes = {
Derek Lamberti50db4e82019-03-13 14:16:15 +000082 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +010083 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +000084 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +000085 DataType::QAsymmU8,
86 DataType::QSymmS16
Derek Lamberti50db4e82019-03-13 14:16:15 +000087 };
88
89 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
90 "Reference activation: input type not supported.");
91
92 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
93 "Reference activation: output type not supported.");
94
95 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
96 "Reference activation: input and output types mismatched.");
97
98 supported &= CheckSupportRule(ShapesAreSameRank(input, output), reasonIfUnsupported,
99 "Reference activation: input and output shapes are of different rank.");
100
101
102 struct ActivationFunctionSupported : public Rule
103 {
104 ActivationFunctionSupported(const ActivationDescriptor& desc)
105 {
106 switch(desc.m_Function)
107 {
108 case ActivationFunction::Abs:
109 case ActivationFunction::BoundedReLu:
David Monahan3b3c3812020-02-25 09:03:29 +0000110 case ActivationFunction::Elu:
Colm Donelan03fbeaf2020-02-26 15:39:23 +0000111 case ActivationFunction::HardSwish:
Derek Lamberti50db4e82019-03-13 14:16:15 +0000112 case ActivationFunction::LeakyReLu:
113 case ActivationFunction::Linear:
114 case ActivationFunction::ReLu:
115 case ActivationFunction::Sigmoid:
116 case ActivationFunction::SoftReLu:
117 case ActivationFunction::Sqrt:
118 case ActivationFunction::Square:
119 case ActivationFunction::TanH:
120 {
121 m_Res = true;
122 break;
123 }
124 default:
125 {
126 m_Res = false;
127 break;
128 }
129 }
130 }
131 };
132
133 // Function is supported
134 supported &= CheckSupportRule(ActivationFunctionSupported(descriptor), reasonIfUnsupported,
135 "Reference activation: function not supported.");
136
137 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100138}
139
140bool RefLayerSupport::IsAdditionSupported(const TensorInfo& input0,
141 const TensorInfo& input1,
142 const TensorInfo& output,
143 Optional<std::string&> reasonIfUnsupported) const
144{
Derek Lamberti50db4e82019-03-13 14:16:15 +0000145 bool supported = true;
146
Keith Davis0c2eeac2020-02-11 16:51:50 +0000147 std::array<DataType,6> supportedTypes = {
Derek Lamberti50db4e82019-03-13 14:16:15 +0000148 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100149 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000150 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000151 DataType::QAsymmU8,
152 DataType::QSymmS16
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
Francis Murtagh1939df52019-11-13 15:21:09 +0000182 std::array<DataType, 4> supportedTypes =
Nikhil Raj68c2c902019-09-19 11:21:11 +0100183 {
184 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000185 DataType::QAsymmU8,
186 DataType::QSymmS16,
Francis Murtagh1939df52019-11-13 15:21:09 +0000187 DataType::Signed32
Nikhil Raj68c2c902019-09-19 11:21:11 +0100188 };
189
190 bool supported = true;
191
192 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
193 "Reference ArgMinMax: input is not a supported type.");
194 supported &= CheckSupportRule(TypeIs(output, DataType::Signed32), reasonIfUnsupported,
195 "Reference ArgMinMax: output type not supported");
196
197 return supported;
198}
199
arovir011c7c81b2018-10-08 11:34:28 +0100200bool RefLayerSupport::IsBatchNormalizationSupported(const TensorInfo& input,
201 const TensorInfo& output,
202 const TensorInfo& mean,
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100203 const TensorInfo& variance,
arovir011c7c81b2018-10-08 11:34:28 +0100204 const TensorInfo& beta,
205 const TensorInfo& gamma,
206 const BatchNormalizationDescriptor& descriptor,
207 Optional<std::string&> reasonIfUnsupported) const
208{
Jan Eilers8eb25602020-03-09 12:13:48 +0000209 IgnoreUnused(descriptor);
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100210
Matthew Jackson9bff1442019-09-12 09:08:23 +0100211 std::array<DataType, 4> supportedTypes =
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100212 {
213 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100214 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000215 DataType::QAsymmU8,
216 DataType::QSymmS16
Matteo Martincigh3122bd52019-06-03 16:54:25 +0100217 };
218
219 bool supported = true;
220
221 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
222 "Reference batch normalization: input is not a supported type.");
223
224 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
225 "Reference batch normalization: output is not a supported type.");
226
227 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
228 "Reference batch normalization: input and output types are mismatched");
229
230 supported &= CheckSupportRule(TypeAnyOf(mean, supportedTypes), reasonIfUnsupported,
231 "Reference batch normalization: mean is not a supported type.");
232
233 supported &= CheckSupportRule(TypeAnyOf(variance, supportedTypes), reasonIfUnsupported,
234 "Reference batch normalization: variance is not a supported type.");
235
236 supported &= CheckSupportRule(TypeAnyOf(beta, supportedTypes), reasonIfUnsupported,
237 "Reference batch normalization: beta is not a supported type.");
238
239 supported &= CheckSupportRule(TypeAnyOf(gamma, supportedTypes), reasonIfUnsupported,
240 "Reference batch normalization: gamma is not a supported type.");
241
242 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100243}
244
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000245bool RefLayerSupport::IsBatchToSpaceNdSupported(const TensorInfo& input,
246 const TensorInfo& output,
247 const BatchToSpaceNdDescriptor& descriptor,
248 Optional<std::string&> reasonIfUnsupported) const
249{
Jan Eilers8eb25602020-03-09 12:13:48 +0000250 IgnoreUnused(descriptor);
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100251
252 bool supported = true;
253
254 std::string batchToSpaceNdLayerStr = "batchToSpaceNd";
255 std::string inputTensorStr = "input";
256 std::string outputTensorStr = "output";
257
258 // Define supported types.
Matthew Jackson9bff1442019-09-12 09:08:23 +0100259 std::array<DataType,4> supportedTypes =
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100260 {
261 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100262 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000263 DataType::QAsymmU8,
264 DataType::QSymmS16
Francis Murtaghd0dfe172019-06-25 10:57:10 +0100265 };
266
267 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
268 "Reference BatchToSpaceNd: input type not supported.");
269
270 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
271 "Reference BatchToSpaceNd: output type not supported.");
272
273 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
274 "Reference BatchToSpaceNd: input and output types mismatched.");
275
276 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 4),
277 reasonIfUnsupported,
278 CreateIncorrectDimensionsErrorMsg(4,
279 output.GetNumDimensions(),
280 batchToSpaceNdLayerStr,
281 outputTensorStr).data());
282
283 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(input, 4),
284 reasonIfUnsupported,
285 CreateIncorrectDimensionsErrorMsg(4,
286 input.GetNumDimensions(),
287 batchToSpaceNdLayerStr,
288 inputTensorStr).data());
289
290 return supported;
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000291}
292
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100293bool RefLayerSupport::IsComparisonSupported(const TensorInfo& input0,
294 const TensorInfo& input1,
295 const TensorInfo& output,
296 const ComparisonDescriptor& descriptor,
297 Optional<std::string&> reasonIfUnsupported) const
298{
Jan Eilers8eb25602020-03-09 12:13:48 +0000299 IgnoreUnused(descriptor);
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100300
301 std::array<DataType, 4> supportedInputTypes =
302 {
303 DataType::Float32,
304 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000305 DataType::QAsymmU8,
306 DataType::QSymmS16
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100307 };
308
309 bool supported = true;
310 supported &= CheckSupportRule(TypeAnyOf(input0, supportedInputTypes), reasonIfUnsupported,
311 "Reference comparison: input 0 is not a supported type");
312
313 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
314 "Reference comparison: input 0 and Input 1 types are mismatched");
315
316 supported &= CheckSupportRule(TypeIs(output, DataType::Boolean), reasonIfUnsupported,
317 "Reference comparison: output is not of type Boolean");
318
319 return supported;
320}
321
Jim Flynn906f9462019-05-10 13:55:21 +0100322bool RefLayerSupport::IsConcatSupported(const std::vector<const TensorInfo*> inputs,
323 const TensorInfo& output,
Jim Flynne242f2d2019-05-22 14:24:13 +0100324 const ConcatDescriptor& descriptor,
Jim Flynn906f9462019-05-10 13:55:21 +0100325 Optional<std::string&> reasonIfUnsupported) const
326{
Jan Eilers8eb25602020-03-09 12:13:48 +0000327 IgnoreUnused(descriptor);
Jim Flynne242f2d2019-05-22 14:24:13 +0100328
329 bool supported = true;
Keith Davis5204aa82020-01-27 15:24:59 +0000330 std::array<DataType,5> supportedTypes =
Jim Flynne242f2d2019-05-22 14:24:13 +0100331 {
332 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100333 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000334 DataType::QAsymmU8,
Keith Davis67e6c542020-02-19 10:08:33 +0000335 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000336 DataType::QSymmS16
Jim Flynne242f2d2019-05-22 14:24:13 +0100337 };
338
339 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
340 "Reference concatenation: output type not supported");
341 for (const TensorInfo* input : inputs)
342 {
Matthew Jackson81e601c2019-07-11 12:07:09 +0100343 BOOST_ASSERT(input != nullptr);
Jim Flynne242f2d2019-05-22 14:24:13 +0100344 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
345 "Reference concatenation: input type not supported");
346
347 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
348 "Reference concatenation: input and output types mismatched.");
349 }
350
351 return supported;
Jim Flynn906f9462019-05-10 13:55:21 +0100352}
353
arovir011c7c81b2018-10-08 11:34:28 +0100354bool RefLayerSupport::IsConstantSupported(const TensorInfo& output,
355 Optional<std::string&> reasonIfUnsupported) const
356{
Keith Davis67e6c542020-02-19 10:08:33 +0000357 std::array<DataType,6> supportedTypes =
Jim Flynne242f2d2019-05-22 14:24:13 +0100358 {
Nina Drozd58ef2c62019-05-16 12:09:18 +0100359 DataType::Float32,
360 DataType::Signed32,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000361 DataType::QAsymmU8,
Keith Davis67e6c542020-02-19 10:08:33 +0000362 DataType::QAsymmS8,
Keith Davis5204aa82020-01-27 15:24:59 +0000363 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000364 DataType::QSymmS16
Nina Drozd58ef2c62019-05-16 12:09:18 +0100365 };
366
367 return CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
368 "Reference constant: output is not a supported type.");
arovir011c7c81b2018-10-08 11:34:28 +0100369}
370
371bool RefLayerSupport::IsConvertFp16ToFp32Supported(const TensorInfo& input,
372 const TensorInfo& output,
373 Optional<std::string&> reasonIfUnsupported) const
374{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100375 return (IsSupportedForDataTypeGeneric(reasonIfUnsupported,
376 input.GetDataType(),
377 &TrueFunc<>,
378 &FalseInputFuncF32<>,
narpra01db2b1602019-01-23 15:23:11 +0000379 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000380 &FalseFuncI32<>,
381 &FalseFuncU8<>) &&
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100382 IsSupportedForDataTypeGeneric(reasonIfUnsupported,
383 output.GetDataType(),
384 &FalseOutputFuncF16<>,
385 &TrueFunc<>,
narpra01db2b1602019-01-23 15:23:11 +0000386 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000387 &FalseFuncI32<>,
388 &FalseFuncU8<>));
arovir011c7c81b2018-10-08 11:34:28 +0100389}
390
391bool RefLayerSupport::IsConvertFp32ToFp16Supported(const TensorInfo& input,
392 const TensorInfo& output,
393 Optional<std::string&> reasonIfUnsupported) const
394{
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100395 return (IsSupportedForDataTypeGeneric(reasonIfUnsupported,
396 input.GetDataType(),
397 &FalseInputFuncF16<>,
398 &TrueFunc<>,
narpra01db2b1602019-01-23 15:23:11 +0000399 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000400 &FalseFuncI32<>,
401 &FalseFuncU8<>) &&
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +0100402 IsSupportedForDataTypeGeneric(reasonIfUnsupported,
403 output.GetDataType(),
404 &TrueFunc<>,
405 &FalseOutputFuncF32<>,
narpra01db2b1602019-01-23 15:23:11 +0000406 &FalseFuncU8<>,
kevmay012b4d88e2019-01-24 14:05:09 +0000407 &FalseFuncI32<>,
408 &FalseFuncU8<>));
arovir011c7c81b2018-10-08 11:34:28 +0100409}
410
411bool RefLayerSupport::IsConvolution2dSupported(const TensorInfo& input,
412 const TensorInfo& output,
413 const Convolution2dDescriptor& descriptor,
414 const TensorInfo& weights,
415 const Optional<TensorInfo>& biases,
416 Optional<std::string&> reasonIfUnsupported) const
417{
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100418 bool supported = true;
419
420 // Define supported types.
Keith Davis0c2eeac2020-02-11 16:51:50 +0000421 std::array<DataType,6> supportedTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000422 {
423 DataType::Float32,
424 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000425 DataType::QAsymmU8,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000426 DataType::QAsymmS8,
Keith Davis5204aa82020-01-27 15:24:59 +0000427 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000428 DataType::QSymmS16
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100429 };
430
431 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000432 "Reference Convolution2d: input is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100433
434 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000435 "Reference Convolution2d: output is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100436
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100437 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000438 "Reference Convolution2d: input and output types mismatched.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100439
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000440 const DataType inputType = input.GetDataType();
Keith Davis0c2eeac2020-02-11 16:51:50 +0000441 if (IsQuantized8BitType(inputType))
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000442 {
Derek Lambertid466a542020-01-22 15:37:29 +0000443 ARMNN_NO_DEPRECATE_WARN_BEGIN
Keith Davis0c2eeac2020-02-11 16:51:50 +0000444 std::array<DataType, 4> supportedWeightTypes =
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000445 {
Derek Lambertif90c56d2020-01-10 17:14:08 +0000446 DataType::QAsymmU8,
Derek Lambertid466a542020-01-22 15:37:29 +0000447 DataType::QSymmS8,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000448 DataType::QAsymmS8,
Derek Lambertid466a542020-01-22 15:37:29 +0000449 DataType::QuantizedSymm8PerAxis // deprecated
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000450 };
Derek Lambertid466a542020-01-22 15:37:29 +0000451 ARMNN_NO_DEPRECATE_WARN_END
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000452
453 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000454 "Reference Convolution2d: weights type not supported for quantized input.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000455 }
456 else
457 {
458 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000459 "Reference Convolution2d: weights is not a supported type.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000460
461 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000462 "Reference Convolution2d: input and weights types mismatched.");
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000463 }
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100464
465 if (biases.has_value())
466 {
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000467 std::array<DataType,3> biasesSupportedTypes =
468 {
469 DataType::Float32,
470 DataType::Float16,
471 DataType::Signed32
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100472 };
Aron Virginas-Tar5edc8812019-11-05 18:00:21 +0000473
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100474 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000475 "Reference Convolution2d: biases is not a supported type.");
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100476 }
Jan Eilers8eb25602020-03-09 12:13:48 +0000477 IgnoreUnused(descriptor);
Mike Kelly2f80f6e2019-05-16 12:41:34 +0100478
479 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100480}
481
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000482bool RefLayerSupport::IsDebugSupported(const TensorInfo& input,
483 const TensorInfo& output,
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000484 Optional<std::string&> reasonIfUnsupported) const
485{
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100486 bool supported = true;
487
Keith Davis0c2eeac2020-02-11 16:51:50 +0000488 std::array<DataType, 7> supportedTypes =
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100489 {
Aron Virginas-Tardb1a2832019-11-12 16:15:11 +0000490 DataType::Float16,
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100491 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000492 DataType::QAsymmU8,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000493 DataType::QAsymmS8,
Keith Davis5204aa82020-01-27 15:24:59 +0000494 DataType::QSymmS8,
Narumol Prangnawaratd2d917d2020-01-09 10:16:39 +0000495 DataType::QSymmS16,
496 DataType::Signed32
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100497 };
498
499 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000500 "Reference for Debug layer: input type not supported");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100501
502 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000503 "Reference for Debug layer: output type not supported");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100504
505 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000506 "Reference for Debug layer: input and output types are mismatched");
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100507
508 return supported;
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000509}
510
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100511bool RefLayerSupport::IsDepthToSpaceSupported(const TensorInfo& input,
512 const TensorInfo& output,
513 const DepthToSpaceDescriptor& descriptor,
514 Optional<std::string&> reasonIfUnsupported) const
515{
Jan Eilers8eb25602020-03-09 12:13:48 +0000516 IgnoreUnused(descriptor);
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100517 bool supported = true;
518
519 std::array<DataType,4> supportedTypes =
520 {
521 DataType::Float32,
522 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000523 DataType::QAsymmU8,
524 DataType::QSymmS16
Aron Virginas-Tar73f66422019-09-23 19:11:59 +0100525 };
526
527 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
528 "Reference DepthToSpace: input type not supported");
529
530 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
531 "Reference DepthToSpace: output type not supported");
532
533 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
534 "Reference DepthToSpace: input and output types are mismatched");
535
536 return supported;
537}
538
arovir011c7c81b2018-10-08 11:34:28 +0100539bool RefLayerSupport::IsDepthwiseConvolutionSupported(const TensorInfo& input,
540 const TensorInfo& output,
541 const DepthwiseConvolution2dDescriptor& descriptor,
542 const TensorInfo& weights,
543 const Optional<TensorInfo>& biases,
544 Optional<std::string&> reasonIfUnsupported) const
545{
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100546 bool supported = true;
547
548 // Define supported types.
Keith Davis0c2eeac2020-02-11 16:51:50 +0000549 std::array<DataType,6> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100550 {
551 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100552 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +0000553 DataType::QSymmS8,
554 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000555 DataType::QAsymmU8,
556 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100557 };
558
559 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
560 "Reference DepthwiseConvolution2d: input is not a supported type.");
561
562 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
563 "Reference DepthwiseConvolution2d: output is not a supported type.");
564
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100565 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
566 "Reference DepthwiseConvolution2d: input and output types mismatched.");
567
Derek Lambertid466a542020-01-22 15:37:29 +0000568 ARMNN_NO_DEPRECATE_WARN_BEGIN
569 std::array<DataType, 3> supportedWeightTypes =
570 {
571 DataType::QAsymmU8,
572 DataType::QSymmS8,
573 DataType::QuantizedSymm8PerAxis // deprecated
574 };
575 ARMNN_NO_DEPRECATE_WARN_END
576
Teresa Charlind8df0262019-11-11 12:28:15 +0000577 const DataType inputType = input.GetDataType();
Keith Davis0c2eeac2020-02-11 16:51:50 +0000578 if (IsQuantized8BitType(inputType))
Teresa Charlind8df0262019-11-11 12:28:15 +0000579 {
Teresa Charlind8df0262019-11-11 12:28:15 +0000580
581 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
582 "Reference convolution2d: weights type not supported for quantized input.");
583 }
584 else
585 {
586 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
587 "Reference DepthwiseConvolution2d: weights is not a supported type.");
588
589 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
590 "Reference DepthwiseConvolution2d: input and weights types mismatched.");
591 }
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100592
593 if (biases.has_value())
594 {
Matthew Jackson252df3a2019-09-11 09:19:18 +0100595 std::array<DataType,3> biasesSupportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100596 {
597 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100598 DataType::Float16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100599 DataType::Signed32
600 };
601 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
602 "Reference DepthwiseConvolution2d: biases is not a supported type.");
603 }
Jan Eilers8eb25602020-03-09 12:13:48 +0000604 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100605
606 return supported;
607
arovir011c7c81b2018-10-08 11:34:28 +0100608}
609
Nattapat Chaimanowong8a54ac02019-03-29 15:25:04 +0000610bool RefLayerSupport::IsDequantizeSupported(const TensorInfo& input,
611 const TensorInfo& output,
612 Optional<std::string&> reasonIfUnsupported) const
613{
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100614 bool supported = true;
615
Ryan OShea9add1202020-02-07 10:06:33 +0000616 std::array<DataType,4> supportedInputTypes = {
617 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000618 DataType::QAsymmU8,
Finn Williamsfd271062019-12-04 14:27:27 +0000619 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000620 DataType::QSymmS16
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100621 };
622
623 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000624 "Reference for Dequantize layer: input type not supported.");
625
626 supported &= CheckSupportRule( TypeNotPerAxisQuantized(input), reasonIfUnsupported,
627 "Reference for Dequantize layer: per-axis quantized input not support .");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100628
Derek Lambertid466a542020-01-22 15:37:29 +0000629 supported &= CheckSupportRule(TypeNotPerAxisQuantized(input), reasonIfUnsupported,
630 "Reference dequantize: per-axis quantized input not support .");
631
Jan Eilersf7107932019-11-01 11:09:36 +0000632 std::array<DataType,2> supportedOutputTypes = {
633 DataType::Float32,
634 DataType::Float16
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100635 };
636
637 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000638 "Reference for Dequantize layer: output type not supported.");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100639
640 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
Keith Davis5204aa82020-01-27 15:24:59 +0000641 "Reference for Dequantize layer: input/output shapes have different num total "
642 "elements.");
Nattapat Chaimanowongafa4e3a2019-04-02 11:41:45 +0100643
644 return supported;
Nattapat Chaimanowong8a54ac02019-03-29 15:25:04 +0000645}
646
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000647bool RefLayerSupport::IsDetectionPostProcessSupported(const TensorInfo& boxEncodings,
648 const TensorInfo& scores,
649 const TensorInfo& anchors,
650 const TensorInfo& detectionBoxes,
651 const TensorInfo& detectionClasses,
652 const TensorInfo& detectionScores,
653 const TensorInfo& numDetections,
654 const DetectionPostProcessDescriptor& descriptor,
655 Optional<std::string&> reasonIfUnsupported) const
Narumol Prangnawaratbc67cef2019-01-31 15:31:54 +0000656{
Jan Eilers8eb25602020-03-09 12:13:48 +0000657 IgnoreUnused(anchors, detectionBoxes, detectionClasses, detectionScores, numDetections, descriptor);
Derek Lamberti901ea112019-12-10 22:07:09 +0000658
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100659 bool supported = true;
660
Mike Kelly4992c342019-08-14 11:33:11 +0100661 std::array<DataType,3> supportedInputTypes =
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100662 {
663 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000664 DataType::QAsymmU8,
665 DataType::QSymmS16
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100666 };
667
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000668 supported &= CheckSupportRule(TypeAnyOf(boxEncodings, supportedInputTypes), reasonIfUnsupported,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100669 "Reference DetectionPostProcess: input 0 is not a supported type.");
670
Derek Lamberti6a5e5e82019-12-05 14:41:20 +0000671 supported &= CheckSupportRule(TypeAnyOf(scores, supportedInputTypes), reasonIfUnsupported,
Aron Virginas-Tara37e1bd2019-06-06 16:08:30 +0100672 "Reference DetectionPostProcess: input 1 is not a supported type.");
673
674 return supported;
Narumol Prangnawaratbc67cef2019-01-31 15:31:54 +0000675}
676
Pablo Tellof0bd6832019-04-26 17:58:13 +0100677bool RefLayerSupport::IsDilatedDepthwiseConvolutionSupported(const TensorInfo& input,
678 const TensorInfo& output,
679 const DepthwiseConvolution2dDescriptor& descriptor,
680 const TensorInfo& weights,
681 const Optional<TensorInfo>& biases,
682 Optional<std::string&> reasonIfUnsupported) const
683{
Aron Virginas-Taraece4ed2019-06-14 17:00:09 +0100684 return IsDepthwiseConvolutionSupported(input, output, descriptor, weights, biases, reasonIfUnsupported);
Pablo Tellof0bd6832019-04-26 17:58:13 +0100685}
686
Aron Virginas-Taraece4ed2019-06-14 17:00:09 +0100687bool RefLayerSupport::IsDivisionSupported(const TensorInfo& input0,
arovir011c7c81b2018-10-08 11:34:28 +0100688 const TensorInfo& input1,
689 const TensorInfo& output,
690 Optional<std::string&> reasonIfUnsupported) const
691{
Sadik Armagan2999a022019-04-09 14:20:12 +0100692 bool supported = true;
693
Matthew Jackson9bff1442019-09-12 09:08:23 +0100694 std::array<DataType,4> supportedTypes = {
Sadik Armagan2999a022019-04-09 14:20:12 +0100695 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100696 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000697 DataType::QAsymmU8,
698 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +0100699 };
700
701 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
702 "Reference division: input 0 is not a supported type.");
703
704 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
705 "Reference division: input 1 is not a supported type.");
706
707 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
708 "Reference division: output is not a supported type.");
709
710 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
711 "Reference division: input 0 and Input 1 types are mismatched");
712
713 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
714 "Reference division: input and output types are mismatched");
715
716 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
717 "Reference division: shapes are not suitable for implicit broadcast.");
718
719 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100720}
721
josh minor4a3c6102020-01-06 16:40:46 -0600722bool RefLayerSupport::IsElementwiseUnarySupported(const TensorInfo& input,
723 const TensorInfo& output,
724 const ElementwiseUnaryDescriptor& descriptor,
725 Optional<std::string&> reasonIfUnsupported) const
726{
Jan Eilers8eb25602020-03-09 12:13:48 +0000727 IgnoreUnused(descriptor);
josh minor4a3c6102020-01-06 16:40:46 -0600728
729 std::array<DataType, 4> supportedTypes =
730 {
731 DataType::Float32,
732 DataType::Float16,
733 DataType::QAsymmU8,
734 DataType::QSymmS16
735 };
736
737 bool supported = true;
738
739 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
740 "Reference elementwise unary: input type not supported");
741
742 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
743 "Reference elementwise unary: output type not supported");
744
745 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
746 "Reference elementwise unary: input and output types not matching");
747
748 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
749 "Reference elementwise unary: input and output shapes"
750 "have different number of total elements");
751
752 return supported;
753}
754
FrancisMurtagh30cdfca2018-12-18 12:57:35 +0000755bool RefLayerSupport::IsEqualSupported(const TensorInfo& input0,
756 const TensorInfo& input1,
757 const TensorInfo& output,
758 Optional<std::string&> reasonIfUnsupported) const
759{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100760 return IsComparisonSupported(input0,
761 input1,
762 output,
763 ComparisonDescriptor(ComparisonOperation::Equal),
764 reasonIfUnsupported);
FrancisMurtagh30cdfca2018-12-18 12:57:35 +0000765}
766
arovir011c7c81b2018-10-08 11:34:28 +0100767bool RefLayerSupport::IsFakeQuantizationSupported(const TensorInfo& input,
768 const FakeQuantizationDescriptor& descriptor,
769 Optional<std::string&> reasonIfUnsupported) const
770{
Jan Eilers8eb25602020-03-09 12:13:48 +0000771 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100772 bool supported = true;
773
774 std::array<DataType,1> supportedTypes =
775 {
776 DataType::Float32
777 };
778
779 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
780 "Reference fake quantization: input type not supported.");
781
782 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100783}
784
785bool RefLayerSupport::IsFloorSupported(const TensorInfo& input,
786 const TensorInfo& output,
787 Optional<std::string&> reasonIfUnsupported) const
788{
Jan Eilers8eb25602020-03-09 12:13:48 +0000789 IgnoreUnused(output);
James Conroy83735b12019-05-30 16:36:59 +0100790 bool supported = true;
791
Matthew Jackson9bff1442019-09-12 09:08:23 +0100792 std::array<DataType,3> supportedTypes =
James Conroy83735b12019-05-30 16:36:59 +0100793 {
James Conroyb40d7102019-06-04 12:32:09 +0100794 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100795 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000796 DataType::QSymmS16
James Conroy83735b12019-05-30 16:36:59 +0100797 };
798
799 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
800 "Reference Floor: input type not supported.");
801
802 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
803 "Reference Floor: output type not supported.");
804
805 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100806}
807
808bool RefLayerSupport::IsFullyConnectedSupported(const TensorInfo& input,
809 const TensorInfo& output,
810 const TensorInfo& weights,
811 const TensorInfo& biases,
812 const FullyConnectedDescriptor& descriptor,
813 Optional<std::string&> reasonIfUnsupported) const
814{
Francis Murtagh46c09d02019-05-28 08:15:28 +0100815 bool supported = true;
816
817 // Define supported types.
Francis Murtaghddb1d062020-03-10 13:51:45 +0000818 std::array<DataType,5> supportedTypes =
Francis Murtagh46c09d02019-05-28 08:15:28 +0100819 {
820 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100821 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000822 DataType::QAsymmU8,
Francis Murtaghddb1d062020-03-10 13:51:45 +0000823 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000824 DataType::QSymmS16
Francis Murtagh46c09d02019-05-28 08:15:28 +0100825 };
826
827 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
828 "Reference Fully Connected: input type not supported.");
829
830 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
831 "Reference Fully Connected: output type not supported.");
832
833 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
834 "Reference Fully Connected: input and output types mismatched.");
835
836 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
837 "Reference Fully Connected: weights type not supported.");
838
Francis Murtaghddb1d062020-03-10 13:51:45 +0000839 ARMNN_NO_DEPRECATE_WARN_BEGIN
840 std::array<DataType, 3> supportedWeightTypes =
841 {
842 DataType::QAsymmU8,
843 DataType::QSymmS8,
844 DataType::QuantizedSymm8PerAxis // deprecated
845 };
846 ARMNN_NO_DEPRECATE_WARN_END
847
848 if (IsQuantized8BitType(input.GetDataType()))
849 {
850
851 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
852 "Reference Fully Connected: weights type not supported for quantized input.");
853 }
854 else
855 {
856 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
857 "Reference Fully Connected: weights is not a supported type.");
858
859 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
860 "Reference Fully Connected: input and weights types mismatched.");
861 }
Francis Murtagh46c09d02019-05-28 08:15:28 +0100862
863 if (descriptor.m_BiasEnabled)
864 {
865 // Defined supported types for bias
Matthew Jackson252df3a2019-09-11 09:19:18 +0100866 std::array<DataType, 3>
Francis Murtagh46c09d02019-05-28 08:15:28 +0100867 supportedBiasTypes =
868 {
869 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100870 DataType::Float16,
Francis Murtagh46c09d02019-05-28 08:15:28 +0100871 DataType::Signed32
872 };
873
874 supported &= CheckSupportRule(TypeAnyOf(biases, supportedBiasTypes), reasonIfUnsupported,
875 "Reference Fully Connected: bias type not supported.");
876
877 supported &= CheckSupportRule(BiasAndWeightsTypesMatch(biases, weights), reasonIfUnsupported,
878 "Reference Fully Connected: bias and weight types mismatch.");
879
880 supported &= CheckSupportRule(BiasAndWeightsTypesCompatible(weights, supportedBiasTypes), reasonIfUnsupported,
881 "Reference Fully Connected: bias type inferred from weights is incompatible.");
882
883 }
884
885 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100886}
887
narpra014951d842019-01-18 16:53:53 +0000888bool RefLayerSupport::IsGatherSupported(const armnn::TensorInfo& input0,
889 const armnn::TensorInfo& input1,
890 const armnn::TensorInfo& output,
891 armnn::Optional<std::string&> reasonIfUnsupported) const
892{
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100893 bool supported = true;
Matthew Jackson9bff1442019-09-12 09:08:23 +0100894 std::array<DataType,4> supportedTypes =
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100895 {
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +0100896 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +0100897 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000898 DataType::QAsymmU8,
899 DataType::QSymmS16
Ellen Norris-Thompsone0dbedf2019-06-24 09:23:38 +0100900 };
901
902 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
903 "Reference Gather: input type not supported");
904
905 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
906 "Reference Gather: output type not supported");
907
908 supported &= CheckSupportRule(TypeIs(input1, DataType::Signed32), reasonIfUnsupported,
909 "Reference Gather: indices (input1) type not supported");
910
911 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
912 "Reference Gather: input and output types not matching");
913
914 return supported;
narpra014951d842019-01-18 16:53:53 +0000915}
916
FrancisMurtagh878f0232018-12-19 10:56:15 +0000917bool RefLayerSupport::IsGreaterSupported(const TensorInfo& input0,
918 const TensorInfo& input1,
919 const TensorInfo& output,
920 Optional<std::string&> reasonIfUnsupported) const
921{
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +0100922 return IsComparisonSupported(input0,
923 input1,
924 output,
925 ComparisonDescriptor(ComparisonOperation::Greater),
926 reasonIfUnsupported);
FrancisMurtagh878f0232018-12-19 10:56:15 +0000927}
928
Derek Lamberti901ea112019-12-10 22:07:09 +0000929bool RefLayerSupport::IsInputSupported(const TensorInfo& /*input*/,
930 Optional<std::string&> /*reasonIfUnsupported*/) const
arovir011c7c81b2018-10-08 11:34:28 +0100931{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +0100932 return true;
arovir011c7c81b2018-10-08 11:34:28 +0100933}
934
Kevin May09ca49c2019-10-09 12:37:34 +0100935bool RefLayerSupport::IsInstanceNormalizationSupported(const TensorInfo& input,
936 const TensorInfo& output,
937 const InstanceNormalizationDescriptor& descriptor,
938 Optional<std::string&> reasonIfUnsupported) const
939{
Jan Eilers8eb25602020-03-09 12:13:48 +0000940 IgnoreUnused(descriptor);
Kevin May09ca49c2019-10-09 12:37:34 +0100941 // Define supported types
942 std::array<DataType, 4> supportedTypes =
943 {
944 DataType::Float32,
945 DataType::Float16
946 };
947
948 bool supported = true;
949
950 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
951 "Reference Instance Normalization: input type not supported.");
952
953 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
954 "Reference Instance Normalization: output type not supported.");
955
956 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
957 "Reference Instance Normalization: input and output types mismatched.");
958
959 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
960 "Reference Instance Normalization: input and output shapes have different "
961 "num total elements.");
962
963 return supported;
964}
965
arovir011c7c81b2018-10-08 11:34:28 +0100966bool RefLayerSupport::IsL2NormalizationSupported(const TensorInfo& input,
967 const TensorInfo& output,
968 const L2NormalizationDescriptor& descriptor,
969 Optional<std::string&> reasonIfUnsupported) const
970{
Jan Eilers8eb25602020-03-09 12:13:48 +0000971 IgnoreUnused(descriptor);
Ferran Balaguerd73d14f2019-06-10 10:29:54 +0100972 // Define supported types
Matthew Jackson252df3a2019-09-11 09:19:18 +0100973 std::array<DataType, 4> supportedTypes =
Ferran Balaguerd73d14f2019-06-10 10:29:54 +0100974 {
975 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +0100976 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +0000977 DataType::QAsymmU8,
978 DataType::QSymmS16
Ferran Balaguerd73d14f2019-06-10 10:29:54 +0100979 };
980
981 bool supported = true;
982
983 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
984 "Reference L2normalization: input type not supported.");
985
986 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
987 "Reference L2normalization: output type not supported.");
988
989 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
990 "Reference L2normalization: input and output types mismatched.");
991
992 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
993 "Reference L2normalization: input and output shapes have different "
994 "num total elements.");
995
996 return supported;
arovir011c7c81b2018-10-08 11:34:28 +0100997}
998
Aron Virginas-Tare662a942019-10-14 15:12:00 +0100999bool RefLayerSupport::IsLogSoftmaxSupported(const TensorInfo& input,
1000 const TensorInfo& output,
1001 const LogSoftmaxDescriptor& descriptor,
1002 Optional<std::string&> reasonIfUnsupported) const
1003{
Jan Eilers8eb25602020-03-09 12:13:48 +00001004 IgnoreUnused(descriptor);
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001005
1006 std::array<DataType, 2> supportedTypes =
1007 {
1008 DataType::Float32,
1009 DataType::Float16
1010 };
1011
1012 bool supported = true;
1013 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1014 "Reference LogSoftmax: input type not supported");
1015
1016 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1017 "Reference LogSoftmax: output type not supported");
1018
1019 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1020 "Reference LogSoftmax: input and output types do not match");
1021
1022 return supported;
1023}
1024
arovir011c7c81b2018-10-08 11:34:28 +01001025bool RefLayerSupport::IsLstmSupported(const TensorInfo& input,
1026 const TensorInfo& outputStateIn,
1027 const TensorInfo& cellStateIn,
1028 const TensorInfo& scratchBuffer,
1029 const TensorInfo& outputStateOut,
1030 const TensorInfo& cellStateOut,
1031 const TensorInfo& output,
1032 const LstmDescriptor& descriptor,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001033 const LstmInputParamsInfo& paramsInfo,
1034 Optional<std::string&> reasonIfUnsupported) const
arovir011c7c81b2018-10-08 11:34:28 +01001035{
Jan Eilers8eb25602020-03-09 12:13:48 +00001036 IgnoreUnused(descriptor);
1037 IgnoreUnused(paramsInfo);
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001038
1039 bool supported = true;
1040
1041 std::array<DataType,2> supportedTypes = {
Conor Kennedyb9971c92019-05-07 07:14:23 +01001042 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001043 DataType::QSymmS16
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001044 };
1045
Jan Eilersd01a83c2019-07-03 18:20:40 +01001046 // check inputs and outputs
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001047 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1048 "Reference Lstm: input is not a supported type.");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001049 supported &= CheckSupportRule(TypesAreEqual(input, outputStateIn), reasonIfUnsupported,
1050 "Reference Lstm: input and outputStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001051 supported &= CheckSupportRule(TypesAreEqual(input, cellStateIn), reasonIfUnsupported,
1052 "Reference Lstm: input and cellStateIn types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001053 supported &= CheckSupportRule(TypesAreEqual(input, scratchBuffer), reasonIfUnsupported,
1054 "Reference Lstm: input and scratchBuffer types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001055 supported &= CheckSupportRule(TypesAreEqual(input, outputStateOut), reasonIfUnsupported,
1056 "Reference Lstm: input and outputStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001057 supported &= CheckSupportRule(TypesAreEqual(input, cellStateOut), reasonIfUnsupported,
1058 "Reference Lstm: input and cellStateOut types are mismatched");
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001059 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1060 "Reference Lstm: input and output types are mismatched");
Jan Eilersd01a83c2019-07-03 18:20:40 +01001061 // check layer parameters
Francis Murtaghbb590b42019-08-14 09:51:36 +01001062 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001063 "Reference Lstm: input and InputToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001064 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001065 "Reference Lstm: input and InputToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001066 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001067 "Reference Lstm: input and InputToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001068 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001069 "Reference Lstm: input and RecurrentToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001070 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToCellWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001071 "Reference Lstm: input and RecurrentToCellWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001072 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001073 "Reference Lstm: input and RecurrentToOutputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001074 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001075 "Reference Lstm: input and ForgetGateBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001076 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001077 "Reference Lstm: input and CellBias types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001078 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001079 "Reference Lstm: input and OutputGateBias types are mismatched");
1080 if (!descriptor.m_CifgEnabled)
1081 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001082 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToInputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001083 "Reference Lstm: input and InputToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001084 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001085 reasonIfUnsupported,
1086 "Reference Lstm: input and RecurrentToInputWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001087 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputGateBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001088 "Reference Lstm: input and InputGateBias types are mismatched");
1089 if (descriptor.m_PeepholeEnabled)
1090 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001091 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToInputWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001092 reasonIfUnsupported,
1093 "Reference Lstm: input and CellToInputWeights types are mismatched");
1094 }
1095 }
1096 if (descriptor.m_PeepholeEnabled)
1097 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001098 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToForgetWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001099 "Reference Lstm: input and CellToForgetWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001100 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToOutputWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001101 "Reference Lstm: input and CellToOutputWeights types are mismatched");
1102 }
1103 if (descriptor.m_ProjectionEnabled)
1104 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001105 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionWeights()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001106 "Reference Lstm: input and mProjectionWeights types are mismatched");
1107 if (paramsInfo.m_ProjectionBias != nullptr)
1108 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001109 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionBias()), reasonIfUnsupported,
Jan Eilersd01a83c2019-07-03 18:20:40 +01001110 "Reference Lstm: input and ProjectionBias types are mismatched");
1111 }
1112 }
1113 if (descriptor.m_LayerNormEnabled)
1114 {
1115 if (!descriptor.m_CifgEnabled)
1116 {
Francis Murtaghbb590b42019-08-14 09:51:36 +01001117 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001118 reasonIfUnsupported,
1119 "Reference Lstm: input and InputLayerNormWeights types are mismatched");
1120 }
Francis Murtaghbb590b42019-08-14 09:51:36 +01001121 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001122 reasonIfUnsupported,
1123 "Reference Lstm: input and ForgetLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001124 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001125 reasonIfUnsupported,
1126 "Reference Lstm: input and CellLayerNormWeights types are mismatched");
Francis Murtaghbb590b42019-08-14 09:51:36 +01001127 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputLayerNormWeights()),
Jan Eilersd01a83c2019-07-03 18:20:40 +01001128 reasonIfUnsupported,
1129 "Reference Lstm: input and OutputLayerNormWeights types are mismatched");
1130 }
Nattapat Chaimanowongeb2b3292019-05-07 12:02:30 +01001131
1132 return supported;
telsoa01c577f2c2018-08-31 09:22:23 +01001133}
1134
saoste012df12b32018-11-28 16:57:20 +00001135bool RefLayerSupport::IsMaximumSupported(const TensorInfo& input0,
1136 const TensorInfo& input1,
1137 const TensorInfo& output,
1138 Optional<std::string&> reasonIfUnsupported) const
1139{
Sadik Armagan2999a022019-04-09 14:20:12 +01001140 bool supported = true;
1141
Keith Davis5204aa82020-01-27 15:24:59 +00001142 std::array<DataType,5> supportedTypes = {
Sadik Armagan2999a022019-04-09 14:20:12 +01001143 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001144 DataType::Float16,
Keith Davis67e6c542020-02-19 10:08:33 +00001145 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001146 DataType::QAsymmU8,
1147 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001148 };
1149
1150 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1151 "Reference maximum: input 0 is not a supported type.");
1152
1153 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1154 "Reference maximum: input 1 is not a supported type.");
1155
1156 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1157 "Reference maximum: output is not a supported type.");
1158
1159 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1160 "Reference maximum: input 0 and Input 1 types are mismatched");
1161
1162 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1163 "Reference maximum: input and output types are mismatched");
1164
1165 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1166 "Reference maximum: shapes are not suitable for implicit broadcast.");
1167
1168 return supported;
saoste012df12b32018-11-28 16:57:20 +00001169}
1170
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001171bool RefLayerSupport::IsMeanSupported(const TensorInfo& input,
1172 const TensorInfo& output,
1173 const MeanDescriptor& descriptor,
1174 Optional<std::string&> reasonIfUnsupported) const
narpra0132b90462018-09-13 11:07:48 +01001175{
James Conroy4d1ff582019-06-10 17:06:39 +01001176 bool supported = true;
1177 std::string meanLayerStr = "Mean";
1178 std::string outputTensorStr = "output";
1179
Matthew Jackson252df3a2019-09-11 09:19:18 +01001180 std::array<DataType,4> supportedTypes =
James Conroy4d1ff582019-06-10 17:06:39 +01001181 {
1182 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001183 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001184 DataType::QAsymmU8,
1185 DataType::QSymmS16
James Conroy4d1ff582019-06-10 17:06:39 +01001186 };
1187
1188 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1189 "Reference Mean: input type not supported.");
1190
1191 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1192 "Reference Mean: input and output types are mismatched");
1193
1194 if (descriptor.m_KeepDims)
1195 {
1196 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, input.GetNumDimensions()),
1197 reasonIfUnsupported,
1198 CreateIncorrectDimensionsErrorMsg(input.GetNumDimensions(),
1199 output.GetNumDimensions(),
1200 meanLayerStr, outputTensorStr).data());
1201 }
1202 else if (descriptor.m_Axis.empty())
1203 {
1204 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1205 reasonIfUnsupported,
1206 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1207 meanLayerStr, outputTensorStr).data());
1208 }
1209 else
1210 {
1211 auto outputDim = input.GetNumDimensions() - boost::numeric_cast<unsigned int>(descriptor.m_Axis.size());
1212
1213 if (outputDim > 0)
1214 {
1215 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, outputDim),
1216 reasonIfUnsupported,
1217 CreateIncorrectDimensionsErrorMsg(outputDim, output.GetNumDimensions(),
1218 meanLayerStr, outputTensorStr).data());
1219 }
1220 else
1221 {
1222 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1223 reasonIfUnsupported,
1224 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1225 meanLayerStr, outputTensorStr).data());
1226 }
1227 }
1228
1229 return supported;
narpra0132b90462018-09-13 11:07:48 +01001230}
1231
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001232bool RefLayerSupport::IsMergerSupported(const std::vector<const TensorInfo*> inputs,
Nikhil Raj8599a412018-11-19 14:51:07 +00001233 const TensorInfo& output,
Jim Flynne242f2d2019-05-22 14:24:13 +01001234 const MergerDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001235 Optional<std::string&> reasonIfUnsupported) const
1236{
Jim Flynne242f2d2019-05-22 14:24:13 +01001237 return IsConcatSupported(inputs, output, descriptor, reasonIfUnsupported);
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001238}
1239
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001240bool RefLayerSupport::IsMemCopySupported(const TensorInfo &input,
1241 const TensorInfo &output,
1242 Optional<std::string &> reasonIfUnsupported) const
1243{
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001244 bool supported = true;
1245
1246 std::array<DataType,5> supportedTypes =
1247 {
1248 DataType::Float32,
1249 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001250 DataType::QAsymmU8,
1251 DataType::QSymmS16,
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001252 DataType::Boolean
1253 };
1254
1255 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1256 "Reference MemCopy: input type not supported");
1257
1258 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1259 "Reference MemCopy: output type not supported");
1260
1261 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1262 "Reference MemCopy: input and output types are mismatched");
1263
1264 return supported;
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001265}
1266
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001267bool RefLayerSupport::IsMinimumSupported(const TensorInfo& input0,
1268 const TensorInfo& input1,
1269 const TensorInfo& output,
1270 Optional<std::string&> reasonIfUnsupported) const
1271{
Sadik Armagan2999a022019-04-09 14:20:12 +01001272 bool supported = true;
1273
Matthew Jackson9bff1442019-09-12 09:08:23 +01001274 std::array<DataType,4> supportedTypes = {
Sadik Armagan2999a022019-04-09 14:20:12 +01001275 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001276 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001277 DataType::QAsymmU8,
1278 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001279 };
1280
1281 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1282 "Reference minimum: input 0 is not a supported type.");
1283
1284 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1285 "Reference minimum: input 1 is not a supported type.");
1286
1287 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1288 "Reference minimum: output is not a supported type.");
1289
1290 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1291 "Reference minimum: input 0 and Input 1 types are mismatched");
1292
1293 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1294 "Reference minimum: input and output types are mismatched");
1295
1296 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1297 "Reference minimum: shapes are not suitable for implicit broadcast.");
1298
1299 return supported;
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00001300}
1301
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001302bool RefLayerSupport::IsMultiplicationSupported(const TensorInfo& input0,
1303 const TensorInfo& input1,
1304 const TensorInfo& output,
1305 Optional<std::string&> reasonIfUnsupported) const
1306{
Sadik Armagan2999a022019-04-09 14:20:12 +01001307 bool supported = true;
1308
Keith Davis67e6c542020-02-19 10:08:33 +00001309 std::array<DataType,6> supportedTypes = {
Sadik Armagan2999a022019-04-09 14:20:12 +01001310 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001311 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001312 DataType::QAsymmU8,
Keith Davis67e6c542020-02-19 10:08:33 +00001313 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001314 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001315 };
1316
1317 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1318 "Reference multiplication: input 0 is not a supported type.");
1319
1320 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1321 "Reference multiplication: input 1 is not a supported type.");
1322
1323 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1324 "Reference multiplication: output is not a supported type.");
1325
1326 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1327 "Reference multiplication: input 0 and Input 1 types are mismatched");
1328
1329 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1330 "Reference multiplication: input and output types are mismatched");
1331
1332 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1333 "Reference multiplication: shapes are not suitable for implicit broadcast.");
1334
1335 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001336}
1337
1338bool RefLayerSupport::IsNormalizationSupported(const TensorInfo& input,
1339 const TensorInfo& output,
1340 const NormalizationDescriptor& descriptor,
1341 Optional<std::string&> reasonIfUnsupported) const
Nina Drozd661dfa72018-10-02 11:14:17 +01001342{
Jan Eilers8eb25602020-03-09 12:13:48 +00001343 IgnoreUnused(descriptor);
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001344
1345 // Define supported types
Matteo Martincigh6aeb7712019-06-05 17:23:29 +01001346 std::array<DataType, 4> supportedTypes =
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001347 {
1348 DataType::Float16,
1349 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001350 DataType::QAsymmU8,
1351 DataType::QSymmS16
Matteo Martincigh2fc70c52019-06-05 14:12:48 +01001352 };
1353
1354 bool supported = true;
1355
1356 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1357 "Reference normalization: input type not supported.");
1358
1359 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1360 "Reference normalization: output type not supported.");
1361
1362 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1363 "Reference normalization: input and output shapes have different "
1364 "num total elements.");
1365
1366 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001367}
1368
Derek Lamberti901ea112019-12-10 22:07:09 +00001369bool RefLayerSupport::IsOutputSupported(const TensorInfo& /*output*/,
1370 Optional<std::string&> /*reasonIfUnsupported*/) const
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001371{
Narumol Prangnawaratb6441e42019-06-04 11:22:00 +01001372 return true;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001373}
1374
1375bool RefLayerSupport::IsPadSupported(const TensorInfo& input,
1376 const TensorInfo& output,
1377 const PadDescriptor& descriptor,
1378 Optional<std::string&> reasonIfUnsupported) const
1379{
Jan Eilers8eb25602020-03-09 12:13:48 +00001380 IgnoreUnused(descriptor);
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001381 bool supported = true;
1382
1383 // Define supported output and inputs types.
Matthew Jackson252df3a2019-09-11 09:19:18 +01001384 std::array<DataType,4> supportedTypes =
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001385 {
1386 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001387 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001388 DataType::QAsymmU8,
1389 DataType::QSymmS16
Narumol Prangnawarate6eaf662019-07-08 08:57:17 +01001390 };
1391
1392 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1393 "Reference pad: input is not a supported type.");
1394
1395 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1396 "Reference pad: output is not a supported type.");
1397
1398 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1399 "Reference pad: input and output types are mismatched.");
1400
1401 return supported;
Nina Drozd661dfa72018-10-02 11:14:17 +01001402}
1403
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001404bool RefLayerSupport::IsPermuteSupported(const TensorInfo& input,
1405 const TensorInfo& output,
1406 const PermuteDescriptor& descriptor,
1407 Optional<std::string&> reasonIfUnsupported) const
1408{
Jan Eilers8eb25602020-03-09 12:13:48 +00001409 IgnoreUnused(descriptor);
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001410 bool supported = true;
1411
1412 // Define supported output and inputs types.
Mike Kellyc9ea45a2020-02-28 18:11:58 +00001413 std::array<DataType, 4> supportedTypes =
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001414 {
1415 DataType::Float32,
Mike Kellyc9ea45a2020-02-28 18:11:58 +00001416 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001417 DataType::QAsymmU8,
1418 DataType::QSymmS16
Narumol Prangnawarat86bb4e12019-07-08 11:36:05 +01001419 };
1420
1421 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1422 "Reference permute: input is not a supported type.");
1423
1424 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1425 "Reference permute: output is not a supported type.");
1426
1427 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1428 "Reference permute: input and output types are mismatched.");
1429
1430 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001431}
1432
1433bool RefLayerSupport::IsPooling2dSupported(const TensorInfo& input,
1434 const TensorInfo& output,
1435 const Pooling2dDescriptor& descriptor,
1436 Optional<std::string&> reasonIfUnsupported) const
1437{
Jan Eilers8eb25602020-03-09 12:13:48 +00001438 IgnoreUnused(descriptor);
Teresa Charlina3b20472019-06-06 11:12:32 +01001439 bool supported = true;
1440
1441 // Define supported output and inputs types.
Keith Davis67e6c542020-02-19 10:08:33 +00001442 std::array<DataType,5> supportedTypes =
Teresa Charlina3b20472019-06-06 11:12:32 +01001443 {
1444 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001445 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001446 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001447 DataType::QAsymmU8,
1448 DataType::QSymmS16
Teresa Charlina3b20472019-06-06 11:12:32 +01001449 };
1450
1451 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1452 "Reference poolind2d: input is not a supported type.");
1453
1454 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1455 "Reference poolind2d: output is not a supported type.");
1456
1457 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1458 "Reference poolind2d: input and output types are mismatched.");
1459
1460 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001461}
1462
Derek Lamberti5f400d62019-03-25 15:41:58 +00001463bool RefLayerSupport::IsQuantizeSupported(const TensorInfo& input,
1464 const TensorInfo& output,
1465 Optional<std::string&> reasonIfUnsupported) const
1466{
1467 bool supported = true;
1468
Finn Williamsfd271062019-12-04 14:27:27 +00001469 // Define supported input types.
Ryan OShea9add1202020-02-07 10:06:33 +00001470 std::array<DataType,6> supportedInputTypes = {
Keith Davis5e51cd82020-01-29 16:52:59 +00001471 DataType::Float32,
Keith Davis3d8bc972020-02-04 09:31:47 +00001472 DataType::Float16,
Ryan OShea9add1202020-02-07 10:06:33 +00001473 DataType::QAsymmS8,
Keith Davis5e51cd82020-01-29 16:52:59 +00001474 DataType::QAsymmU8,
1475 DataType::QSymmS8,
1476 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001477 };
1478
1479 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
1480 "Reference quantize: input type not supported.");
1481
1482 // Define supported output types.
Ryan OShea9add1202020-02-07 10:06:33 +00001483 std::array<DataType,4> supportedOutputTypes = {
Derek Lambertif90c56d2020-01-10 17:14:08 +00001484 DataType::QAsymmU8,
Ryan OShea9add1202020-02-07 10:06:33 +00001485 DataType::QAsymmS8,
Finn Williamsfd271062019-12-04 14:27:27 +00001486 DataType::QSymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001487 DataType::QSymmS16
Derek Lamberti5f400d62019-03-25 15:41:58 +00001488 };
1489 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
1490 "Reference quantize: output type not supported.");
1491
1492 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1493 "Reference quantize: input and output shapes have different num total elements.");
1494
1495 return supported;
1496}
1497
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001498bool RefLayerSupport::IsReshapeSupported(const TensorInfo& input,
Kevin Maya023c402019-12-12 17:28:05 +00001499 const TensorInfo& output,
Matteo Martincigh992d6dc2019-01-10 17:34:20 +00001500 const ReshapeDescriptor& descriptor,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001501 Optional<std::string&> reasonIfUnsupported) const
1502{
Jan Eilers8eb25602020-03-09 12:13:48 +00001503 IgnoreUnused(output);
1504 IgnoreUnused(descriptor);
Nina Drozd2f2778f2019-05-27 10:37:05 +01001505 // Define supported output types.
Keith Davis0c2eeac2020-02-11 16:51:50 +00001506 std::array<DataType,7> supportedOutputTypes =
Nina Drozd2f2778f2019-05-27 10:37:05 +01001507 {
1508 DataType::Float32,
1509 DataType::Float16,
Narumol Prangnawarat0718ee92019-09-13 16:53:38 +01001510 DataType::Signed32,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001511 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001512 DataType::QAsymmU8,
1513 DataType::QSymmS16
Nina Drozd2f2778f2019-05-27 10:37:05 +01001514 };
Keith Davis0c2eeac2020-02-11 16:51:50 +00001515
Nina Drozd2f2778f2019-05-27 10:37:05 +01001516 return CheckSupportRule(TypeAnyOf(input, supportedOutputTypes), reasonIfUnsupported,
1517 "Reference reshape: input type not supported.");
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001518}
1519
1520bool RefLayerSupport::IsResizeBilinearSupported(const TensorInfo& input,
Sadik Armaganc625f002018-12-17 11:32:16 +00001521 const TensorInfo& output,
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001522 Optional<std::string&> reasonIfUnsupported) const
1523{
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001524 bool supported = true;
Matthew Jackson9bff1442019-09-12 09:08:23 +01001525 std::array<DataType,4> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001526 {
1527 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001528 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001529 DataType::QAsymmU8,
1530 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001531 };
Ellen Norris-Thompson3cb85f32019-06-17 11:32:49 +01001532
1533 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1534 "Reference ResizeBilinear: input type not supported");
1535
1536 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1537 "Reference ResizeBilinear: output type not supported");
1538
1539 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1540 "Reference ResizeBilinear: input and output types not matching");
1541
1542 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001543}
1544
Teresa Charlin970f43b2019-07-01 13:51:07 +01001545bool RefLayerSupport::IsResizeSupported(const TensorInfo& input,
1546 const TensorInfo& output,
1547 const ResizeDescriptor& descriptor,
1548 Optional<std::string&> reasonIfUnsupported) const
1549{
Jan Eilers8eb25602020-03-09 12:13:48 +00001550 IgnoreUnused(descriptor);
Teresa Charlin970f43b2019-07-01 13:51:07 +01001551 bool supported = true;
Keith Davis5204aa82020-01-27 15:24:59 +00001552 std::array<DataType,5> supportedTypes =
Teresa Charlin970f43b2019-07-01 13:51:07 +01001553 {
1554 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001555 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001556 DataType::QAsymmU8,
Keith Davis67e6c542020-02-19 10:08:33 +00001557 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001558 DataType::QSymmS16
Teresa Charlin970f43b2019-07-01 13:51:07 +01001559 };
1560
1561 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1562 "Reference Resize: input type not supported");
1563
1564 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1565 "Reference Resize: output type not supported");
1566
1567 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1568 "Reference Resize: input and output types not matching");
1569
1570 return supported;
1571}
1572
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001573bool RefLayerSupport::IsRsqrtSupported(const TensorInfo& input,
1574 const TensorInfo& output,
1575 Optional<std::string&> reasonIfUnsupported) const
1576{
josh minor4a3c6102020-01-06 16:40:46 -06001577 return IsElementwiseUnarySupported(input,
1578 output,
1579 ElementwiseUnaryDescriptor(UnaryOperation::Rsqrt),
1580 reasonIfUnsupported);
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +00001581}
1582
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001583bool RefLayerSupport::IsSliceSupported(const TensorInfo& input,
1584 const TensorInfo& output,
1585 const SliceDescriptor& descriptor,
1586 Optional<std::string&> reasonIfUnsupported) const
1587{
Jan Eilers8eb25602020-03-09 12:13:48 +00001588 IgnoreUnused(descriptor);
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001589 bool supported = true;
1590
1591 std::array<DataType, 3> supportedTypes =
1592 {
1593 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001594 DataType::QAsymmU8,
1595 DataType::QSymmS16
Aron Virginas-Tar92b9f872019-09-17 17:27:04 +01001596 };
1597
1598 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1599 "Reference Slice: input type not supported");
1600
1601 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1602 "Reference Slice: output type not supported");
1603
1604 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1605 "Reference Slice: input and output types are mismatched");
1606
1607 return supported;
1608}
1609
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001610bool RefLayerSupport::IsSoftmaxSupported(const TensorInfo& input,
1611 const TensorInfo& output,
1612 const SoftmaxDescriptor& descriptor,
1613 Optional<std::string&> reasonIfUnsupported) const
1614{
Jan Eilers8eb25602020-03-09 12:13:48 +00001615 IgnoreUnused(descriptor);
nikraj01248683f2019-05-29 16:46:50 +01001616 bool supported = true;
Keith Davis0c2eeac2020-02-11 16:51:50 +00001617 std::array<DataType,6> supportedTypes =
nikraj01248683f2019-05-29 16:46:50 +01001618 {
1619 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001620 DataType::Float16,
Keith Davis0c2eeac2020-02-11 16:51:50 +00001621 DataType::QSymmS8,
1622 DataType::QAsymmS8,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001623 DataType::QAsymmU8,
1624 DataType::QSymmS16
nikraj01248683f2019-05-29 16:46:50 +01001625 };
1626
1627 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001628 "Reference Softmax: output type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001629
1630 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001631 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001632
1633 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
Aron Virginas-Tare662a942019-10-14 15:12:00 +01001634 "Reference Softmax: input type not supported");
nikraj01248683f2019-05-29 16:46:50 +01001635
1636 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001637}
1638
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001639bool RefLayerSupport::IsSpaceToBatchNdSupported(const TensorInfo& input,
1640 const TensorInfo& output,
1641 const SpaceToBatchNdDescriptor& descriptor,
1642 Optional<std::string&> reasonIfUnsupported) const
1643{
Jan Eilers8eb25602020-03-09 12:13:48 +00001644 IgnoreUnused(descriptor);
nikraj01120522a2019-05-31 11:33:07 +01001645 bool supported = true;
Matthew Jackson9bff1442019-09-12 09:08:23 +01001646 std::array<DataType,4> supportedTypes =
nikraj01120522a2019-05-31 11:33:07 +01001647 {
1648 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001649 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001650 DataType::QAsymmU8,
1651 DataType::QSymmS16
nikraj01120522a2019-05-31 11:33:07 +01001652 };
1653
1654 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1655 "Reference SpaceToBatchNd: input type not supported");
1656
1657 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1658 "Reference SpaceToBatchNd: output type not supported");
1659
1660 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1661 "Reference SpaceToBatchNd: input and output types are mismatched");
1662
1663 return supported;
Nattapat Chaimanowong3ea76d52018-11-09 14:10:38 +00001664}
1665
Keith Davisa57eccb2019-06-14 17:33:22 +01001666bool RefLayerSupport::IsSpaceToDepthSupported(const TensorInfo& input,
Keith Davis51910332019-06-26 15:28:43 +01001667 const TensorInfo& output,
1668 const SpaceToDepthDescriptor& descriptor,
1669 Optional<std::string&> reasonIfUnsupported) const
Keith Davisa57eccb2019-06-14 17:33:22 +01001670{
1671
Jan Eilers8eb25602020-03-09 12:13:48 +00001672 IgnoreUnused(descriptor);
Keith Davisa57eccb2019-06-14 17:33:22 +01001673 bool supported = true;
1674
Matthew Jackson9bff1442019-09-12 09:08:23 +01001675 std::array<DataType,4> supportedTypes =
Keith Davisa57eccb2019-06-14 17:33:22 +01001676 {
1677 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001678 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001679 DataType::QAsymmU8,
1680 DataType::QSymmS16
Keith Davisa57eccb2019-06-14 17:33:22 +01001681 };
1682
1683 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1684 "Reference SpaceToDepth: input type not supported");
1685
1686 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1687 "Reference SpaceToDepth: output type not supported");
1688
1689 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1690 "Reference SpaceToDepth: input and output types are mismatched");
1691
1692 return supported;
1693}
1694
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001695bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1696 const ViewsDescriptor& descriptor,
1697 Optional<std::string&> reasonIfUnsupported) const
1698{
Jan Eilers8eb25602020-03-09 12:13:48 +00001699 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001700 bool supported = true;
Matthew Jackson9bff1442019-09-12 09:08:23 +01001701 std::array<DataType,4> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001702 {
1703 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001704 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001705 DataType::QAsymmU8,
1706 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001707 };
1708
1709 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1710 "Reference splitter: input type not supported");
1711
1712 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001713}
1714
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001715bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1716 const std::vector<std::reference_wrapper<TensorInfo>>& outputs,
1717 const ViewsDescriptor& descriptor,
1718 Optional<std::string&> reasonIfUnsupported) const
1719{
Jan Eilers8eb25602020-03-09 12:13:48 +00001720 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001721 bool supported = true;
Matthew Jackson9bff1442019-09-12 09:08:23 +01001722 std::array<DataType,4> supportedTypes =
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001723 {
1724 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001725 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001726 DataType::QAsymmU8,
1727 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001728 };
1729
1730 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1731 "Reference splitter: output type not supported");
1732 for (const TensorInfo output : outputs)
1733 {
1734 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1735 "Reference splitter: input type not supported");
1736
1737 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1738 "Reference splitter: input and output types mismatched.");
1739 }
1740
1741 return supported;
Narumol Prangnawarat15eb5832019-05-20 15:31:05 +01001742}
1743
Matthew Jackson81e601c2019-07-11 12:07:09 +01001744bool RefLayerSupport::IsStackSupported(const std::vector<const TensorInfo*>& inputs,
1745 const TensorInfo& output,
1746 const StackDescriptor& descriptor,
1747 Optional<std::string&> reasonIfUnsupported) const
1748{
Jan Eilers8eb25602020-03-09 12:13:48 +00001749 IgnoreUnused(descriptor);
Matthew Jackson81e601c2019-07-11 12:07:09 +01001750
1751 bool supported = true;
Matthew Jacksone69c3992019-09-09 14:31:21 +01001752 std::array<DataType,4> supportedTypes =
Matthew Jackson81e601c2019-07-11 12:07:09 +01001753 {
1754 DataType::Float32,
Matthew Jacksone69c3992019-09-09 14:31:21 +01001755 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001756 DataType::QAsymmU8,
1757 DataType::QSymmS16
Matthew Jackson81e601c2019-07-11 12:07:09 +01001758 };
1759
1760 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1761 "Reference stack: output type not supported");
1762 for (const TensorInfo* input : inputs)
1763 {
1764 BOOST_ASSERT(input != nullptr);
1765 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
1766 "Reference stack: input type not supported");
1767
1768 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
1769 "Reference stack: input and output types mismatched.");
1770 }
1771
1772 return supported;
1773}
1774
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00001775bool RefLayerSupport::IsStridedSliceSupported(const TensorInfo& input,
1776 const TensorInfo& output,
1777 const StridedSliceDescriptor& descriptor,
1778 Optional<std::string&> reasonIfUnsupported) const
1779{
Jan Eilers8eb25602020-03-09 12:13:48 +00001780 IgnoreUnused(descriptor);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001781 bool supported = true;
1782
1783 std::array<DataType,3> supportedTypes =
1784 {
1785 DataType::Float32,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001786 DataType::QAsymmU8,
1787 DataType::QSymmS16
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +01001788 };
1789
1790 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1791 "Reference StridedSlice: input type not supported");
1792
1793 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1794 "Reference StridedSlice: output type not supported");
1795
1796 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1797 "Reference StridedSlice: input and output types are mismatched");
1798
1799 return supported;
Nattapat Chaimanowong1216b582018-11-23 15:33:41 +00001800}
1801
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001802bool RefLayerSupport::IsSubtractionSupported(const TensorInfo& input0,
1803 const TensorInfo& input1,
1804 const TensorInfo& output,
1805 Optional<std::string&> reasonIfUnsupported) const
1806{
Sadik Armagan2999a022019-04-09 14:20:12 +01001807 bool supported = true;
1808
Matthew Jackson9bff1442019-09-12 09:08:23 +01001809 std::array<DataType,4> supportedTypes = {
Sadik Armagan2999a022019-04-09 14:20:12 +01001810 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001811 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001812 DataType::QAsymmU8,
1813 DataType::QSymmS16
Sadik Armagan2999a022019-04-09 14:20:12 +01001814 };
1815
1816 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1817 "Reference subtraction: input 0 is not a supported type.");
1818
1819 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1820 "Reference subtraction: input 1 is not a supported type.");
1821
1822 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1823 "Reference subtraction: output is not a supported type.");
1824
1825 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1826 "Reference subtraction: input 0 and Input 1 types are mismatched");
1827
1828 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1829 "Reference subtraction: input and output types are mismatched");
1830
1831 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1832 "Reference subtraction: shapes are not suitable for implicit broadcast.");
1833
1834 return supported;
Aron Virginas-Tarb5acbb72018-10-15 11:11:51 +01001835}
1836
Matteo Martincighab9e5252019-06-13 17:27:46 +01001837bool RefLayerSupport::IsPreluSupported(const TensorInfo& input,
1838 const TensorInfo& alpha,
1839 const TensorInfo& output,
1840 Optional<std::string&> reasonIfUnsupported) const
1841{
1842 bool supported = true;
1843
Matthew Jackson9bff1442019-09-12 09:08:23 +01001844 std::array<DataType, 4> supportedTypes
Matteo Martincighab9e5252019-06-13 17:27:46 +01001845 {
1846 DataType::Float32,
Matthew Jackson9bff1442019-09-12 09:08:23 +01001847 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001848 DataType::QAsymmU8,
1849 DataType::QSymmS16
Matteo Martincighab9e5252019-06-13 17:27:46 +01001850 };
1851
1852 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1853 "PReLU: input is not a supported type.");
1854
1855 supported &= CheckSupportRule(TypeAnyOf(alpha, supportedTypes), reasonIfUnsupported,
1856 "PReLU: alpha is not a supported type.");
1857
1858 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1859 "PReLU: output is not a supported type.");
1860
1861 supported &= CheckSupportRule(TypesAreEqual(input, alpha, output), reasonIfUnsupported,
1862 "PReLU: input, alpha and output types are mismatched");
1863
1864 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input, alpha, output), reasonIfUnsupported,
1865 "PReLU: shapes are not suitable for implicit broadcast");
1866
1867 return supported;
1868}
1869
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01001870bool RefLayerSupport::IsTransposeConvolution2dSupported(const TensorInfo& input,
1871 const TensorInfo& output,
1872 const TransposeConvolution2dDescriptor& descriptor,
1873 const TensorInfo& weights,
1874 const Optional<TensorInfo>& biases,
1875 Optional<std::string&> reasonIfUnsupported) const
1876{
Jan Eilers8eb25602020-03-09 12:13:48 +00001877 IgnoreUnused(descriptor);
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01001878 bool supported = true;
1879
Matthew Jackson252df3a2019-09-11 09:19:18 +01001880 std::array<DataType,4> supportedTypes =
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01001881 {
1882 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001883 DataType::Float16,
Derek Lambertif90c56d2020-01-10 17:14:08 +00001884 DataType::QAsymmU8,
1885 DataType::QSymmS16
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01001886 };
1887
1888 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1889 "Reference TransposeConvolution2d: input is not a supported type.");
1890
1891 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1892 "Reference TransposeConvolution2d: output is not a supported type.");
1893
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01001894 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1895 "Reference TransposeConvolution2d: input and output types mismatched.");
1896
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00001897
1898 const DataType inputType = input.GetDataType();
Derek Lambertif90c56d2020-01-10 17:14:08 +00001899 if (inputType == DataType::QAsymmU8)
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00001900 {
Derek Lambertid466a542020-01-22 15:37:29 +00001901 ARMNN_NO_DEPRECATE_WARN_BEGIN
1902 std::array<DataType, 3> supportedWeightTypes =
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00001903 {
Derek Lambertif90c56d2020-01-10 17:14:08 +00001904 DataType::QAsymmU8,
Derek Lambertid466a542020-01-22 15:37:29 +00001905 DataType::QSymmS8,
1906 DataType::QuantizedSymm8PerAxis //Deprecated
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00001907 };
Derek Lambertid466a542020-01-22 15:37:29 +00001908 ARMNN_NO_DEPRECATE_WARN_END
Aron Virginas-Tar94d3b932019-11-11 12:54:47 +00001909
1910 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
1911 "Reference TransposeConvolution2d: weights type not supported for "
1912 "quantized input.");
1913 }
1914 else
1915 {
1916 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
1917 "Reference TransposeConvolution2d: weights is not a supported type.");
1918
1919 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
1920 "Reference TransposeConvolution2d: input and weights types mismatched.");
1921 }
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01001922
1923 if (biases.has_value())
1924 {
Matthew Jackson252df3a2019-09-11 09:19:18 +01001925 std::array<DataType,3> biasesSupportedTypes =
Aron Virginas-Tar651aafe2019-08-05 11:52:05 +01001926 {
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01001927 DataType::Float32,
Matthew Jackson252df3a2019-09-11 09:19:18 +01001928 DataType::Float16,
Aron Virginas-Tar98180ef2019-06-26 15:02:47 +01001929 DataType::Signed32
1930 };
1931 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
1932 "Reference TransposeConvolution2d: biases is not a supported type.");
1933 }
1934
1935 return supported;
1936}
1937
Mike Kellyc9ea45a2020-02-28 18:11:58 +00001938bool RefLayerSupport::IsTransposeSupported(const TensorInfo& input,
1939 const TensorInfo& output,
1940 const TransposeDescriptor& descriptor,
1941 Optional<std::string&> reasonIfUnsupported) const
1942{
Jan Eilers8eb25602020-03-09 12:13:48 +00001943 IgnoreUnused(descriptor);
Mike Kellyc9ea45a2020-02-28 18:11:58 +00001944 bool supported = true;
1945
1946 // Define supported output and inputs types.
1947 std::array<DataType, 4> supportedTypes =
1948 {
1949 DataType::Float32,
1950 DataType::Float16,
1951 DataType::QAsymmU8,
1952 DataType::QSymmS16
1953 };
1954
1955 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1956 "Reference transpose: input is not a supported type.");
1957
1958 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1959 "Reference transpose: output is not a supported type.");
1960
1961 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1962 "Reference transpose: input and output types are mismatched.");
1963
1964 return supported;
1965}
1966
arovir011c7c81b2018-10-08 11:34:28 +01001967} // namespace armnn