From 81beae3a870004795275e9266bc43d845b9f78db Mon Sep 17 00:00:00 2001 From: Matthew Sloyan Date: Tue, 13 Jul 2021 19:46:11 +0100 Subject: IVGCVSW-6119 ConstTensorsAsInput: FullyConnected * Constant weights and biases are now stored as Constant layers. * Updated Serializer, Deserializer and unit tests to reflect this. * Updated TfLiteDelegate, TfLiteParser and OnnxParser. * Updated Schema with IsConstant and ConstantTensorsAsInputs. * Updated Ref backend to handle constant weights and bias as inputs rather than reading from member variables. * Added dynamic or constant input EndToEnd tests. !android-nn-driver:5959 Signed-off-by: Matthew Sloyan Change-Id: Ibf3cf437df1100e4b322b0d303c575c6339f9696 --- src/armnn/BackendHelper.cpp | 47 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) (limited to 'src/armnn/BackendHelper.cpp') diff --git a/src/armnn/BackendHelper.cpp b/src/armnn/BackendHelper.cpp index 13bde0aafa..9ab30f8fb2 100644 --- a/src/armnn/BackendHelper.cpp +++ b/src/armnn/BackendHelper.cpp @@ -5,6 +5,7 @@ #include #include +#include #include @@ -399,22 +400,48 @@ bool LayerSupportHandle::IsFullyConnectedSupported(const TensorInfo& input, const FullyConnectedDescriptor& descriptor, Optional reasonIfUnsupported) { - if(!descriptor.m_ConstantWeights && !m_BackendId.IsUndefined()) + if(!m_BackendId.IsUndefined()) { - auto capability = GetCapability("NonConstWeights", m_BackendId); - if (capability.has_value() && capability.value().GetValue().AsBool() == true) + auto capability = GetCapability("ConstantTensorsAsInputs", m_BackendId); + if(!capability.has_value() || capability.value().GetValue().AsBool() == false) { - return true; + if(!weights.IsConstant()) + { + return false; + } + if(descriptor.m_BiasEnabled) + { + if(!biases.IsConstant()) + { + return false; + } + } + + // At the first stage we will only print a warning. this is to give + // backend developers a chance to adopt and read weights from input slots. + ARMNN_LOG(warning) << "The backend makes use of a deprecated interface to read constant tensors. " + "If you are a backend developer please find more information in our " + "doxygen documentation on github https://github.com/ARM-software/armnn " + "under the keyword 'ConstTensorsAsInputs'."; + } + + if(!descriptor.m_ConstantWeights) + { + auto capability = GetCapability("NonConstWeights", m_BackendId); + if (capability.has_value() && capability.value().GetValue().AsBool() == true) + { + return true; + } + return false; } - return false; } return m_LayerSupport->IsFullyConnectedSupported(input, - output, - weights, - biases, - descriptor, - reasonIfUnsupported.value()); + output, + weights, + biases, + descriptor, + reasonIfUnsupported.value()); } bool LayerSupportHandle::IsGatherSupported(const TensorInfo& input0, -- cgit v1.2.1