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 --- .../workloads/RefFullyConnectedWorkload.cpp | 42 ++++++---------------- 1 file changed, 11 insertions(+), 31 deletions(-) (limited to 'src/backends/reference/workloads') diff --git a/src/backends/reference/workloads/RefFullyConnectedWorkload.cpp b/src/backends/reference/workloads/RefFullyConnectedWorkload.cpp index 99e3eab075..5a7951ec48 100644 --- a/src/backends/reference/workloads/RefFullyConnectedWorkload.cpp +++ b/src/backends/reference/workloads/RefFullyConnectedWorkload.cpp @@ -16,20 +16,6 @@ RefFullyConnectedWorkload::RefFullyConnectedWorkload( const FullyConnectedQueueDescriptor& descriptor, const WorkloadInfo& info) : BaseWorkload(descriptor, info) { - if (descriptor.m_Parameters.m_ConstantWeights) - { - m_Weight = std::make_unique(*(descriptor.m_Weight)); - const TensorInfo& rWeightInfo = m_Weight->GetTensorInfo(); - m_WeightShape = rWeightInfo.GetShape(); - m_WeightDecoder = MakeDecoder(rWeightInfo, m_Weight->Map(true)); - - if (descriptor.m_Parameters.m_BiasEnabled) - { - m_Bias = std::make_unique(*(descriptor.m_Bias)); - const TensorInfo& biasInfo = m_Bias->GetTensorInfo(); - m_BiasDecoder = MakeDecoder(biasInfo, m_Bias->Map(true)); - } - } } void RefFullyConnectedWorkload::PostAllocationConfigure() @@ -44,18 +30,15 @@ void RefFullyConnectedWorkload::PostAllocationConfigure(std::vector 1); m_InputShape = inputInfo.GetShape(); - if (!m_Data.m_Parameters.m_ConstantWeights) + const TensorInfo& rWeightInfo = GetTensorInfo(inputs[1]); + ARMNN_ASSERT(inputInfo.GetNumDimensions() > 1); + m_WeightShape = rWeightInfo.GetShape(); + m_WeightDecoder = MakeDecoder(rWeightInfo); + + if (m_Data.m_Parameters.m_BiasEnabled) { - const TensorInfo& rWeightInfo = GetTensorInfo(inputs[1]); - ARMNN_ASSERT(inputInfo.GetNumDimensions() > 1); - m_WeightShape = rWeightInfo.GetShape(); - m_WeightDecoder = MakeDecoder(rWeightInfo); - - if (m_Data.m_Parameters.m_BiasEnabled) - { - const TensorInfo& biasInfo = GetTensorInfo(inputs[2]); - m_BiasDecoder = MakeDecoder(biasInfo); - } + const TensorInfo& biasInfo = GetTensorInfo(inputs[2]); + m_BiasDecoder = MakeDecoder(biasInfo); } const TensorInfo& outputInfo = GetTensorInfo(outputs[0]); @@ -87,13 +70,10 @@ void RefFullyConnectedWorkload::Execute(std::vector inputs, std: std::unique_ptr> inputDecoder = MakeDecoder(GetTensorInfo(inputs[0]), inputs[0]->Map()); std::unique_ptr> OutputEncoder = MakeEncoder(GetTensorInfo(outputs[0]), outputs[0]->Map()); - if (!m_Data.m_Parameters.m_ConstantWeights) + m_WeightDecoder->Reset(inputs[1]->Map()); + if (m_Data.m_Parameters.m_BiasEnabled) { - m_WeightDecoder->Reset(inputs[1]->Map()); - if (m_Data.m_Parameters.m_BiasEnabled) - { - m_BiasDecoder->Reset(inputs[2]->Map()); - } + m_BiasDecoder->Reset(inputs[2]->Map()); } FullyConnected(m_InputShape, -- cgit v1.2.1