15 #include <arm_compute/core/CL/CLKernelLibrary.h> 16 #include <arm_compute/runtime/CL/CLScheduler.h> 18 #include <fmt/format.h> 30 ClContextControl::ClContextControl(arm_compute::CLTuner *tuner,
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]);
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{});
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);
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);
189 , m_TuningLevel(tuningLevel)
198 m_Tuner.load_from_file(filename);
200 catch (
const std::exception& e)
202 throw armnn::Exception(std::string(
"Failed to load tuned parameters file '") + filename +
"': " +
211 m_Tuner.save_to_file(filename);
213 catch (
const std::exception& e)
215 throw armnn::Exception(std::string(
"Failed to save tuned parameters file to '") + filename +
"': " +
static IGpuAccTunedParameters * CreateRaw(Mode mode, TuningLevel tunerMode)
Creates an IClTunedParameters with the given mode.
#define ARMNN_DISABLE_LEAK_CHECKING_IN_SCOPE()
static void Destroy(IGpuAccTunedParameters *params)
static IGpuAccTunedParametersPtr Create(Mode mode, TuningLevel tunerMode)
Copyright (c) 2021 ARM Limited and Contributors.
void IgnoreUnused(Ts &&...)
virtual void Load(const char *filename)
Loads an existing set of tuned parameters from the given file.
#define ARMNN_ASSERT(COND)
virtual ~ClContextControl()
std::shared_ptr< IGpuAccTunedParameters > IGpuAccTunedParametersPtr
The following API is replaced by the backend options API.
arm_compute::CLTuner m_Tuner
Manages a set of GpuAcc parameters which have been tuned for maximum performance. ...
Base class for all ArmNN exceptions so that users can filter to just those.
void UnloadOpenClRuntime()
virtual void Save(const char *filename) const
Saves the current set of tuned parameters to the given file.
ClTunedParameters(armnn::IGpuAccTunedParameters::Mode mode, armnn::IGpuAccTunedParameters::TuningLevel tuningLevel)