12 #include <arm_compute/core/CL/OpenCL.h>
13 #include <arm_compute/core/CL/CLKernelLibrary.h>
14 #include <arm_compute/runtime/CL/CLScheduler.h>
15 #include <arm_compute/runtime/CL/CLTunerTypes.h>
20 struct ClBackendContext::ClContextControlWrapper
22 ClContextControlWrapper(arm_compute::CLTuner* tuner,
23 arm_compute::CLGEMMHeuristicsHandle* heuristicsHandle,
24 bool profilingEnabled)
25 : m_ClContextControl(tuner, heuristicsHandle, profilingEnabled)
30 if (arm_compute::CLScheduler::get().context()() != NULL)
36 arm_compute::CLScheduler::get().sync();
38 catch (
const cl::Error&)
40 ARMNN_LOG(warning) <<
"Runtime::UnloadNetwork(): an error occurred while waiting for "
41 "the queued CL requests to finish";
51 if (arm_compute::CLScheduler::get().context()() != NULL)
54 m_ClContextControl.ClearClCache();
58 ClContextControl m_ClContextControl;
67 arm_compute::CLTuner* tuner =
nullptr;
68 arm_compute::CLGEMMHeuristicsHandle* mlgoTuner =
nullptr;
70 if (useLegacyTunerAPI)
72 auto clTunerParams = PolymorphicDowncast<ClTunedParameters*>(
74 tuner = &clTunerParams->m_Tuner;
101 TuningLevel tuningLevel = ConvertTuningLevel(clTunerParams->m_TuningLevel, clTunerParams->m_Mode);
108 auto tuningLevel = defaultTuningLevel;
112 if (name ==
"KernelProfilingEnabled")
114 kernelProfiling |= ParseBooleanBackendOption(value, false);
115 }
else if (name ==
"TuningFile")
118 }
else if (name ==
"TuningLevel")
122 else if (name ==
"MLGOTuningFilePath")
129 m_Tuner = std::make_unique<arm_compute::CLTuner>(
true);
133 if (!m_TuningFile.empty())
137 ARMNN_LOG(
info) <<
"Loading Gpu tuning data from file: " << m_TuningFile;
138 m_Tuner->load_from_file(m_TuningFile.c_str());
140 catch (
const std::exception& e)
154 ARMNN_LOG(
info) <<
"Loading Gpu MLGO tuning data from file: " << m_TuningFile;
160 catch (
const std::exception& e)
166 tuner = m_Tuner.get();
169 m_ClContextControlWrapper = std::make_unique<ClContextControlWrapper>(
181 bool ClBackendContext::AfterLoadNetwork(
NetworkId networkId)
184 std::lock_guard<std::mutex> lockGuard(m_Mutex);
185 m_NetworkIds.insert(networkId);
192 return m_ClContextControlWrapper->Sync();
195 bool ClBackendContext::AfterUnloadNetwork(
NetworkId networkId)
197 bool clearCache =
false;
199 std::lock_guard<std::mutex> lockGuard(m_Mutex);
200 m_NetworkIds.erase(networkId);
201 clearCache = m_NetworkIds.empty();
206 m_ClContextControlWrapper->ClearClCache();
214 return m_ClContextControlWrapper->Sync();
217 ClBackendContext::~ClBackendContext()
219 if (m_Tuner && !m_TuningFile.empty())
223 m_Tuner->save_to_file(m_TuningFile.c_str());
225 catch(
const std::exception& e)
227 ARMNN_LOG(
warning) <<
"Could not save GpuAcc tuner data to file " << m_TuningFile;