ArmNN
 24.02
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 30 of file ClContextControl.cpp.

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

References ARMNN_ASSERT, armnn::IgnoreUnused(), and ClContextControl::LoadOpenClRuntime().

◆ ~ClContextControl()

~ClContextControl ( )
virtual

Definition at line 73 of file ClContextControl.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 ClContextControl::UnloadOpenClRuntime().

Member Function Documentation

◆ ClearClCache()

void ClearClCache ( )

Definition at line 164 of file ClContextControl.cpp.

165 {
166  DoLoadOpenClRuntime(true);
167 }

◆ LoadOpenClRuntime()

void LoadOpenClRuntime ( )

Definition at line 92 of file ClContextControl.cpp.

93 {
94  DoLoadOpenClRuntime(true);
95 }

Referenced by ClContextControl::ClContextControl().

◆ UnloadOpenClRuntime()

void UnloadOpenClRuntime ( )

Definition at line 97 of file ClContextControl.cpp.

98 {
99  DoLoadOpenClRuntime(false);
100 }

Referenced by ClContextControl::~ClContextControl().


The documentation for this class was generated from the following files:
ARMNN_ASSERT
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
armnn::ClContextControl::UnloadOpenClRuntime
void UnloadOpenClRuntime()
Definition: ClContextControl.cpp:97
armnn::ClContextControl::LoadOpenClRuntime
void LoadOpenClRuntime()
Definition: ClContextControl.cpp:92
armnn::IgnoreUnused
void IgnoreUnused(Ts &&...)
Definition: IgnoreUnused.hpp:14