ArmNN
 24.05
ClContextControl Class Reference

#include <ClContextControl.hpp>

Public Member Functions

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

Detailed Description

Definition at line 13 of file ClContextControl.hpp.

Constructor & Destructor Documentation

◆ ClContextControl()

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

Definition at line 27 of file ClContextControl.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 
58  // Removes the use of global CL command queue.
59  cl::CommandQueue::setDefault(cl::CommandQueue{});
60 
61  // Always load the OpenCL runtime.
63 }

References ClContextControl::LoadOpenClRuntime().

◆ ~ClContextControl()

~ClContextControl ( )
virtual

Definition at line 65 of file ClContextControl.cpp.

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

References ClContextControl::UnloadOpenClRuntime().

Member Function Documentation

◆ ClearClCache()

void ClearClCache ( )

Definition at line 156 of file ClContextControl.cpp.

157 {
158  DoLoadOpenClRuntime(true);
159 }

◆ LoadOpenClRuntime()

void LoadOpenClRuntime ( )

Definition at line 84 of file ClContextControl.cpp.

85 {
86  DoLoadOpenClRuntime(true);
87 }

Referenced by ClContextControl::ClContextControl().

◆ UnloadOpenClRuntime()

void UnloadOpenClRuntime ( )

Definition at line 89 of file ClContextControl.cpp.

90 {
91  DoLoadOpenClRuntime(false);
92 }

Referenced by ClContextControl::~ClContextControl().


The documentation for this class was generated from the following files:
armnn::ClContextControl::UnloadOpenClRuntime
void UnloadOpenClRuntime()
Definition: ClContextControl.cpp:89
armnn::ClContextControl::LoadOpenClRuntime
void LoadOpenClRuntime()
Definition: ClContextControl.cpp:84