From 992d6dc57d8463729910b688f0fb5825d0d3ccf2 Mon Sep 17 00:00:00 2001 From: Matteo Martincigh Date: Thu, 10 Jan 2019 17:34:20 +0000 Subject: [PATCH] IVGCVSW-2454 Refactor ArmNN to support pluggable backends from a separate code base * Made the virtual functions in ILayerSupport.hpp pure * Created a LayerSupportBase class with the default implementation of the interface * Made the backend layer support classes inherit from the base class, instead of directly from the interface * Refactored the profiler and the profiling event classes to use the BackendId instead of the Compute * Implemented a proper MemCopy support method * Changed Compute to BackendId in the profiling API and objects * Removed static references to pluggable backends !android-nn-driver:492 Change-Id: Id6332b5f48c980819e0a09adc818d1effd057296 --- include/armnn/BackendId.hpp | 23 +- include/armnn/ILayerSupport.hpp | 90 +++--- include/armnn/LayerSupport.hpp | 152 +++++----- src/armnn/Layer.cpp | 2 +- src/armnn/LayerSupport.cpp | 239 +++++++-------- src/armnn/Profiling.cpp | 8 +- src/armnn/Profiling.hpp | 18 +- src/armnn/ProfilingEvent.cpp | 12 +- src/armnn/ProfilingEvent.hpp | 18 +- src/armnn/test/ProfilingEventTest.cpp | 20 +- src/backends/backendsCommon/CMakeLists.txt | 3 +- src/backends/backendsCommon/ILayerSupport.cpp | 346 ---------------------- src/backends/backendsCommon/LayerSupportBase.cpp | 355 +++++++++++++++++++++++ src/backends/backendsCommon/LayerSupportBase.hpp | 223 ++++++++++++++ src/backends/backendsCommon/WorkloadFactory.cpp | 24 +- src/backends/backendsCommon/common.mk | 2 +- src/backends/cl/ClLayerSupport.cpp | 11 + src/backends/cl/ClLayerSupport.hpp | 9 +- src/backends/neon/NeonLayerSupport.cpp | 19 +- src/backends/neon/NeonLayerSupport.hpp | 12 +- src/backends/reference/RefLayerSupport.cpp | 13 + src/backends/reference/RefLayerSupport.hpp | 11 +- 22 files changed, 960 insertions(+), 650 deletions(-) delete mode 100644 src/backends/backendsCommon/ILayerSupport.cpp create mode 100644 src/backends/backendsCommon/LayerSupportBase.cpp create mode 100644 src/backends/backendsCommon/LayerSupportBase.hpp diff --git a/include/armnn/BackendId.hpp b/include/armnn/BackendId.hpp index 8de985e..8720607 100644 --- a/include/armnn/BackendId.hpp +++ b/include/armnn/BackendId.hpp @@ -20,13 +20,13 @@ namespace armnn // enum class Compute { + Undefined = 0, /// CPU Execution: Reference C++ kernels - CpuRef = 0, + CpuRef = 1, /// CPU Execution: NEON: ArmCompute - CpuAcc = 1, + CpuAcc = 2, /// GPU Execution: OpenCL: ArmCompute - GpuAcc = 2, - Undefined = 5 + GpuAcc = 3 }; /// Deprecated function that will be removed together with @@ -46,7 +46,8 @@ constexpr char const* GetComputeDeviceAsCString(Compute compute) /// the Compute enum inline std::ostream& operator<<(std::ostream& os, const std::vector& compute) { - for (const Compute& comp : compute) { + for (const Compute& comp : compute) + { os << GetComputeDeviceAsCString(comp) << " "; } return os; @@ -56,7 +57,8 @@ inline std::ostream& operator<<(std::ostream& os, const std::vector& co /// the Compute enum inline std::ostream& operator<<(std::ostream& os, const std::set& compute) { - for (const Compute& comp : compute) { + for (const Compute& comp : compute) + { os << GetComputeDeviceAsCString(comp) << " "; } return os; @@ -70,13 +72,10 @@ inline std::ostream& operator<<(std::ostream& os, const Compute& compute) return os; } -struct UninitializedBackendId {}; - class BackendId final { public: - BackendId() { GetComputeDeviceAsCString(Compute::Undefined); } - BackendId(UninitializedBackendId) { GetComputeDeviceAsCString(Compute::Undefined); } + BackendId() : m_Id(GetComputeDeviceAsCString(Compute::Undefined)) {} BackendId(const std::string& id) : m_Id{id} {} BackendId(const char* id) : m_Id{id} {} @@ -132,7 +131,7 @@ private: std::string m_Id; }; -} +} // namespace armnn namespace std { @@ -163,7 +162,7 @@ inline std::ostream& operator<<(std::ostream& os, const BackendId& id) template