ArmNN
 21.02
ClBackendContext Class Reference

#include <ClBackendContext.hpp>

Inheritance diagram for ClBackendContext:
IBackendContext

Public Member Functions

 ClBackendContext (const IRuntime::CreationOptions &options)
 
bool BeforeLoadNetwork (NetworkId networkId) override
 Before and after Load network events. More...
 
bool AfterLoadNetwork (NetworkId networkId) override
 
bool BeforeUnloadNetwork (NetworkId networkId) override
 Before and after Unload network events. More...
 
bool AfterUnloadNetwork (NetworkId networkId) override
 
 ~ClBackendContext () override
 
- Public Member Functions inherited from IBackendContext
virtual ~IBackendContext ()
 

Protected Attributes

arm_compute::CLGEMMHeuristicsHandle m_MLGOTuner
 
std::string m_MLGOTuningFile
 

Additional Inherited Members

- Protected Member Functions inherited from IBackendContext
 IBackendContext (const IRuntime::CreationOptions &)
 

Detailed Description

Definition at line 17 of file ClBackendContext.hpp.

Constructor & Destructor Documentation

◆ ClBackendContext()

Definition at line 140 of file ClBackendContext.cpp.

References ARMNN_ASSERT_MSG, ARMNN_LOG, armnn::ConfigureTuner(), armnn::Exhaustive, IGpuAccTunedParameters::Exhaustive, armnn::info, IRuntime::CreationOptions::m_BackendOptions, IRuntime::CreationOptions::m_EnableGpuProfiling, IRuntime::CreationOptions::m_GpuAccTunedParameters, ClBackendContext::m_MLGOTuner, ClBackendContext::m_MLGOTuningFile, armnn::None, armnn::Normal, IGpuAccTunedParameters::Normal, armnn::ParseFile(), armnn::ParseOptions(), armnn::ParseTuningLevel(), armnn::Rapid, IGpuAccTunedParameters::Rapid, IGpuAccTunedParameters::UseTunedParameters, and armnn::warning.

Referenced by BOOST_AUTO_TEST_CASE().

141  : IBackendContext(options)
142  , m_TuningFile()
143 {
144  bool kernelProfiling = options.m_EnableGpuProfiling;
145 
146  arm_compute::CLTuner* tuner = nullptr;
147  arm_compute::CLGEMMHeuristicsHandle* mlgoTuner = nullptr;
148  bool useLegacyTunerAPI = options.m_GpuAccTunedParameters.get() != nullptr;
149  if (useLegacyTunerAPI)
150  {
151  auto clTunerParams = PolymorphicDowncast<ClTunedParameters*>(
152  options.m_GpuAccTunedParameters.get());
153  tuner = &clTunerParams->m_Tuner;
154 
155  if (tuner)
156  {
157  auto ConvertTuningLevel = [](IGpuAccTunedParameters::TuningLevel level,
159  {
161  {
162  return TuningLevel::None;
163  }
164 
165  switch(level)
166  {
168  return TuningLevel::Rapid;
170  return TuningLevel::Normal;
173  default:
174  {
175  ARMNN_ASSERT_MSG(false, "Tuning level not recognised.");
176  return TuningLevel::None;
177  }
178  }
179  };
180 
181  TuningLevel tuningLevel = ConvertTuningLevel(clTunerParams->m_TuningLevel, clTunerParams->m_Mode);
182  ConfigureTuner(*tuner, tuningLevel);
183  }
184  }
185  else //New backend options API
186  {
187  const TuningLevel defaultTuningLevel = TuningLevel::None;
188  auto tuningLevel = defaultTuningLevel;
189 
190  ParseOptions(options.m_BackendOptions, "GpuAcc", [&](std::string name, const BackendOptions::Var& value)
191  {
192  if (name == "KernelProfilingEnabled")
193  {
194  kernelProfiling |= ParseBoolean(value, false);
195  } else if (name == "TuningFile")
196  {
197  m_TuningFile = ParseFile(value, "");
198  } else if (name == "TuningLevel")
199  {
200  tuningLevel = ParseTuningLevel(value, defaultTuningLevel);
201  }
202  else if (name == "MLGOTuningFilePath")
203  {
204  m_MLGOTuningFile = ParseFile(value, "");
205  }
206  });
207 
208  // Create the tuner, in tuning mode initially.
209  m_Tuner = std::make_unique<arm_compute::CLTuner>(true);
210 
211  ConfigureTuner(*(m_Tuner.get()), tuningLevel);
212 
213  if (!m_TuningFile.empty() && tuningLevel == TuningLevel::None)
214  {
215  try
216  {
217  ARMNN_LOG(info) << "Loading Gpu tuning data from file: " << m_TuningFile;
218  m_Tuner->load_from_file(m_TuningFile.c_str());
219  }
220  catch (const std::exception& e)
221  {
222  ARMNN_LOG(warning) << "Could not load GpuAcc tuner data file.";
223  }
224  }
225 
226  if (!m_MLGOTuningFile.empty())
227  {
228  try
229  {
230  ARMNN_LOG(info) << "Loading Gpu MLGO tuning data from file: " << m_TuningFile;
231  if(m_MLGOTuner.reload_from_file(m_MLGOTuningFile.c_str()))
232  {
233  mlgoTuner = &m_MLGOTuner;
234  }
235  }
236  catch (const std::exception& e)
237  {
238  ARMNN_LOG(warning) << "Could not load GpuAcc MLGO tuner data file.";
239  }
240  }
241 
242  tuner = m_Tuner.get();
243  }
244 
245  m_ClContextControlWrapper = std::make_unique<ClContextControlWrapper>(
246  tuner,
247  mlgoTuner,
248  kernelProfiling
249  );
250 }
void ParseOptions(const std::vector< BackendOptions > &options, BackendId backend, F f)
#define ARMNN_LOG(severity)
Definition: Logging.hpp:202
void ConfigureTuner(arm_compute::CLTuner &tuner, TuningLevel level)
#define ARMNN_ASSERT_MSG(COND, MSG)
Definition: Assert.hpp:15
std::string ParseFile(const BackendOptions::Var &value, std::string defaultValue)
TuningLevel ParseTuningLevel(const BackendOptions::Var &value, TuningLevel defaultValue)
arm_compute::CLGEMMHeuristicsHandle m_MLGOTuner
IBackendContext(const IRuntime::CreationOptions &)

◆ ~ClBackendContext()

~ClBackendContext ( )
override

Definition at line 288 of file ClBackendContext.cpp.

References ARMNN_LOG, and armnn::warning.

289 {
290  if (m_Tuner && !m_TuningFile.empty())
291  {
292  try
293  {
294  m_Tuner->save_to_file(m_TuningFile.c_str());
295  }
296  catch(const std::exception& e)
297  {
298  ARMNN_LOG(warning) << "Could not save GpuAcc tuner data to file " << m_TuningFile;
299  }
300  }
301 }
#define ARMNN_LOG(severity)
Definition: Logging.hpp:202

Member Function Documentation

◆ AfterLoadNetwork()

bool AfterLoadNetwork ( NetworkId  networkId)
overridevirtual

Implements IBackendContext.

Definition at line 257 of file ClBackendContext.cpp.

258 {
259  {
260  std::lock_guard<std::mutex> lockGuard(m_Mutex);
261  m_NetworkIds.insert(networkId);
262  }
263  return true;
264 }

◆ AfterUnloadNetwork()

bool AfterUnloadNetwork ( NetworkId  networkId)
overridevirtual

Implements IBackendContext.

Definition at line 271 of file ClBackendContext.cpp.

272 {
273  bool clearCache = false;
274  {
275  std::lock_guard<std::mutex> lockGuard(m_Mutex);
276  m_NetworkIds.erase(networkId);
277  clearCache = m_NetworkIds.empty();
278  }
279 
280  if (clearCache)
281  {
282  m_ClContextControlWrapper->ClearClCache();
283  }
284 
285  return true;
286 }

◆ BeforeLoadNetwork()

bool BeforeLoadNetwork ( NetworkId  networkId)
overridevirtual

Before and after Load network events.

Implements IBackendContext.

Definition at line 252 of file ClBackendContext.cpp.

253 {
254  return true;
255 }

◆ BeforeUnloadNetwork()

bool BeforeUnloadNetwork ( NetworkId  networkId)
overridevirtual

Before and after Unload network events.

Implements IBackendContext.

Definition at line 266 of file ClBackendContext.cpp.

267 {
268  return m_ClContextControlWrapper->Sync();
269 }

Member Data Documentation

◆ m_MLGOTuner

arm_compute::CLGEMMHeuristicsHandle m_MLGOTuner
protected

Definition at line 41 of file ClBackendContext.hpp.

Referenced by ClBackendContext::ClBackendContext().

◆ m_MLGOTuningFile

std::string m_MLGOTuningFile
protected

Definition at line 42 of file ClBackendContext.hpp.

Referenced by ClBackendContext::ClBackendContext().


The documentation for this class was generated from the following files: