From 58ef2c6f797f6bdb962016c519ebbc980ec2ed50 Mon Sep 17 00:00:00 2001 From: Nina Drozd Date: Thu, 16 May 2019 12:09:18 +0100 Subject: IVGCVSW-2967 Support QSymm16 for Constant workloads * Validate that output is any of supported types in WorkloadData * Validate that output is any of supported types in RefLayerSupport * Add test for constant with QuantisedSymm16 in LayerTests * Add test for creating constant workload in RefCreateWorkloadTests * Add test for constant with QuantisedSymm16 in RefLayerTests * Refactor RefConstantWorkload - BaseWorkload instead of TypedWorkload * Refactor RefConstantWorkload - remove m_RanOnce, use PostAllocationConfigure() Signed-off-by: Nina Drozd Change-Id: Ic30e61319ef4ff9c367689901f7c6d498142a9c5 --- src/backends/reference/RefLayerSupport.cpp | 16 +++++---- src/backends/reference/RefWorkloadFactory.cpp | 3 +- src/backends/reference/RefWorkloadFactory.hpp | 1 - .../reference/test/RefCreateWorkloadTests.cpp | 33 +++++++++++++++++ src/backends/reference/test/RefLayerTests.cpp | 3 +- .../reference/workloads/RefConstantWorkload.cpp | 41 ++++++++-------------- .../reference/workloads/RefConstantWorkload.hpp | 20 ++--------- 7 files changed, 63 insertions(+), 54 deletions(-) (limited to 'src/backends/reference') diff --git a/src/backends/reference/RefLayerSupport.cpp b/src/backends/reference/RefLayerSupport.cpp index 858bd878ae..7beff72dad 100644 --- a/src/backends/reference/RefLayerSupport.cpp +++ b/src/backends/reference/RefLayerSupport.cpp @@ -306,13 +306,15 @@ bool RefLayerSupport::IsConcatSupported(const std::vector inp bool RefLayerSupport::IsConstantSupported(const TensorInfo& output, Optional reasonIfUnsupported) const { - return IsSupportedForDataTypeGeneric(reasonIfUnsupported, - output.GetDataType(), - &FalseFunc<>, - &TrueFunc<>, - &TrueFunc<>, - &TrueFunc<>, - &FalseFunc<>); + std::array supportedTypes = { + DataType::Float32, + DataType::Signed32, + DataType::QuantisedAsymm8, + DataType::QuantisedSymm16 + }; + + return CheckSupportRule(TypeAnyOf(output, supportedTypes), reasonIfUnsupported, + "Reference constant: output is not a supported type."); } bool RefLayerSupport::IsConvertFp16ToFp32Supported(const TensorInfo& input, diff --git a/src/backends/reference/RefWorkloadFactory.cpp b/src/backends/reference/RefWorkloadFactory.cpp index 8c37fabe7c..45c43a92ac 100644 --- a/src/backends/reference/RefWorkloadFactory.cpp +++ b/src/backends/reference/RefWorkloadFactory.cpp @@ -253,8 +253,7 @@ std::unique_ptr RefWorkloadFactory::CreateL2Normalization(const L2Nor std::unique_ptr RefWorkloadFactory::CreateConstant(const ConstantQueueDescriptor& descriptor, const WorkloadInfo& info) const { - return MakeWorkloadHelper(descriptor, info); + return std::make_unique(descriptor, info); } std::unique_ptr RefWorkloadFactory::CreateReshape(const ReshapeQueueDescriptor& descriptor, diff --git a/src/backends/reference/RefWorkloadFactory.hpp b/src/backends/reference/RefWorkloadFactory.hpp index 86f1ec3c14..cbfcbfa363 100644 --- a/src/backends/reference/RefWorkloadFactory.hpp +++ b/src/backends/reference/RefWorkloadFactory.hpp @@ -187,7 +187,6 @@ private: template std::unique_ptr MakeWorkload(const QueueDescriptorType& descriptor, const WorkloadInfo& info) const; - }; } // namespace armnn diff --git a/src/backends/reference/test/RefCreateWorkloadTests.cpp b/src/backends/reference/test/RefCreateWorkloadTests.cpp index 024bfe1e0c..4827d2867d 100644 --- a/src/backends/reference/test/RefCreateWorkloadTests.cpp +++ b/src/backends/reference/test/RefCreateWorkloadTests.cpp @@ -701,4 +701,37 @@ BOOST_AUTO_TEST_CASE(CreateMergerDim3Uint8Workload) RefCreateMergerWorkloadTest({ 2, 3, 2, 10 }, 3); } +template +static void RefCreateConstantWorkloadTest(const armnn::TensorShape& outputShape) +{ + armnn::Graph graph; + RefWorkloadFactory factory; + auto workload = CreateConstantWorkloadTest(factory, graph, outputShape); + + // Check output is as expected + auto queueDescriptor = workload->GetData(); + auto outputHandle = boost::polymorphic_downcast(queueDescriptor.m_Outputs[0]); + BOOST_TEST((outputHandle->GetTensorInfo() == TensorInfo(outputShape, DataType))); +} + +BOOST_AUTO_TEST_CASE(CreateConstantUint8Workload) +{ + RefCreateConstantWorkloadTest({ 2, 3, 2, 10 }); +} + +BOOST_AUTO_TEST_CASE(CreateConstantInt16Workload) +{ + RefCreateConstantWorkloadTest({ 2, 3, 2, 10 }); +} + +BOOST_AUTO_TEST_CASE(CreateConstantFloat32Workload) +{ + RefCreateConstantWorkloadTest({ 2, 3, 2, 10 }); +} + +BOOST_AUTO_TEST_CASE(CreateConstantSigned32Workload) +{ + RefCreateConstantWorkloadTest({ 2, 3, 2, 10 }); +} + BOOST_AUTO_TEST_SUITE_END() diff --git a/src/backends/reference/test/RefLayerTests.cpp b/src/backends/reference/test/RefLayerTests.cpp index 053de9e14f..55a25167f5 100644 --- a/src/backends/reference/test/RefLayerTests.cpp +++ b/src/backends/reference/test/RefLayerTests.cpp @@ -385,7 +385,8 @@ ARMNN_AUTO_TEST_CASE(PadUint84d, PadUint84dTest) // Constant ARMNN_AUTO_TEST_CASE(Constant, ConstantTest) -ARMNN_AUTO_TEST_CASE(ConstantUint8, ConstantUint8Test) +ARMNN_AUTO_TEST_CASE(ConstantUint8, ConstantUint8CustomQuantizationScaleAndOffsetTest) +ARMNN_AUTO_TEST_CASE(ConstantInt16, ConstantInt16CustomQuantizationScaleAndOffsetTest) // Concat ARMNN_AUTO_TEST_CASE(Concatenation1d, Concatenation1dTest) diff --git a/src/backends/reference/workloads/RefConstantWorkload.cpp b/src/backends/reference/workloads/RefConstantWorkload.cpp index e074c6fb04..3506198410 100644 --- a/src/backends/reference/workloads/RefConstantWorkload.cpp +++ b/src/backends/reference/workloads/RefConstantWorkload.cpp @@ -16,37 +16,26 @@ namespace armnn { -template -void RefConstantWorkload::Execute() const -{ - // Considering the reference backend independently, it could be possible to initialise the intermediate tensor - // created by the layer output handler at workload construction time, rather than at workload execution time. - // However, this is not an option for other backends (e.g. CL). For consistency, we prefer to align all - // implementations. - // A similar argument can be made about performing the memory copy in the first place (the layer output handler - // could have a non-owning reference to the layer output tensor managed by the const input layer); again, this is - // not an option for other backends, and the extra complexity required to make this work for the reference backend - // may not be worth the effort (skipping a memory copy in the first inference). - ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefConstantWorkload_Execute"); +RefConstantWorkload::RefConstantWorkload( + const ConstantQueueDescriptor& descriptor, const WorkloadInfo& info) + : BaseWorkload(descriptor, info) {} - if (!m_RanOnce) - { - const ConstantQueueDescriptor& data = this->m_Data; - - BOOST_ASSERT(data.m_LayerOutput != nullptr); +void RefConstantWorkload::PostAllocationConfigure() +{ + const ConstantQueueDescriptor& data = this->m_Data; - const TensorInfo& outputInfo = GetTensorInfo(data.m_Outputs[0]); - BOOST_ASSERT(data.m_LayerOutput->GetTensorInfo().GetNumBytes() == outputInfo.GetNumBytes()); + BOOST_ASSERT(data.m_LayerOutput != nullptr); - memcpy(GetOutputTensorData(0, data), data.m_LayerOutput->GetConstTensor(), - outputInfo.GetNumBytes()); + const TensorInfo& outputInfo = GetTensorInfo(data.m_Outputs[0]); + BOOST_ASSERT(data.m_LayerOutput->GetTensorInfo().GetNumBytes() == outputInfo.GetNumBytes()); - m_RanOnce = true; - } + memcpy(GetOutputTensorData(0, data), data.m_LayerOutput->GetConstTensor(), + outputInfo.GetNumBytes()); } -template class RefConstantWorkload; -template class RefConstantWorkload; -template class RefConstantWorkload; +void RefConstantWorkload::Execute() const +{ + ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefConstantWorkload_Execute"); +} } //namespace armnn diff --git a/src/backends/reference/workloads/RefConstantWorkload.hpp b/src/backends/reference/workloads/RefConstantWorkload.hpp index 75d7ecce26..ada488a7b2 100644 --- a/src/backends/reference/workloads/RefConstantWorkload.hpp +++ b/src/backends/reference/workloads/RefConstantWorkload.hpp @@ -14,27 +14,13 @@ namespace armnn { // Base class template providing an implementation of the Constant layer common to all data types. -template -class RefConstantWorkload : public TypedWorkload +class RefConstantWorkload : public BaseWorkload { public: - RefConstantWorkload(const ConstantQueueDescriptor& descriptor, const WorkloadInfo& info) - : TypedWorkload(descriptor, info) - , m_RanOnce(false) - { - } - - using TypedWorkload::m_Data; - using TypedWorkload::TypedWorkload; + RefConstantWorkload(const ConstantQueueDescriptor& descriptor, const WorkloadInfo& info); + void PostAllocationConfigure() override; virtual void Execute() const override; - -private: - mutable bool m_RanOnce; }; -using RefConstantFloat32Workload = RefConstantWorkload; -using RefConstantUint8Workload = RefConstantWorkload; -using RefConstantInt32Workload = RefConstantWorkload; - } //namespace armnn -- cgit v1.2.1