From 46c09d0094b708c70bb4770693c9e704b1fbfeb1 Mon Sep 17 00:00:00 2001 From: Francis Murtagh Date: Tue, 28 May 2019 08:15:28 +0100 Subject: IVGCVSW-2970 Support QSymm16 for FullyConnected workloads * Add support for QSymm16 for FullyConnected * Add templating to Uint8 RefLayerTest to test QSymm16 Change-Id: Ie6e989daf2ca966d6c6805b8017126eb77ebfec4 Signed-off-by: Francis Murtagh --- src/backends/reference/RefLayerSupport.cpp | 82 ++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 11 deletions(-) (limited to 'src/backends/reference/RefLayerSupport.cpp') diff --git a/src/backends/reference/RefLayerSupport.cpp b/src/backends/reference/RefLayerSupport.cpp index b6da628be3..9be1ed6d74 100644 --- a/src/backends/reference/RefLayerSupport.cpp +++ b/src/backends/reference/RefLayerSupport.cpp @@ -12,6 +12,7 @@ #include #include +#include #include @@ -108,9 +109,29 @@ struct TypeAnyOf : public Rule TypeAnyOf(const TensorInfo& info, const Container& c) { m_Res = std::any_of(c.begin(), c.end(), [&info](DataType dt) - { - return dt == info.GetDataType(); - }); + { + return dt == info.GetDataType(); + }); + } +}; + +struct BiasAndWeightsTypesMatch : public Rule +{ + BiasAndWeightsTypesMatch(const TensorInfo& biases, const TensorInfo& weights) + { + m_Res = biases.GetDataType() == GetBiasTypeFromWeightsType(weights.GetDataType()).value(); + } +}; + +struct BiasAndWeightsTypesCompatible : public Rule +{ + template + BiasAndWeightsTypesCompatible(const TensorInfo& info, const Container& c) + { + m_Res = std::any_of(c.begin(), c.end(), [&info](DataType dt) + { + return dt == GetBiasTypeFromWeightsType(info.GetDataType()).value(); + }); } }; @@ -569,14 +590,53 @@ bool RefLayerSupport::IsFullyConnectedSupported(const TensorInfo& input, const FullyConnectedDescriptor& descriptor, Optional reasonIfUnsupported) const { - ignore_unused(output); - ignore_unused(weights); - ignore_unused(biases); - ignore_unused(descriptor); - return IsSupportedForDataTypeRef(reasonIfUnsupported, - input.GetDataType(), - &TrueFunc<>, - &TrueFunc<>); + bool supported = true; + + // Define supported types. + std::array supportedTypes = + { + DataType::Float32, + DataType::QuantisedAsymm8, + DataType::QuantisedSymm16 + }; + + supported &= CheckSupportRule(TypeAnyOf(input, supportedTypes), reasonIfUnsupported, + "Reference Fully Connected: input type not supported."); + + supported &= CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, + "Reference Fully Connected: output type not supported."); + + supported &= CheckSupportRule(TypesAreEqual(input, output), reasonIfUnsupported, + "Reference Fully Connected: input and output types mismatched."); + + supported &= CheckSupportRule(TypeAnyOf(weights, supportedTypes), reasonIfUnsupported, + "Reference Fully Connected: weights type not supported."); + + supported &= CheckSupportRule(TypesAreEqual(input, weights), reasonIfUnsupported, + "Reference Fully Connected: input and weight types mismatched."); + + if (descriptor.m_BiasEnabled) + { + // Defined supported types for bias + std::array + supportedBiasTypes = + { + DataType::Float32, + DataType::Signed32 + }; + + supported &= CheckSupportRule(TypeAnyOf(biases, supportedBiasTypes), reasonIfUnsupported, + "Reference Fully Connected: bias type not supported."); + + supported &= CheckSupportRule(BiasAndWeightsTypesMatch(biases, weights), reasonIfUnsupported, + "Reference Fully Connected: bias and weight types mismatch."); + + supported &= CheckSupportRule(BiasAndWeightsTypesCompatible(weights, supportedBiasTypes), reasonIfUnsupported, + "Reference Fully Connected: bias type inferred from weights is incompatible."); + + } + + return supported; } bool RefLayerSupport::IsGatherSupported(const armnn::TensorInfo& input0, -- cgit v1.2.1