14 #include <arm_compute/core/CL/CLKernelLibrary.h> 15 #include <arm_compute/runtime/CL/CLScheduler.h> 17 #include <boost/assert.hpp> 18 #include <boost/format.hpp> 19 #include <boost/polymorphic_cast.hpp> 31 ClContextControl::ClContextControl(arm_compute::CLTuner *tuner,
32 bool profilingEnabled)
34 , m_ProfilingEnabled(profilingEnabled)
41 std::vector<cl::Platform> platforms;
42 cl::Platform::get(&platforms);
45 cl::Platform::setDefault(platforms[0]);
47 std::vector<cl::Device> devices;
48 platforms[0].getDevices(CL_DEVICE_TYPE_GPU, &devices);
51 cl::Device::setDefault(devices[0]);
56 "Could not initialize the CL runtime. Error description: %1%. CL error code: %2%" 57 ) % clError.what() % clError.err()));
61 cl::Context::setDefault(cl::Context{});
62 BOOST_ASSERT(cl::Context::getDefault()() == NULL);
65 cl::CommandQueue::setDefault(cl::CommandQueue{});
66 BOOST_ASSERT(cl::CommandQueue::getDefault()() == NULL);
86 std::cerr <<
"A CL error occurred unloading the runtime tuner parameters: " 87 << clError.what() <<
". CL error code is: " << clError.err() << std::endl;
93 DoLoadOpenClRuntime(
true);
98 DoLoadOpenClRuntime(
false);
101 void ClContextControl::DoLoadOpenClRuntime(
bool updateTunedParameters)
103 cl::Device device = cl::Device::getDefault();
105 cl::CommandQueue commandQueue;
107 if (arm_compute::CLScheduler::get().is_initialised() && arm_compute::CLScheduler::get().context()() != NULL)
110 arm_compute::CLScheduler::get().sync();
115 arm_compute::CLKernelLibrary::get().clear_programs_cache();
118 arm_compute::CLScheduler::get().init(context, commandQueue, device);
119 arm_compute::CLKernelLibrary::get().init(
".", context, device);
132 context = cl::Context(device);
137 bool profilingNeededForClTuner = updateTunedParameters && m_Tuner &&
138 m_Tuner->tune_new_kernels();
140 if (m_ProfilingEnabled || profilingNeededForClTuner)
143 commandQueue = cl::CommandQueue(context, device, CL_QUEUE_PROFILING_ENABLE);
148 commandQueue = cl::CommandQueue(context, device);
154 "Could not initialize the CL runtime. Error description: %1%. CL error code: %2%" 155 ) % clError.what() % clError.err()));
159 arm_compute::CLKernelLibrary::get().init(
".", context, device);
160 arm_compute::CLScheduler::get().init(context, commandQueue, device, m_Tuner);
165 DoLoadOpenClRuntime(
true);
188 , m_TuningLevel(tuningLevel)
197 m_Tuner.load_from_file(filename);
199 catch (
const std::exception& e)
201 throw armnn::Exception(std::string(
"Failed to load tuned parameters file '") + filename +
"': " +
210 m_Tuner.save_to_file(filename);
212 catch (
const std::exception& e)
214 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.
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)