aboutsummaryrefslogtreecommitdiff
path: root/src/backends/cl/ClBackendContext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/backends/cl/ClBackendContext.cpp')
-rw-r--r--src/backends/cl/ClBackendContext.cpp133
1 files changed, 14 insertions, 119 deletions
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::ClContextControlWrapper> ClBackendContext::Get()
-{
- static std::shared_ptr<ClBackendContext::ClContextControlWrapper> instance
- = std::make_shared<ClBackendContext::ClContextControlWrapper>();
- // 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<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;
-}
-
-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<ClTunedParameters*>(
@@ -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<ClContextControlWrapper>(
+ tuner,
+ mlgoTuner,
+ kernelProfiling
+ );
}
bool ClBackendContext::BeforeLoadNetwork(NetworkId)