Revert "IVGCVSW-2056 + IVGCVSW-2064 : move ClContextControl to the ClBackend"
authorDavid Beck <david.beck@arm.com>
Mon, 5 Nov 2018 13:40:33 +0000 (13:40 +0000)
committerMatthew Bentham <matthew.bentham@arm.com>
Mon, 5 Nov 2018 17:26:57 +0000 (17:26 +0000)
This reverts commit d4dfa684941a21314b70593d01b0fc2167eebad4.

Change-Id: Id61ce69215505c3cf5d30ec2a7ec9127fb2554fc

37 files changed:
CMakeLists.txt
include/armnn/ArmNN.hpp
include/armnn/IBackend.hpp [deleted file]
include/armnn/Types.hpp
src/armnn/LayerSupport.cpp
src/armnn/LoadedNetwork.cpp
src/armnn/LoadedNetwork.hpp
src/armnn/Runtime.cpp
src/armnn/Runtime.hpp
src/backends/backendsCommon/BackendContextRegistry.cpp [deleted file]
src/backends/backendsCommon/BackendContextRegistry.hpp [deleted file]
src/backends/backendsCommon/BackendRegistry.hpp
src/backends/backendsCommon/CMakeLists.txt
src/backends/backendsCommon/IBackendContext.hpp [deleted file]
src/backends/backendsCommon/IBackendInternal.hpp
src/backends/backendsCommon/LayerSupportRegistry.hpp
src/backends/backendsCommon/RegistryCommon.hpp
src/backends/backendsCommon/WorkloadFactory.cpp
src/backends/backendsCommon/common.mk
src/backends/backendsCommon/test/BackendRegistryTests.cpp
src/backends/cl/CMakeLists.txt
src/backends/cl/ClBackend.cpp
src/backends/cl/ClBackend.hpp
src/backends/cl/ClBackendContext.cpp [deleted file]
src/backends/cl/ClBackendContext.hpp [deleted file]
src/backends/cl/ClLayerSupport.cpp
src/backends/cl/backend.mk
src/backends/neon/CMakeLists.txt
src/backends/neon/NeonBackend.cpp
src/backends/neon/NeonBackend.hpp
src/backends/neon/NeonLayerSupport.cpp
src/backends/neon/backend.mk
src/backends/reference/CMakeLists.txt
src/backends/reference/RefBackend.cpp
src/backends/reference/RefBackend.hpp
src/backends/reference/RefLayerSupport.cpp
src/backends/reference/backend.mk

index e8d00de..48176c1 100644 (file)
@@ -154,7 +154,6 @@ list(APPEND armnn_sources
     include/armnn/ILayerSupport.hpp
     include/armnn/INetwork.hpp
     include/armnn/IProfiler.hpp
-    include/armnn/IBackend.hpp
     include/armnn/IRuntime.hpp
     include/armnn/LayerSupport.hpp
     include/armnn/LstmParams.hpp
index a9bb451..f03b79d 100644 (file)
@@ -7,7 +7,6 @@
 #include "BackendId.hpp"
 #include "Descriptors.hpp"
 #include "Exceptions.hpp"
-#include "IBackend.hpp"
 #include "IRuntime.hpp"
 #include "INetwork.hpp"
 #include "LayerSupport.hpp"
diff --git a/include/armnn/IBackend.hpp b/include/armnn/IBackend.hpp
deleted file mode 100644 (file)
index 34df91c..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-//
-// Copyright © 2017 Arm Ltd. All rights reserved.
-// SPDX-License-Identifier: MIT
-//
-#pragma once
-
-#include "BackendId.hpp"
-
-namespace armnn
-{
-
-class IBackend
-{
-protected:
-    IBackend() {}
-    virtual ~IBackend() {}
-
-public:
-    virtual const BackendId& GetId() const = 0;
-};
-
-} // namespace armnn
\ No newline at end of file
index 2249a36..cd6e17b 100644 (file)
@@ -139,6 +139,20 @@ enum class OutputShapeRounding
     Ceiling     = 1
 };
 
+/// Each backend should implement an IBackend.
+class IBackend
+{
+protected:
+    IBackend() {}
+    virtual ~IBackend() {}
+
+public:
+    virtual const BackendId& GetId() const = 0;
+};
+
+using IBackendSharedPtr = std::shared_ptr<IBackend>;
+using IBackendUniquePtr = std::unique_ptr<IBackend, void(*)(IBackend* backend)>;
+
 /// Device specific knowledge to be passed to the optimizer.
 class IDeviceSpec
 {
@@ -208,6 +222,4 @@ private:
 /// Define LayerGuid type.
 using LayerGuid = unsigned int;
 
-struct EmptyInitializer {};
-
 } // namespace armnn
index e3009e2..fb3ce43 100644 (file)
@@ -39,7 +39,7 @@ void CopyErrorMessage(char* truncatedString, const char* fullString, size_t maxL
     bool isSupported; \
     try { \
         auto factoryFunc = LayerSupportRegistryInstance().GetFactory(backendId); \
-        auto layerSupportObject = factoryFunc(EmptyInitializer()); \
+        auto layerSupportObject = factoryFunc(); \
         isSupported = layerSupportObject->func(__VA_ARGS__, Optional<std::string&>(reasonIfUnsupportedFull)); \
         CopyErrorMessage(reasonIfUnsupported, reasonIfUnsupportedFull.c_str(), reasonIfUnsupportedMaxLength); \
     } catch (InvalidArgumentException e) { \
index 97c8360..f58a115 100644 (file)
@@ -38,7 +38,6 @@ std::string ToErrorMessage(const char * prefix, const ExceptionType & error)
 } // anonymous
 
 std::unique_ptr<LoadedNetwork> LoadedNetwork::MakeLoadedNetwork(std::unique_ptr<OptimizedNetwork> net,
-                                                                const IRuntime::CreationOptions& options,
                                                                 std::string & errorMessage)
 {
     std::unique_ptr<LoadedNetwork> loadedNetwork;
@@ -53,7 +52,7 @@ std::unique_ptr<LoadedNetwork> LoadedNetwork::MakeLoadedNetwork(std::unique_ptr<
 
     try
     {
-        loadedNetwork.reset(new LoadedNetwork(std::move(net), options));
+        loadedNetwork.reset(new LoadedNetwork(std::move(net)));
     }
     catch (const armnn::RuntimeException& error)
     {
@@ -71,8 +70,7 @@ std::unique_ptr<LoadedNetwork> LoadedNetwork::MakeLoadedNetwork(std::unique_ptr<
     return loadedNetwork;
 }
 
-LoadedNetwork::LoadedNetwork(std::unique_ptr<OptimizedNetwork> net,
-                             const IRuntime::CreationOptions& options)
+LoadedNetwork::LoadedNetwork(std::unique_ptr<OptimizedNetwork> net)
     : m_OptimizedNetwork(std::move(net))
     , m_WorkingMemLock(m_WorkingMemMutex, std::defer_lock)
 {
@@ -91,7 +89,7 @@ LoadedNetwork::LoadedNetwork(std::unique_ptr<OptimizedNetwork> net,
         if (m_Backends.count(backend) == 0)
         {
             auto createBackend = BackendRegistryInstance().GetFactory(backend);
-            auto it = m_Backends.emplace(std::make_pair(backend, createBackend(EmptyInitializer())));
+            auto it = m_Backends.emplace(std::make_pair(backend, createBackend()));
             m_WorkloadFactories.emplace(std::make_pair(backend,
                                                        it.first->second->CreateWorkloadFactory()));
         }
index b36b69b..65dd4ec 100644 (file)
@@ -40,7 +40,6 @@ public:
     Status EnqueueWorkload(const InputTensors& inputTensors, const OutputTensors& outputTensors);
 
     static std::unique_ptr<LoadedNetwork> MakeLoadedNetwork(std::unique_ptr<OptimizedNetwork> net,
-                                                            const IRuntime::CreationOptions& options,
                                                             std::string & errorMessage);
 
     // NOTE we return by reference as the purpose of this method is only to provide
@@ -52,7 +51,7 @@ public:
     void FreeWorkingMemory();
 
 private:
-    LoadedNetwork(std::unique_ptr<OptimizedNetwork> net, const IRuntime::CreationOptions& options);
+    LoadedNetwork(std::unique_ptr<OptimizedNetwork> net);
 
     void EnqueueInput(const BindableLayer& layer, ITensorHandle* tensorHandle, const TensorInfo& tensorInfo);
 
index 7691364..37e25a7 100644 (file)
@@ -6,10 +6,15 @@
 
 #include <armnn/Version.hpp>
 #include <backendsCommon/BackendRegistry.hpp>
-#include <backendsCommon/BackendContextRegistry.hpp>
 
 #include <iostream>
 
+#ifdef ARMCOMPUTECL_ENABLED
+#include <arm_compute/core/CL/OpenCL.h>
+#include <arm_compute/core/CL/CLKernelLibrary.h>
+#include <arm_compute/runtime/CL/CLScheduler.h>
+#endif
+
 #include <boost/log/trivial.hpp>
 #include <boost/polymorphic_cast.hpp>
 
@@ -52,7 +57,6 @@ Status Runtime::LoadNetwork(NetworkId& networkIdOut,
     IOptimizedNetwork* rawNetwork = inNetwork.release();
     unique_ptr<LoadedNetwork> loadedNetwork = LoadedNetwork::MakeLoadedNetwork(
         std::unique_ptr<OptimizedNetwork>(boost::polymorphic_downcast<OptimizedNetwork*>(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<std::mutex> 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<IProfiler> 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()
index 694e1e5..e4d4d4d 100644 (file)
@@ -10,7 +10,8 @@
 #include <armnn/IRuntime.hpp>
 #include <armnn/Tensor.hpp>
 #include <armnn/BackendId.hpp>
-#include <backendsCommon/IBackendContext.hpp>
+
+#include <cl/ClContextControl.hpp>
 
 #include <mutex>
 #include <unordered_map>
@@ -86,13 +87,14 @@ private:
     }
 
     mutable std::mutex m_Mutex;
+
     std::unordered_map<NetworkId, std::unique_ptr<LoadedNetwork>> m_LoadedNetworks;
-    CreationOptions m_Options;
+
+    ClContextControl m_ClContextControl;
+
     int m_NetworkIdCounter;
-    DeviceSpec m_DeviceSpec;
 
-    using BackendContextMap = std::unordered_map<BackendId, IBackendContextUniquePtr>;
-    BackendContextMap m_BackendContexts;
+    DeviceSpec m_DeviceSpec;
 };
 
 }
diff --git a/src/backends/backendsCommon/BackendContextRegistry.cpp b/src/backends/backendsCommon/BackendContextRegistry.cpp
deleted file mode 100644 (file)
index 0168a12..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-//
-// Copyright © 2017 Arm Ltd. All rights reserved.
-// SPDX-License-Identifier: MIT
-//
-
-#include "BackendContextRegistry.hpp"
-
-namespace armnn
-{
-
-BackendContextRegistry& BackendContextRegistryInstance()
-{
-    static BackendContextRegistry instance;
-    return instance;
-}
-
-} // namespace armnn
diff --git a/src/backends/backendsCommon/BackendContextRegistry.hpp b/src/backends/backendsCommon/BackendContextRegistry.hpp
deleted file mode 100644 (file)
index 23830a0..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-//
-// Copyright © 2017 Arm Ltd. All rights reserved.
-// SPDX-License-Identifier: MIT
-//
-#pragma once
-
-#include "IBackendContext.hpp"
-#include "RegistryCommon.hpp"
-
-#include <armnn/IRuntime.hpp>
-#include <armnn/Types.hpp>
-
-namespace armnn
-{
-
-using BackendContextRegistry = RegistryCommon<IBackendContext,
-                                              IBackendContextUniquePtr,
-                                              IRuntime::CreationOptions>;
-
-BackendContextRegistry& BackendContextRegistryInstance();
-
-template <>
-struct RegisteredTypeName<IBackendContext>
-{
-    static const char * Name() { return "IBackendContext"; }
-};
-
-} // namespace armnn
index ba2d26a..145da88 100644 (file)
@@ -12,9 +12,7 @@
 namespace armnn
 {
 
-using BackendRegistry = RegistryCommon<IBackendInternal,
-                                       IBackendInternalUniquePtr,
-                                       EmptyInitializer>;
+using BackendRegistry = RegistryCommon<IBackendInternal, IBackendInternalUniquePtr>;
 
 BackendRegistry& BackendRegistryInstance();
 
index cb89aeb..9dd9b92 100644 (file)
@@ -4,14 +4,11 @@
 #
 
 list(APPEND armnnBackendsCommon_sources
-    BackendContextRegistry.cpp
-    BackendContextRegistry.hpp
     BackendRegistry.cpp
     BackendRegistry.hpp
     CpuTensorHandle.cpp
     CpuTensorHandleFwd.hpp
     CpuTensorHandle.hpp
-    IBackendContext.hpp
     IBackendInternal.hpp
     ILayerSupport.cpp
     ITensorHandle.hpp
diff --git a/src/backends/backendsCommon/IBackendContext.hpp b/src/backends/backendsCommon/IBackendContext.hpp
deleted file mode 100644 (file)
index d073d12..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-//
-// Copyright © 2017 Arm Ltd. All rights reserved.
-// SPDX-License-Identifier: MIT
-//
-#pragma once
-
-#include <armnn/IRuntime.hpp>
-#include <memory>
-
-namespace armnn
-{
-
-class IBackendContext
-{
-public:
-    virtual ~IBackendContext() {}
-
-protected:
-    IBackendContext(const IRuntime::CreationOptions& options) {}
-
-private:
-    IBackendContext() = delete;
-};
-
-using IBackendContextUniquePtr = std::unique_ptr<IBackendContext>;
-
-} // namespace armnn
index a24b600..7e44dbd 100644 (file)
@@ -4,8 +4,7 @@
 //
 #pragma once
 
-#include <armnn/IBackend.hpp>
-#include <memory>
+#include <armnn/Types.hpp>
 
 namespace armnn
 {
@@ -14,6 +13,8 @@ class IWorkloadFactory;
 class IBackendInternal : public IBackend
 {
 protected:
+    // Creation must be done through a specific
+    // backend interface.
     IBackendInternal() = default;
 
 public:
index 6124685..a5efad0 100644 (file)
@@ -6,13 +6,11 @@
 
 #include "RegistryCommon.hpp"
 #include <armnn/ILayerSupport.hpp>
-#include <armnn/Types.hpp>
 
 namespace armnn
 {
-using LayerSupportRegistry = RegistryCommon<ILayerSupport,
-                                            ILayerSupportSharedPtr,
-                                            EmptyInitializer>;
+
+using LayerSupportRegistry = RegistryCommon<ILayerSupport, ILayerSupportSharedPtr>;
 
 LayerSupportRegistry& LayerSupportRegistryInstance();
 
index 3dbfad2..03bd338 100644 (file)
@@ -22,11 +22,11 @@ struct RegisteredTypeName
     static const char * Name() { return "UNKNOWN"; }
 };
 
-template <typename RegisteredType, typename PointerType, typename ParamType>
+template <typename RegisteredType, typename PointerType>
 class RegistryCommon
 {
 public:
-    using FactoryFunction = std::function<PointerType(const ParamType&)>;
+    using FactoryFunction = std::function<PointerType()>;
 
     void Register(const BackendId& id, FactoryFunction factory)
     {
@@ -53,20 +53,6 @@ public:
         return it->second;
     }
 
-    FactoryFunction GetFactory(const BackendId& id,
-                               FactoryFunction defaultFactory) const
-    {
-        auto it = m_Factories.find(id);
-        if (it == m_Factories.end())
-        {
-            return defaultFactory;
-        }
-        else
-        {
-            return it->second;
-        }
-    }
-
     size_t Size() const
     {
         return m_Factories.size();
@@ -131,4 +117,4 @@ struct StaticRegistryInitializer
     }
 };
 
-} // namespace armnn
\ No newline at end of file
+} // namespace armnn
index 83a20e8..9f97452 100644 (file)
@@ -68,7 +68,7 @@ bool IWorkloadFactory::IsLayerSupported(const BackendId& backendId,
 
     auto const& layerSupportRegistry = LayerSupportRegistryInstance();
     auto layerSupportFactory = layerSupportRegistry.GetFactory(backendId);
-    auto layerSupportObject = layerSupportFactory(EmptyInitializer());
+    auto layerSupportObject = layerSupportFactory();
 
     switch(layer.GetType())
     {
index 152ada3..b1583b9 100644 (file)
@@ -8,7 +8,6 @@
 # file in the root of ArmNN
 
 COMMON_SOURCES := \
-    BackendContextRegistry.cpp \
     BackendRegistry.cpp \
     CpuTensorHandle.cpp \
     ILayerSupport.cpp \
@@ -27,4 +26,3 @@ COMMON_TEST_SOURCES := \
     test/WorkloadDataValidation.cpp \
     test/TensorCopyUtils.cpp \
     test/LayerTests.cpp
-
index 4afe273..0bc655b 100644 (file)
@@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE(TestRegistryHelper)
     StaticRegistryInitializer<BackendRegistry> factoryHelper(
         BackendRegistryInstance(),
         "HelloWorld",
-        [&called](const EmptyInitializer&)
+        [&called]()
         {
             called = true;
             return armnn::IBackendInternalUniquePtr(nullptr);
@@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE(TestRegistryHelper)
     // sanity check: the factory still not called
     BOOST_TEST(called == false);
 
-    factoryFunction(EmptyInitializer());
+    factoryFunction();
     BOOST_TEST(called == true);
 }
 
@@ -81,7 +81,7 @@ BOOST_AUTO_TEST_CASE(TestDirectCallToRegistry)
     bool called = false;
     BackendRegistryInstance().Register(
         "HelloWorld",
-        [&called](const EmptyInitializer&)
+        [&called]()
         {
             called = true;
             return armnn::IBackendInternalUniquePtr(nullptr);
@@ -96,7 +96,7 @@ BOOST_AUTO_TEST_CASE(TestDirectCallToRegistry)
     // sanity check: the factory still not called
     BOOST_TEST(called == false);
 
-    factoryFunction(EmptyInitializer());
+    factoryFunction();
     BOOST_TEST(called == true);
 }
 
index 3025458..d751854 100644 (file)
@@ -3,23 +3,18 @@
 # 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
     )
@@ -29,10 +24,20 @@ 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/armnn)
 target_include_directories(armnnClBackend PRIVATE ${PROJECT_SOURCE_DIR}/src/armnnUtils)
 target_include_directories(armnnClBackend PRIVATE ${PROJECT_SOURCE_DIR}/src/backends)
-
index 5d5cad5..b1857a3 100644 (file)
@@ -8,7 +8,6 @@
 #include "ClWorkloadFactory.hpp"
 
 #include <backendsCommon/BackendRegistry.hpp>
-#include <boost/log/trivial.hpp>
 
 namespace armnn
 {
@@ -20,13 +19,13 @@ static StaticRegistryInitializer<BackendRegistry> g_RegisterHelper
 {
     BackendRegistryInstance(),
     ClBackend::GetIdStatic(),
-    [](const EmptyInitializer&)
+    []()
     {
         return IBackendInternalUniquePtr(new ClBackend);
     }
 };
 
-} // anonymous namespace
+}
 
 const BackendId& ClBackend::GetIdStatic()
 {
@@ -39,4 +38,4 @@ IBackendInternal::IWorkloadFactoryPtr ClBackend::CreateWorkloadFactory() const
     return std::make_unique<ClWorkloadFactory>();
 }
 
-} // namespace armnn
\ No newline at end of file
+} // namespace armnn
index 381d808..223aeb3 100644 (file)
@@ -12,8 +12,8 @@ namespace armnn
 class ClBackend : public IBackendInternal
 {
 public:
-    ClBackend() = default;
-    ~ClBackend() override = default;
+    ClBackend()  = default;
+    ~ClBackend() = 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
deleted file mode 100644 (file)
index 7789415..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-//
-// Copyright © 2017 Arm Ltd. All rights reserved.
-// SPDX-License-Identifier: MIT
-//
-
-#include "ClBackendContext.hpp"
-#include "ClBackendId.hpp"
-#include "ClContextControl.hpp"
-
-#include <backendsCommon/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
deleted file mode 100644 (file)
index 4aaa8a9..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-//
-// Copyright © 2017 Arm Ltd. All rights reserved.
-// SPDX-License-Identifier: MIT
-//
-#pragma once
-
-#include <backendsCommon/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
index ab62eee..f4e14c2 100644 (file)
@@ -53,7 +53,7 @@ ILayerSupportSharedPtr GetLayerSupportPointer()
 static StaticRegistryInitializer<LayerSupportRegistry> g_RegisterHelper{
     LayerSupportRegistryInstance(),
     ClBackendId(),
-    [](const EmptyInitializer&)
+    []()
     {
         return GetLayerSupportPointer();
     }
index 8433240..97df8e4 100644 (file)
@@ -8,7 +8,6 @@
 # file in the root of ArmNN
 
 BACKEND_SOURCES := \
-        ClBackendContext.cpp \
         ClBackend.cpp \
         ClContextControl.cpp \
         ClLayerSupport.cpp \
@@ -55,4 +54,3 @@ BACKEND_TEST_SOURCES := \
         test/ClRuntimeTests.cpp \
         test/Fp16SupportTest.cpp \
         test/OpenClTimerTest.cpp
-
index 0f7759d..badad2f 100644 (file)
@@ -3,20 +3,17 @@
 # SPDX-License-Identifier: MIT
 #
 
-list(APPEND armnnNeonBackend_sources
-    NeonBackendId.hpp
-    NeonLayerSupport.cpp
-    NeonLayerSupport.hpp
-    NeonWorkloadFactory.cpp
-    NeonWorkloadFactory.hpp
-)
-
 if(ARMCOMPUTENEON)
     list(APPEND armnnNeonBackend_sources
         NeonBackend.cpp
         NeonBackend.hpp
+        NeonBackendId.hpp
         NeonInterceptorScheduler.hpp
         NeonInterceptorScheduler.cpp
+        NeonLayerSupport.cpp
+        NeonLayerSupport.hpp
+        NeonWorkloadFactory.cpp
+        NeonWorkloadFactory.hpp
         NeonTensorHandle.hpp
         NeonTimer.hpp
         NeonTimer.cpp
@@ -27,10 +24,18 @@ if(ARMCOMPUTENEON)
     if(BUILD_UNIT_TESTS)
         add_subdirectory(test)
     endif()
+
+else()
+    list(APPEND armnnNeonBackend_sources
+        NeonBackendId.hpp
+        NeonLayerSupport.cpp
+        NeonLayerSupport.hpp
+        NeonWorkloadFactory.cpp
+        NeonWorkloadFactory.hpp
+    )
 endif()
 
 add_library(armnnNeonBackend OBJECT ${armnnNeonBackend_sources})
 target_include_directories(armnnNeonBackend PRIVATE ${PROJECT_SOURCE_DIR}/src/armnn)
 target_include_directories(armnnNeonBackend PRIVATE ${PROJECT_SOURCE_DIR}/src/armnnUtils)
 target_include_directories(armnnNeonBackend PRIVATE ${PROJECT_SOURCE_DIR}/src/backends)
-
index 1e9f633..7058d24 100644 (file)
@@ -9,6 +9,8 @@
 
 #include <backendsCommon/BackendRegistry.hpp>
 
+#include <boost/cast.hpp>
+
 namespace armnn
 {
 
@@ -19,7 +21,7 @@ static StaticRegistryInitializer<BackendRegistry> g_RegisterHelper
 {
     BackendRegistryInstance(),
     NeonBackend::GetIdStatic(),
-    [](const EmptyInitializer&)
+    []()
     {
         return IBackendInternalUniquePtr(new NeonBackend);
     }
index 27ad94d..b8bbd78 100644 (file)
@@ -12,8 +12,8 @@ namespace armnn
 class NeonBackend : public IBackendInternal
 {
 public:
-    NeonBackend() = default;
-    ~NeonBackend() override = default;
+    NeonBackend()  = default;
+    ~NeonBackend() = default;
 
     static const BackendId& GetIdStatic();
     const BackendId& GetId() const override { return GetIdStatic(); }
index 4704135..a4a6b67 100644 (file)
@@ -49,7 +49,7 @@ ILayerSupportSharedPtr GetLayerSupportPointer()
 static StaticRegistryInitializer<LayerSupportRegistry> g_RegisterHelper{
     LayerSupportRegistryInstance(),
     NeonBackendId(),
-    [](const EmptyInitializer&)
+    []()
     {
         return GetLayerSupportPointer();
     }
index 29b3527..8f7e72b 100644 (file)
@@ -49,4 +49,3 @@ BACKEND_TEST_SOURCES := \
         test/NeonOptimizedNetworkTests.cpp \
         test/NeonRuntimeTests.cpp \
         test/NeonTimerTest.cpp
-
index 1799275..ff16f18 100644 (file)
@@ -23,4 +23,3 @@ add_subdirectory(workloads)
 if(BUILD_UNIT_TESTS)
     add_subdirectory(test)
 endif()
-
index 91fc3c9..b6fb0ff 100644 (file)
@@ -9,6 +9,8 @@
 
 #include <backendsCommon/BackendRegistry.hpp>
 
+#include <boost/cast.hpp>
+
 namespace armnn
 {
 
@@ -19,7 +21,7 @@ static StaticRegistryInitializer<BackendRegistry> g_RegisterHelper
 {
     BackendRegistryInstance(),
     RefBackend::GetIdStatic(),
-    [](const EmptyInitializer&)
+    []()
     {
         return IBackendInternalUniquePtr(new RefBackend);
     }
index e2f264d..48a9d52 100644 (file)
@@ -12,8 +12,8 @@ namespace armnn
 class RefBackend : public IBackendInternal
 {
 public:
-    RefBackend() = default;
-    ~RefBackend() override = default;
+    RefBackend()  = default;
+    ~RefBackend() = default;
 
     static const BackendId& GetIdStatic();
     const BackendId& GetId() const override { return GetIdStatic(); }
index 1e8fa75..629903e 100644 (file)
@@ -31,7 +31,7 @@ ILayerSupportSharedPtr GetLayerSupportPointer()
 static StaticRegistryInitializer<LayerSupportRegistry> g_RegisterHelper{
     LayerSupportRegistryInstance(),
     RefBackendId(),
-    [](const EmptyInitializer&)
+    []()
     {
         return GetLayerSupportPointer();
     }
index 8a8a78a..007efce 100644 (file)
@@ -71,4 +71,3 @@ BACKEND_TEST_SOURCES := \
         test/RefLayerTests.cpp \
         test/RefOptimizedNetworkTests.cpp \
         test/RefRuntimeTests.cpp
-