aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/backends/ClContextControl.cpp
diff options
context:
space:
mode:
authortelsoa01 <telmo.soares@arm.com>2018-08-31 09:22:23 +0100
committertelsoa01 <telmo.soares@arm.com>2018-08-31 09:22:23 +0100
commitc577f2c6a3b4ddb6ba87a882723c53a248afbeba (patch)
treebd7d4c148df27f8be6649d313efb24f536b7cf34 /src/armnn/backends/ClContextControl.cpp
parent4c7098bfeab1ffe1cdc77f6c15548d3e73274746 (diff)
downloadarmnn-c577f2c6a3b4ddb6ba87a882723c53a248afbeba.tar.gz
Release 18.08
Diffstat (limited to 'src/armnn/backends/ClContextControl.cpp')
-rw-r--r--src/armnn/backends/ClContextControl.cpp61
1 files changed, 31 insertions, 30 deletions
diff --git a/src/armnn/backends/ClContextControl.cpp b/src/armnn/backends/ClContextControl.cpp
index f086328e55..68e878da79 100644
--- a/src/armnn/backends/ClContextControl.cpp
+++ b/src/armnn/backends/ClContextControl.cpp
@@ -16,6 +16,7 @@
#include <boost/format.hpp>
#include <boost/log/trivial.hpp>
#include <boost/polymorphic_cast.hpp>
+#include <boost/core/ignore_unused.hpp>
#include "LeakChecking.hpp"
@@ -29,22 +30,27 @@ class Device;
namespace armnn
{
-ClContextControl::ClContextControl(IClTunedParameters* clTunedParameters)
+ClContextControl::ClContextControl(IGpuAccTunedParameters* clTunedParameters,
+ bool profilingEnabled)
: m_clTunedParameters(boost::polymorphic_downcast<ClTunedParameters*>(clTunedParameters))
+ , m_ProfilingEnabled(profilingEnabled)
{
+ // Ignore m_ProfilingEnabled if unused to avoid compiling problems when ArmCompute is disabled.
+ boost::ignore_unused(m_ProfilingEnabled);
+
#ifdef ARMCOMPUTECL_ENABLED
try
{
std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
- // Select default platform as the first element
+ // Selects default platform for the first element.
cl::Platform::setDefault(platforms[0]);
std::vector<cl::Device> devices;
platforms[0].getDevices(CL_DEVICE_TYPE_GPU, &devices);
- // Select default device as the first element
+ // Selects default device for the first element.
cl::Device::setDefault(devices[0]);
}
catch (const cl::Error& clError)
@@ -54,15 +60,15 @@ ClContextControl::ClContextControl(IClTunedParameters* clTunedParameters)
) % clError.what() % clError.err()));
}
- // Remove the use of global CL context
+ // Removes the use of global CL context.
cl::Context::setDefault(cl::Context{});
BOOST_ASSERT(cl::Context::getDefault()() == NULL);
- // Remove the use of global CL command queue
+ // Removes the use of global CL command queue.
cl::CommandQueue::setDefault(cl::CommandQueue{});
BOOST_ASSERT(cl::CommandQueue::getDefault()() == NULL);
- // always load the OpenCL runtime
+ // Always load the OpenCL runtime.
LoadOpenClRuntime();
#endif
}
@@ -70,14 +76,14 @@ ClContextControl::ClContextControl(IClTunedParameters* clTunedParameters)
ClContextControl::~ClContextControl()
{
#ifdef ARMCOMPUTECL_ENABLED
- // load the OpencCL runtime without the tuned parameters to free the memory for them
+ // Load the OpencCL runtime without the tuned parameters to free the memory for them.
try
{
UnloadOpenClRuntime();
}
catch (const cl::Error& clError)
{
- // this should not happen, it is ignored if it does
+ // This should not happen, it is ignored if it does.
// Coverity fix: BOOST_LOG_TRIVIAL (previously used here to report the error) may throw an
// exception of type std::length_error.
@@ -107,23 +113,23 @@ void ClContextControl::DoLoadOpenClRuntime(bool useTunedParameters)
if (arm_compute::CLScheduler::get().context()() != NULL)
{
- // wait for all queued CL requests to finish before reinitialising it
+ // Wait for all queued CL requests to finish before reinitialising it.
arm_compute::CLScheduler::get().sync();
}
try
{
arm_compute::CLKernelLibrary::get().clear_programs_cache();
- // initialise the scheduler with a dummy context to release the LLVM data (which only happens when there are no
+ // Initialise the scheduler with a dummy context to release the LLVM data (which only happens when there are no
// context references); it is initialised again, with a proper context, later.
arm_compute::CLScheduler::get().init(context, commandQueue, device);
arm_compute::CLKernelLibrary::get().init(".", context, device);
{
//
- // Here we replace the context with a new one which in
- // the memory leak checks shows as an extra allocation but
- // because of the scope of the leak check it doesn't count
+ // Here we replace the context with a new one in which
+ // the memory leak checks show it as an extra allocation but
+ // because of the scope of the leak checks, it doesn't count
// the disposal of the original object. On the other hand it
// does count the creation of this context which it flags
// as a memory leak. By adding the following line we prevent
@@ -133,24 +139,19 @@ void ClContextControl::DoLoadOpenClRuntime(bool useTunedParameters)
context = cl::Context(device);
}
- bool enableProfiling = false;
-#if ARMNN_PROFILING_ENABLED
- enableProfiling = true;
-#endif
- if (useTunedParameters &&
- m_clTunedParameters && m_clTunedParameters->m_Mode == IClTunedParameters::Mode::UpdateTunedParameters)
- {
- enableProfiling = true; // Needed for the CLTuner to work.
- }
+ // NOTE: In this specific case profiling has to be enabled on the command queue
+ // in order for the CLTuner to work.
+ bool profilingNeededForClTuner = useTunedParameters && m_clTunedParameters &&
+ m_clTunedParameters->m_Mode == IGpuAccTunedParameters::Mode::UpdateTunedParameters;
- if (enableProfiling)
+ if (m_ProfilingEnabled || profilingNeededForClTuner)
{
- // Create a new queue with profiling enabled
+ // Create a new queue with profiling enabled.
commandQueue = cl::CommandQueue(context, device, CL_QUEUE_PROFILING_ENABLE);
}
else
{
- // Use default queue
+ // Use default queue.
commandQueue = cl::CommandQueue(context, device);
}
}
@@ -178,22 +179,22 @@ void ClContextControl::ClearClCache()
DoLoadOpenClRuntime(true);
}
-armnn::IClTunedParameters* IClTunedParameters::CreateRaw(armnn::IClTunedParameters::Mode mode)
+armnn::IGpuAccTunedParameters* IGpuAccTunedParameters::CreateRaw(armnn::IGpuAccTunedParameters::Mode mode)
{
return new ClTunedParameters(mode);
}
-armnn::IClTunedParametersPtr IClTunedParameters::Create(armnn::IClTunedParameters::Mode mode)
+armnn::IGpuAccTunedParametersPtr IGpuAccTunedParameters::Create(armnn::IGpuAccTunedParameters::Mode mode)
{
- return IClTunedParametersPtr(CreateRaw(mode), &IClTunedParameters::Destroy);
+ return IGpuAccTunedParametersPtr(CreateRaw(mode), &IGpuAccTunedParameters::Destroy);
}
-void IClTunedParameters::Destroy(IClTunedParameters* params)
+void IGpuAccTunedParameters::Destroy(IGpuAccTunedParameters* params)
{
delete params;
}
-ClTunedParameters::ClTunedParameters(armnn::IClTunedParameters::Mode mode)
+ClTunedParameters::ClTunedParameters(armnn::IGpuAccTunedParameters::Mode mode)
: m_Mode(mode)
#ifdef ARMCOMPUTECL_ENABLED
, m_Tuner(mode == ClTunedParameters::Mode::UpdateTunedParameters)