15 #include <arm_compute/core/CL/CLKernelLibrary.h> 16 #include <arm_compute/runtime/CL/CLScheduler.h> 18 #include <boost/format.hpp> 30 ClContextControl::ClContextControl(arm_compute::CLTuner *tuner,
31 bool profilingEnabled)
33 , m_ProfilingEnabled(profilingEnabled)
40 std::vector<cl::Platform> platforms;
41 cl::Platform::get(&platforms);
44 cl::Platform::setDefault(platforms[0]);
46 std::vector<cl::Device> devices;
47 platforms[0].getDevices(CL_DEVICE_TYPE_GPU, &devices);
50 cl::Device::setDefault(devices[0]);
55 "Could not initialize the CL runtime. Error description: %1%. CL error code: %2%" 56 ) % clError.what() % clError.err()));
60 cl::Context::setDefault(cl::Context{});
64 cl::CommandQueue::setDefault(cl::CommandQueue{});
85 std::cerr <<
"A CL error occurred unloading the runtime tuner parameters: " 86 << clError.what() <<
". CL error code is: " << clError.err() << std::endl;
92 DoLoadOpenClRuntime(
true);
97 DoLoadOpenClRuntime(
false);
100 void ClContextControl::DoLoadOpenClRuntime(
bool updateTunedParameters)
102 cl::Device device = cl::Device::getDefault();
104 cl::CommandQueue commandQueue;
106 if (arm_compute::CLScheduler::get().is_initialised() && arm_compute::CLScheduler::get().context()() != NULL)
109 arm_compute::CLScheduler::get().sync();
114 arm_compute::CLKernelLibrary::get().clear_programs_cache();
117 arm_compute::CLScheduler::get().init(context, commandQueue, device);
118 arm_compute::CLKernelLibrary::get().init(
".", context, device);
131 context = cl::Context(device);
136 bool profilingNeededForClTuner = updateTunedParameters && m_Tuner &&
137 m_Tuner->tune_new_kernels();
139 if (m_ProfilingEnabled || profilingNeededForClTuner)
142 commandQueue = cl::CommandQueue(context, device, CL_QUEUE_PROFILING_ENABLE);
147 commandQueue = cl::CommandQueue(context, device);
153 "Could not initialize the CL runtime. Error description: %1%. CL error code: %2%" 154 ) % clError.what() % clError.err()));
158 arm_compute::CLKernelLibrary::get().init(
".", context, device);
159 arm_compute::CLScheduler::get().init(context, commandQueue, device, m_Tuner);
164 DoLoadOpenClRuntime(
true);
187 , m_TuningLevel(tuningLevel)
196 m_Tuner.load_from_file(filename);
198 catch (
const std::exception& e)
200 throw armnn::Exception(std::string(
"Failed to load tuned parameters file '") + filename +
"': " +
209 m_Tuner.save_to_file(filename);
211 catch (
const std::exception& e)
213 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) 2020 ARM Limited.
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)