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{});
57 if (cl::Context::getDefault()() != NULL)
59 throw armnn::Exception(
"GpuFsaContextControl: Unable to remove the global CL context");
63 cl::CommandQueue::setDefault(cl::CommandQueue{});
64 if (cl::CommandQueue::getDefault()() != NULL)
66 throw armnn::Exception(
"GpuFsaContextControl: Unable to remove the global CL command queue");
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 GpuFsaContextControl::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);