diff options
Diffstat (limited to 'src/backends')
-rw-r--r-- | src/backends/cl/ClLayerSupport.cpp | 15 | ||||
-rw-r--r-- | src/backends/cl/ClLayerSupport.hpp | 5 | ||||
-rw-r--r-- | src/backends/cl/ClWorkloadFactory.cpp | 8 | ||||
-rw-r--r-- | src/backends/cl/ClWorkloadFactory.hpp | 5 | ||||
-rw-r--r-- | src/backends/cl/backend.mk | 3 | ||||
-rw-r--r-- | src/backends/cl/test/ClCreateWorkloadTests.cpp | 25 | ||||
-rw-r--r-- | src/backends/cl/test/ClLayerTests.cpp | 3 | ||||
-rw-r--r-- | src/backends/cl/workloads/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/backends/cl/workloads/ClLogSoftmaxWorkload.cpp | 48 | ||||
-rw-r--r-- | src/backends/cl/workloads/ClLogSoftmaxWorkload.hpp | 35 | ||||
-rw-r--r-- | src/backends/cl/workloads/ClWorkloads.hpp | 3 |
11 files changed, 147 insertions, 7 deletions
diff --git a/src/backends/cl/ClLayerSupport.cpp b/src/backends/cl/ClLayerSupport.cpp index 0bff96345a..74b5aadb03 100644 --- a/src/backends/cl/ClLayerSupport.cpp +++ b/src/backends/cl/ClLayerSupport.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd. All rights reserved. +// Copyright © 2017 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -38,6 +38,7 @@ #include "workloads/ClGatherWorkload.hpp" #include "workloads/ClInstanceNormalizationWorkload.hpp" #include "workloads/ClL2NormalizationFloatWorkload.hpp" +#include "workloads/ClLogSoftmaxWorkload.hpp" #include "workloads/ClLstmFloatWorkload.hpp" #include "workloads/ClMaximumWorkload.hpp" #include "workloads/ClMeanWorkload.hpp" @@ -516,6 +517,18 @@ bool ClLayerSupport::IsL2NormalizationSupported(const TensorInfo& input, descriptor); } +bool ClLayerSupport::IsLogSoftmaxSupported(const TensorInfo& input, + const TensorInfo& output, + const LogSoftmaxDescriptor& descriptor, + Optional<std::string&> reasonIfUnsupported) const +{ + FORWARD_WORKLOAD_VALIDATE_FUNC(ClLogSoftmaxWorkloadValidate, + reasonIfUnsupported, + input, + output, + descriptor); +} + bool ClLayerSupport::IsLstmSupported(const TensorInfo& input, const TensorInfo& outputStateIn, const TensorInfo& cellStateIn, diff --git a/src/backends/cl/ClLayerSupport.hpp b/src/backends/cl/ClLayerSupport.hpp index 49100bf6a2..ed0486e33b 100644 --- a/src/backends/cl/ClLayerSupport.hpp +++ b/src/backends/cl/ClLayerSupport.hpp @@ -149,6 +149,11 @@ public: const L2NormalizationDescriptor& descriptor, Optional<std::string&> reasonIfUnsupported = EmptyOptional()) const override; + bool IsLogSoftmaxSupported(const TensorInfo& input, + const TensorInfo& output, + const LogSoftmaxDescriptor& descriptor, + Optional<std::string&> reasonIfUnsupported = EmptyOptional()) const override; + bool IsLstmSupported(const TensorInfo& input, const TensorInfo& outputStateIn, const TensorInfo& cellStateIn, diff --git a/src/backends/cl/ClWorkloadFactory.cpp b/src/backends/cl/ClWorkloadFactory.cpp index 9bbf661c3c..58e17df5b8 100644 --- a/src/backends/cl/ClWorkloadFactory.cpp +++ b/src/backends/cl/ClWorkloadFactory.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd. All rights reserved. +// Copyright © 2017 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "ClWorkloadFactory.hpp" @@ -341,6 +341,12 @@ std::unique_ptr<IWorkload> ClWorkloadFactory::CreateL2Normalization(const L2Norm return MakeWorkload<ClL2NormalizationFloatWorkload, NullWorkload>(descriptor, info); } +std::unique_ptr<IWorkload> ClWorkloadFactory::CreateLogSoftmax(const LogSoftmaxQueueDescriptor& descriptor, + const WorkloadInfo& info) const +{ + return MakeWorkload<ClLogSoftmaxWorkload>(descriptor, info, m_MemoryManager->GetIntraLayerManager()); +} + std::unique_ptr<IWorkload> ClWorkloadFactory::CreateLstm(const LstmQueueDescriptor& descriptor, const WorkloadInfo& info) const { diff --git a/src/backends/cl/ClWorkloadFactory.hpp b/src/backends/cl/ClWorkloadFactory.hpp index d1e41b0e07..779da5202a 100644 --- a/src/backends/cl/ClWorkloadFactory.hpp +++ b/src/backends/cl/ClWorkloadFactory.hpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd. All rights reserved. +// Copyright © 2017 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #pragma once @@ -125,6 +125,9 @@ public: std::unique_ptr<IWorkload> CreateL2Normalization(const L2NormalizationQueueDescriptor& descriptor, const WorkloadInfo& info) const override; + std::unique_ptr<IWorkload> CreateLogSoftmax(const LogSoftmaxQueueDescriptor& descriptor, + const WorkloadInfo& info) const override; + std::unique_ptr<IWorkload> CreateLstm(const LstmQueueDescriptor& descriptor, const WorkloadInfo& info) const override; diff --git a/src/backends/cl/backend.mk b/src/backends/cl/backend.mk index 87be2caeb2..269057a952 100644 --- a/src/backends/cl/backend.mk +++ b/src/backends/cl/backend.mk @@ -1,5 +1,5 @@ # -# Copyright © 2017 ARM Ltd. All rights reserved. +# Copyright © 2017 ARM Ltd and Contributors. All rights reserved. # SPDX-License-Identifier: MIT # @@ -45,6 +45,7 @@ BACKEND_SOURCES := \ workloads/ClGatherWorkload.cpp \ workloads/ClInstanceNormalizationWorkload.cpp \ workloads/ClL2NormalizationFloatWorkload.cpp \ + workloads/ClLogSoftmaxWorkload.cpp \ workloads/ClLstmFloatWorkload.cpp \ workloads/ClMaximumWorkload.cpp \ workloads/ClMeanWorkload.cpp \ diff --git a/src/backends/cl/test/ClCreateWorkloadTests.cpp b/src/backends/cl/test/ClCreateWorkloadTests.cpp index 896d486ebf..1dd0abeadd 100644 --- a/src/backends/cl/test/ClCreateWorkloadTests.cpp +++ b/src/backends/cl/test/ClCreateWorkloadTests.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd. All rights reserved. +// Copyright © 2017 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -793,6 +793,29 @@ BOOST_AUTO_TEST_CASE(CreateL2NormalizationFloat16NhwcWorkload) ClL2NormalizationWorkloadTest<ClL2NormalizationFloatWorkload, armnn::DataType::Float16>(DataLayout::NHWC); } +template <typename LogSoftmaxWorkloadType, typename armnn::DataType DataType> +static void ClCreateLogSoftmaxWorkloadTest() +{ + Graph graph; + ClWorkloadFactory factory = + ClWorkloadFactoryHelper::GetFactory(ClWorkloadFactoryHelper::GetMemoryManager()); + + auto workload = CreateLogSoftmaxWorkloadTest<LogSoftmaxWorkloadType, DataType>(factory, graph); + + // Checks that outputs and inputs are as we expect them (see definition of CreateLogSoftmaxWorkloadTest). + LogSoftmaxQueueDescriptor queueDescriptor = workload->GetData(); + auto inputHandle = PolymorphicDowncast<IClTensorHandle*>(queueDescriptor.m_Inputs[0]); + auto outputHandle = PolymorphicDowncast<IClTensorHandle*>(queueDescriptor.m_Outputs[0]); + + BOOST_TEST(CompareIClTensorHandleShape(inputHandle, {4, 1})); + BOOST_TEST(CompareIClTensorHandleShape(outputHandle, {4, 1})); +} + +BOOST_AUTO_TEST_CASE(CreateLogSoftmaxFloat32WorkloadTest) +{ + ClCreateLogSoftmaxWorkloadTest<ClLogSoftmaxWorkload, armnn::DataType::Float32>(); +} + template <typename LstmWorkloadType> static void ClCreateLstmWorkloadTest() { diff --git a/src/backends/cl/test/ClLayerTests.cpp b/src/backends/cl/test/ClLayerTests.cpp index ac22d992af..4a3bd44429 100644 --- a/src/backends/cl/test/ClLayerTests.cpp +++ b/src/backends/cl/test/ClLayerTests.cpp @@ -668,6 +668,9 @@ ARMNN_AUTO_TEST_CASE(Simple3dSoftmaxUint8, Simple3dSoftmaxUint8Test, 1.0f) ARMNN_AUTO_TEST_CASE(Simple4dSoftmax, Simple4dSoftmaxTest, 1.0f) ARMNN_AUTO_TEST_CASE(Simple4dSoftmaxUint8, Simple4dSoftmaxUint8Test, 1.0f) +// LogSoftmax +ARMNN_AUTO_TEST_CASE(LogSoftmaxFloat32_1, LogSoftmaxTest1<DataType::Float32>) + // Space To Batch Nd ARMNN_AUTO_TEST_CASE(SpaceToBatchNdSimpleFloat32, SpaceToBatchNdSimpleFloat32Test) ARMNN_AUTO_TEST_CASE(SpaceToBatchNdMultiChannelsFloat32, SpaceToBatchNdMultiChannelsFloat32Test) diff --git a/src/backends/cl/workloads/CMakeLists.txt b/src/backends/cl/workloads/CMakeLists.txt index fe9c9fa5c7..24c09ad429 100644 --- a/src/backends/cl/workloads/CMakeLists.txt +++ b/src/backends/cl/workloads/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright © 2017 Arm Ltd. All rights reserved. +# Copyright © 2017 Arm Ltd anc Contributors. All rights reserved. # SPDX-License-Identifier: MIT # @@ -50,6 +50,8 @@ list(APPEND armnnClBackendWorkloads_sources ClInstanceNormalizationWorkload.hpp ClL2NormalizationFloatWorkload.cpp ClL2NormalizationFloatWorkload.hpp + ClLogSoftmaxWorkload.cpp + ClLogSoftmaxWorkload.hpp ClLstmFloatWorkload.cpp ClLstmFloatWorkload.hpp ClMaximumWorkload.cpp diff --git a/src/backends/cl/workloads/ClLogSoftmaxWorkload.cpp b/src/backends/cl/workloads/ClLogSoftmaxWorkload.cpp new file mode 100644 index 0000000000..bd14d514d2 --- /dev/null +++ b/src/backends/cl/workloads/ClLogSoftmaxWorkload.cpp @@ -0,0 +1,48 @@ +// +// Copyright © 2020 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "ClLogSoftmaxWorkload.hpp" +#include "ClWorkloadUtils.hpp" + +#include <aclCommon/ArmComputeTensorUtils.hpp> +#include <aclCommon/ArmComputeUtils.hpp> + +#include <cl/ClTensorHandle.hpp> + +namespace armnn +{ + +arm_compute::Status ClLogSoftmaxWorkloadValidate(const TensorInfo& input, + const TensorInfo& output, + const LogSoftmaxDescriptor& descriptor) +{ + const arm_compute::TensorInfo aclInputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(input); + const arm_compute::TensorInfo aclOutputInfo = armcomputetensorutils::BuildArmComputeTensorInfo(output); + + unsigned int aclAxis = ComputeSoftmaxAclAxis<unsigned int>(descriptor, input); + return arm_compute::CLLogSoftmaxLayer::validate(&aclInputInfo, &aclOutputInfo, descriptor.m_Beta, aclAxis); +} + +ClLogSoftmaxWorkload::ClLogSoftmaxWorkload(const LogSoftmaxQueueDescriptor& descriptor, const WorkloadInfo& info, + std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) + : BaseWorkload<LogSoftmaxQueueDescriptor>(descriptor, info) + , m_LogSoftmaxLayer(memoryManager) +{ + m_Data.ValidateInputsOutputs("ClLogSoftmaxWorkload", 1, 1); + + arm_compute::ICLTensor& input = static_cast<ClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); + arm_compute::ICLTensor& output = static_cast<ClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); + + unsigned int aclAxis = ComputeSoftmaxAclAxis<unsigned int>(m_Data.m_Parameters, info.m_InputTensorInfos[0]); + m_LogSoftmaxLayer.configure(&input, &output, m_Data.m_Parameters.m_Beta, aclAxis); +} + +void ClLogSoftmaxWorkload::Execute() const +{ + ARMNN_SCOPED_PROFILING_EVENT_CL("ClLogSoftmaxWorkload_Execute"); + RunClFunction(m_LogSoftmaxLayer, CHECK_LOCATION()); +} + +} // namespace armnn diff --git a/src/backends/cl/workloads/ClLogSoftmaxWorkload.hpp b/src/backends/cl/workloads/ClLogSoftmaxWorkload.hpp new file mode 100644 index 0000000000..9b531add19 --- /dev/null +++ b/src/backends/cl/workloads/ClLogSoftmaxWorkload.hpp @@ -0,0 +1,35 @@ +// +// Copyright © 2020 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include <armnn/Descriptors.hpp> + +#include <arm_compute/core/Error.h> +#include <arm_compute/runtime/MemoryManagerOnDemand.h> +#include <arm_compute/runtime/CL/functions/CLSoftmaxLayer.h> + + +#include <backendsCommon/Workload.hpp> + +namespace armnn +{ + +arm_compute::Status ClLogSoftmaxWorkloadValidate(const TensorInfo& input, + const TensorInfo& output, + const LogSoftmaxDescriptor& descriptor); + +class ClLogSoftmaxWorkload : public BaseWorkload<LogSoftmaxQueueDescriptor> +{ +public: + ClLogSoftmaxWorkload(const LogSoftmaxQueueDescriptor& descriptor, const WorkloadInfo& info, + std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager); + void Execute() const override; + +private: + mutable arm_compute::CLLogSoftmaxLayer m_LogSoftmaxLayer; +}; + +} // namespace armnn diff --git a/src/backends/cl/workloads/ClWorkloads.hpp b/src/backends/cl/workloads/ClWorkloads.hpp index 99f3e62de7..b48e5a62f6 100644 --- a/src/backends/cl/workloads/ClWorkloads.hpp +++ b/src/backends/cl/workloads/ClWorkloads.hpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd. All rights reserved. +// Copyright © 2017 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -24,6 +24,7 @@ #include "ClGatherWorkload.hpp" #include "ClInstanceNormalizationWorkload.hpp" #include "ClL2NormalizationFloatWorkload.hpp" +#include "ClLogSoftmaxWorkload.hpp" #include "ClLstmFloatWorkload.hpp" #include "ClConcatWorkload.hpp" #include "ClMaximumWorkload.hpp" |