15 #include <arm_compute/core/CL/CLKernelLibrary.h>
16 #include <arm_compute/runtime/CL/CLScheduler.h>
18 #include <fmt/format.h>
31 arm_compute::CLGEMMHeuristicsHandle* heuristicsHandle,
32 bool profilingEnabled)
34 , m_HeuristicsHandle(heuristicsHandle)
35 , m_ProfilingEnabled(profilingEnabled)
42 std::vector<cl::Platform> platforms;
43 cl::Platform::get(&platforms);
46 cl::Platform::setDefault(platforms[0]);
48 std::vector<cl::Device> devices;
49 platforms[0].getDevices(CL_DEVICE_TYPE_GPU, &devices);
52 cl::Device::setDefault(devices[0]);
54 catch (
const cl::Error& clError)
57 "Could not initialize the CL runtime. Error description: {0}. CL error code: {1}",
58 clError.what(), clError.err()));
62 cl::Context::setDefault(cl::Context{});
66 cl::CommandQueue::setDefault(cl::CommandQueue{});
80 catch (
const cl::Error& clError)
87 std::cerr <<
"A CL error occurred unloading the runtime tuner parameters: "
88 << clError.what() <<
". CL error code is: " << clError.err() << std::endl;
94 DoLoadOpenClRuntime(
true);
99 DoLoadOpenClRuntime(
false);
102 void ClContextControl::DoLoadOpenClRuntime(
bool updateTunedParameters)
104 cl::Device device = cl::Device::getDefault();
106 cl::CommandQueue commandQueue;
108 if (arm_compute::CLScheduler::get().is_initialised() && arm_compute::CLScheduler::get().context()() != NULL)
111 arm_compute::CLScheduler::get().sync();
116 arm_compute::CLKernelLibrary::get().clear_programs_cache();
119 arm_compute::CLScheduler::get().init(context, commandQueue, device);
120 arm_compute::CLKernelLibrary::get().init(
".", context, device);
133 context = cl::Context(device);
138 bool profilingNeededForClTuner = updateTunedParameters && m_Tuner &&
139 m_Tuner->tune_new_kernels();
141 if (m_ProfilingEnabled || profilingNeededForClTuner)
144 commandQueue = cl::CommandQueue(context, device, CL_QUEUE_PROFILING_ENABLE);
149 commandQueue = cl::CommandQueue(context, device);
152 catch (
const cl::Error& clError)
154 throw ClRuntimeUnavailableException(fmt::format(
155 "Could not initialize the CL runtime. Error description: {0}. CL error code: {1}",
156 clError.what(), clError.err()));
160 arm_compute::CLKernelLibrary::get().init(
".", context, device);
161 arm_compute::CLScheduler::get().init(context, commandQueue, device, m_Tuner, m_HeuristicsHandle);
166 DoLoadOpenClRuntime(
true);