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

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

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

◆ ~ClContextControl()

~ClContextControl ( )
virtual

Definition at line 71 of file ClContextControl.cpp.

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

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

Member Function Documentation

◆ ClearClCache()

void ClearClCache ( )

Definition at line 162 of file ClContextControl.cpp.

163 {
164  DoLoadOpenClRuntime(true);
165 }

◆ LoadOpenClRuntime()

void LoadOpenClRuntime ( )

Definition at line 90 of file ClContextControl.cpp.

Referenced by ClContextControl::ClContextControl().

91 {
92  DoLoadOpenClRuntime(true);
93 }

◆ UnloadOpenClRuntime()

void UnloadOpenClRuntime ( )

Definition at line 95 of file ClContextControl.cpp.

References ARMNN_DISABLE_LEAK_CHECKING_IN_SCOPE, and armnn::Error.

Referenced by ClContextControl::~ClContextControl().

96 {
97  DoLoadOpenClRuntime(false);
98 }

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