IVGCVSW-3830 Add NEON workload for RSQRT
authorAron Virginas-Tar <Aron.Virginas-Tar@arm.com>
Tue, 10 Sep 2019 12:55:09 +0000 (13:55 +0100)
committerÁron Virginás-Tar <aron.virginas-tar@arm.com>
Tue, 10 Sep 2019 13:56:46 +0000 (13:56 +0000)
Signed-off-by: Aron Virginas-Tar <Aron.Virginas-Tar@arm.com>
Change-Id: Ida590b7d28dbee40e496794c42b682d740427cca

src/backends/neon/NeonLayerSupport.cpp
src/backends/neon/NeonLayerSupport.hpp
src/backends/neon/NeonWorkloadFactory.cpp
src/backends/neon/backend.mk
src/backends/neon/test/NeonCreateWorkloadTests.cpp
src/backends/neon/test/NeonLayerTests.cpp
src/backends/neon/workloads/CMakeLists.txt
src/backends/neon/workloads/NeonRsqrtWorkload.cpp [new file with mode: 0644]
src/backends/neon/workloads/NeonRsqrtWorkload.hpp [new file with mode: 0644]
src/backends/neon/workloads/NeonWorkloads.hpp

index 67c1560..0d4d4c3 100644 (file)
@@ -42,6 +42,7 @@
 #include "workloads/NeonQuantizeWorkload.hpp"
 #include "workloads/NeonQuantizedLstmWorkload.hpp"
 #include "workloads/NeonResizeWorkload.hpp"
+#include "workloads/NeonRsqrtWorkload.hpp"
 #include "workloads/NeonSoftmaxBaseWorkload.hpp"
 #include "workloads/NeonSpaceToDepthWorkload.hpp"
 #include "workloads/NeonSplitterWorkload.hpp"
@@ -547,6 +548,13 @@ bool NeonLayerSupport::IsResizeBilinearSupported(const TensorInfo& input,
     return IsResizeSupported(input, output, descriptor, reasonIfUnsupported);
 }
 
+bool NeonLayerSupport::IsRsqrtSupported(const TensorInfo& input,
+                                        const TensorInfo& output,
+                                        Optional<std::string&> reasonIfUnsupported) const
+{
+    FORWARD_WORKLOAD_VALIDATE_FUNC(NeonRsqrtWorkloadValidate, reasonIfUnsupported, input, output);
+}
+
 bool NeonLayerSupport::IsSoftmaxSupported(const TensorInfo& input,
                                           const TensorInfo& output,
                                           const SoftmaxDescriptor& descriptor,
index 16a7030..cc4798e 100644 (file)
@@ -191,6 +191,10 @@ public:
                                    const TensorInfo& output,
                                    Optional<std::string&> reasonIfUnsupported = EmptyOptional()) const override;
 
+    bool IsRsqrtSupported(const TensorInfo& input,
+                          const TensorInfo& output,
+                          Optional<std::string&> reasonIfUnsupported = EmptyOptional()) const override;
+
     bool IsSoftmaxSupported(const TensorInfo& input,
                             const TensorInfo& output,
                             const SoftmaxDescriptor& descriptor,
index fc1a65d..441e27f 100644 (file)
@@ -401,7 +401,7 @@ std::unique_ptr<IWorkload> NeonWorkloadFactory::CreateDebug(const DebugQueueDesc
 std::unique_ptr<IWorkload> NeonWorkloadFactory::CreateRsqrt(const RsqrtQueueDescriptor &descriptor,
                                                             const WorkloadInfo &info) const
 {
-    return MakeWorkloadHelper<NullWorkload, NullWorkload>(descriptor, info);
+    return std::make_unique<NeonRsqrtWorkload>(descriptor, info);
 }
 
 std::unique_ptr<IWorkload> NeonWorkloadFactory::CreateTransposeConvolution2d(
index 706e8b0..5eae9e5 100644 (file)
@@ -50,6 +50,7 @@ BACKEND_SOURCES := \
         workloads/NeonQuantizeWorkload.cpp \
         workloads/NeonReshapeWorkload.cpp \
         workloads/NeonResizeWorkload.cpp \
+        workloads/NeonRsqrtWorkload.cpp \
         workloads/NeonSoftmaxBaseWorkload.cpp \
         workloads/NeonSoftmaxFloatWorkload.cpp \
         workloads/NeonSoftmaxUint8Workload.cpp \
index 643ecd5..6a4f612 100644 (file)
@@ -181,6 +181,36 @@ BOOST_AUTO_TEST_CASE(CreateMultiplicationUint8Workload)
                                       DataType::QuantisedAsymm8>();
 }
 
+template <typename WorkloadType,
+          typename DescriptorType,
+          typename LayerType,
+          armnn::DataType DataType>
+static void NeonCreateElementwiseUnaryWorkloadTest()
+{
+    Graph graph;
+    NeonWorkloadFactory factory =
+        NeonWorkloadFactoryHelper::GetFactory(NeonWorkloadFactoryHelper::GetMemoryManager());
+
+    auto workload = CreateElementwiseUnaryWorkloadTest
+        <WorkloadType, DescriptorType, LayerType, DataType>(factory, graph);
+
+    DescriptorType queueDescriptor = workload->GetData();
+
+    auto inputHandle  = boost::polymorphic_downcast<IAclTensorHandle*>(queueDescriptor.m_Inputs[0]);
+    auto outputHandle = boost::polymorphic_downcast<IAclTensorHandle*>(queueDescriptor.m_Outputs[0]);
+
+    BOOST_TEST(TestNeonTensorHandleInfo(inputHandle, TensorInfo({2, 3}, DataType)));
+    BOOST_TEST(TestNeonTensorHandleInfo(outputHandle, TensorInfo({2, 3}, DataType)));
+}
+
+BOOST_AUTO_TEST_CASE(CreateRsqrtFloat32Workload)
+{
+    NeonCreateElementwiseUnaryWorkloadTest<NeonRsqrtWorkload,
+                                           RsqrtQueueDescriptor,
+                                           RsqrtLayer,
+                                           DataType::Float32>();
+}
+
 template <typename BatchNormalizationWorkloadType, typename armnn::DataType DataType>
 static void NeonCreateBatchNormalizationWorkloadTest(DataLayout dataLayout)
 {
index d9f78e8..0566567 100644 (file)
@@ -859,6 +859,12 @@ ARMNN_AUTO_TEST_CASE(Abs3d, Abs3dTest<DataType::Float32>)
 
 ARMNN_AUTO_TEST_CASE(AbsZero, AbsZeroTest<DataType::Float32>)
 
+// Rsqrt
+ARMNN_AUTO_TEST_CASE(Rsqrt2d, Rsqrt2dTest<DataType::Float32>)
+ARMNN_AUTO_TEST_CASE(Rsqrt3d, Rsqrt3dTest<DataType::Float32>)
+ARMNN_AUTO_TEST_CASE(RsqrtZero, RsqrtZeroTest<DataType::Float32>)
+ARMNN_AUTO_TEST_CASE(RsqrtNegative, RsqrtNegativeTest<DataType::Float32>)
+
 #if defined(ARMNNREF_ENABLED)
 
 // The ARMNN_COMPARE_REF_AUTO_TEST_CASE and the ARMNN_COMPARE_REF_FIXTURE_TEST_CASE test units are not available
index e0831be..9004391 100644 (file)
@@ -62,6 +62,8 @@ list(APPEND armnnNeonBackendWorkloads_sources
     NeonReshapeWorkload.hpp
     NeonResizeWorkload.cpp
     NeonResizeWorkload.hpp
+    NeonRsqrtWorkload.cpp
+    NeonRsqrtWorkload.hpp
     NeonSoftmaxBaseWorkload.cpp
     NeonSoftmaxBaseWorkload.hpp
     NeonSoftmaxFloatWorkload.cpp
diff --git a/src/backends/neon/workloads/NeonRsqrtWorkload.cpp b/src/backends/neon/workloads/NeonRsqrtWorkload.cpp
new file mode 100644 (file)
index 0000000..b629283
--- /dev/null
@@ -0,0 +1,43 @@
+//
+// Copyright © 2019 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "NeonRsqrtWorkload.hpp"
+
+#include "NeonWorkloadUtils.hpp"
+
+#include <aclCommon/ArmComputeTensorHandle.hpp>
+#include <aclCommon/ArmComputeTensorUtils.hpp>
+
+#include <boost/cast.hpp>
+
+namespace armnn
+{
+
+arm_compute::Status NeonRsqrtWorkloadValidate(const TensorInfo& input, const TensorInfo& output)
+{
+    const arm_compute::TensorInfo aclInput  = armcomputetensorutils::BuildArmComputeTensorInfo(input);
+    const arm_compute::TensorInfo aclOutput = armcomputetensorutils::BuildArmComputeTensorInfo(output);
+
+    return arm_compute::NERsqrtLayer::validate(&aclInput, &aclOutput);
+}
+
+NeonRsqrtWorkload::NeonRsqrtWorkload(const RsqrtQueueDescriptor& descriptor, const WorkloadInfo& info)
+    : BaseWorkload<RsqrtQueueDescriptor>(descriptor, info)
+{
+    m_Data.ValidateInputsOutputs("NeonRsqrtWorkload", 1, 1);
+
+    arm_compute::ITensor& input  = boost::polymorphic_downcast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
+    arm_compute::ITensor& output = boost::polymorphic_downcast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
+
+    m_RsqrtLayer.configure(&input, &output);
+}
+
+void NeonRsqrtWorkload::Execute() const
+{
+    ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonRsqrtWorkload_Execute");
+    m_RsqrtLayer.run();
+}
+
+} // namespace armnn
diff --git a/src/backends/neon/workloads/NeonRsqrtWorkload.hpp b/src/backends/neon/workloads/NeonRsqrtWorkload.hpp
new file mode 100644 (file)
index 0000000..6f6031e
--- /dev/null
@@ -0,0 +1,28 @@
+//
+// Copyright © 2019 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include <backendsCommon/Workload.hpp>
+
+#include <arm_compute/core/Error.h>
+#include <arm_compute/runtime/NEON/functions/NEElementwiseUnaryLayer.h>
+
+namespace armnn
+{
+
+arm_compute::Status NeonRsqrtWorkloadValidate(const TensorInfo& input, const TensorInfo& output);
+
+class NeonRsqrtWorkload : public BaseWorkload<RsqrtQueueDescriptor>
+{
+public:
+    NeonRsqrtWorkload(const RsqrtQueueDescriptor& descriptor, const WorkloadInfo& info);
+    virtual void Execute() const override;
+
+private:
+    mutable arm_compute::NERsqrtLayer m_RsqrtLayer;
+};
+
+} // namespace armnn
index d807e80..4f30f33 100644 (file)
@@ -33,6 +33,7 @@
 #include "NeonQuantizeWorkload.hpp"
 #include "NeonReshapeWorkload.hpp"
 #include "NeonResizeWorkload.hpp"
+#include "NeonRsqrtWorkload.hpp"
 #include "NeonSoftmaxFloatWorkload.hpp"
 #include "NeonSoftmaxUint8Workload.hpp"
 #include "NeonSpaceToDepthWorkload.hpp"