12 #include <arm_compute/core/CL/CLKernelLibrary.h> 13 #include <arm_compute/runtime/CL/CLScheduler.h> 15 #include <boost/assert.hpp> 16 #include <boost/format.hpp> 17 #include <boost/polymorphic_cast.hpp> 18 #include <boost/core/ignore_unused.hpp> 30 ClContextControl::ClContextControl(arm_compute::CLTuner *tuner,
31 bool profilingEnabled)
33 , m_ProfilingEnabled(profilingEnabled)
36 boost::ignore_unused(m_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{});
61 BOOST_ASSERT(cl::Context::getDefault()() == NULL);
64 cl::CommandQueue::setDefault(cl::CommandQueue{});
65 BOOST_ASSERT(cl::CommandQueue::getDefault()() == NULL);
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 +
"': " +
void UnloadOpenClRuntime()
std::shared_ptr< IGpuAccTunedParameters > IGpuAccTunedParametersPtr
The following API is replaced by the backend options API.
static IGpuAccTunedParametersPtr Create(Mode mode, TuningLevel tunerMode)
ClTunedParameters(armnn::IGpuAccTunedParameters::Mode mode, armnn::IGpuAccTunedParameters::TuningLevel tuningLevel)
virtual ~ClContextControl()
arm_compute::CLTuner m_Tuner
virtual void Save(const char *filename) const
virtual void Load(const char *filename)
Base class for all ArmNN exceptions so that users can filter to just those.
#define ARMNN_DISABLE_LEAK_CHECKING_IN_SCOPE()
static void Destroy(IGpuAccTunedParameters *params)
static IGpuAccTunedParameters * CreateRaw(Mode mode, TuningLevel tunerMode)