11 #include <arm_compute/core/CL/OpenCL.h> 12 #include <arm_compute/core/CL/CLKernelLibrary.h> 13 #include <arm_compute/runtime/CL/CLScheduler.h> 14 #include <arm_compute/runtime/CL/CLTunerTypes.h> 16 #include <boost/polymorphic_cast.hpp> 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.
IsInt();
87 "Using default(" <<
static_cast<int>(defaultValue) <<
")";
115 template <
typename F>
118 for (
auto optionsGroup : options)
120 if (optionsGroup.GetBackendId() == backend)
122 for (
size_t i=0; i < optionsGroup.GetOptionCount(); i++)
133 tuner.set_tune_new_kernels(
true);
138 tuner.set_tuner_mode(arm_compute::CLTunerMode::RAPID);
141 tuner.set_tuner_mode(arm_compute::CLTunerMode::NORMAL);
144 tuner.set_tuner_mode(arm_compute::CLTunerMode::EXHAUSTIVE);
148 tuner.set_tune_new_kernels(
false);
159 arm_compute::CLTuner* tuner =
nullptr;
161 if (useLegacyTunerAPI)
163 auto clTunerParams = boost::polymorphic_downcast<ClTunedParameters*>(
165 tuner = &clTunerParams->m_Tuner;
187 BOOST_ASSERT_MSG(
false,
"Tuning level not recognised.");
193 TuningLevel tuningLevel = ConvertTuningLevel(clTunerParams->m_TuningLevel, clTunerParams->m_Mode);
200 auto tuningLevel = defaultTuningLevel;
204 if (name ==
"KernelProfilingEnabled")
206 kernelProfiling |= ParseBoolean(value, false);
207 }
else if (name ==
"TuningFile")
210 }
else if (name ==
"TuningLevel")
217 m_Tuner = std::make_unique<arm_compute::CLTuner>(
true);
221 if (!m_TuningFile.empty())
225 m_Tuner->load_from_file(m_TuningFile.c_str());
226 }
catch (
const std::exception& e)
231 tuner = m_Tuner.get();
235 m_ClContextControlWrapper = std::make_unique<ClContextControlWrapper>(
249 std::lock_guard<std::mutex> lockGuard(m_Mutex);
250 m_NetworkIds.insert(networkId);
257 return m_ClContextControlWrapper->Sync();
262 bool clearCache =
false;
264 std::lock_guard<std::mutex> lockGuard(m_Mutex);
265 m_NetworkIds.erase(networkId);
266 clearCache = m_NetworkIds.empty();
271 m_ClContextControlWrapper->ClearClCache();
279 if (m_Tuner && !m_TuningFile.empty())
283 m_Tuner->save_to_file(m_TuningFile.c_str());
285 catch(
const std::exception& e)
287 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.
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 GetName() const
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)
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
bool BeforeUnloadNetwork(NetworkId networkId) override
Before and after Unload network events.