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 bool profilingEnabled)
25 : m_ClContextControl(tuner, profilingEnabled)
30 if (arm_compute::CLScheduler::get().context()() != NULL)
36 arm_compute::CLScheduler::get().sync();
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;
63 std::transform(value.begin(), value.end(), value.begin(),
64 [](
unsigned char c){
return std::tolower(c); });
82 int v = value.
AsInt();
87 "Using default(" <<
static_cast<int>(defaultValue) <<
")";
116 tuner.set_tune_new_kernels(
true);
121 tuner.set_tuner_mode(arm_compute::CLTunerMode::RAPID);
124 tuner.set_tuner_mode(arm_compute::CLTunerMode::NORMAL);
127 tuner.set_tuner_mode(arm_compute::CLTunerMode::EXHAUSTIVE);
131 tuner.set_tune_new_kernels(
false);
142 arm_compute::CLTuner* tuner =
nullptr;
144 if (useLegacyTunerAPI)
146 auto clTunerParams = PolymorphicDowncast<ClTunedParameters*>(
148 tuner = &clTunerParams->m_Tuner;
176 TuningLevel tuningLevel = ConvertTuningLevel(clTunerParams->m_TuningLevel, clTunerParams->m_Mode);
183 auto tuningLevel = defaultTuningLevel;
187 if (name ==
"KernelProfilingEnabled")
189 kernelProfiling |= ParseBoolean(value, false);
190 }
else if (name ==
"TuningFile")
193 }
else if (name ==
"TuningLevel")
200 m_Tuner = std::make_unique<arm_compute::CLTuner>(
true);
208 m_Tuner->load_from_file(m_TuningFile.c_str());
210 catch (
const std::exception& e)
215 tuner = m_Tuner.get();
218 m_ClContextControlWrapper = std::make_unique<ClContextControlWrapper>(
232 std::lock_guard<std::mutex> lockGuard(m_Mutex);
233 m_NetworkIds.insert(networkId);
240 return m_ClContextControlWrapper->Sync();
245 bool clearCache =
false;
247 std::lock_guard<std::mutex> lockGuard(m_Mutex);
248 m_NetworkIds.erase(networkId);
249 clearCache = m_NetworkIds.empty();
254 m_ClContextControlWrapper->ClearClCache();
262 if (m_Tuner && !m_TuningFile.empty())
266 m_Tuner->save_to_file(m_TuningFile.c_str());
268 catch(
const std::exception& e)
270 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) 2020 ARM Limited.
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.
bool AfterLoadNetwork(NetworkId networkId) override
std::string LowerString(std::string value)
bool BeforeUnloadNetwork(NetworkId networkId) override
Before and after Unload network events.