aboutsummaryrefslogtreecommitdiff
path: root/src/backends/cl
diff options
context:
space:
mode:
Diffstat (limited to 'src/backends/cl')
-rw-r--r--src/backends/cl/CMakeLists.txt27
-rw-r--r--src/backends/cl/ClBackend.cpp7
-rw-r--r--src/backends/cl/ClBackend.hpp4
-rw-r--r--src/backends/cl/ClBackendContext.cpp111
-rw-r--r--src/backends/cl/ClBackendContext.hpp23
-rw-r--r--src/backends/cl/ClLayerSupport.cpp2
-rw-r--r--src/backends/cl/backend.mk2
7 files changed, 153 insertions, 23 deletions
diff --git a/src/backends/cl/CMakeLists.txt b/src/backends/cl/CMakeLists.txt
index 7182332956..a0f1e4d9cc 100644
--- a/src/backends/cl/CMakeLists.txt
+++ b/src/backends/cl/CMakeLists.txt
@@ -3,18 +3,23 @@
# SPDX-License-Identifier: MIT
#
+list(APPEND armnnClBackend_sources
+ ClBackendId.hpp
+ ClLayerSupport.cpp
+ ClLayerSupport.hpp
+ ClWorkloadFactory.cpp
+ ClWorkloadFactory.hpp
+)
+
if(ARMCOMPUTECL)
list(APPEND armnnClBackend_sources
+ ClBackendContext.cpp
+ ClBackendContext.hpp
ClBackend.cpp
ClBackend.hpp
- ClBackendId.hpp
ClContextControl.cpp
ClContextControl.hpp
- ClLayerSupport.cpp
- ClLayerSupport.hpp
ClTensorHandle.hpp
- ClWorkloadFactory.cpp
- ClWorkloadFactory.hpp
OpenClTimer.cpp
OpenClTimer.hpp
)
@@ -24,20 +29,10 @@ if(ARMCOMPUTECL)
if(BUILD_UNIT_TESTS)
add_subdirectory(test)
endif()
-
-else()
- list(APPEND armnnClBackend_sources
- ClBackendId.hpp
- ClContextControl.cpp
- ClContextControl.hpp
- ClLayerSupport.cpp
- ClLayerSupport.hpp
- ClWorkloadFactory.cpp
- ClWorkloadFactory.hpp
- )
endif()
add_library(armnnClBackend OBJECT ${armnnClBackend_sources})
target_include_directories(armnnClBackend PRIVATE ${PROJECT_SOURCE_DIR}/src)
target_include_directories(armnnClBackend PRIVATE ${PROJECT_SOURCE_DIR}/src/armnn)
target_include_directories(armnnClBackend PRIVATE ${PROJECT_SOURCE_DIR}/src/armnnUtils)
+
diff --git a/src/backends/cl/ClBackend.cpp b/src/backends/cl/ClBackend.cpp
index d6a3a89391..da91de8e48 100644
--- a/src/backends/cl/ClBackend.cpp
+++ b/src/backends/cl/ClBackend.cpp
@@ -8,8 +8,7 @@
#include "ClWorkloadFactory.hpp"
#include <backends/BackendRegistry.hpp>
-
-#include <boost/cast.hpp>
+#include <boost/log/trivial.hpp>
namespace armnn
{
@@ -21,13 +20,13 @@ static StaticRegistryInitializer<BackendRegistry> g_RegisterHelper
{
BackendRegistryInstance(),
ClBackend::GetIdStatic(),
- []()
+ [](const EmptyInitializer&)
{
return IBackendInternalUniquePtr(new ClBackend);
}
};
-}
+} // anonymous namespace
const BackendId& ClBackend::GetIdStatic()
{
diff --git a/src/backends/cl/ClBackend.hpp b/src/backends/cl/ClBackend.hpp
index 4eae6c92ec..201702eee3 100644
--- a/src/backends/cl/ClBackend.hpp
+++ b/src/backends/cl/ClBackend.hpp
@@ -12,8 +12,8 @@ namespace armnn
class ClBackend : public IBackendInternal
{
public:
- ClBackend() = default;
- ~ClBackend() = default;
+ ClBackend() = default;
+ ~ClBackend() override = default;
static const BackendId& GetIdStatic();
const BackendId& GetId() const override { return GetIdStatic(); }
diff --git a/src/backends/cl/ClBackendContext.cpp b/src/backends/cl/ClBackendContext.cpp
new file mode 100644
index 0000000000..4d1be33fc6
--- /dev/null
+++ b/src/backends/cl/ClBackendContext.cpp
@@ -0,0 +1,111 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "ClBackendContext.hpp"
+#include "ClBackendId.hpp"
+#include "ClContextControl.hpp"
+
+#include <backends/BackendContextRegistry.hpp>
+#include <boost/log/trivial.hpp>
+
+#include <mutex>
+
+#ifdef ARMCOMPUTECL_ENABLED
+// Needed for the CL scheduler calls
+#include <arm_compute/core/CL/OpenCL.h>
+#include <arm_compute/core/CL/CLKernelLibrary.h>
+#include <arm_compute/runtime/CL/CLScheduler.h>
+#endif
+
+namespace armnn
+{
+
+namespace
+{
+
+static StaticRegistryInitializer<BackendContextRegistry> g_RegisterHelper
+{
+ BackendContextRegistryInstance(),
+ ClBackendId(),
+ [](const IRuntime::CreationOptions& options)
+ {
+ return IBackendContextUniquePtr(new ClBackendContext{options});
+ }
+};
+
+static std::mutex g_ContextControlMutex;
+
+std::shared_ptr<ClBackendContext::ContextControlWrapper>
+GetContextControlWrapper(const IRuntime::CreationOptions& options)
+{
+ static std::weak_ptr<ClBackendContext::ContextControlWrapper> contextControlWrapper;
+
+ std::lock_guard<std::mutex> lockGuard(g_ContextControlMutex);
+ std::shared_ptr<ClBackendContext::ContextControlWrapper> result;
+
+ if (contextControlWrapper.expired())
+ {
+ result = std::make_shared<ClBackendContext::ContextControlWrapper>(options);
+ contextControlWrapper = result;
+ }
+ else
+ {
+ result = contextControlWrapper.lock();
+ }
+
+ return result;
+}
+
+} // anonymous namespace
+
+
+#ifdef ARMCOMPUTECL_ENABLED
+struct ClBackendContext::ContextControlWrapper
+{
+ ContextControlWrapper(const IRuntime::CreationOptions& options)
+ : m_ClContextControl{options.m_GpuAccTunedParameters.get(),
+ options.m_EnableGpuProfiling}
+ {
+ }
+
+ ~ContextControlWrapper()
+ {
+ 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();
+ m_ClContextControl.ClearClCache();
+ }
+ catch (const cl::Error&)
+ {
+ BOOST_LOG_TRIVIAL(warning) << "WARNING: Runtime::UnloadNetwork(): an error occurred while waiting for "
+ "the queued CL requests to finish";
+ }
+ }
+ }
+
+ ClContextControl m_ClContextControl;
+};
+#else //ARMCOMPUTECL_ENABLED
+struct ClBackendContext::ContextControlWrapper
+{
+ ContextControlWrapper(const IRuntime::CreationOptions&){}
+};
+#endif //ARMCOMPUTECL_ENABLED
+
+ClBackendContext::ClBackendContext(const IRuntime::CreationOptions& options)
+: IBackendContext{options}
+, m_ContextControl{GetContextControlWrapper(options)}
+{
+}
+
+ClBackendContext::~ClBackendContext()
+{
+}
+
+} // namespace armnn \ No newline at end of file
diff --git a/src/backends/cl/ClBackendContext.hpp b/src/backends/cl/ClBackendContext.hpp
new file mode 100644
index 0000000000..3df403efc5
--- /dev/null
+++ b/src/backends/cl/ClBackendContext.hpp
@@ -0,0 +1,23 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+#pragma once
+
+#include <backends/IBackendContext.hpp>
+
+namespace armnn
+{
+
+class ClBackendContext : public IBackendContext
+{
+public:
+ ClBackendContext(const IRuntime::CreationOptions& options);
+ ~ClBackendContext() override;
+
+ struct ContextControlWrapper;
+private:
+ std::shared_ptr<ContextControlWrapper> m_ContextControl;
+};
+
+} // namespace armnn \ No newline at end of file
diff --git a/src/backends/cl/ClLayerSupport.cpp b/src/backends/cl/ClLayerSupport.cpp
index 6c5704d7ab..ebb90a5abf 100644
--- a/src/backends/cl/ClLayerSupport.cpp
+++ b/src/backends/cl/ClLayerSupport.cpp
@@ -53,7 +53,7 @@ ILayerSupportSharedPtr GetLayerSupportPointer()
static StaticRegistryInitializer<LayerSupportRegistry> g_RegisterHelper{
LayerSupportRegistryInstance(),
ClBackendId(),
- []()
+ [](const EmptyInitializer&)
{
return GetLayerSupportPointer();
}
diff --git a/src/backends/cl/backend.mk b/src/backends/cl/backend.mk
index 97df8e4903..8433240ae9 100644
--- a/src/backends/cl/backend.mk
+++ b/src/backends/cl/backend.mk
@@ -8,6 +8,7 @@
# file in the root of ArmNN
BACKEND_SOURCES := \
+ ClBackendContext.cpp \
ClBackend.cpp \
ClContextControl.cpp \
ClLayerSupport.cpp \
@@ -54,3 +55,4 @@ BACKEND_TEST_SOURCES := \
test/ClRuntimeTests.cpp \
test/Fp16SupportTest.cpp \
test/OpenClTimerTest.cpp
+