From a959ee5f7753c073d62b0bf16ae86d18ce6fd8cc Mon Sep 17 00:00:00 2001 From: keidav01 Date: Wed, 19 Dec 2018 10:04:58 +0000 Subject: [PATCH] IVGCVSW-2211 Maximum operator support (CL) * Added CLMaximumWorkload implementation * Added CL unit tests Change-Id: I922c83fe25d17be21a5d0f4e861038463cb09789 --- src/backends/cl/ClLayerSupport.cpp | 13 ++++++ src/backends/cl/ClLayerSupport.hpp | 5 +++ src/backends/cl/ClWorkloadFactory.cpp | 2 +- src/backends/cl/backend.mk | 1 + src/backends/cl/test/ClLayerTests.cpp | 8 ++++ src/backends/cl/workloads/CMakeLists.txt | 2 + src/backends/cl/workloads/ClMaximumWorkload.cpp | 58 +++++++++++++++++++++++++ src/backends/cl/workloads/ClMaximumWorkload.hpp | 29 +++++++++++++ src/backends/cl/workloads/ClWorkloads.hpp | 1 + 9 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 src/backends/cl/workloads/ClMaximumWorkload.cpp create mode 100644 src/backends/cl/workloads/ClMaximumWorkload.hpp diff --git a/src/backends/cl/ClLayerSupport.cpp b/src/backends/cl/ClLayerSupport.cpp index d02dfb9..719412b 100644 --- a/src/backends/cl/ClLayerSupport.cpp +++ b/src/backends/cl/ClLayerSupport.cpp @@ -27,6 +27,7 @@ #include "workloads/ClFullyConnectedWorkload.hpp" #include "workloads/ClL2NormalizationFloatWorkload.hpp" #include "workloads/ClLstmFloatWorkload.hpp" +#include "workloads/ClMaximumWorkload.hpp" #include "workloads/ClMeanWorkload.hpp" #include "workloads/ClMergerWorkload.hpp" #include "workloads/ClMultiplicationWorkload.hpp" @@ -392,6 +393,18 @@ bool ClLayerSupport::IsLstmSupported(const TensorInfo& input, cellToOutputWeights); } +bool ClLayerSupport::IsMaximumSupported(const TensorInfo& input0, + const TensorInfo& input1, + const TensorInfo& output, + Optional reasonIfUnsupported) const +{ + FORWARD_WORKLOAD_VALIDATE_FUNC(ClMaximumWorkloadValidate, + reasonIfUnsupported, + input0, + input1, + output); +} + bool ClLayerSupport::IsMeanSupported(const TensorInfo& input, const TensorInfo& output, const MeanDescriptor& descriptor, diff --git a/src/backends/cl/ClLayerSupport.hpp b/src/backends/cl/ClLayerSupport.hpp index d040a54..4281dfe 100644 --- a/src/backends/cl/ClLayerSupport.hpp +++ b/src/backends/cl/ClLayerSupport.hpp @@ -126,6 +126,11 @@ public: const TensorInfo* cellToOutputWeights, Optional reasonIfUnsupported = EmptyOptional()) const override; + bool IsMaximumSupported(const TensorInfo& input0, + const TensorInfo& input1, + const TensorInfo& output, + Optional reasonIfUnsupported = EmptyOptional()) const override; + bool IsMeanSupported(const TensorInfo& input, const TensorInfo& output, const MeanDescriptor& descriptor, diff --git a/src/backends/cl/ClWorkloadFactory.cpp b/src/backends/cl/ClWorkloadFactory.cpp index 942defb..37d9b31 100644 --- a/src/backends/cl/ClWorkloadFactory.cpp +++ b/src/backends/cl/ClWorkloadFactory.cpp @@ -299,7 +299,7 @@ std::unique_ptr ClWorkloadFactory::CreateConvertFp32ToFp16( std::unique_ptr ClWorkloadFactory::CreateMaximum(const MaximumQueueDescriptor& descriptor, const WorkloadInfo& info) const { - return MakeWorkload(descriptor, info); + return MakeWorkload(descriptor, info); } std::unique_ptr ClWorkloadFactory::CreateMean(const MeanQueueDescriptor& descriptor, diff --git a/src/backends/cl/backend.mk b/src/backends/cl/backend.mk index 71b6008..ef56356 100644 --- a/src/backends/cl/backend.mk +++ b/src/backends/cl/backend.mk @@ -28,6 +28,7 @@ BACKEND_SOURCES := \ workloads/ClFullyConnectedWorkload.cpp \ workloads/ClL2NormalizationFloatWorkload.cpp \ workloads/ClLstmFloatWorkload.cpp \ + workloads/ClMaximumWorkload.cpp \ workloads/ClMeanWorkload.cpp \ workloads/ClMergerWorkload.cpp \ workloads/ClMultiplicationWorkload.cpp \ diff --git a/src/backends/cl/test/ClLayerTests.cpp b/src/backends/cl/test/ClLayerTests.cpp index 90b93d7..b89fba6 100755 --- a/src/backends/cl/test/ClLayerTests.cpp +++ b/src/backends/cl/test/ClLayerTests.cpp @@ -336,6 +336,14 @@ ARMNN_AUTO_TEST_CASE(SimpleConvertFp32ToFp16, SimpleConvertFp32ToFp16Test) ARMNN_AUTO_TEST_CASE(AdditionAfterMaxPool, AdditionAfterMaxPoolTest) +//Max +ARMNN_AUTO_TEST_CASE(MaximumSimple, MaximumSimpleTest) +ARMNN_AUTO_TEST_CASE(MaximumBroadcast1Element, MaximumBroadcast1ElementTest) +ARMNN_AUTO_TEST_CASE(MaximumBroadcast1DVector, MaximumBroadcast1DVectorTest) +ARMNN_AUTO_TEST_CASE(MaximumUint8, MaximumUint8Test) +ARMNN_AUTO_TEST_CASE(MaximumBroadcast1ElementUint8, MaximumBroadcast1ElementUint8Test) +ARMNN_AUTO_TEST_CASE(MaximumBroadcast1DVectorUint8, MaximumBroadcast1DVectorUint8Test) + // Mean ARMNN_AUTO_TEST_CASE(MeanUint8Simple, MeanUint8SimpleTest) ARMNN_AUTO_TEST_CASE(MeanUint8SimpleAxis, MeanUint8SimpleAxisTest) diff --git a/src/backends/cl/workloads/CMakeLists.txt b/src/backends/cl/workloads/CMakeLists.txt index 11a0fd2..d769e57 100644 --- a/src/backends/cl/workloads/CMakeLists.txt +++ b/src/backends/cl/workloads/CMakeLists.txt @@ -32,6 +32,8 @@ list(APPEND armnnClBackendWorkloads_sources ClL2NormalizationFloatWorkload.hpp ClLstmFloatWorkload.cpp ClLstmFloatWorkload.hpp + ClMaximumWorkload.cpp + ClMaximumWorkload.hpp ClMeanWorkload.cpp ClMeanWorkload.hpp ClMergerWorkload.cpp diff --git a/src/backends/cl/workloads/ClMaximumWorkload.cpp b/src/backends/cl/workloads/ClMaximumWorkload.cpp new file mode 100644 index 0000000..cd3192d --- /dev/null +++ b/src/backends/cl/workloads/ClMaximumWorkload.cpp @@ -0,0 +1,58 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "ClMaximumWorkload.hpp" + +#include "ClWorkloadUtils.hpp" + +#include +#include + +#include + +#include +#include +#include + +namespace armnn +{ + +using namespace armcomputetensorutils; + +arm_compute::Status ClMaximumWorkloadValidate(const TensorInfo& input0, + const TensorInfo& input1, + const TensorInfo& output) +{ + const arm_compute::TensorInfo aclInput0Info = BuildArmComputeTensorInfo(input0); + const arm_compute::TensorInfo aclInput1Info = BuildArmComputeTensorInfo(input1); + const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output); + + const arm_compute::Status aclStatus = arm_compute::CLElementwiseMax::validate(&aclInput0Info, + &aclInput1Info, + &aclOutputInfo); + + return aclStatus; +} + +ClMaximumWorkload::ClMaximumWorkload(const MaximumQueueDescriptor& descriptor, + const WorkloadInfo& info) + : BaseWorkload(descriptor, info) +{ + m_Data.ValidateInputsOutputs("ClMaximumWorkload", 2, 1); + + arm_compute::ICLTensor& input0 = static_cast(m_Data.m_Inputs[0])->GetTensor(); + arm_compute::ICLTensor& input1 = static_cast(m_Data.m_Inputs[1])->GetTensor(); + arm_compute::ICLTensor& output = static_cast(m_Data.m_Outputs[0])->GetTensor(); + + m_MaximumLayer.configure(&input0, &input1, &output); +} + +void ClMaximumWorkload::Execute() const +{ + ARMNN_SCOPED_PROFILING_EVENT_CL("ClMaximumWorkload_Execute"); + RunClFunction(m_MaximumLayer, CHECK_LOCATION()); +} + +} //namespace armnn diff --git a/src/backends/cl/workloads/ClMaximumWorkload.hpp b/src/backends/cl/workloads/ClMaximumWorkload.hpp new file mode 100644 index 0000000..e8cc5ba --- /dev/null +++ b/src/backends/cl/workloads/ClMaximumWorkload.hpp @@ -0,0 +1,29 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include + +#include + +namespace armnn +{ + +arm_compute::Status ClMaximumWorkloadValidate(const TensorInfo& input0, + const TensorInfo& input1, + const TensorInfo& output); + +class ClMaximumWorkload : public BaseWorkload +{ +public: + ClMaximumWorkload(const MaximumQueueDescriptor& descriptor, const WorkloadInfo& info); + void Execute() const override; + +private: + mutable arm_compute::CLElementwiseMax m_MaximumLayer; +}; + +} //namespace armnn \ No newline at end of file diff --git a/src/backends/cl/workloads/ClWorkloads.hpp b/src/backends/cl/workloads/ClWorkloads.hpp index 9e74327..b0b78cd 100644 --- a/src/backends/cl/workloads/ClWorkloads.hpp +++ b/src/backends/cl/workloads/ClWorkloads.hpp @@ -17,6 +17,7 @@ #include "ClL2NormalizationFloatWorkload.hpp" #include "ClLstmFloatWorkload.hpp" #include "ClMergerWorkload.hpp" +#include "ClMaximumWorkload.hpp" #include "ClMeanWorkload.hpp" #include "ClMultiplicationWorkload.hpp" #include "ClNormalizationFloatWorkload.hpp" -- 2.7.4