ArmNN  NotReleased
ClBackendContext Class Reference

#include <ClBackendContext.hpp>

Inheritance diagram for ClBackendContext:
IBackendContext

Public Member Functions

 ClBackendContext (const IRuntime::CreationOptions &options)
 
bool BeforeLoadNetwork (NetworkId networkId) override
 
bool AfterLoadNetwork (NetworkId networkId) override
 
bool BeforeUnloadNetwork (NetworkId networkId) override
 
bool AfterUnloadNetwork (NetworkId networkId) override
 
 ~ClBackendContext () override
 
- Public Member Functions inherited from IBackendContext
virtual ~IBackendContext ()
 

Additional Inherited Members

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

Detailed Description

Definition at line 16 of file ClBackendContext.hpp.

Constructor & Destructor Documentation

◆ ClBackendContext()

Definition at line 153 of file ClBackendContext.cpp.

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

155  , m_TuningFile()
156 {
157  bool kernelProfiling = options.m_EnableGpuProfiling;
158 
159  arm_compute::CLTuner* tuner = nullptr;
160  bool useLegacyTunerAPI = options.m_GpuAccTunedParameters.get() != nullptr;
161  if (useLegacyTunerAPI)
162  {
163  auto clTunerParams = boost::polymorphic_downcast<ClTunedParameters*>(
164  options.m_GpuAccTunedParameters.get());
165  tuner = &clTunerParams->m_Tuner;
166 
167  if (tuner)
168  {
169  auto ConvertTuningLevel = [](IGpuAccTunedParameters::TuningLevel level,
171  {
173  {
174  return TuningLevel::None;
175  }
176 
177  switch(level)
178  {
180  return TuningLevel::Rapid;
182  return TuningLevel::Normal;
185  default:
186  {
187  BOOST_ASSERT_MSG(false, "Tuning level not recognised.");
188  return TuningLevel::None;
189  }
190  }
191  };
192 
193  TuningLevel tuningLevel = ConvertTuningLevel(clTunerParams->m_TuningLevel, clTunerParams->m_Mode);
194  ConfigureTuner(*tuner, tuningLevel);
195  }
196  }
197  else //New backend options API
198  {
199  const TuningLevel defaultTuningLevel = TuningLevel::None;
200  auto tuningLevel = defaultTuningLevel;
201 
202  ParseOptions(options.m_BackendOptions, "GpuAcc", [&](std::string name, const BackendOptions::Var& value)
203  {
204  if (name == "KernelProfilingEnabled")
205  {
206  kernelProfiling |= ParseBoolean(value, false);
207  } else if (name == "TuningFile")
208  {
209  m_TuningFile = ParseFile(value, "");
210  } else if (name == "TuningLevel")
211  {
212  tuningLevel = ParseTuningLevel(value, defaultTuningLevel);
213  }
214  });
215 
216  // Create the tuner, in tuning mode initially.
217  m_Tuner = std::make_unique<arm_compute::CLTuner>(true);
218 
219  ConfigureTuner(*(m_Tuner.get()), tuningLevel);
220 
221  if (!m_TuningFile.empty())
222  {
223  try
224  {
225  m_Tuner->load_from_file(m_TuningFile.c_str());
226  } catch (const std::exception& e)
227  {
228  ARMNN_LOG(warning) << "Could not load GpuAcc tuner data file.";
229  }
230 
231  tuner = m_Tuner.get();
232  }
233  }
234 
235  m_ClContextControlWrapper = std::make_unique<ClContextControlWrapper>(
236  tuner,
237  kernelProfiling
238  );
239 }
std::string ParseFile(const BackendOptions::Var &value, std::string defaultValue)
IBackendContext(const IRuntime::CreationOptions &)
void ConfigureTuner(arm_compute::CLTuner &tuner, TuningLevel level)
#define ARMNN_LOG(severity)
Definition: Logging.hpp:163
TuningLevel ParseTuningLevel(const BackendOptions::Var &value, TuningLevel defaultValue)
void ParseOptions(const std::vector< BackendOptions > &options, BackendId backend, F f)
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ ~ClBackendContext()

~ClBackendContext ( )
override

Definition at line 277 of file ClBackendContext.cpp.

References ARMNN_LOG, and armnn::warning.

278 {
279  if (m_Tuner && !m_TuningFile.empty())
280  {
281  try
282  {
283  m_Tuner->save_to_file(m_TuningFile.c_str());
284  }
285  catch(const std::exception& e)
286  {
287  ARMNN_LOG(warning) << "Could not save GpuAcc tuner data to file " << m_TuningFile;
288  }
289  }
290 }
#define ARMNN_LOG(severity)
Definition: Logging.hpp:163

Member Function Documentation

◆ AfterLoadNetwork()

bool AfterLoadNetwork ( NetworkId  networkId)
overridevirtual

Implements IBackendContext.

Definition at line 246 of file ClBackendContext.cpp.

247 {
248  {
249  std::lock_guard<std::mutex> lockGuard(m_Mutex);
250  m_NetworkIds.insert(networkId);
251  }
252  return true;
253 }

◆ AfterUnloadNetwork()

bool AfterUnloadNetwork ( NetworkId  networkId)
overridevirtual

Implements IBackendContext.

Definition at line 260 of file ClBackendContext.cpp.

261 {
262  bool clearCache = false;
263  {
264  std::lock_guard<std::mutex> lockGuard(m_Mutex);
265  m_NetworkIds.erase(networkId);
266  clearCache = m_NetworkIds.empty();
267  }
268 
269  if (clearCache)
270  {
271  m_ClContextControlWrapper->ClearClCache();
272  }
273 
274  return true;
275 }

◆ BeforeLoadNetwork()

bool BeforeLoadNetwork ( NetworkId  networkId)
overridevirtual

Implements IBackendContext.

Definition at line 241 of file ClBackendContext.cpp.

242 {
243  return true;
244 }

◆ BeforeUnloadNetwork()

bool BeforeUnloadNetwork ( NetworkId  networkId)
overridevirtual

Implements IBackendContext.

Definition at line 255 of file ClBackendContext.cpp.

256 {
257  return m_ClContextControlWrapper->Sync();
258 }

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