2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
6 #include "RefLayerSupport.hpp"
7 #include "RefBackendId.hpp"
9 #include <armnn/Types.hpp>
10 #include <armnn/Descriptors.hpp>
11 #include <armnn/BackendRegistry.hpp>
13 #include <armnnUtils/DataLayoutIndexed.hpp>
15 #include <InternalTypes.hpp>
16 #include <LayerSupportCommon.hpp>
18 #include <backendsCommon/LayerSupportRules.hpp>
20 #include <boost/cast.hpp>
21 #include <boost/core/ignore_unused.hpp>
27 using namespace boost;
35 template<typename Float32Func, typename Uint8Func, typename ... Params>
36 bool IsSupportedForDataTypeRef(Optional<std::string&> reasonIfUnsupported,
38 Float32Func floatFuncPtr,
39 Uint8Func uint8FuncPtr,
42 return IsSupportedForDataTypeGeneric(reasonIfUnsupported,
44 &FalseFunc<Params...>,
47 &FalseFunc<Params...>,
48 &FalseFunc<Params...>,
49 std::forward<Params>(params)...);
52 } // anonymous namespace
57 std::string CreateIncorrectDimensionsErrorMsg(unsigned int expected,
59 std::string& layerStr,
60 std::string& tensorName)
62 std::string errorMsg = "Reference " + layerStr + ": Expected " + std::to_string(expected) + " dimensions but got" +
63 " " + std::to_string(actual) + " dimensions instead, for the '" + tensorName + "' tensor.";
68 } // anonymous namespace
70 bool RefLayerSupport::IsAbsSupported(const TensorInfo& input, const TensorInfo& output,
71 Optional<std::string&> reasonIfUnsupported) const
73 return IsElementwiseUnarySupported(input,
75 ElementwiseUnaryDescriptor(UnaryOperation::Abs),
79 bool RefLayerSupport::IsActivationSupported(const TensorInfo& input,
80 const TensorInfo& output,
81 const ActivationDescriptor& descriptor,
82 Optional<std::string&> reasonIfUnsupported) const
84 bool supported = true;
86 // Define supported types.
87 std::array<DataType,4> supportedTypes = {
94 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
95 "Reference activation: input type not supported.");
97 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
98 "Reference activation: output type not supported.");
100 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
101 "Reference activation: input and output types mismatched.");
103 supported &= CheckSupportRule(ShapesAreSameRank(input, output), reasonIfUnsupported,
104 "Reference activation: input and output shapes are of different rank.");
107 struct ActivationFunctionSupported : public Rule
109 ActivationFunctionSupported(const ActivationDescriptor& desc)
111 switch(desc.m_Function)
113 case ActivationFunction::Abs:
114 case ActivationFunction::BoundedReLu:
115 case ActivationFunction::LeakyReLu:
116 case ActivationFunction::Linear:
117 case ActivationFunction::ReLu:
118 case ActivationFunction::Sigmoid:
119 case ActivationFunction::SoftReLu:
120 case ActivationFunction::Sqrt:
121 case ActivationFunction::Square:
122 case ActivationFunction::TanH:
136 // Function is supported
137 supported &= CheckSupportRule(ActivationFunctionSupported(descriptor), reasonIfUnsupported,
138 "Reference activation: function not supported.");
143 bool RefLayerSupport::IsAdditionSupported(const TensorInfo& input0,
144 const TensorInfo& input1,
145 const TensorInfo& output,
146 Optional<std::string&> reasonIfUnsupported) const
148 bool supported = true;
150 std::array<DataType,5> supportedTypes = {
158 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
159 "Reference addition: input 0 is not a supported type.");
161 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
162 "Reference addition: input 1 is not a supported type.");
164 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
165 "Reference addition: output is not a supported type.");
167 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
168 "Reference addition: input 0 and Input 1 types are mismatched");
170 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
171 "Reference addition: input and output types are mismatched");
173 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
174 "Reference addition: shapes are not suitable for implicit broadcast.");
179 bool RefLayerSupport::IsArgMinMaxSupported(const armnn::TensorInfo &input, const armnn::TensorInfo &output,
180 const armnn::ArgMinMaxDescriptor &descriptor,
181 armnn::Optional<std::string &> reasonIfUnsupported) const
183 ignore_unused(descriptor);
185 std::array<DataType, 4> supportedTypes =
193 bool supported = true;
195 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
196 "Reference ArgMinMax: input is not a supported type.");
197 supported &= CheckSupportRule(TypeIs(output, DataType::Signed32), reasonIfUnsupported,
198 "Reference ArgMinMax: output type not supported");
203 bool RefLayerSupport::IsBatchNormalizationSupported(const TensorInfo& input,
204 const TensorInfo& output,
205 const TensorInfo& mean,
206 const TensorInfo& variance,
207 const TensorInfo& beta,
208 const TensorInfo& gamma,
209 const BatchNormalizationDescriptor& descriptor,
210 Optional<std::string&> reasonIfUnsupported) const
212 ignore_unused(descriptor);
214 std::array<DataType, 4> supportedTypes =
222 bool supported = true;
224 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
225 "Reference batch normalization: input is not a supported type.");
227 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
228 "Reference batch normalization: output is not a supported type.");
230 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
231 "Reference batch normalization: input and output types are mismatched");
233 supported &= CheckSupportRule(TypeAnyOf(mean, supportedTypes), reasonIfUnsupported,
234 "Reference batch normalization: mean is not a supported type.");
236 supported &= CheckSupportRule(TypeAnyOf(variance, supportedTypes), reasonIfUnsupported,
237 "Reference batch normalization: variance is not a supported type.");
239 supported &= CheckSupportRule(TypeAnyOf(beta, supportedTypes), reasonIfUnsupported,
240 "Reference batch normalization: beta is not a supported type.");
242 supported &= CheckSupportRule(TypeAnyOf(gamma, supportedTypes), reasonIfUnsupported,
243 "Reference batch normalization: gamma is not a supported type.");
248 bool RefLayerSupport::IsBatchToSpaceNdSupported(const TensorInfo& input,
249 const TensorInfo& output,
250 const BatchToSpaceNdDescriptor& descriptor,
251 Optional<std::string&> reasonIfUnsupported) const
253 ignore_unused(descriptor);
255 bool supported = true;
257 std::string batchToSpaceNdLayerStr = "batchToSpaceNd";
258 std::string inputTensorStr = "input";
259 std::string outputTensorStr = "output";
261 // Define supported types.
262 std::array<DataType,4> supportedTypes =
270 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
271 "Reference BatchToSpaceNd: input type not supported.");
273 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
274 "Reference BatchToSpaceNd: output type not supported.");
276 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
277 "Reference BatchToSpaceNd: input and output types mismatched.");
279 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 4),
281 CreateIncorrectDimensionsErrorMsg(4,
282 output.GetNumDimensions(),
283 batchToSpaceNdLayerStr,
284 outputTensorStr).data());
286 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(input, 4),
288 CreateIncorrectDimensionsErrorMsg(4,
289 input.GetNumDimensions(),
290 batchToSpaceNdLayerStr,
291 inputTensorStr).data());
296 bool RefLayerSupport::IsComparisonSupported(const TensorInfo& input0,
297 const TensorInfo& input1,
298 const TensorInfo& output,
299 const ComparisonDescriptor& descriptor,
300 Optional<std::string&> reasonIfUnsupported) const
302 boost::ignore_unused(descriptor);
304 std::array<DataType, 4> supportedInputTypes =
312 bool supported = true;
313 supported &= CheckSupportRule(TypeAnyOf(input0, supportedInputTypes), reasonIfUnsupported,
314 "Reference comparison: input 0 is not a supported type");
316 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
317 "Reference comparison: input 0 and Input 1 types are mismatched");
319 supported &= CheckSupportRule(TypeIs(output, DataType::Boolean), reasonIfUnsupported,
320 "Reference comparison: output is not of type Boolean");
325 bool RefLayerSupport::IsConcatSupported(const std::vector<const TensorInfo*> inputs,
326 const TensorInfo& output,
327 const ConcatDescriptor& descriptor,
328 Optional<std::string&> reasonIfUnsupported) const
330 ignore_unused(descriptor);
332 bool supported = true;
333 std::array<DataType,5> supportedTypes =
342 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
343 "Reference concatenation: output type not supported");
344 for (const TensorInfo* input : inputs)
346 BOOST_ASSERT(input != nullptr);
347 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
348 "Reference concatenation: input type not supported");
350 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
351 "Reference concatenation: input and output types mismatched.");
357 bool RefLayerSupport::IsConstantSupported(const TensorInfo& output,
358 Optional<std::string&> reasonIfUnsupported) const
360 std::array<DataType,5> supportedTypes =
369 return CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
370 "Reference constant: output is not a supported type.");
373 bool RefLayerSupport::IsConvertFp16ToFp32Supported(const TensorInfo& input,
374 const TensorInfo& output,
375 Optional<std::string&> reasonIfUnsupported) const
377 return (IsSupportedForDataTypeGeneric(reasonIfUnsupported,
380 &FalseInputFuncF32<>,
384 IsSupportedForDataTypeGeneric(reasonIfUnsupported,
385 output.GetDataType(),
386 &FalseOutputFuncF16<>,
393 bool RefLayerSupport::IsConvertFp32ToFp16Supported(const TensorInfo& input,
394 const TensorInfo& output,
395 Optional<std::string&> reasonIfUnsupported) const
397 return (IsSupportedForDataTypeGeneric(reasonIfUnsupported,
399 &FalseInputFuncF16<>,
404 IsSupportedForDataTypeGeneric(reasonIfUnsupported,
405 output.GetDataType(),
407 &FalseOutputFuncF32<>,
413 bool RefLayerSupport::IsConvolution2dSupported(const TensorInfo& input,
414 const TensorInfo& output,
415 const Convolution2dDescriptor& descriptor,
416 const TensorInfo& weights,
417 const Optional<TensorInfo>& biases,
418 Optional<std::string&> reasonIfUnsupported) const
420 bool supported = true;
422 // Define supported types.
423 std::array<DataType,5> supportedTypes =
432 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
433 "Reference Convolution2d: input is not a supported type.");
435 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
436 "Reference Convolution2d: output is not a supported type.");
438 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
439 "Reference Convolution2d: input and output types mismatched.");
441 const DataType inputType = input.GetDataType();
442 if (inputType == DataType::QAsymmU8)
444 ARMNN_NO_DEPRECATE_WARN_BEGIN
445 std::array<DataType, 3> supportedWeightTypes =
449 DataType::QuantizedSymm8PerAxis // deprecated
451 ARMNN_NO_DEPRECATE_WARN_END
453 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
454 "Reference Convolution2d: weights type not supported for quantized input.");
458 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
459 "Reference Convolution2d: weights is not a supported type.");
461 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
462 "Reference Convolution2d: input and weights types mismatched.");
465 if (biases.has_value())
467 std::array<DataType,3> biasesSupportedTypes =
474 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
475 "Reference Convolution2d: biases is not a supported type.");
477 ignore_unused(descriptor);
482 bool RefLayerSupport::IsDebugSupported(const TensorInfo& input,
483 const TensorInfo& output,
484 Optional<std::string&> reasonIfUnsupported) const
486 bool supported = true;
488 std::array<DataType, 6> supportedTypes =
498 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
499 "Reference for Debug layer: input type not supported");
501 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
502 "Reference for Debug layer: output type not supported");
504 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
505 "Reference for Debug layer: input and output types are mismatched");
510 bool RefLayerSupport::IsDepthToSpaceSupported(const TensorInfo& input,
511 const TensorInfo& output,
512 const DepthToSpaceDescriptor& descriptor,
513 Optional<std::string&> reasonIfUnsupported) const
515 ignore_unused(descriptor);
516 bool supported = true;
518 std::array<DataType,4> supportedTypes =
526 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
527 "Reference DepthToSpace: input type not supported");
529 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
530 "Reference DepthToSpace: output type not supported");
532 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
533 "Reference DepthToSpace: input and output types are mismatched");
538 bool RefLayerSupport::IsDepthwiseConvolutionSupported(const TensorInfo& input,
539 const TensorInfo& output,
540 const DepthwiseConvolution2dDescriptor& descriptor,
541 const TensorInfo& weights,
542 const Optional<TensorInfo>& biases,
543 Optional<std::string&> reasonIfUnsupported) const
545 bool supported = true;
547 // Define supported types.
548 std::array<DataType,4> supportedTypes =
556 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
557 "Reference DepthwiseConvolution2d: input is not a supported type.");
559 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
560 "Reference DepthwiseConvolution2d: output is not a supported type.");
562 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
563 "Reference DepthwiseConvolution2d: input and output types mismatched.");
565 ARMNN_NO_DEPRECATE_WARN_BEGIN
566 std::array<DataType, 3> supportedWeightTypes =
570 DataType::QuantizedSymm8PerAxis // deprecated
572 ARMNN_NO_DEPRECATE_WARN_END
574 const DataType inputType = input.GetDataType();
575 if (inputType == DataType::QAsymmU8)
578 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
579 "Reference convolution2d: weights type not supported for quantized input.");
583 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
584 "Reference DepthwiseConvolution2d: weights is not a supported type.");
586 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
587 "Reference DepthwiseConvolution2d: input and weights types mismatched.");
590 if (biases.has_value())
592 std::array<DataType,3> biasesSupportedTypes =
598 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
599 "Reference DepthwiseConvolution2d: biases is not a supported type.");
601 ignore_unused(descriptor);
607 bool RefLayerSupport::IsDequantizeSupported(const TensorInfo& input,
608 const TensorInfo& output,
609 Optional<std::string&> reasonIfUnsupported) const
611 bool supported = true;
613 std::array<DataType,3> supportedInputTypes = {
619 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
620 "Reference for Dequantize layer: input type not supported.");
622 supported &= CheckSupportRule( TypeNotPerAxisQuantized(input), reasonIfUnsupported,
623 "Reference for Dequantize layer: per-axis quantized input not support .");
625 supported &= CheckSupportRule(TypeNotPerAxisQuantized(input), reasonIfUnsupported,
626 "Reference dequantize: per-axis quantized input not support .");
628 std::array<DataType,2> supportedOutputTypes = {
633 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
634 "Reference for Dequantize layer: output type not supported.");
636 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
637 "Reference for Dequantize layer: input/output shapes have different num total "
643 bool RefLayerSupport::IsDetectionPostProcessSupported(const TensorInfo& boxEncodings,
644 const TensorInfo& scores,
645 const TensorInfo& anchors,
646 const TensorInfo& detectionBoxes,
647 const TensorInfo& detectionClasses,
648 const TensorInfo& detectionScores,
649 const TensorInfo& numDetections,
650 const DetectionPostProcessDescriptor& descriptor,
651 Optional<std::string&> reasonIfUnsupported) const
653 boost::ignore_unused(anchors, detectionBoxes, detectionClasses, detectionScores, numDetections, descriptor);
655 bool supported = true;
657 std::array<DataType,3> supportedInputTypes =
664 supported &= CheckSupportRule(TypeAnyOf(boxEncodings, supportedInputTypes), reasonIfUnsupported,
665 "Reference DetectionPostProcess: input 0 is not a supported type.");
667 supported &= CheckSupportRule(TypeAnyOf(scores, supportedInputTypes), reasonIfUnsupported,
668 "Reference DetectionPostProcess: input 1 is not a supported type.");
673 bool RefLayerSupport::IsDilatedDepthwiseConvolutionSupported(const TensorInfo& input,
674 const TensorInfo& output,
675 const DepthwiseConvolution2dDescriptor& descriptor,
676 const TensorInfo& weights,
677 const Optional<TensorInfo>& biases,
678 Optional<std::string&> reasonIfUnsupported) const
680 return IsDepthwiseConvolutionSupported(input, output, descriptor, weights, biases, reasonIfUnsupported);
683 bool RefLayerSupport::IsDivisionSupported(const TensorInfo& input0,
684 const TensorInfo& input1,
685 const TensorInfo& output,
686 Optional<std::string&> reasonIfUnsupported) const
688 bool supported = true;
690 std::array<DataType,4> supportedTypes = {
697 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
698 "Reference division: input 0 is not a supported type.");
700 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
701 "Reference division: input 1 is not a supported type.");
703 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
704 "Reference division: output is not a supported type.");
706 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
707 "Reference division: input 0 and Input 1 types are mismatched");
709 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
710 "Reference division: input and output types are mismatched");
712 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
713 "Reference division: shapes are not suitable for implicit broadcast.");
718 bool RefLayerSupport::IsElementwiseUnarySupported(const TensorInfo& input,
719 const TensorInfo& output,
720 const ElementwiseUnaryDescriptor& descriptor,
721 Optional<std::string&> reasonIfUnsupported) const
723 boost::ignore_unused(descriptor);
725 std::array<DataType, 4> supportedTypes =
733 bool supported = true;
735 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
736 "Reference elementwise unary: input type not supported");
738 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
739 "Reference elementwise unary: output type not supported");
741 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
742 "Reference elementwise unary: input and output types not matching");
744 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
745 "Reference elementwise unary: input and output shapes"
746 "have different number of total elements");
751 bool RefLayerSupport::IsEqualSupported(const TensorInfo& input0,
752 const TensorInfo& input1,
753 const TensorInfo& output,
754 Optional<std::string&> reasonIfUnsupported) const
756 return IsComparisonSupported(input0,
759 ComparisonDescriptor(ComparisonOperation::Equal),
760 reasonIfUnsupported);
763 bool RefLayerSupport::IsFakeQuantizationSupported(const TensorInfo& input,
764 const FakeQuantizationDescriptor& descriptor,
765 Optional<std::string&> reasonIfUnsupported) const
767 ignore_unused(descriptor);
768 bool supported = true;
770 std::array<DataType,1> supportedTypes =
775 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
776 "Reference fake quantization: input type not supported.");
781 bool RefLayerSupport::IsFloorSupported(const TensorInfo& input,
782 const TensorInfo& output,
783 Optional<std::string&> reasonIfUnsupported) const
785 ignore_unused(output);
786 bool supported = true;
788 std::array<DataType,3> supportedTypes =
795 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
796 "Reference Floor: input type not supported.");
798 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
799 "Reference Floor: output type not supported.");
804 bool RefLayerSupport::IsFullyConnectedSupported(const TensorInfo& input,
805 const TensorInfo& output,
806 const TensorInfo& weights,
807 const TensorInfo& biases,
808 const FullyConnectedDescriptor& descriptor,
809 Optional<std::string&> reasonIfUnsupported) const
811 bool supported = true;
813 // Define supported types.
814 std::array<DataType,4> supportedTypes =
822 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
823 "Reference Fully Connected: input type not supported.");
825 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
826 "Reference Fully Connected: output type not supported.");
828 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
829 "Reference Fully Connected: input and output types mismatched.");
831 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
832 "Reference Fully Connected: weights type not supported.");
834 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
835 "Reference Fully Connected: input and weight types mismatched.");
837 if (descriptor.m_BiasEnabled)
839 // Defined supported types for bias
840 std::array<DataType, 3>
848 supported &= CheckSupportRule(TypeAnyOf(biases, supportedBiasTypes), reasonIfUnsupported,
849 "Reference Fully Connected: bias type not supported.");
851 supported &= CheckSupportRule(BiasAndWeightsTypesMatch(biases, weights), reasonIfUnsupported,
852 "Reference Fully Connected: bias and weight types mismatch.");
854 supported &= CheckSupportRule(BiasAndWeightsTypesCompatible(weights, supportedBiasTypes), reasonIfUnsupported,
855 "Reference Fully Connected: bias type inferred from weights is incompatible.");
862 bool RefLayerSupport::IsGatherSupported(const armnn::TensorInfo& input0,
863 const armnn::TensorInfo& input1,
864 const armnn::TensorInfo& output,
865 armnn::Optional<std::string&> reasonIfUnsupported) const
867 bool supported = true;
868 std::array<DataType,4> supportedTypes =
876 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
877 "Reference Gather: input type not supported");
879 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
880 "Reference Gather: output type not supported");
882 supported &= CheckSupportRule(TypeIs(input1, DataType::Signed32), reasonIfUnsupported,
883 "Reference Gather: indices (input1) type not supported");
885 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
886 "Reference Gather: input and output types not matching");
891 bool RefLayerSupport::IsGreaterSupported(const TensorInfo& input0,
892 const TensorInfo& input1,
893 const TensorInfo& output,
894 Optional<std::string&> reasonIfUnsupported) const
896 return IsComparisonSupported(input0,
899 ComparisonDescriptor(ComparisonOperation::Greater),
900 reasonIfUnsupported);
903 bool RefLayerSupport::IsInputSupported(const TensorInfo& /*input*/,
904 Optional<std::string&> /*reasonIfUnsupported*/) const
909 bool RefLayerSupport::IsInstanceNormalizationSupported(const TensorInfo& input,
910 const TensorInfo& output,
911 const InstanceNormalizationDescriptor& descriptor,
912 Optional<std::string&> reasonIfUnsupported) const
914 ignore_unused(descriptor);
915 // Define supported types
916 std::array<DataType, 4> supportedTypes =
922 bool supported = true;
924 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
925 "Reference Instance Normalization: input type not supported.");
927 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
928 "Reference Instance Normalization: output type not supported.");
930 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
931 "Reference Instance Normalization: input and output types mismatched.");
933 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
934 "Reference Instance Normalization: input and output shapes have different "
935 "num total elements.");
940 bool RefLayerSupport::IsL2NormalizationSupported(const TensorInfo& input,
941 const TensorInfo& output,
942 const L2NormalizationDescriptor& descriptor,
943 Optional<std::string&> reasonIfUnsupported) const
945 ignore_unused(descriptor);
946 // Define supported types
947 std::array<DataType, 4> supportedTypes =
955 bool supported = true;
957 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
958 "Reference L2normalization: input type not supported.");
960 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
961 "Reference L2normalization: output type not supported.");
963 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
964 "Reference L2normalization: input and output types mismatched.");
966 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
967 "Reference L2normalization: input and output shapes have different "
968 "num total elements.");
973 bool RefLayerSupport::IsLogSoftmaxSupported(const TensorInfo& input,
974 const TensorInfo& output,
975 const LogSoftmaxDescriptor& descriptor,
976 Optional<std::string&> reasonIfUnsupported) const
978 ignore_unused(descriptor);
980 std::array<DataType, 2> supportedTypes =
986 bool supported = true;
987 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
988 "Reference LogSoftmax: input type not supported");
990 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
991 "Reference LogSoftmax: output type not supported");
993 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
994 "Reference LogSoftmax: input and output types do not match");
999 bool RefLayerSupport::IsLstmSupported(const TensorInfo& input,
1000 const TensorInfo& outputStateIn,
1001 const TensorInfo& cellStateIn,
1002 const TensorInfo& scratchBuffer,
1003 const TensorInfo& outputStateOut,
1004 const TensorInfo& cellStateOut,
1005 const TensorInfo& output,
1006 const LstmDescriptor& descriptor,
1007 const LstmInputParamsInfo& paramsInfo,
1008 Optional<std::string&> reasonIfUnsupported) const
1010 ignore_unused(descriptor);
1011 ignore_unused(paramsInfo);
1013 bool supported = true;
1015 std::array<DataType,2> supportedTypes = {
1020 // check inputs and outputs
1021 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1022 "Reference Lstm: input is not a supported type.");
1023 supported &= CheckSupportRule(TypesAreEqual(input, outputStateIn), reasonIfUnsupported,
1024 "Reference Lstm: input and outputStateIn types are mismatched");
1025 supported &= CheckSupportRule(TypesAreEqual(input, cellStateIn), reasonIfUnsupported,
1026 "Reference Lstm: input and cellStateIn types are mismatched");
1027 supported &= CheckSupportRule(TypesAreEqual(input, scratchBuffer), reasonIfUnsupported,
1028 "Reference Lstm: input and scratchBuffer types are mismatched");
1029 supported &= CheckSupportRule(TypesAreEqual(input, outputStateOut), reasonIfUnsupported,
1030 "Reference Lstm: input and outputStateOut types are mismatched");
1031 supported &= CheckSupportRule(TypesAreEqual(input, cellStateOut), reasonIfUnsupported,
1032 "Reference Lstm: input and cellStateOut types are mismatched");
1033 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1034 "Reference Lstm: input and output types are mismatched");
1035 // check layer parameters
1036 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToForgetWeights()), reasonIfUnsupported,
1037 "Reference Lstm: input and InputToForgetWeights types are mismatched");
1038 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToCellWeights()), reasonIfUnsupported,
1039 "Reference Lstm: input and InputToCellWeights types are mismatched");
1040 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToOutputWeights()), reasonIfUnsupported,
1041 "Reference Lstm: input and InputToOutputWeights types are mismatched");
1042 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToForgetWeights()), reasonIfUnsupported,
1043 "Reference Lstm: input and RecurrentToForgetWeights types are mismatched");
1044 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToCellWeights()), reasonIfUnsupported,
1045 "Reference Lstm: input and RecurrentToCellWeights types are mismatched");
1046 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToOutputWeights()), reasonIfUnsupported,
1047 "Reference Lstm: input and RecurrentToOutputWeights types are mismatched");
1048 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetGateBias()), reasonIfUnsupported,
1049 "Reference Lstm: input and ForgetGateBias types are mismatched");
1050 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellBias()), reasonIfUnsupported,
1051 "Reference Lstm: input and CellBias types are mismatched");
1052 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputGateBias()), reasonIfUnsupported,
1053 "Reference Lstm: input and OutputGateBias types are mismatched");
1054 if (!descriptor.m_CifgEnabled)
1056 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputToInputWeights()), reasonIfUnsupported,
1057 "Reference Lstm: input and InputToInputWeights types are mismatched");
1058 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetRecurrentToInputWeights()),
1059 reasonIfUnsupported,
1060 "Reference Lstm: input and RecurrentToInputWeights types are mismatched");
1061 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputGateBias()), reasonIfUnsupported,
1062 "Reference Lstm: input and InputGateBias types are mismatched");
1063 if (descriptor.m_PeepholeEnabled)
1065 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToInputWeights()),
1066 reasonIfUnsupported,
1067 "Reference Lstm: input and CellToInputWeights types are mismatched");
1070 if (descriptor.m_PeepholeEnabled)
1072 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToForgetWeights()), reasonIfUnsupported,
1073 "Reference Lstm: input and CellToForgetWeights types are mismatched");
1074 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellToOutputWeights()), reasonIfUnsupported,
1075 "Reference Lstm: input and CellToOutputWeights types are mismatched");
1077 if (descriptor.m_ProjectionEnabled)
1079 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionWeights()), reasonIfUnsupported,
1080 "Reference Lstm: input and mProjectionWeights types are mismatched");
1081 if (paramsInfo.m_ProjectionBias != nullptr)
1083 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetProjectionBias()), reasonIfUnsupported,
1084 "Reference Lstm: input and ProjectionBias types are mismatched");
1087 if (descriptor.m_LayerNormEnabled)
1089 if (!descriptor.m_CifgEnabled)
1091 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetInputLayerNormWeights()),
1092 reasonIfUnsupported,
1093 "Reference Lstm: input and InputLayerNormWeights types are mismatched");
1095 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetForgetLayerNormWeights()),
1096 reasonIfUnsupported,
1097 "Reference Lstm: input and ForgetLayerNormWeights types are mismatched");
1098 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetCellLayerNormWeights()),
1099 reasonIfUnsupported,
1100 "Reference Lstm: input and CellLayerNormWeights types are mismatched");
1101 supported &= CheckSupportRule(TypesAreEqual(input, paramsInfo.GetOutputLayerNormWeights()),
1102 reasonIfUnsupported,
1103 "Reference Lstm: input and OutputLayerNormWeights types are mismatched");
1109 bool RefLayerSupport::IsMaximumSupported(const TensorInfo& input0,
1110 const TensorInfo& input1,
1111 const TensorInfo& output,
1112 Optional<std::string&> reasonIfUnsupported) const
1114 bool supported = true;
1116 std::array<DataType,5> supportedTypes = {
1124 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1125 "Reference maximum: input 0 is not a supported type.");
1127 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1128 "Reference maximum: input 1 is not a supported type.");
1130 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1131 "Reference maximum: output is not a supported type.");
1133 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1134 "Reference maximum: input 0 and Input 1 types are mismatched");
1136 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1137 "Reference maximum: input and output types are mismatched");
1139 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1140 "Reference maximum: shapes are not suitable for implicit broadcast.");
1145 bool RefLayerSupport::IsMeanSupported(const TensorInfo& input,
1146 const TensorInfo& output,
1147 const MeanDescriptor& descriptor,
1148 Optional<std::string&> reasonIfUnsupported) const
1150 bool supported = true;
1151 std::string meanLayerStr = "Mean";
1152 std::string outputTensorStr = "output";
1154 std::array<DataType,4> supportedTypes =
1162 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1163 "Reference Mean: input type not supported.");
1165 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1166 "Reference Mean: input and output types are mismatched");
1168 if (descriptor.m_KeepDims)
1170 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, input.GetNumDimensions()),
1171 reasonIfUnsupported,
1172 CreateIncorrectDimensionsErrorMsg(input.GetNumDimensions(),
1173 output.GetNumDimensions(),
1174 meanLayerStr, outputTensorStr).data());
1176 else if (descriptor.m_Axis.empty())
1178 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1179 reasonIfUnsupported,
1180 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1181 meanLayerStr, outputTensorStr).data());
1185 auto outputDim = input.GetNumDimensions() - boost::numeric_cast<unsigned int>(descriptor.m_Axis.size());
1189 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, outputDim),
1190 reasonIfUnsupported,
1191 CreateIncorrectDimensionsErrorMsg(outputDim, output.GetNumDimensions(),
1192 meanLayerStr, outputTensorStr).data());
1196 supported &= CheckSupportRule(TensorNumDimensionsAreCorrect(output, 1),
1197 reasonIfUnsupported,
1198 CreateIncorrectDimensionsErrorMsg(1, output.GetNumDimensions(),
1199 meanLayerStr, outputTensorStr).data());
1206 bool RefLayerSupport::IsMergerSupported(const std::vector<const TensorInfo*> inputs,
1207 const TensorInfo& output,
1208 const MergerDescriptor& descriptor,
1209 Optional<std::string&> reasonIfUnsupported) const
1211 return IsConcatSupported(inputs, output, descriptor, reasonIfUnsupported);
1214 bool RefLayerSupport::IsMemCopySupported(const TensorInfo &input,
1215 const TensorInfo &output,
1216 Optional<std::string &> reasonIfUnsupported) const
1218 bool supported = true;
1220 std::array<DataType,5> supportedTypes =
1229 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1230 "Reference MemCopy: input type not supported");
1232 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1233 "Reference MemCopy: output type not supported");
1235 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1236 "Reference MemCopy: input and output types are mismatched");
1241 bool RefLayerSupport::IsMinimumSupported(const TensorInfo& input0,
1242 const TensorInfo& input1,
1243 const TensorInfo& output,
1244 Optional<std::string&> reasonIfUnsupported) const
1246 bool supported = true;
1248 std::array<DataType,4> supportedTypes = {
1255 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1256 "Reference minimum: input 0 is not a supported type.");
1258 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1259 "Reference minimum: input 1 is not a supported type.");
1261 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1262 "Reference minimum: output is not a supported type.");
1264 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1265 "Reference minimum: input 0 and Input 1 types are mismatched");
1267 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1268 "Reference minimum: input and output types are mismatched");
1270 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1271 "Reference minimum: shapes are not suitable for implicit broadcast.");
1276 bool RefLayerSupport::IsMultiplicationSupported(const TensorInfo& input0,
1277 const TensorInfo& input1,
1278 const TensorInfo& output,
1279 Optional<std::string&> reasonIfUnsupported) const
1281 bool supported = true;
1283 std::array<DataType,5> supportedTypes = {
1291 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1292 "Reference multiplication: input 0 is not a supported type.");
1294 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1295 "Reference multiplication: input 1 is not a supported type.");
1297 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1298 "Reference multiplication: output is not a supported type.");
1300 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1301 "Reference multiplication: input 0 and Input 1 types are mismatched");
1303 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1304 "Reference multiplication: input and output types are mismatched");
1306 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1307 "Reference multiplication: shapes are not suitable for implicit broadcast.");
1312 bool RefLayerSupport::IsNormalizationSupported(const TensorInfo& input,
1313 const TensorInfo& output,
1314 const NormalizationDescriptor& descriptor,
1315 Optional<std::string&> reasonIfUnsupported) const
1317 ignore_unused(descriptor);
1319 // Define supported types
1320 std::array<DataType, 4> supportedTypes =
1328 bool supported = true;
1330 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1331 "Reference normalization: input type not supported.");
1333 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1334 "Reference normalization: output type not supported.");
1336 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1337 "Reference normalization: input and output shapes have different "
1338 "num total elements.");
1343 bool RefLayerSupport::IsOutputSupported(const TensorInfo& /*output*/,
1344 Optional<std::string&> /*reasonIfUnsupported*/) const
1349 bool RefLayerSupport::IsPadSupported(const TensorInfo& input,
1350 const TensorInfo& output,
1351 const PadDescriptor& descriptor,
1352 Optional<std::string&> reasonIfUnsupported) const
1354 ignore_unused(descriptor);
1355 bool supported = true;
1357 // Define supported output and inputs types.
1358 std::array<DataType,4> supportedTypes =
1366 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1367 "Reference pad: input is not a supported type.");
1369 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1370 "Reference pad: output is not a supported type.");
1372 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1373 "Reference pad: input and output types are mismatched.");
1378 bool RefLayerSupport::IsPermuteSupported(const TensorInfo& input,
1379 const TensorInfo& output,
1380 const PermuteDescriptor& descriptor,
1381 Optional<std::string&> reasonIfUnsupported) const
1383 ignore_unused(descriptor);
1384 bool supported = true;
1386 // Define supported output and inputs types.
1387 std::array<DataType,3> supportedTypes =
1394 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1395 "Reference permute: input is not a supported type.");
1397 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1398 "Reference permute: output is not a supported type.");
1400 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1401 "Reference permute: input and output types are mismatched.");
1406 bool RefLayerSupport::IsPooling2dSupported(const TensorInfo& input,
1407 const TensorInfo& output,
1408 const Pooling2dDescriptor& descriptor,
1409 Optional<std::string&> reasonIfUnsupported) const
1411 ignore_unused(descriptor);
1412 bool supported = true;
1414 // Define supported output and inputs types.
1415 std::array<DataType,4> supportedTypes =
1423 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1424 "Reference poolind2d: input is not a supported type.");
1426 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1427 "Reference poolind2d: output is not a supported type.");
1429 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1430 "Reference poolind2d: input and output types are mismatched.");
1435 bool RefLayerSupport::IsQuantizeSupported(const TensorInfo& input,
1436 const TensorInfo& output,
1437 Optional<std::string&> reasonIfUnsupported) const
1439 bool supported = true;
1441 // Define supported input types.
1442 std::array<DataType,5> supportedInputTypes = {
1450 supported &= CheckSupportRule(TypeAnyOf(input, supportedInputTypes), reasonIfUnsupported,
1451 "Reference quantize: input type not supported.");
1453 // Define supported output types.
1454 std::array<DataType,3> supportedOutputTypes = {
1459 supported &= CheckSupportRule(TypeAnyOf(output, supportedOutputTypes), reasonIfUnsupported,
1460 "Reference quantize: output type not supported.");
1462 supported &= CheckSupportRule(ShapesAreSameTotalSize(input, output), reasonIfUnsupported,
1463 "Reference quantize: input and output shapes have different num total elements.");
1468 bool RefLayerSupport::IsReshapeSupported(const TensorInfo& input,
1469 const TensorInfo& output,
1470 const ReshapeDescriptor& descriptor,
1471 Optional<std::string&> reasonIfUnsupported) const
1473 ignore_unused(output);
1474 ignore_unused(descriptor);
1475 // Define supported output types.
1476 std::array<DataType,6> supportedOutputTypes =
1485 return CheckSupportRule(TypeAnyOf(input, supportedOutputTypes), reasonIfUnsupported,
1486 "Reference reshape: input type not supported.");
1489 bool RefLayerSupport::IsResizeBilinearSupported(const TensorInfo& input,
1490 const TensorInfo& output,
1491 Optional<std::string&> reasonIfUnsupported) const
1493 bool supported = true;
1494 std::array<DataType,4> supportedTypes =
1502 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1503 "Reference ResizeBilinear: input type not supported");
1505 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1506 "Reference ResizeBilinear: output type not supported");
1508 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1509 "Reference ResizeBilinear: input and output types not matching");
1514 bool RefLayerSupport::IsResizeSupported(const TensorInfo& input,
1515 const TensorInfo& output,
1516 const ResizeDescriptor& descriptor,
1517 Optional<std::string&> reasonIfUnsupported) const
1519 boost::ignore_unused(descriptor);
1520 bool supported = true;
1521 std::array<DataType,5> supportedTypes =
1530 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1531 "Reference Resize: input type not supported");
1533 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1534 "Reference Resize: output type not supported");
1536 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1537 "Reference Resize: input and output types not matching");
1542 bool RefLayerSupport::IsRsqrtSupported(const TensorInfo& input,
1543 const TensorInfo& output,
1544 Optional<std::string&> reasonIfUnsupported) const
1546 return IsElementwiseUnarySupported(input,
1548 ElementwiseUnaryDescriptor(UnaryOperation::Rsqrt),
1549 reasonIfUnsupported);
1552 bool RefLayerSupport::IsSliceSupported(const TensorInfo& input,
1553 const TensorInfo& output,
1554 const SliceDescriptor& descriptor,
1555 Optional<std::string&> reasonIfUnsupported) const
1557 boost::ignore_unused(descriptor);
1558 bool supported = true;
1560 std::array<DataType, 3> supportedTypes =
1567 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1568 "Reference Slice: input type not supported");
1570 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1571 "Reference Slice: output type not supported");
1573 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1574 "Reference Slice: input and output types are mismatched");
1579 bool RefLayerSupport::IsSoftmaxSupported(const TensorInfo& input,
1580 const TensorInfo& output,
1581 const SoftmaxDescriptor& descriptor,
1582 Optional<std::string&> reasonIfUnsupported) const
1584 boost::ignore_unused(descriptor);
1585 bool supported = true;
1586 std::array<DataType,4> supportedTypes =
1594 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1595 "Reference Softmax: output type not supported");
1597 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1598 "Reference Softmax: input type not supported");
1600 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1601 "Reference Softmax: input type not supported");
1606 bool RefLayerSupport::IsSpaceToBatchNdSupported(const TensorInfo& input,
1607 const TensorInfo& output,
1608 const SpaceToBatchNdDescriptor& descriptor,
1609 Optional<std::string&> reasonIfUnsupported) const
1611 boost::ignore_unused(descriptor);
1612 bool supported = true;
1613 std::array<DataType,4> supportedTypes =
1621 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1622 "Reference SpaceToBatchNd: input type not supported");
1624 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1625 "Reference SpaceToBatchNd: output type not supported");
1627 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1628 "Reference SpaceToBatchNd: input and output types are mismatched");
1633 bool RefLayerSupport::IsSpaceToDepthSupported(const TensorInfo& input,
1634 const TensorInfo& output,
1635 const SpaceToDepthDescriptor& descriptor,
1636 Optional<std::string&> reasonIfUnsupported) const
1639 ignore_unused(descriptor);
1640 bool supported = true;
1642 std::array<DataType,4> supportedTypes =
1650 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1651 "Reference SpaceToDepth: input type not supported");
1653 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1654 "Reference SpaceToDepth: output type not supported");
1656 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1657 "Reference SpaceToDepth: input and output types are mismatched");
1662 bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1663 const ViewsDescriptor& descriptor,
1664 Optional<std::string&> reasonIfUnsupported) const
1666 ignore_unused(descriptor);
1667 bool supported = true;
1668 std::array<DataType,4> supportedTypes =
1676 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1677 "Reference splitter: input type not supported");
1682 bool RefLayerSupport::IsSplitterSupported(const TensorInfo& input,
1683 const std::vector<std::reference_wrapper<TensorInfo>>& outputs,
1684 const ViewsDescriptor& descriptor,
1685 Optional<std::string&> reasonIfUnsupported) const
1687 ignore_unused(descriptor);
1688 bool supported = true;
1689 std::array<DataType,4> supportedTypes =
1697 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1698 "Reference splitter: output type not supported");
1699 for (const TensorInfo output : outputs)
1701 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1702 "Reference splitter: input type not supported");
1704 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1705 "Reference splitter: input and output types mismatched.");
1711 bool RefLayerSupport::IsStackSupported(const std::vector<const TensorInfo*>& inputs,
1712 const TensorInfo& output,
1713 const StackDescriptor& descriptor,
1714 Optional<std::string&> reasonIfUnsupported) const
1716 ignore_unused(descriptor);
1718 bool supported = true;
1719 std::array<DataType,4> supportedTypes =
1727 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1728 "Reference stack: output type not supported");
1729 for (const TensorInfo* input : inputs)
1731 BOOST_ASSERT(input != nullptr);
1732 supported &= CheckSupportRule(TypeAnyOf(*input, supportedTypes), reasonIfUnsupported,
1733 "Reference stack: input type not supported");
1735 supported &= CheckSupportRule(TypesAreEqual(*input, output), reasonIfUnsupported,
1736 "Reference stack: input and output types mismatched.");
1742 bool RefLayerSupport::IsStridedSliceSupported(const TensorInfo& input,
1743 const TensorInfo& output,
1744 const StridedSliceDescriptor& descriptor,
1745 Optional<std::string&> reasonIfUnsupported) const
1747 ignore_unused(descriptor);
1748 bool supported = true;
1750 std::array<DataType,3> supportedTypes =
1757 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1758 "Reference StridedSlice: input type not supported");
1760 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1761 "Reference StridedSlice: output type not supported");
1763 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1764 "Reference StridedSlice: input and output types are mismatched");
1769 bool RefLayerSupport::IsSubtractionSupported(const TensorInfo& input0,
1770 const TensorInfo& input1,
1771 const TensorInfo& output,
1772 Optional<std::string&> reasonIfUnsupported) const
1774 bool supported = true;
1776 std::array<DataType,4> supportedTypes = {
1783 supported &= CheckSupportRule(TypeAnyOf(input0, supportedTypes), reasonIfUnsupported,
1784 "Reference subtraction: input 0 is not a supported type.");
1786 supported &= CheckSupportRule(TypeAnyOf(input1, supportedTypes), reasonIfUnsupported,
1787 "Reference subtraction: input 1 is not a supported type.");
1789 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1790 "Reference subtraction: output is not a supported type.");
1792 supported &= CheckSupportRule(TypesAreEqual(input0, input1), reasonIfUnsupported,
1793 "Reference subtraction: input 0 and Input 1 types are mismatched");
1795 supported &= CheckSupportRule(TypesAreEqual(input0, output), reasonIfUnsupported,
1796 "Reference subtraction: input and output types are mismatched");
1798 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input0, input1, output), reasonIfUnsupported,
1799 "Reference subtraction: shapes are not suitable for implicit broadcast.");
1804 bool RefLayerSupport::IsPreluSupported(const TensorInfo& input,
1805 const TensorInfo& alpha,
1806 const TensorInfo& output,
1807 Optional<std::string&> reasonIfUnsupported) const
1809 bool supported = true;
1811 std::array<DataType, 4> supportedTypes
1819 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1820 "PReLU: input is not a supported type.");
1822 supported &= CheckSupportRule(TypeAnyOf(alpha, supportedTypes), reasonIfUnsupported,
1823 "PReLU: alpha is not a supported type.");
1825 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1826 "PReLU: output is not a supported type.");
1828 supported &= CheckSupportRule(TypesAreEqual(input, alpha, output), reasonIfUnsupported,
1829 "PReLU: input, alpha and output types are mismatched");
1831 supported &= CheckSupportRule(ShapesAreBroadcastCompatible(input, alpha, output), reasonIfUnsupported,
1832 "PReLU: shapes are not suitable for implicit broadcast");
1837 bool RefLayerSupport::IsTransposeConvolution2dSupported(const TensorInfo& input,
1838 const TensorInfo& output,
1839 const TransposeConvolution2dDescriptor& descriptor,
1840 const TensorInfo& weights,
1841 const Optional<TensorInfo>& biases,
1842 Optional<std::string&> reasonIfUnsupported) const
1844 boost::ignore_unused(descriptor);
1845 bool supported = true;
1847 std::array<DataType,4> supportedTypes =
1855 supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported,
1856 "Reference TransposeConvolution2d: input is not a supported type.");
1858 supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported,
1859 "Reference TransposeConvolution2d: output is not a supported type.");
1861 supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported,
1862 "Reference TransposeConvolution2d: input and output types mismatched.");
1865 const DataType inputType = input.GetDataType();
1866 if (inputType == DataType::QAsymmU8)
1868 ARMNN_NO_DEPRECATE_WARN_BEGIN
1869 std::array<DataType, 3> supportedWeightTypes =
1873 DataType::QuantizedSymm8PerAxis //Deprecated
1875 ARMNN_NO_DEPRECATE_WARN_END
1877 supported &= CheckSupportRule(TypeAnyOf(weights, supportedWeightTypes), reasonIfUnsupported,
1878 "Reference TransposeConvolution2d: weights type not supported for "
1879 "quantized input.");
1883 supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported,
1884 "Reference TransposeConvolution2d: weights is not a supported type.");
1886 supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported,
1887 "Reference TransposeConvolution2d: input and weights types mismatched.");
1890 if (biases.has_value())
1892 std::array<DataType,3> biasesSupportedTypes =
1898 supported &= CheckSupportRule(TypeAnyOf(biases.value(), biasesSupportedTypes), reasonIfUnsupported,
1899 "Reference TransposeConvolution2d: biases is not a supported type.");
1905 } // namespace armnn