From: Ruomei Yan Date: Thu, 25 Apr 2019 13:24:05 +0000 (+0100) Subject: IVGCVSW-2773 Integrate new CL tuner into ArmNN X-Git-Tag: submit/tizen/20200316.035456~678 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=49937f3da53c78a5fdd8fdfbd007993572d5f926;p=platform%2Fupstream%2Farmnn.git IVGCVSW-2773 Integrate new CL tuner into ArmNN !android-nn-driver:1038 Change-Id: Ia94743a64109b5eddcd44b03cf6ba5b3a4de4e53 Signed-off-by: Ruomei Yan --- diff --git a/include/armnn/IRuntime.hpp b/include/armnn/IRuntime.hpp index 34487d5..0366663 100644 --- a/include/armnn/IRuntime.hpp +++ b/include/armnn/IRuntime.hpp @@ -115,10 +115,17 @@ public: UpdateTunedParameters }; + enum class TuningLevel + { + Rapid = 0, + Normal = 1, + Exhaustive = 2 + }; + /// Creates an IClTunedParameters with the given mode. /// @{ - static IGpuAccTunedParameters* CreateRaw(Mode mode); - static IGpuAccTunedParametersPtr Create(Mode mode); + static IGpuAccTunedParameters* CreateRaw(Mode mode, TuningLevel tunerMode); + static IGpuAccTunedParametersPtr Create(Mode mode, TuningLevel tunerMode); /// @} static void Destroy(IGpuAccTunedParameters* params); diff --git a/src/backends/cl/ClContextControl.cpp b/src/backends/cl/ClContextControl.cpp index ac0b8c8..268430e 100644 --- a/src/backends/cl/ClContextControl.cpp +++ b/src/backends/cl/ClContextControl.cpp @@ -162,6 +162,27 @@ void ClContextControl::DoLoadOpenClRuntime(bool useTunedParameters) if (useTunedParameters && m_clTunedParameters) { tuner = &m_clTunedParameters->m_Tuner; + auto clTuner = boost::polymorphic_downcast(tuner); + + auto ConvertTuningLevel = [](IGpuAccTunedParameters::TuningLevel 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: + { + BOOST_ASSERT_MSG(false, "Tuning level not recognised."); + return arm_compute::CLTunerMode::NORMAL; + } + } + }; + + clTuner->set_tuner_mode(ConvertTuningLevel(m_clTunedParameters->m_TuningLevel)); } arm_compute::CLScheduler::get().init(context, commandQueue, device, tuner); } @@ -171,14 +192,16 @@ void ClContextControl::ClearClCache() DoLoadOpenClRuntime(true); } -armnn::IGpuAccTunedParameters* IGpuAccTunedParameters::CreateRaw(armnn::IGpuAccTunedParameters::Mode mode) +armnn::IGpuAccTunedParameters* IGpuAccTunedParameters::CreateRaw(armnn::IGpuAccTunedParameters::Mode mode, + armnn::IGpuAccTunedParameters::TuningLevel tuningLevel) { - return new ClTunedParameters(mode); + return new ClTunedParameters(mode, tuningLevel); } -armnn::IGpuAccTunedParametersPtr IGpuAccTunedParameters::Create(armnn::IGpuAccTunedParameters::Mode mode) +armnn::IGpuAccTunedParametersPtr IGpuAccTunedParameters::Create(armnn::IGpuAccTunedParameters::Mode mode, + armnn::IGpuAccTunedParameters::TuningLevel tuningLevel) { - return IGpuAccTunedParametersPtr(CreateRaw(mode), &IGpuAccTunedParameters::Destroy); + return IGpuAccTunedParametersPtr(CreateRaw(mode, tuningLevel), &IGpuAccTunedParameters::Destroy); } void IGpuAccTunedParameters::Destroy(IGpuAccTunedParameters* params) @@ -186,8 +209,10 @@ void IGpuAccTunedParameters::Destroy(IGpuAccTunedParameters* params) delete params; } -ClTunedParameters::ClTunedParameters(armnn::IGpuAccTunedParameters::Mode mode) +ClTunedParameters::ClTunedParameters(armnn::IGpuAccTunedParameters::Mode mode, + armnn::IGpuAccTunedParameters::TuningLevel tuningLevel) : m_Mode(mode) + , m_TuningLevel(ClTunedParameters::TuningLevel::Rapid) , m_Tuner(mode == ClTunedParameters::Mode::UpdateTunedParameters) { } diff --git a/src/backends/cl/ClContextControl.hpp b/src/backends/cl/ClContextControl.hpp index 8575329..8a5abf7 100644 --- a/src/backends/cl/ClContextControl.hpp +++ b/src/backends/cl/ClContextControl.hpp @@ -45,12 +45,13 @@ private: class ClTunedParameters : public IGpuAccTunedParameters { public: - ClTunedParameters(armnn::IGpuAccTunedParameters::Mode mode); + ClTunedParameters(armnn::IGpuAccTunedParameters::Mode mode, armnn::IGpuAccTunedParameters::TuningLevel tuningLevel); virtual void Load(const char* filename); virtual void Save(const char* filename) const; Mode m_Mode; + TuningLevel m_TuningLevel; arm_compute::CLTuner m_Tuner; };