From 9df2d951616e3d76b67a9852d5324de96633f0f9 Mon Sep 17 00:00:00 2001 From: David Beck Date: Wed, 10 Oct 2018 15:11:44 +0100 Subject: IVGCVSW-1952 : add BackendId class to prepare for the replacement of Compute enum !armnn:152674 Change-Id: I1bcdfdfbfb73e502d58f35717e2558e24651013c --- CMakeLists.txt | 10 ++- include/armnn/BackendId.hpp | 132 ++++++++++++++++++++++++++++++++++ include/armnn/Types.hpp | 16 +---- include/armnn/TypesUtils.hpp | 36 +--------- src/backends/BackendRegistry.cpp | 24 +++++-- src/backends/BackendRegistry.hpp | 13 ++-- src/backends/cl/ClBackend.cpp | 4 +- src/backends/cl/ClBackend.hpp | 2 +- src/backends/neon/NeonBackend.cpp | 4 +- src/backends/neon/NeonBackend.hpp | 2 +- src/backends/reference/RefBackend.cpp | 4 +- src/backends/reference/RefBackend.hpp | 2 +- src/backends/test/BackendIdTests.cpp | 27 +++++++ 13 files changed, 205 insertions(+), 71 deletions(-) create mode 100644 include/armnn/BackendId.hpp create mode 100644 src/backends/test/BackendIdTests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 501da806ad..dfda4d1d93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,18 +147,23 @@ endif() list(APPEND armnn_sources include/armnn/ArmNN.hpp + include/armnn/BackendId.hpp include/armnn/Descriptors.hpp include/armnn/DescriptorsFwd.hpp - include/armnn/IRuntime.hpp + include/armnn/Exceptions.hpp include/armnn/ILayerSupport.hpp include/armnn/INetwork.hpp + include/armnn/IProfiler.hpp + include/armnn/IRuntime.hpp + include/armnn/LayerSupport.hpp + include/armnn/LstmParams.hpp + include/armnn/NetworkFwd.hpp include/armnn/Optional.hpp include/armnn/Tensor.hpp include/armnn/TensorFwd.hpp include/armnn/Types.hpp include/armnn/TypesUtils.hpp include/armnn/Utils.hpp - include/armnn/LayerSupport.hpp include/armnn/Version.hpp src/armnn/layers/LayerCloneBase.hpp src/armnn/layers/LayerWithParameters.hpp @@ -378,6 +383,7 @@ if(BUILD_UNIT_TESTS) src/armnn/test/InstrumentTests.cpp src/armnn/test/ObservableTest.cpp src/armnn/test/OptionalTest.cpp + src/backends/test/BackendIdTests.cpp src/backends/test/BackendRegistryTests.cpp src/backends/test/IsLayerSupportedTestImpl.hpp src/backends/test/WorkloadDataValidation.cpp diff --git a/include/armnn/BackendId.hpp b/include/armnn/BackendId.hpp new file mode 100644 index 0000000000..d1f06beba7 --- /dev/null +++ b/include/armnn/BackendId.hpp @@ -0,0 +1,132 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// +#pragma once + +#include +#include +#include +#include + +namespace armnn +{ + +// +// The Compute enum is now deprecated and it is now +// replaced by BackendId +// +enum class Compute +{ + /// CPU Execution: Reference C++ kernels + CpuRef = 0, + /// CPU Execution: NEON: ArmCompute + CpuAcc = 1, + /// GPU Execution: OpenCL: ArmCompute + GpuAcc = 2, + Undefined = 5 +}; + +constexpr char const* GetComputeDeviceAsCString(Compute compute) +{ + switch (compute) + { + case armnn::Compute::CpuRef: return "CpuRef"; + case armnn::Compute::CpuAcc: return "CpuAcc"; + case armnn::Compute::GpuAcc: return "GpuAcc"; + default: return "Unknown"; + } +} + +inline std::ostream& operator<<(std::ostream& os, const std::vector& compute) +{ + for (const Compute& comp : compute) { + os << GetComputeDeviceAsCString(comp) << " "; + } + return os; +} + +inline std::ostream& operator<<(std::ostream& os, const std::set& compute) +{ + for (const Compute& comp : compute) { + os << GetComputeDeviceAsCString(comp) << " "; + } + return os; +} + +inline std::ostream& operator<<(std::ostream& os, const Compute& compute) +{ + os << GetComputeDeviceAsCString(compute); + return os; +} + +class BackendId final +{ +public: + BackendId(const std::string& id) : m_Id{id} {} + BackendId(const char* id) : m_Id{id} {} + BackendId(Compute compute) : m_Id{GetComputeDeviceAsCString(compute)} {} + + operator std::string() const { return m_Id; } + + BackendId& operator=(const std::string& other) + { + m_Id = other; + return *this; + } + + BackendId& operator=(Compute compute) + { + BackendId temp{compute}; + std::swap(temp.m_Id, m_Id); + return *this; + } + + bool operator==(const BackendId& other) const + { + return m_Id == other.m_Id; + } + + bool operator<(const BackendId& other) const + { + return m_Id < other.m_Id; + } + + const std::string& Get() const { return m_Id; } + +private: + // backend Id mustn't be empty: + BackendId() = delete; + std::string m_Id; +}; + +template