From 9efb57d62197aeb7d868c289bb34166c132f0287 Mon Sep 17 00:00:00 2001 From: David Beck Date: Mon, 5 Nov 2018 13:40:33 +0000 Subject: Revert "IVGCVSW-2056 + IVGCVSW-2064 : move ClContextControl to the ClBackend" This reverts commit d4dfa684941a21314b70593d01b0fc2167eebad4. Change-Id: Id61ce69215505c3cf5d30ec2a7ec9127fb2554fc --- src/armnn/Runtime.cpp | 52 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 18 deletions(-) (limited to 'src/armnn/Runtime.cpp') diff --git a/src/armnn/Runtime.cpp b/src/armnn/Runtime.cpp index 769136486d..37e25a7fb6 100644 --- a/src/armnn/Runtime.cpp +++ b/src/armnn/Runtime.cpp @@ -6,10 +6,15 @@ #include #include -#include #include +#ifdef ARMCOMPUTECL_ENABLED +#include +#include +#include +#endif + #include #include @@ -52,7 +57,6 @@ Status Runtime::LoadNetwork(NetworkId& networkIdOut, IOptimizedNetwork* rawNetwork = inNetwork.release(); unique_ptr loadedNetwork = LoadedNetwork::MakeLoadedNetwork( std::unique_ptr(boost::polymorphic_downcast(rawNetwork)), - m_Options, errorMessage); if (!loadedNetwork) @@ -74,6 +78,24 @@ Status Runtime::LoadNetwork(NetworkId& networkIdOut, Status Runtime::UnloadNetwork(NetworkId networkId) { +#ifdef ARMCOMPUTECL_ENABLED + if (arm_compute::CLScheduler::get().context()() != NULL) + { + // Waits for all queued CL requests to finish before unloading the network they may be using. + try + { + // Coverity fix: arm_compute::CLScheduler::sync() may throw an exception of type cl::Error. + arm_compute::CLScheduler::get().sync(); + } + catch (const cl::Error&) + { + BOOST_LOG_TRIVIAL(warning) << "WARNING: Runtime::UnloadNetwork(): an error occurred while waiting for " + "the queued CL requests to finish"; + return Status::Failure; + } + } +#endif + { std::lock_guard lockGuard(m_Mutex); @@ -82,6 +104,14 @@ Status Runtime::UnloadNetwork(NetworkId networkId) BOOST_LOG_TRIVIAL(warning) << "WARNING: Runtime::UnloadNetwork(): " << networkId << " not found!"; return Status::Failure; } + +#ifdef ARMCOMPUTECL_ENABLED + if (arm_compute::CLScheduler::get().context()() != NULL && m_LoadedNetworks.empty()) + { + // There are no loaded networks left, so clear the CL cache to free up memory + m_ClContextControl.ClearClCache(); + } +#endif } BOOST_LOG_TRIVIAL(debug) << "Runtime::UnloadNetwork(): Unloaded network with ID: " << networkId; @@ -101,26 +131,12 @@ const std::shared_ptr Runtime::GetProfiler(NetworkId networkId) const } Runtime::Runtime(const CreationOptions& options) - : m_Options{options} + : m_ClContextControl(options.m_GpuAccTunedParameters.get(), + options.m_EnableGpuProfiling) , m_NetworkIdCounter(0) , m_DeviceSpec{BackendRegistryInstance().GetBackendIds()} { BOOST_LOG_TRIVIAL(info) << "ArmNN v" << ARMNN_VERSION << "\n"; - - for (const auto& id : BackendContextRegistryInstance().GetBackendIds()) - { - // Store backend contexts for the supported ones - if (m_DeviceSpec.GetSupportedBackends().count(id) > 0) - { - // Don't throw an exception, rather return a dummy factory if not - // found. - auto factoryFun = BackendContextRegistryInstance().GetFactory( - id, [](const CreationOptions&) { return IBackendContextUniquePtr(); } - ); - - m_BackendContexts.emplace(std::make_pair(id, factoryFun(options))); - } - } } Runtime::~Runtime() -- cgit v1.2.1