12 #include <arm_compute/core/CL/CLKernelLibrary.h>
13 #include <arm_compute/runtime/CL/CLScheduler.h>
15 #include <fmt/format.h>
28 arm_compute::CLGEMMHeuristicsHandle* heuristicsHandle,
29 bool profilingEnabled)
31 , m_HeuristicsHandle(heuristicsHandle)
32 , m_ProfilingEnabled(profilingEnabled)
36 std::vector<cl::Platform> platforms;
37 cl::Platform::get(&platforms);
40 cl::Platform::setDefault(platforms[0]);
42 std::vector<cl::Device> devices;
43 platforms[0].getDevices(CL_DEVICE_TYPE_GPU, &devices);
46 cl::Device::setDefault(devices[0]);
48 catch (
const cl::Error& clError)
51 "Could not initialize the CL runtime. Error description: {0}. CL error code: {1}",
52 clError.what(), clError.err()));
56 cl::Context::setDefault(cl::Context{});
59 cl::CommandQueue::setDefault(cl::CommandQueue{});
72 catch (
const cl::Error& clError)
79 std::cerr <<
"A CL error occurred unloading the runtime tuner parameters: "
80 << clError.what() <<
". CL error code is: " << clError.err() << std::endl;
86 DoLoadOpenClRuntime(
true);
91 DoLoadOpenClRuntime(
false);
94 void ClContextControl::DoLoadOpenClRuntime(
bool updateTunedParameters)
96 cl::Device device = cl::Device::getDefault();
98 cl::CommandQueue commandQueue;
100 if (arm_compute::CLScheduler::get().is_initialised() && arm_compute::CLScheduler::get().context()() != NULL)
103 arm_compute::CLScheduler::get().sync();
108 arm_compute::CLKernelLibrary::get().clear_programs_cache();
111 arm_compute::CLScheduler::get().init(context, commandQueue, device);
112 arm_compute::CLKernelLibrary::get().init(
".", context, device);
125 context = cl::Context(device);
130 bool profilingNeededForClTuner = updateTunedParameters && m_Tuner &&
131 m_Tuner->tune_new_kernels();
133 if (m_ProfilingEnabled || profilingNeededForClTuner)
136 commandQueue = cl::CommandQueue(context, device, CL_QUEUE_PROFILING_ENABLE);
141 commandQueue = cl::CommandQueue(context, device);
144 catch (
const cl::Error& clError)
146 throw ClRuntimeUnavailableException(fmt::format(
147 "Could not initialize the CL runtime. Error description: {0}. CL error code: {1}",
148 clError.what(), clError.err()));
152 arm_compute::CLKernelLibrary::get().init(
".", context, device);
153 arm_compute::CLScheduler::get().init(context, commandQueue, device, m_Tuner, m_HeuristicsHandle);
158 DoLoadOpenClRuntime(
true);