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();
39 catch (
const cl::Error&)
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;
68 arm_compute::CLTuner* tuner =
nullptr;
69 arm_compute::CLGEMMHeuristicsHandle* mlgoTuner =
nullptr;
71 if (useLegacyTunerAPI)
73 auto clTunerParams = PolymorphicDowncast<ClTunedParameters*>(
75 tuner = &clTunerParams->m_Tuner;
103 TuningLevel tuningLevel = ConvertTuningLevel(clTunerParams->m_TuningLevel, clTunerParams->m_Mode);
110 auto tuningLevel = defaultTuningLevel;
114 if (name ==
"KernelProfilingEnabled")
116 kernelProfiling |= ParseBooleanBackendOption(value, false);
117 }
else if (name ==
"TuningFile")
120 }
else if (name ==
"TuningLevel")
124 else if (name ==
"MLGOTuningFilePath")
131 m_Tuner = std::make_unique<arm_compute::CLTuner>(
true);
135 if (!m_TuningFile.empty())
139 ARMNN_LOG(
info) <<
"Loading Gpu tuning data from file: " << m_TuningFile;
140 m_Tuner->load_from_file(m_TuningFile.c_str());
142 catch (
const std::exception& e)
156 ARMNN_LOG(
info) <<
"Loading Gpu MLGO tuning data from file: " << m_TuningFile;
162 catch (
const std::exception& e)
168 tuner = m_Tuner.get();
171 m_ClContextControlWrapper = std::make_unique<ClContextControlWrapper>(
183 bool ClBackendContext::AfterLoadNetwork(
NetworkId networkId)
186 std::lock_guard<std::mutex> lockGuard(m_Mutex);
187 m_NetworkIds.insert(networkId);
194 return m_ClContextControlWrapper->Sync();
197 bool ClBackendContext::AfterUnloadNetwork(
NetworkId networkId)
199 bool clearCache =
false;
201 std::lock_guard<std::mutex> lockGuard(m_Mutex);
202 m_NetworkIds.erase(networkId);
203 clearCache = m_NetworkIds.empty();
208 m_ClContextControlWrapper->ClearClCache();
216 return m_ClContextControlWrapper->Sync();
219 ClBackendContext::~ClBackendContext()
221 if (m_Tuner && !m_TuningFile.empty())
225 m_Tuner->save_to_file(m_TuningFile.c_str());
227 catch(
const std::exception& e)
229 ARMNN_LOG(
warning) <<
"Could not save GpuAcc tuner data to file " << m_TuningFile;