13 #include <arm_compute/core/CL/OpenCL.h> 14 #include <arm_compute/core/CL/CLKernelLibrary.h> 15 #include <arm_compute/runtime/CL/CLScheduler.h> 16 #include <arm_compute/runtime/CL/CLTunerTypes.h> 21 struct ClBackendContext::ClContextControlWrapper
23 ClContextControlWrapper(arm_compute::CLTuner* tuner,
24 arm_compute::CLGEMMHeuristicsHandle* heuristicsHandle,
25 bool profilingEnabled)
26 : m_ClContextControl(tuner, heuristicsHandle, profilingEnabled)
31 if (arm_compute::CLScheduler::get().context()() != NULL)
37 arm_compute::CLScheduler::get().sync();
41 ARMNN_LOG(
warning) <<
"Runtime::UnloadNetwork(): an error occurred while waiting for " 42 "the queued CL requests to finish";
52 if (arm_compute::CLScheduler::get().context()() != NULL)
55 m_ClContextControl.ClearClCache();
59 ClContextControl m_ClContextControl;
64 std::transform(value.begin(), value.end(), value.begin(),
65 [](
unsigned char c){
return std::tolower(c); });
83 int v = value.
AsInt();
88 "Using default(" <<
static_cast<int>(defaultValue) <<
")";
117 tuner.set_tune_new_kernels(
true);
122 ARMNN_LOG(
info) <<
"Gpu tuning is activated. TuningLevel: Rapid (1)";
123 tuner.set_tuner_mode(arm_compute::CLTunerMode::RAPID);
126 ARMNN_LOG(
info) <<
"Gpu tuning is activated. TuningLevel: Normal (2)";
127 tuner.set_tuner_mode(arm_compute::CLTunerMode::NORMAL);
130 ARMNN_LOG(
info) <<
"Gpu tuning is activated. TuningLevel: Exhaustive (3)";
131 tuner.set_tuner_mode(arm_compute::CLTunerMode::EXHAUSTIVE);
135 tuner.set_tune_new_kernels(
false);
146 arm_compute::CLTuner* tuner =
nullptr;
147 arm_compute::CLGEMMHeuristicsHandle* mlgoTuner =
nullptr;
149 if (useLegacyTunerAPI)
151 auto clTunerParams = PolymorphicDowncast<ClTunedParameters*>(
153 tuner = &clTunerParams->m_Tuner;
181 TuningLevel tuningLevel = ConvertTuningLevel(clTunerParams->m_TuningLevel, clTunerParams->m_Mode);
188 auto tuningLevel = defaultTuningLevel;
192 if (name ==
"KernelProfilingEnabled")
194 kernelProfiling |= ParseBoolean(value, false);
195 }
else if (name ==
"TuningFile")
198 }
else if (name ==
"TuningLevel")
202 else if (name ==
"MLGOTuningFilePath")
209 m_Tuner = std::make_unique<arm_compute::CLTuner>(
true);
217 ARMNN_LOG(
info) <<
"Loading Gpu tuning data from file: " << m_TuningFile;
218 m_Tuner->load_from_file(m_TuningFile.c_str());
220 catch (
const std::exception& e)
230 ARMNN_LOG(
info) <<
"Loading Gpu MLGO tuning data from file: " << m_TuningFile;
236 catch (
const std::exception& e)
242 tuner = m_Tuner.get();
245 m_ClContextControlWrapper = std::make_unique<ClContextControlWrapper>(
260 std::lock_guard<std::mutex> lockGuard(m_Mutex);
261 m_NetworkIds.insert(networkId);
268 return m_ClContextControlWrapper->Sync();
273 bool clearCache =
false;
275 std::lock_guard<std::mutex> lockGuard(m_Mutex);
276 m_NetworkIds.erase(networkId);
277 clearCache = m_NetworkIds.empty();
282 m_ClContextControlWrapper->ClearClCache();
290 if (m_Tuner && !m_TuningFile.empty())
294 m_Tuner->save_to_file(m_TuningFile.c_str());
296 catch(
const std::exception& e)
298 ARMNN_LOG(
warning) <<
"Could not save GpuAcc tuner data to file " << m_TuningFile;
Very basic type safe variant.
bool BeforeLoadNetwork(NetworkId networkId) override
Before and after Load network events.
void ParseOptions(const std::vector< BackendOptions > &options, BackendId backend, F f)
bool AfterUnloadNetwork(NetworkId networkId) override
#define ARMNN_LOG(severity)
Copyright (c) 2021 ARM Limited and Contributors.
void ConfigureTuner(arm_compute::CLTuner &tuner, TuningLevel level)
~ClBackendContext() override
ClBackendContext(const IRuntime::CreationOptions &options)
std::shared_ptr< IGpuAccTunedParameters > m_GpuAccTunedParameters
If set, uses the GpuAcc tuned parameters from the given object when executing GPU workloads...
std::vector< BackendOptions > m_BackendOptions
Pass backend specific options.
#define ARMNN_ASSERT_MSG(COND, MSG)
std::string AsString() const
bool ParseBoolean(const BackendOptions::Var &value, bool defaultValue)
bool m_EnableGpuProfiling
Setting this flag will allow the user to obtain GPU profiling information from the runtime...
bool AsBool() const
Value getters.
std::string ParseFile(const BackendOptions::Var &value, std::string defaultValue)
TuningLevel ParseTuningLevel(const BackendOptions::Var &value, TuningLevel defaultValue)
bool IsBool() const
Type getters.
arm_compute::CLGEMMHeuristicsHandle m_MLGOTuner
bool AfterLoadNetwork(NetworkId networkId) override
std::string LowerString(std::string value)
std::string m_MLGOTuningFile
bool BeforeUnloadNetwork(NetworkId networkId) override
Before and after Unload network events.