diff options
author | Cathal Corbett <cathal.corbett@arm.com> | 2023-01-11 13:03:21 +0000 |
---|---|---|
committer | Cathal Corbett <cathal.corbett@arm.com> | 2023-01-11 16:39:24 +0000 |
commit | d9e55f05847792edbbf6a8c2c4d3901d37f63d1f (patch) | |
tree | dc090a997991ef97dfc976eea24cfba1f732ea68 /src/backends/aclCommon | |
parent | 9c843c3e99a8cb1951399171ceddb01c43924fa2 (diff) | |
download | armnn-d9e55f05847792edbbf6a8c2c4d3901d37f63d1f.tar.gz |
Move tuning and IClTensorHandle code from cl to aclCommon backend.
* Required to enable easier future merging and rebase into experimental/GpuFsa
as part of IVGCVSW-7380.
Signed-off-by: Cathal Corbett <cathal.corbett@arm.com>
Change-Id: I066dcf00523ff430a0908666e452548ab848bd86
Diffstat (limited to 'src/backends/aclCommon')
-rw-r--r-- | src/backends/aclCommon/ArmComputeTuningUtils.cpp | 60 | ||||
-rw-r--r-- | src/backends/aclCommon/ArmComputeTuningUtils.hpp | 84 | ||||
-rw-r--r-- | src/backends/aclCommon/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/backends/aclCommon/IClTensorHandle.hpp | 22 | ||||
-rw-r--r-- | src/backends/aclCommon/common.mk | 1 |
5 files changed, 171 insertions, 1 deletions
diff --git a/src/backends/aclCommon/ArmComputeTuningUtils.cpp b/src/backends/aclCommon/ArmComputeTuningUtils.cpp new file mode 100644 index 0000000000..4680541ae5 --- /dev/null +++ b/src/backends/aclCommon/ArmComputeTuningUtils.cpp @@ -0,0 +1,60 @@ +// +// Copyright © 2023 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "ArmComputeTuningUtils.hpp" + +namespace armnn +{ + +IGpuAccTunedParameters* IGpuAccTunedParameters::CreateRaw(IGpuAccTunedParameters::Mode mode, + IGpuAccTunedParameters::TuningLevel tuningLevel) +{ + return new ClTunedParameters(mode, tuningLevel); +} + +IGpuAccTunedParametersPtr IGpuAccTunedParameters::Create(IGpuAccTunedParameters::Mode mode, + IGpuAccTunedParameters::TuningLevel tuningLevel) +{ + return IGpuAccTunedParametersPtr(CreateRaw(mode, tuningLevel), &IGpuAccTunedParameters::Destroy); +} + +void IGpuAccTunedParameters::Destroy(IGpuAccTunedParameters* params) +{ + delete params; +} + +ClTunedParameters::ClTunedParameters(IGpuAccTunedParameters::Mode mode, + IGpuAccTunedParameters::TuningLevel tuningLevel) + : m_Mode(mode) + , m_TuningLevel(tuningLevel) + , m_Tuner(mode == ClTunedParameters::Mode::UpdateTunedParameters) +{ +} + +void ClTunedParameters::Load(const char* filename) +{ + try + { + m_Tuner.load_from_file(filename); + } + catch (const std::exception& e) + { + throw Exception(std::string("Failed to load tuned parameters file '") + filename + "': " + e.what()); + } +} + +void ClTunedParameters::Save(const char* filename) const +{ + try + { + m_Tuner.save_to_file(filename); + } + catch (const std::exception& e) + { + throw Exception(std::string("Failed to save tuned parameters file to '") + filename + "': " + e.what()); + } +} + +}
\ No newline at end of file diff --git a/src/backends/aclCommon/ArmComputeTuningUtils.hpp b/src/backends/aclCommon/ArmComputeTuningUtils.hpp new file mode 100644 index 0000000000..6d99d3f08e --- /dev/null +++ b/src/backends/aclCommon/ArmComputeTuningUtils.hpp @@ -0,0 +1,84 @@ +// +// Copyright © 2023 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// +#pragma once + +#include <armnn/BackendOptions.hpp> +#include <armnn/IRuntime.hpp> +#include <armnn/Logging.hpp> + +#include <arm_compute/runtime/CL/CLTuner.h> +#include <arm_compute/runtime/CL/CLTunerTypes.h> +#include <arm_compute/runtime/CL/CLGEMMHeuristicsHandle.h> + +namespace armnn +{ + +enum class TuningLevel +{ + None, + Rapid, + Normal, + Exhaustive +}; + +inline TuningLevel ParseTuningLevel(const BackendOptions::Var& value, TuningLevel defaultValue) +{ + if (value.IsInt()) + { + int v = value.AsInt(); + if (v > static_cast<int>(TuningLevel::Exhaustive) || + v < static_cast<int>(TuningLevel::None)) + { + ARMNN_LOG(warning) << "Invalid GpuAcc tuning level ("<< v << ") selected. " + "Using default(" << static_cast<int>(defaultValue) << ")"; + } else + { + return static_cast<TuningLevel>(v); + } + } + return defaultValue; +} + +inline void ConfigureTuner(arm_compute::CLTuner &tuner, TuningLevel level) +{ + tuner.set_tune_new_kernels(true); // Turn on tuning initially. + + switch (level) + { + case TuningLevel::Rapid: + ARMNN_LOG(info) << "Gpu tuning is activated. TuningLevel: Rapid (1)"; + tuner.set_tuner_mode(arm_compute::CLTunerMode::RAPID); + break; + case TuningLevel::Normal: + ARMNN_LOG(info) << "Gpu tuning is activated. TuningLevel: Normal (2)"; + tuner.set_tuner_mode(arm_compute::CLTunerMode::NORMAL); + break; + case TuningLevel::Exhaustive: + ARMNN_LOG(info) << "Gpu tuning is activated. TuningLevel: Exhaustive (3)"; + tuner.set_tuner_mode(arm_compute::CLTunerMode::EXHAUSTIVE); + break; + case TuningLevel::None: + default: + tuner.set_tune_new_kernels(false); // Turn off tuning. Set to "use" only mode. + break; + } +} + +class ClTunedParameters : public IGpuAccTunedParameters +{ +public: + ClTunedParameters(IGpuAccTunedParameters::Mode mode, IGpuAccTunedParameters::TuningLevel tuningLevel); + + virtual void Load(const char* filename); + virtual void Save(const char* filename) const; + + Mode m_Mode; + TuningLevel m_TuningLevel; + + arm_compute::CLTuner m_Tuner; + arm_compute::CLGEMMHeuristicsHandle m_HeuristicsHandle; +}; + +}
\ No newline at end of file diff --git a/src/backends/aclCommon/CMakeLists.txt b/src/backends/aclCommon/CMakeLists.txt index 05fbe6cca9..b3bf89e750 100644 --- a/src/backends/aclCommon/CMakeLists.txt +++ b/src/backends/aclCommon/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright © 2017 Arm Ltd. All rights reserved. +# Copyright © 2017, 2023 Arm Ltd and Contributors. All rights reserved. # SPDX-License-Identifier: MIT # @@ -8,9 +8,12 @@ list(APPEND armnnAclCommon_sources ArmComputeTensorHandle.hpp ArmComputeTensorUtils.hpp ArmComputeTensorUtils.cpp + ArmComputeTuningUtils.hpp + ArmComputeTuningUtils.cpp ArmComputeUtils.hpp BaseMemoryManager.cpp BaseMemoryManager.hpp + IClTensorHandle.hpp ) if(BUILD_UNIT_TESTS) diff --git a/src/backends/aclCommon/IClTensorHandle.hpp b/src/backends/aclCommon/IClTensorHandle.hpp new file mode 100644 index 0000000000..48cf5f57d6 --- /dev/null +++ b/src/backends/aclCommon/IClTensorHandle.hpp @@ -0,0 +1,22 @@ +// +// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// +#pragma once + +#include <arm_compute/core/CL/ICLTensor.h> +#include <arm_compute/runtime/MemoryGroup.h> + +namespace armnn +{ + +class IClTensorHandle : public IAclTensorHandle +{ +public: + virtual arm_compute::ICLTensor& GetTensor() = 0; + virtual arm_compute::ICLTensor const& GetTensor() const = 0; + virtual arm_compute::DataType GetDataType() const = 0; + virtual void SetMemoryGroup(const std::shared_ptr<arm_compute::IMemoryGroup>& memoryGroup) = 0; +}; + +} //namespace armnn
\ No newline at end of file diff --git a/src/backends/aclCommon/common.mk b/src/backends/aclCommon/common.mk index 0ba966af14..b113269df9 100644 --- a/src/backends/aclCommon/common.mk +++ b/src/backends/aclCommon/common.mk @@ -9,6 +9,7 @@ COMMON_SOURCES := \ ArmComputeTensorUtils.cpp \ + ArmComputeTuningUtils.cpp \ BaseMemoryManager.cpp # COMMON_TEST_SOURCES contains the list of files to be included |