From d69c1c595375b904a7f19f562ac1d54098184b4e Mon Sep 17 00:00:00 2001 From: Cathal Corbett Date: Thu, 12 Jan 2023 11:17:03 +0000 Subject: Merge 'main' onto 'experimental/GpuFsa'. * I6c71be11e9b73694747b27fe9febab8d9669b4d4 Signed-off-by: Cathal Corbett Change-Id: Iccaf50e2484559979d801ee9d0e130e848554733 --- src/backends/cl/ClBackendContext.cpp | 133 ++++------------------------------- 1 file changed, 14 insertions(+), 119 deletions(-) (limited to 'src/backends/cl/ClBackendContext.cpp') diff --git a/src/backends/cl/ClBackendContext.cpp b/src/backends/cl/ClBackendContext.cpp index 62c6b038da..adee2763ba 100644 --- a/src/backends/cl/ClBackendContext.cpp +++ b/src/backends/cl/ClBackendContext.cpp @@ -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 // @@ -20,20 +20,11 @@ namespace armnn struct ClBackendContext::ClContextControlWrapper { - ClContextControlWrapper() {} - - bool IsInitialised() - { - return m_Initialised; - } - - void Init(arm_compute::CLTuner* tuner, - arm_compute::CLGEMMHeuristicsHandle* heuristicsHandle, - bool profilingEnabled) - { - m_ClContextControl = ClContextControl(tuner, heuristicsHandle, profilingEnabled); - m_Initialised = true; - } + ClContextControlWrapper(arm_compute::CLTuner* tuner, + arm_compute::CLGEMMHeuristicsHandle* heuristicsHandle, + bool profilingEnabled) + : m_ClContextControl(tuner, heuristicsHandle, profilingEnabled) + {} bool Sync() { @@ -62,106 +53,12 @@ struct ClBackendContext::ClContextControlWrapper { // There are no loaded networks left, so clear the CL cache to free up memory m_ClContextControl.ClearClCache(); - m_Initialised = false; } } -private: - bool m_Initialised; ClContextControl m_ClContextControl; - }; -/** - * Returns a shared_ptr to the CLContextControlWrapper. This wraps the CLContextControl and ensures that we only create - * and use one at a time. - */ -std::shared_ptr ClBackendContext::Get() -{ - static std::shared_ptr instance - = std::make_shared(); - // Instantiated on first use. - return instance; -} - -std::string LowerString(std::string value) -{ - std::transform(value.begin(), value.end(), value.begin(), - [](unsigned char c){ return std::tolower(c); }); - - return value; -} - -enum class TuningLevel -{ - None, - Rapid, - Normal, - Exhaustive -}; - - -TuningLevel ParseTuningLevel(const BackendOptions::Var& value, TuningLevel defaultValue) -{ - if (value.IsInt()) - { - int v = value.AsInt(); - if (v > static_cast(TuningLevel::Exhaustive) || - v < static_cast(TuningLevel::None)) - { - ARMNN_LOG(warning) << "Invalid GpuAcc tuning level ("<< v << ") selected. " - "Using default(" << static_cast(defaultValue) << ")"; - } else - { - return static_cast(v); - } - } - return defaultValue; -} - -bool ParseBoolean(const BackendOptions::Var& value, bool defaultValue) -{ - if (value.IsBool()) - { - return value.AsBool(); - } - return defaultValue; -} - -std::string ParseFile(const BackendOptions::Var& value, std::string defaultValue) -{ - if (value.IsString()) - { - return value.AsString(); - } - return defaultValue; -} - -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; - } -} - ClBackendContext::ClBackendContext(const IRuntime::CreationOptions& options) : IBackendContext(options) , m_TuningFile() @@ -171,7 +68,6 @@ ClBackendContext::ClBackendContext(const IRuntime::CreationOptions& options) arm_compute::CLTuner* tuner = nullptr; arm_compute::CLGEMMHeuristicsHandle* mlgoTuner = nullptr; bool useLegacyTunerAPI = options.m_GpuAccTunedParameters.get() != nullptr; - if (useLegacyTunerAPI) { auto clTunerParams = PolymorphicDowncast( @@ -217,17 +113,17 @@ ClBackendContext::ClBackendContext(const IRuntime::CreationOptions& options) { if (name == "KernelProfilingEnabled") { - kernelProfiling |= ParseBoolean(value, false); + kernelProfiling |= ParseBooleanBackendOption(value, false); } else if (name == "TuningFile") { - m_TuningFile = ParseFile(value, ""); + m_TuningFile = ParseStringBackendOption(value, ""); } else if (name == "TuningLevel") { tuningLevel = ParseTuningLevel(value, defaultTuningLevel); } else if (name == "MLGOTuningFilePath") { - m_MLGOTuningFile = ParseFile(value, ""); + m_MLGOTuningFile = ParseStringBackendOption(value, ""); } }); @@ -272,12 +168,11 @@ ClBackendContext::ClBackendContext(const IRuntime::CreationOptions& options) tuner = m_Tuner.get(); } - m_ClContextControlWrapper = Get(); - - if (!m_ClContextControlWrapper->IsInitialised()) - { - m_ClContextControlWrapper->Init(tuner, mlgoTuner, kernelProfiling); - } + m_ClContextControlWrapper = std::make_unique( + tuner, + mlgoTuner, + kernelProfiling + ); } bool ClBackendContext::BeforeLoadNetwork(NetworkId) -- cgit v1.2.1