aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDavid Beck <david.beck@arm.com>2018-10-10 15:11:44 +0100
committerMatthew Bentham <matthew.bentham@arm.com>2018-10-22 16:57:53 +0100
commit9df2d951616e3d76b67a9852d5324de96633f0f9 (patch)
tree37a57a98ef8aafba748d332bfc686e2b022398d6 /include
parent6b779f0e437127bfa71a529e9b848b5e41683ab8 (diff)
downloadarmnn-9df2d951616e3d76b67a9852d5324de96633f0f9.tar.gz
IVGCVSW-1952 : add BackendId class to prepare for the replacement of Compute enum
!armnn:152674 Change-Id: I1bcdfdfbfb73e502d58f35717e2558e24651013c
Diffstat (limited to 'include')
-rw-r--r--include/armnn/BackendId.hpp132
-rw-r--r--include/armnn/Types.hpp16
-rw-r--r--include/armnn/TypesUtils.hpp36
3 files changed, 137 insertions, 47 deletions
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 <set>
+#include <unordered_set>
+#include <string>
+#include <memory>
+
+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>& compute)
+{
+ for (const Compute& comp : compute) {
+ os << GetComputeDeviceAsCString(comp) << " ";
+ }
+ return os;
+}
+
+inline std::ostream& operator<<(std::ostream& os, const std::set<Compute>& 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 <template <class...> class TContainer>
+inline std::ostream& operator<<(std::ostream& os,
+ const TContainer<BackendId>& ids)
+{
+ os << '[';
+ for (const auto& id : ids) { os << id.Get() << " "; }
+ os << ']';
+ return os;
+}
+
+using BackendIdSet = std::unordered_set<BackendId>;
+
+} // namespace armnn
+
+namespace std
+{
+
+// make BackendId compatible with std hashtables by reusing the hash
+// function for strings
+template <>
+struct hash<armnn::BackendId>
+{
+ std::size_t operator()(const armnn::BackendId& id) const
+ {
+ std::hash<std::string> hasher;
+ return hasher(id.Get());
+ }
+};
+
+} // namespace std
diff --git a/include/armnn/Types.hpp b/include/armnn/Types.hpp
index b7ee9472a3..4afc50b1b1 100644
--- a/include/armnn/Types.hpp
+++ b/include/armnn/Types.hpp
@@ -7,6 +7,7 @@
#include <array>
#include <memory>
#include "ILayerSupport.hpp"
+#include "BackendId.hpp"
namespace armnn
{
@@ -94,17 +95,6 @@ enum class OutputShapeRounding
Ceiling = 1
};
-enum class Compute
-{
- /// CPU Execution: Reference C++ kernels
- CpuRef = 0,
- /// CPU Execution: NEON: ArmCompute
- CpuAcc = 1,
- /// GPU Execution: OpenCL: ArmCompute
- GpuAcc = 2,
- Undefined = 5
-};
-
/// Each backend should implement an IBackend.
class IBackend
{
@@ -113,7 +103,7 @@ protected:
virtual ~IBackend() {}
public:
- virtual const std::string& GetId() const = 0;
+ virtual const BackendId& GetId() const = 0;
virtual const ILayerSupport& GetLayerSupport() const = 0;
};
@@ -189,4 +179,4 @@ private:
/// Define LayerGuid type.
using LayerGuid = unsigned int;
-}
+} // namespace armnn
diff --git a/include/armnn/TypesUtils.hpp b/include/armnn/TypesUtils.hpp
index c6db905bb9..a9755bd112 100644
--- a/include/armnn/TypesUtils.hpp
+++ b/include/armnn/TypesUtils.hpp
@@ -15,9 +15,9 @@
namespace armnn
{
-constexpr char const* GetStatusAsCString(Status compute)
+constexpr char const* GetStatusAsCString(Status status)
{
- switch (compute)
+ switch (status)
{
case armnn::Status::Success: return "Status::Success";
case armnn::Status::Failure: return "Status::Failure";
@@ -25,17 +25,6 @@ constexpr char const* GetStatusAsCString(Status compute)
}
}
-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";
- }
-}
-
constexpr char const* GetActivationFunctionAsCString(ActivationFunction activation)
{
switch (activation)
@@ -194,27 +183,6 @@ inline std::ostream& operator<<(std::ostream& os, Status stat)
return os;
}
-inline std::ostream& operator<<(std::ostream& os, const std::vector<Compute>& compute)
-{
- for (const Compute& comp : compute) {
- os << GetComputeDeviceAsCString(comp) << " ";
- }
- return os;
-}
-
-inline std::ostream& operator<<(std::ostream& os, const std::set<Compute>& 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;
-}
inline std::ostream & operator<<(std::ostream & os, const armnn::TensorShape & shape)
{