ArmNN
 24.08
GpuFsaContextControl Class Reference

#include <GpuFsaContextControl.hpp>

Public Member Functions

 GpuFsaContextControl (arm_compute::CLTuner *=nullptr, arm_compute::CLGEMMHeuristicsHandle *=nullptr, bool profilingEnabled=false)
 
virtual ~GpuFsaContextControl ()
 
void LoadOpenClRuntime ()
 
void UnloadOpenClRuntime ()
 
void ClearClCache ()
 

Detailed Description

Definition at line 13 of file GpuFsaContextControl.hpp.

Constructor & Destructor Documentation

◆ GpuFsaContextControl()

GpuFsaContextControl ( arm_compute::CLTuner *  tuner = nullptr,
arm_compute::CLGEMMHeuristicsHandle *  heuristicsHandle = nullptr,
bool  profilingEnabled = false 
)

Definition at line 27 of file GpuFsaContextControl.cpp.

30  : m_Tuner(tuner)
31  , m_HeuristicsHandle(heuristicsHandle)
32  , m_ProfilingEnabled(profilingEnabled)
33 {
34  try
35  {
36  std::vector<cl::Platform> platforms;
37  cl::Platform::get(&platforms);
38 
39  // Selects default platform for the first element.
40  cl::Platform::setDefault(platforms[0]);
41 
42  std::vector<cl::Device> devices;
43  platforms[0].getDevices(CL_DEVICE_TYPE_GPU, &devices);
44 
45  // Selects default device for the first element.
46  cl::Device::setDefault(devices[0]);
47  }
48  catch (const cl::Error& clError)
49  {
50  throw ClRuntimeUnavailableException(fmt::format(
51  "Could not initialize the CL runtime. Error description: {0}. CL error code: {1}",
52  clError.what(), clError.err()));
53  }
54 
55  // Removes the use of global CL context.
56  cl::Context::setDefault(cl::Context{});
57  if (cl::Context::getDefault()() != NULL)
58  {
59  throw armnn::Exception("GpuFsaContextControl: Unable to remove the global CL context");
60  }
61 
62  // Removes the use of global CL command queue.
63  cl::CommandQueue::setDefault(cl::CommandQueue{});
64  if (cl::CommandQueue::getDefault()() != NULL)
65  {
66  throw armnn::Exception("GpuFsaContextControl: Unable to remove the global CL command queue");
67  }
68 
69  // Always load the OpenCL runtime.
71 }

References GpuFsaContextControl::LoadOpenClRuntime().

◆ ~GpuFsaContextControl()

~GpuFsaContextControl ( )
virtual

Definition at line 73 of file GpuFsaContextControl.cpp.

74 {
75  // Load the OpencCL runtime without the tuned parameters to free the memory for them.
76  try
77  {
79  }
80  catch (const cl::Error& clError)
81  {
82  // This should not happen, it is ignored if it does.
83 
84  // Coverity fix: BOOST_LOG_TRIVIAL (previously used here to report the error) may throw an
85  // exception of type std::length_error.
86  // Using stderr instead in this context as there is no point in nesting try-catch blocks here.
87  std::cerr << "A CL error occurred unloading the runtime tuner parameters: "
88  << clError.what() << ". CL error code is: " << clError.err() << std::endl;
89  }
90 }

References GpuFsaContextControl::UnloadOpenClRuntime().

Member Function Documentation

◆ ClearClCache()

void ClearClCache ( )

Definition at line 164 of file GpuFsaContextControl.cpp.

165 {
166  DoLoadOpenClRuntime(true);
167 }

◆ LoadOpenClRuntime()

void LoadOpenClRuntime ( )

Definition at line 92 of file GpuFsaContextControl.cpp.

93 {
94  DoLoadOpenClRuntime(true);
95 }

Referenced by GpuFsaContextControl::GpuFsaContextControl().

◆ UnloadOpenClRuntime()

void UnloadOpenClRuntime ( )

Definition at line 97 of file GpuFsaContextControl.cpp.

98 {
99  DoLoadOpenClRuntime(false);
100 }

Referenced by GpuFsaContextControl::~GpuFsaContextControl().


The documentation for this class was generated from the following files:
armnn::GpuFsaContextControl::UnloadOpenClRuntime
void UnloadOpenClRuntime()
Definition: GpuFsaContextControl.cpp:97
armnn::GpuFsaContextControl::LoadOpenClRuntime
void LoadOpenClRuntime()
Definition: GpuFsaContextControl.cpp:92
armnn::Exception
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46