From ef7e6b64a28c685c9da605a25c24a44f5f93b597 Mon Sep 17 00:00:00 2001 From: Derek Lamberti Date: Tue, 4 Feb 2020 14:49:16 +0000 Subject: IVGCVSW-4389 Enable ClTuner in ClContextControl Change-Id: If169736c4523a92f9aa10eac13e320eb41088624 Signed-off-by: Derek Lamberti --- src/backends/cl/ClBackendContext.cpp | 119 +++++++++++++++++------------------ 1 file changed, 59 insertions(+), 60 deletions(-) diff --git a/src/backends/cl/ClBackendContext.cpp b/src/backends/cl/ClBackendContext.cpp index b435c29323..bf56145885 100644 --- a/src/backends/cl/ClBackendContext.cpp +++ b/src/backends/cl/ClBackendContext.cpp @@ -136,78 +136,77 @@ ClBackendContext::ClBackendContext(const IRuntime::CreationOptions& options) auto tuningLevel = defaultTuningLevel; m_TuningFile = ""; - arm_compute::CLTuner* tuner = nullptr; - if (m_TuningFile.empty() == false) + bool useLegacyTunerAPI = options.m_GpuAccTunedParameters.get() != nullptr; + if (useLegacyTunerAPI) { - bool useLegacyTunerAPI = options.m_GpuAccTunedParameters.get() != nullptr; - if (useLegacyTunerAPI) - { - auto clTunerParams = boost::polymorphic_downcast( - options.m_GpuAccTunedParameters.get()); - auto clTuner = &clTunerParams->m_Tuner; + auto clTunerParams = boost::polymorphic_downcast( + options.m_GpuAccTunedParameters.get()); + auto clTuner = &clTunerParams->m_Tuner; - if (clTuner) - { - auto ConvertTuningLevel = [](IGpuAccTunedParameters::TuningLevel level) + if (clTuner) + { + auto ConvertTuningLevel = [](IGpuAccTunedParameters::TuningLevel level) + { + switch(level) { - switch(level) + case IGpuAccTunedParameters::TuningLevel::Rapid: + return arm_compute::CLTunerMode::RAPID; + case IGpuAccTunedParameters::TuningLevel::Normal: + return arm_compute::CLTunerMode::NORMAL; + case IGpuAccTunedParameters::TuningLevel::Exhaustive: + return arm_compute::CLTunerMode::EXHAUSTIVE; + default: { - case IGpuAccTunedParameters::TuningLevel::Rapid: - return arm_compute::CLTunerMode::RAPID; - case IGpuAccTunedParameters::TuningLevel::Normal: - return arm_compute::CLTunerMode::NORMAL; - case IGpuAccTunedParameters::TuningLevel::Exhaustive: - return arm_compute::CLTunerMode::EXHAUSTIVE; - default: - { - BOOST_ASSERT_MSG(false, "Tuning level not recognised."); - return arm_compute::CLTunerMode::NORMAL; - } + BOOST_ASSERT_MSG(false, "Tuning level not recognised."); + return arm_compute::CLTunerMode::NORMAL; } - }; + } + }; - clTuner->set_tuner_mode(ConvertTuningLevel(clTunerParams->m_TuningLevel)); - clTuner->set_tune_new_kernels( - clTunerParams->m_Mode == armnn::IGpuAccTunedParameters::Mode::UpdateTunedParameters); - } + clTuner->set_tuner_mode(ConvertTuningLevel(clTunerParams->m_TuningLevel)); + clTuner->set_tune_new_kernels( + clTunerParams->m_Mode == armnn::IGpuAccTunedParameters::Mode::UpdateTunedParameters); } - else //New backend options API - { - ParseOptions(options.m_BackendOptions, "GpuAcc", [&](std::string name, const BackendOptions::Var& value) + } + else //New backend options API + { + ParseOptions(options.m_BackendOptions, "GpuAcc", [&](std::string name, const BackendOptions::Var& value) + { + if (name == "KernelProfilingEnabled") { - if (name == "KernelProfilingEnabled") - { - kernelProfiling |= ParseBoolean(value, false); - } else if (name == "TuningFile") - { - m_TuningFile = ParseFile(value, ""); - } else if (name == "TuningLevel") - { - tuningLevel = ParseTuningLevel(value, defaultTuningLevel); - } - }); + kernelProfiling |= ParseBoolean(value, false); + } else if (name == "TuningFile") + { + m_TuningFile = ParseFile(value, ""); + } else if (name == "TuningLevel") + { + tuningLevel = ParseTuningLevel(value, defaultTuningLevel); + } + }); - // Create the tuner, in tuning mode initially. - m_Tuner = std::make_unique(true); + // Create the tuner, in tuning mode initially. + m_Tuner = std::make_unique(true); - switch (tuningLevel) - { - case TuningLevel::Rapid: - m_Tuner->set_tuner_mode(arm_compute::CLTunerMode::RAPID); - break; - case TuningLevel::Normal: - m_Tuner->set_tuner_mode(arm_compute::CLTunerMode::NORMAL); - break; - case TuningLevel::Exhaustive: - m_Tuner->set_tuner_mode(arm_compute::CLTunerMode::EXHAUSTIVE); - break; - case TuningLevel::None: - default: - m_Tuner->set_tune_new_kernels(false); // Turn of tuning. Set to "use" only mode. - break; - } + switch (tuningLevel) + { + case TuningLevel::Rapid: + m_Tuner->set_tuner_mode(arm_compute::CLTunerMode::RAPID); + break; + case TuningLevel::Normal: + m_Tuner->set_tuner_mode(arm_compute::CLTunerMode::NORMAL); + break; + case TuningLevel::Exhaustive: + m_Tuner->set_tuner_mode(arm_compute::CLTunerMode::EXHAUSTIVE); + break; + case TuningLevel::None: + default: + m_Tuner->set_tune_new_kernels(false); // Turn of tuning. Set to "use" only mode. + break; + } + if (!m_TuningFile.empty()) + { try { m_Tuner->load_from_file(m_TuningFile.c_str()); -- cgit v1.2.1