ArmNN
 21.05
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  class TensorHandleFactoryRegistry& tensorHandleFactoryRegistry,
81  const ModelOptions& modelOptions,
82  MemorySourceFlags inputFlags,
83  MemorySourceFlags outputFlags) const
84 {
85  IgnoreUnused(inputFlags);
86  IgnoreUnused(outputFlags);
87  return CreateWorkloadFactory(tensorHandleFactoryRegistry, modelOptions);
88 }
89 
91 {
92  return IBackendContextPtr{};
93 }
94 
96  const ModelOptions&) const
97 {
99 }
100 
103 {
105 }
106 
108 {
109  if (!modelOptions.empty())
110  {
111  for (auto optionsGroup : modelOptions)
112  {
113  if (optionsGroup.GetBackendId() == GetId())
114  {
115  return ILayerSupportSharedPtr{};
116  }
117  }
118  }
119 
120  return GetLayerSupport();
121 }
122 
123 // Default implementation of OptimizeSubgraphView for backward compatibility with the old API.
124 // Override this method with a custom optimization implementation.
126 {
127  bool optimizationAttempted = false;
128 
130  SubGraphUniquePtr optSubgraph = OptimizeSubGraph(subgraph, optimizationAttempted);
132 
133  OptimizationViews result;
134  if (!optimizationAttempted)
135  {
136  result.AddUntouchedSubgraph(SubgraphView(subgraph));
137  }
138  else if (optSubgraph)
139  {
140  result.AddSubstitution({subgraph, SubgraphView(*optSubgraph.get())});
141  }
142  else
143  {
144  result.AddFailedSubgraph(SubgraphView(subgraph));
145  }
146 
147  return result;
148 }
149 
151  const ModelOptions& /*modelOptions*/) const
152 {
153  return OptimizeSubgraphView(subgraph);
154 }
155 
157 {
158  return !GetHandleFactoryPreferences().empty();
159 }
160 
162  MemorySourceFlags /*inputFlags*/,
163  MemorySourceFlags /*outputFlags*/)
164 {
165  return RegisterTensorHandleFactories(registry);
166 }
167 
169 {
170  auto favorites = GetHandleFactoryPreferences();
171  if (favorites.empty())
172  {
174  }
175 
176  return favorites[0];
177 }
178 
179 std::vector<ITensorHandleFactory::FactoryId> IBackendInternal::GetHandleFactoryPreferences() const
180 {
181  return std::vector<ITensorHandleFactory::FactoryId>();
182 }
183 
184 } // namespace armnn
virtual void RegisterTensorHandleFactories(class TensorHandleFactoryRegistry &)
(Optional) Register TensorHandleFactories Either this method or CreateMemoryManager() and IWorkloadFa...
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
unsigned int MemorySourceFlags
Copyright (c) 2021 ARM Limited and Contributors.
std::unique_ptr< IMemoryManager > IMemoryManagerUniquePtr
void IgnoreUnused(Ts &&...)
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