ArmNN
 21.02
IBackendInternal.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
8 
9 namespace armnn
10 {
11 
13 IBackendInternal::ISubGraphConverterPtr IBackendInternal::CreateSubGraphConverter(
14  const std::shared_ptr<SubGraph>& /*subGrapg*/) const
15 {
16  return ISubGraphConverterPtr{};
17 }
18 
20 {
21  return Optimizations{};
22 }
23 
24 IBackendInternal::SubGraphUniquePtr IBackendInternal::OptimizeSubGraph(const SubGraph& /*subGraph*/,
25  bool& optimizationAttempted) const
26 {
27  optimizationAttempted = false;
28  return nullptr;
29 }
31 
33 {
34  return IMemoryManagerUniquePtr();
35 }
36 
38  class TensorHandleFactoryRegistry& /*tensorHandleFactoryRegistry*/) const
39 {
40  return IWorkloadFactoryPtr{};
41 }
42 
44  const IMemoryManagerSharedPtr& memoryManager,
45  const ModelOptions& modelOptions) const
46 {
47  if (!modelOptions.empty())
48  {
49  for (auto optionsGroup : modelOptions)
50  {
51  if (optionsGroup.GetBackendId() == GetId())
52  {
53  return IWorkloadFactoryPtr{};
54  }
55  }
56  }
57 
58  return CreateWorkloadFactory(memoryManager);
59 }
60 
62  class TensorHandleFactoryRegistry& tensorHandleFactoryRegistry,
63  const ModelOptions& modelOptions) const
64 {
65  if (!modelOptions.empty())
66  {
67  for (auto optionsGroup : modelOptions)
68  {
69  if (optionsGroup.GetBackendId() == GetId())
70  {
71  return IWorkloadFactoryPtr{};
72  }
73  }
74  }
75 
76  return CreateWorkloadFactory(tensorHandleFactoryRegistry);
77 }
78 
80 {
81  return IBackendContextPtr{};
82 }
83 
85  const ModelOptions&) const
86 {
88 }
89 
92 {
94 }
95 
97 {
98  if (!modelOptions.empty())
99  {
100  for (auto optionsGroup : modelOptions)
101  {
102  if (optionsGroup.GetBackendId() == GetId())
103  {
104  return ILayerSupportSharedPtr{};
105  }
106  }
107  }
108 
109  return GetLayerSupport();
110 }
111 
112 // Default implementation of OptimizeSubgraphView for backward compatibility with the old API.
113 // Override this method with a custom optimization implementation.
115 {
116  bool optimizationAttempted = false;
117 
119  SubGraphUniquePtr optSubgraph = OptimizeSubGraph(subgraph, optimizationAttempted);
121 
122  OptimizationViews result;
123  if (!optimizationAttempted)
124  {
125  result.AddUntouchedSubgraph(SubgraphView(subgraph));
126  }
127  else if (optSubgraph)
128  {
129  result.AddSubstitution({subgraph, SubgraphView(*optSubgraph.get())});
130  }
131  else
132  {
133  result.AddFailedSubgraph(SubgraphView(subgraph));
134  }
135 
136  return result;
137 }
138 
140  const ModelOptions& /*modelOptions*/) const
141 {
142  return OptimizeSubgraphView(subgraph);
143 }
144 
146 {
147  return !GetHandleFactoryPreferences().empty();
148 }
149 
151 {
152  auto favorites = GetHandleFactoryPreferences();
153  if (favorites.empty())
154  {
156  }
157 
158  return favorites[0];
159 }
160 
161 std::vector<ITensorHandleFactory::FactoryId> IBackendInternal::GetHandleFactoryPreferences() const
162 {
163  return std::vector<ITensorHandleFactory::FactoryId>();
164 }
165 
166 } // namespace armnn
std::unique_ptr< IWorkloadFactory > IWorkloadFactoryPtr
std::vector< OptimizationPtr > Optimizations
#define ARMNN_NO_DEPRECATE_WARN_BEGIN
Definition: Deprecated.hpp:33
virtual IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions &) const
Create the runtime context of the backend.
std::vector< BackendOptions > ModelOptions
Copyright (c) 2021 ARM Limited and Contributors.
std::unique_ptr< IMemoryManager > IMemoryManagerUniquePtr
ITensorHandleFactory::FactoryId GetBackwardCompatibleFavoriteHandleFactory()
virtual const BackendId & GetId() const =0
virtual std::vector< ITensorHandleFactory::FactoryId > GetHandleFactoryPreferences() const
(Optional) Returns a vector of supported TensorHandleFactory ids in preference order.
virtual IWorkloadFactoryPtr CreateWorkloadFactory(const IMemoryManagerSharedPtr &memoryManager=nullptr) const =0
The SubgraphView class represents a subgraph of a Graph.
std::unique_ptr< armnn::profiling::IBackendProfiling > IBackendProfilingPtr
#define ARMNN_NO_DEPRECATE_WARN_END
Definition: Deprecated.hpp:34
std::shared_ptr< IBackendModelContext > IBackendSpecificModelContextPtr
bool SupportsTensorAllocatorAPI() const
std::shared_ptr< IMemoryManager > IMemoryManagerSharedPtr
virtual Optimizations GetOptimizations() const
void AddUntouchedSubgraph(SubgraphView &&subgraph)
std::shared_ptr< ILayerSupport > ILayerSupportSharedPtr
virtual IBackendProfilingContextPtr CreateBackendProfilingContext(const IRuntime::CreationOptions &creationOptions, IBackendProfilingPtr &backendProfiling)
Create context specifically used for profiling interaction from backends.
virtual ILayerSupportSharedPtr GetLayerSupport() const =0
virtual IBackendSpecificModelContextPtr CreateBackendSpecificModelContext(const ModelOptions &modelOptions) const
virtual OptimizationViews OptimizeSubgraphView(const SubgraphView &subgraph) const
virtual SubGraphUniquePtr OptimizeSubGraph(const SubGraph &subGraph, bool &optimizationAttempted) const
virtual ARMNN_NO_DEPRECATE_WARN_END IMemoryManagerUniquePtr CreateMemoryManager() const
virtual ISubGraphConverterPtr CreateSubGraphConverter(const std::shared_ptr< SubGraph > &subGraph) const
static const FactoryId LegacyFactoryId
std::shared_ptr< armnn::profiling::IBackendProfilingContext > IBackendProfilingContextPtr
This is the bridge between backend and backend profiling we&#39;ll keep it in the backend namespace...
std::unique_ptr< IBackendContext > IBackendContextPtr