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 --- include/armnn/BackendId.hpp | 132 +++++++++++++++++++++++++++++++++++++++++++ include/armnn/Types.hpp | 16 +----- include/armnn/TypesUtils.hpp | 36 +----------- 3 files changed, 137 insertions(+), 47 deletions(-) create mode 100644 include/armnn/BackendId.hpp (limited to 'include') 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