ArmNN
 20.02
ClContextControl Class Reference

#include <ClContextControl.hpp>

Public Member Functions

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

Detailed Description

Definition at line 15 of file ClContextControl.hpp.

Constructor & Destructor Documentation

◆ ClContextControl()

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

Definition at line 31 of file ClContextControl.cpp.

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

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

◆ ~ClContextControl()

~ClContextControl ( )
virtual

Definition at line 72 of file ClContextControl.cpp.

References armnn::Error, and ClContextControl::UnloadOpenClRuntime().

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

Member Function Documentation

◆ ClearClCache()

void ClearClCache ( )

Definition at line 163 of file ClContextControl.cpp.

164 {
165  DoLoadOpenClRuntime(true);
166 }

◆ LoadOpenClRuntime()

void LoadOpenClRuntime ( )

Definition at line 91 of file ClContextControl.cpp.

Referenced by ClContextControl::ClContextControl().

92 {
93  DoLoadOpenClRuntime(true);
94 }

◆ UnloadOpenClRuntime()

void UnloadOpenClRuntime ( )

Definition at line 96 of file ClContextControl.cpp.

References ARMNN_DISABLE_LEAK_CHECKING_IN_SCOPE, and armnn::Error.

Referenced by ClContextControl::~ClContextControl().

97 {
98  DoLoadOpenClRuntime(false);
99 }

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