ArmNN  NotReleased
IBackendInternal.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <armnn/Types.hpp>
9 #include <armnn/IRuntime.hpp>
10 #include <armnn/Deprecated.hpp>
11 
13 #include <SubgraphView.hpp>
15 
16 #include "IBackendContext.hpp"
19 #include "IMemoryManager.hpp"
20 #include "ITensorHandleFactory.hpp"
21 #include "OptimizationViews.hpp"
22 
23 #include <vector>
24 #include <memory>
25 
26 namespace armnn
27 {
28 class IWorkloadFactory;
29 class IMemoryManager;
30 class ILayerSupport;
31 
33 {
34  uint32_t m_Major;
35  uint32_t m_Minor;
36 
37  constexpr BackendVersion()
38  : m_Major(0)
39  , m_Minor(0)
40  {}
41  constexpr BackendVersion(uint32_t major, uint32_t minor)
42  : m_Major(major)
43  , m_Minor(minor)
44  {}
45 
46  bool operator==(const BackendVersion& other) const
47  {
48  return this == &other ||
49  (this->m_Major == other.m_Major &&
50  this->m_Minor == other.m_Minor);
51  }
52 
53  bool operator<=(const BackendVersion& other) const
54  {
55  return this->m_Major < other.m_Major ||
56  (this->m_Major == other.m_Major &&
57  this->m_Minor <= other.m_Minor);
58  }
59 };
60 
61 inline std::ostream& operator<<(std::ostream& os, const BackendVersion& backendVersion)
62 {
63  os << "[" << backendVersion.m_Major << "." << backendVersion.m_Minor << "]";
64 
65  return os;
66 }
67 
68 class IBackendInternal : public IBackend
69 {
70 protected:
71  // Creation must be done through a specific
72  // backend interface.
73  IBackendInternal() = default;
74 
75 public:
76  // Allow backends created by the factory function
77  // to be destroyed through IBackendInternal.
78  ~IBackendInternal() override = default;
79 
80  using IWorkloadFactoryPtr = std::unique_ptr<IWorkloadFactory>;
81  using IBackendContextPtr = std::unique_ptr<IBackendContext>;
82  // This is the bridge between backend and backend profiling we'll keep it in the backend namespace.
83  using IBackendProfilingContextPtr = std::shared_ptr<armnn::profiling::IBackendProfilingContext>;
84  using IBackendProfilingPtr = std::unique_ptr<armnn::profiling::IBackendProfiling>;
85  using OptimizationPtr = std::unique_ptr<Optimization>;
86  using Optimizations = std::vector<OptimizationPtr>;
87  using ILayerSupportSharedPtr = std::shared_ptr<ILayerSupport>;
88 
89  using IMemoryManagerUniquePtr = std::unique_ptr<IMemoryManager>;
90  using IMemoryManagerSharedPtr = std::shared_ptr<IMemoryManager>;
91 
92  using GraphUniquePtr = std::unique_ptr<Graph>;
93  using SubgraphViewUniquePtr = std::unique_ptr<SubgraphView>;
94 
96  using ISubGraphConverterPtr ARMNN_DEPRECATED_MSG("This type is no longer supported")
97  = std::unique_ptr<ISubGraphConverter>;
98  using SubGraphUniquePtr ARMNN_DEPRECATED_MSG("SubGraph is deprecated, use SubgraphView instead")
99  = std::unique_ptr<SubGraph>;
100 
101  ARMNN_DEPRECATED_MSG("This method is no longer supported")
102  virtual ISubGraphConverterPtr CreateSubGraphConverter(const std::shared_ptr<SubGraph>& subGraph) const;
103 
104  ARMNN_DEPRECATED_MSG("Use \"OptimizationViews OptimizeSubgraphView(const SubgraphView&)\" instead")
105  virtual Optimizations GetOptimizations() const;
106 
107  ARMNN_DEPRECATED_MSG("Use \"OptimizationViews OptimizeSubgraphView(const SubgraphView&)\" instead")
108  virtual SubGraphUniquePtr OptimizeSubGraph(const SubGraph& subGraph, bool& optimizationAttempted) const;
110 
111  virtual IMemoryManagerUniquePtr CreateMemoryManager() const;
112 
113  virtual IWorkloadFactoryPtr CreateWorkloadFactory(
114  const IMemoryManagerSharedPtr& memoryManager = nullptr) const = 0;
115 
116  virtual IWorkloadFactoryPtr CreateWorkloadFactory(
117  class TensorHandleFactoryRegistry& tensorHandleFactoryRegistry) const;
118 
126  virtual IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions&) const;
127 
129  virtual IBackendProfilingContextPtr CreateBackendProfilingContext(const IRuntime::CreationOptions& creationOptions,
130  IBackendProfilingPtr& backendProfiling);
131 
132  virtual ILayerSupportSharedPtr GetLayerSupport() const = 0;
133 
134  virtual OptimizationViews OptimizeSubgraphView(const SubgraphView& subgraph) const;
135 
136  bool SupportsTensorAllocatorAPI() const;
137 
138  ITensorHandleFactory::FactoryId GetBackwardCompatibleFavoriteHandleFactory();
139 
141  virtual std::vector<ITensorHandleFactory::FactoryId> GetHandleFactoryPreferences() const;
142 
146  virtual void RegisterTensorHandleFactories(class TensorHandleFactoryRegistry& /*registry*/) {}
147 
149  static constexpr BackendVersion GetApiVersion() { return BackendVersion(1, 0); }
150 };
151 
152 using IBackendInternalUniquePtr = std::unique_ptr<IBackendInternal>;
153 
154 } // namespace armnn
std::unique_ptr< IBackendInternal > IBackendInternalUniquePtr
std::unique_ptr< Optimization > OptimizationPtr
std::unique_ptr< IWorkloadFactory > IWorkloadFactoryPtr
std::unique_ptr< SubgraphView > SubgraphViewUniquePtr
std::vector< OptimizationPtr > Optimizations
Each backend should implement an IBackend.
Definition: Types.hpp:144
std::unique_ptr< IBackendContext > IBackendContextPtr
std::shared_ptr< IMemoryManager > IMemoryManagerSharedPtr
std::unique_ptr< Graph > GraphUniquePtr
ITensorHandleFactory::FactoryId FactoryId
#define ARMNN_NO_DEPRECATE_WARN_BEGIN
Definition: Deprecated.hpp:33
std::unique_ptr< SubGraph > instead
std::shared_ptr< armnn::profiling::IBackendProfilingContext > IBackendProfilingContextPtr
std::unique_ptr< IMemoryManager > IMemoryManagerUniquePtr
bool operator<=(const BackendVersion &other) const
static constexpr BackendVersion GetApiVersion()
Returns the version of the Backend API.
bool operator==(const BackendVersion &other) const
std::shared_ptr< ILayerSupport > ILayerSupportSharedPtr
#define ARMNN_DEPRECATED_MSG(message)
Definition: Deprecated.hpp:43
std::unique_ptr< armnn::profiling::IBackendProfiling > IBackendProfilingPtr
constexpr BackendVersion(uint32_t major, uint32_t minor)
std::ostream & operator<<(std::ostream &os, const std::vector< Compute > &compute)
Definition: BackendId.hpp:47
#define ARMNN_NO_DEPRECATE_WARN_END
Definition: Deprecated.hpp:34