ArmNN
 24.02
GpuFsaBackendContext Class Reference

#include <GpuFsaBackendContext.hpp>

Inheritance diagram for GpuFsaBackendContext:
[legend]
Collaboration diagram for GpuFsaBackendContext:
[legend]

Public Member Functions

 GpuFsaBackendContext (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
 
bool AfterEnqueueWorkload (NetworkId networkId) override
 
 ~GpuFsaBackendContext () 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 GpuFsaBackendContext.hpp.

Constructor & Destructor Documentation

◆ GpuFsaBackendContext()

Definition at line 61 of file GpuFsaBackendContext.cpp.

62  : IBackendContext(options)
63  , m_TuningFile()
64 {
65  bool kernelProfiling = options.m_EnableGpuProfiling;
66 
67  arm_compute::CLTuner* tuner = nullptr;
68  arm_compute::CLGEMMHeuristicsHandle* mlgoTuner = nullptr;
69  bool useLegacyTunerAPI = options.m_GpuAccTunedParameters.get() != nullptr;
70  if (useLegacyTunerAPI)
71  {
72  auto clTunerParams = PolymorphicDowncast<ClTunedParameters*>(
73  options.m_GpuAccTunedParameters.get());
74  tuner = &clTunerParams->m_Tuner;
75 
76  if (tuner)
77  {
78  auto ConvertTuningLevel = [](IGpuAccTunedParameters::TuningLevel level,
80  {
82  {
83  return TuningLevel::None;
84  }
85 
86  switch(level)
87  {
89  return TuningLevel::Rapid;
91  return TuningLevel::Normal;
94  default:
95  {
96  ARMNN_LOG(warning) << "Tuning level not recognised.";
97  return TuningLevel::None;
98  }
99  }
100  };
101 
102  TuningLevel tuningLevel = ConvertTuningLevel(clTunerParams->m_TuningLevel, clTunerParams->m_Mode);
103  ConfigureTuner(*tuner, tuningLevel);
104  }
105  }
106  else //New backend options API
107  {
108  const TuningLevel defaultTuningLevel = TuningLevel::None;
109  auto tuningLevel = defaultTuningLevel;
110 
111  ParseOptions(options.m_BackendOptions, "GpuFsa", [&](std::string name, const BackendOptions::Var& value)
112  {
113  if (name == "KernelProfilingEnabled")
114  {
115  kernelProfiling |= ParseBooleanBackendOption(value, false);
116  } else if (name == "TuningFile")
117  {
118  m_TuningFile = ParseStringBackendOption(value, "");
119  } else if (name == "TuningLevel")
120  {
121  tuningLevel = ParseTuningLevel(value, defaultTuningLevel);
122  }
123  else if (name == "MLGOTuningFilePath")
124  {
126  }
127  });
128 
129  // Create the tuner, in tuning mode initially.
130  m_Tuner = std::make_unique<arm_compute::CLTuner>(true);
131 
132  ConfigureTuner(*(m_Tuner.get()), tuningLevel);
133 
134  if (!m_TuningFile.empty())
135  {
136  try
137  {
138  ARMNN_LOG(info) << "Loading Gpu tuning data from file: " << m_TuningFile;
139  m_Tuner->load_from_file(m_TuningFile.c_str());
140  }
141  catch (const std::exception& e)
142  {
143  // Warn if not tuning, otherwise tuning will generate new params
144  if (tuningLevel == TuningLevel::None)
145  {
146  ARMNN_LOG(warning) << "Could not load GpuFsa tuner data file.";
147  }
148  }
149  }
150 
151  if (!m_MLGOTuningFile.empty())
152  {
153  try
154  {
155  ARMNN_LOG(info) << "Loading Gpu MLGO tuning data from file: " << m_TuningFile;
156  if(m_MLGOTuner.reload_from_file(m_MLGOTuningFile.c_str()))
157  {
158  mlgoTuner = &m_MLGOTuner;
159  }
160  }
161  catch (const std::exception& e)
162  {
163  ARMNN_LOG(warning) << "Could not load GpuFsa MLGO tuner data file.";
164  }
165  }
166 
167  tuner = m_Tuner.get();
168  }
169 
170  m_GpuFsaContextControlWrapper = std::make_unique<GpuFsaContextControlWrapper>(
171  tuner,
172  mlgoTuner,
173  kernelProfiling
174  );
175 }

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

◆ ~GpuFsaBackendContext()

~GpuFsaBackendContext ( )
override

Definition at line 218 of file GpuFsaBackendContext.cpp.

219 {
220  if (m_Tuner && !m_TuningFile.empty())
221  {
222  try
223  {
224  m_Tuner->save_to_file(m_TuningFile.c_str());
225  }
226  catch(const std::exception& e)
227  {
228  ARMNN_LOG(warning) << "Could not save GpuFsa tuner data to file " << m_TuningFile;
229  }
230  }
231 }

References ARMNN_LOG, and armnn::warning.

Member Function Documentation

◆ AfterEnqueueWorkload()

bool AfterEnqueueWorkload ( NetworkId  networkId)
overridevirtual

Implements IBackendContext.

Definition at line 213 of file GpuFsaBackendContext.cpp.

214 {
215  return m_GpuFsaContextControlWrapper->Sync();
216 }

◆ AfterLoadNetwork()

bool AfterLoadNetwork ( NetworkId  networkId)
overridevirtual

Implements IBackendContext.

Definition at line 182 of file GpuFsaBackendContext.cpp.

183 {
184  {
185  std::lock_guard<std::mutex> lockGuard(m_Mutex);
186  m_NetworkIds.insert(networkId);
187  }
188  return true;
189 }

◆ AfterUnloadNetwork()

bool AfterUnloadNetwork ( NetworkId  networkId)
overridevirtual

Implements IBackendContext.

Definition at line 196 of file GpuFsaBackendContext.cpp.

197 {
198  bool clearCache = false;
199  {
200  std::lock_guard<std::mutex> lockGuard(m_Mutex);
201  m_NetworkIds.erase(networkId);
202  clearCache = m_NetworkIds.empty();
203  }
204 
205  if (clearCache)
206  {
207  m_GpuFsaContextControlWrapper->ClearClCache();
208  }
209 
210  return true;
211 }

◆ BeforeLoadNetwork()

bool BeforeLoadNetwork ( NetworkId  networkId)
overridevirtual

Before and after Load network events.

Implements IBackendContext.

Definition at line 177 of file GpuFsaBackendContext.cpp.

178 {
179  return true;
180 }

◆ BeforeUnloadNetwork()

bool BeforeUnloadNetwork ( NetworkId  networkId)
overridevirtual

Before and after Unload network events.

Implements IBackendContext.

Definition at line 191 of file GpuFsaBackendContext.cpp.

192 {
193  return m_GpuFsaContextControlWrapper->Sync();
194 }

Member Data Documentation

◆ m_MLGOTuner

arm_compute::CLGEMMHeuristicsHandle m_MLGOTuner
protected

Definition at line 43 of file GpuFsaBackendContext.hpp.

Referenced by GpuFsaBackendContext::GpuFsaBackendContext().

◆ m_MLGOTuningFile

std::string m_MLGOTuningFile
protected

Definition at line 44 of file GpuFsaBackendContext.hpp.

Referenced by GpuFsaBackendContext::GpuFsaBackendContext().


The documentation for this class was generated from the following files:
armnn::TuningLevel::Exhaustive
@ Exhaustive
armnn::IGpuAccTunedParameters::Mode
Mode
Definition: IRuntime.hpp:316
armnn::IGpuAccTunedParameters::TuningLevel::Rapid
@ Rapid
armnn::TuningLevel::None
@ None
armnn::ParseStringBackendOption
std::string ParseStringBackendOption(const armnn::BackendOptions::Var &value, std::string defaultValue)
Definition: BackendOptions.hpp:321
armnn::IGpuAccTunedParameters::TuningLevel
TuningLevel
Definition: IRuntime.hpp:322
armnn::IGpuAccTunedParameters::TuningLevel::Exhaustive
@ Exhaustive
ARMNN_LOG
#define ARMNN_LOG(severity)
Definition: Logging.hpp:212
armnn::IGpuAccTunedParameters::Mode::UseTunedParameters
@ UseTunedParameters
armnn::ParseTuningLevel
TuningLevel ParseTuningLevel(const BackendOptions::Var &value, TuningLevel defaultValue)
Definition: ArmComputeTuningUtils.hpp:26
armnn::ConfigureTuner
void ConfigureTuner(arm_compute::CLTuner &tuner, TuningLevel level)
Definition: ArmComputeTuningUtils.hpp:44
armnn::IGpuAccTunedParameters::TuningLevel::Normal
@ Normal
armnn::IBackendContext::IBackendContext
IBackendContext(const IRuntime::CreationOptions &)
Definition: IBackendContext.hpp:17
armnn::ParseOptions
void ParseOptions(const std::vector< BackendOptions > &options, BackendId backend, F f)
Definition: BackendOptions.hpp:297
armnn::TuningLevel::Rapid
@ Rapid
armnn::TuningLevel::Normal
@ Normal
armnn::GpuFsaBackendContext::m_MLGOTuner
arm_compute::CLGEMMHeuristicsHandle m_MLGOTuner
Definition: GpuFsaBackendContext.hpp:43
armnn::TuningLevel
TuningLevel
Definition: ArmComputeTuningUtils.hpp:18
armnn::GpuFsaBackendContext::m_MLGOTuningFile
std::string m_MLGOTuningFile
Definition: GpuFsaBackendContext.hpp:44