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 GpuFsaBackendContext::GpuFsaContextControlWrapper
22 GpuFsaContextControlWrapper(arm_compute::CLTuner* tuner,
23 arm_compute::CLGEMMHeuristicsHandle* heuristicsHandle,
24 bool profilingEnabled)
25 : m_GpuFsaContextControl(tuner, heuristicsHandle, profilingEnabled)
30 if (arm_compute::CLScheduler::get().context()() != NULL)
36 arm_compute::CLScheduler::get().sync();
38 catch (
const cl::Error& err)
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_GpuFsaContextControl.ClearClCache();
58 GpuFsaContextControl m_GpuFsaContextControl;
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;
102 TuningLevel tuningLevel = ConvertTuningLevel(clTunerParams->m_TuningLevel, clTunerParams->m_Mode);
109 auto tuningLevel = defaultTuningLevel;
113 if (name ==
"KernelProfilingEnabled")
115 kernelProfiling |= ParseBooleanBackendOption(value, false);
116 }
else if (name ==
"TuningFile")
119 }
else if (name ==
"TuningLevel")
123 else if (name ==
"MLGOTuningFilePath")
130 m_Tuner = std::make_unique<arm_compute::CLTuner>(
true);
134 if (!m_TuningFile.empty())
138 ARMNN_LOG(
info) <<
"Loading Gpu tuning data from file: " << m_TuningFile;
139 m_Tuner->load_from_file(m_TuningFile.c_str());
141 catch (
const std::exception& e)
155 ARMNN_LOG(
info) <<
"Loading Gpu MLGO tuning data from file: " << m_TuningFile;
161 catch (
const std::exception& e)
167 tuner = m_Tuner.get();
170 m_GpuFsaContextControlWrapper = std::make_unique<GpuFsaContextControlWrapper>(
182 bool GpuFsaBackendContext::AfterLoadNetwork(
NetworkId networkId)
185 std::lock_guard<std::mutex> lockGuard(m_Mutex);
186 m_NetworkIds.insert(networkId);
191 bool GpuFsaBackendContext::BeforeUnloadNetwork(
NetworkId)
193 return m_GpuFsaContextControlWrapper->Sync();
196 bool GpuFsaBackendContext::AfterUnloadNetwork(
NetworkId networkId)
198 bool clearCache =
false;
200 std::lock_guard<std::mutex> lockGuard(m_Mutex);
201 m_NetworkIds.erase(networkId);
202 clearCache = m_NetworkIds.empty();
207 m_GpuFsaContextControlWrapper->ClearClCache();
213 bool GpuFsaBackendContext::AfterEnqueueWorkload(
NetworkId)
215 return m_GpuFsaContextControlWrapper->Sync();
218 GpuFsaBackendContext::~GpuFsaBackendContext()
220 if (m_Tuner && !m_TuningFile.empty())
224 m_Tuner->save_to_file(m_TuningFile.c_str());
226 catch(
const std::exception& e)
228 ARMNN_LOG(
warning) <<
"Could not save GpuFsa tuner data to file " << m_TuningFile;