ArmNN
 20.08
MockBackend Class Reference

#include <MockBackend.hpp>

Inheritance diagram for MockBackend:
IBackendInternal IBackend

Public Member Functions

 MockBackend ()=default
 
 ~MockBackend ()=default
 
const BackendIdGetId () const override
 
IBackendInternal::IMemoryManagerUniquePtr CreateMemoryManager () const override
 
IBackendInternal::IWorkloadFactoryPtr CreateWorkloadFactory (const IBackendInternal::IMemoryManagerSharedPtr &memoryManager=nullptr) const override
 
IBackendInternal::IBackendContextPtr CreateBackendContext (const IRuntime::CreationOptions &) const override
 Create the runtime context of the backend. More...
 
IBackendInternal::IBackendProfilingContextPtr CreateBackendProfilingContext (const IRuntime::CreationOptions &creationOptions, IBackendProfilingPtr &backendProfiling) override
 Create context specifically used for profiling interaction from backends. More...
 
IBackendInternal::Optimizations GetOptimizations () const override
 
IBackendInternal::ILayerSupportSharedPtr GetLayerSupport () const override
 
OptimizationViews OptimizeSubgraphView (const SubgraphView &subgraph) const override
 
- Public Member Functions inherited from IBackendInternal
 ~IBackendInternal () override=default
 Allow backends created by the factory function to be destroyed through IBackendInternal. More...
 
virtual ISubGraphConverterPtr CreateSubGraphConverter (const std::shared_ptr< SubGraph > &subGraph) const
 
virtual SubGraphUniquePtr OptimizeSubGraph (const SubGraph &subGraph, bool &optimizationAttempted) const
 
virtual IWorkloadFactoryPtr CreateWorkloadFactory (class TensorHandleFactoryRegistry &tensorHandleFactoryRegistry) const
 
bool SupportsTensorAllocatorAPI () const
 
ITensorHandleFactory::FactoryId GetBackwardCompatibleFavoriteHandleFactory ()
 
virtual std::vector< ITensorHandleFactory::FactoryIdGetHandleFactoryPreferences () const
 (Optional) Returns a vector of supported TensorHandleFactory ids in preference order. More...
 
virtual void RegisterTensorHandleFactories (class TensorHandleFactoryRegistry &)
 (Optional) Register TensorHandleFactories Either this method or CreateMemoryManager() and IWorkloadFactory::CreateTensor()/IWorkloadFactory::CreateSubtensor() methods must be implemented. More...
 

Static Public Member Functions

static const BackendIdGetIdStatic ()
 
- Static Public Member Functions inherited from IBackendInternal
static constexpr BackendVersion GetApiVersion ()
 Returns the version of the Backend API. More...
 

Additional Inherited Members

- Public Types inherited from IBackendInternal
using IWorkloadFactoryPtr = std::unique_ptr< IWorkloadFactory >
 
using IBackendContextPtr = std::unique_ptr< IBackendContext >
 
using IBackendProfilingContextPtr = std::shared_ptr< armnn::profiling::IBackendProfilingContext >
 This is the bridge between backend and backend profiling we'll keep it in the backend namespace. More...
 
using IBackendProfilingPtr = std::unique_ptr< armnn::profiling::IBackendProfiling >
 
using OptimizationPtr = std::unique_ptr< Optimization >
 
using Optimizations = std::vector< OptimizationPtr >
 
using ILayerSupportSharedPtr = std::shared_ptr< ILayerSupport >
 
using IMemoryManagerUniquePtr = std::unique_ptr< IMemoryManager >
 
using IMemoryManagerSharedPtr = std::shared_ptr< IMemoryManager >
 
using GraphUniquePtr = std::unique_ptr< Graph >
 
using SubgraphViewUniquePtr = std::unique_ptr< SubgraphView >
 
using supported = std::unique_ptr< ISubGraphConverter >
 
using instead = std::unique_ptr< SubGraph >
 
- Protected Member Functions inherited from IBackendInternal
 IBackendInternal ()=default
 Creation must be done through a specific backend interface. More...
 
- Protected Member Functions inherited from IBackend
 IBackend ()
 
virtual ~IBackend ()
 

Detailed Description

Definition at line 143 of file MockBackend.hpp.

Constructor & Destructor Documentation

◆ MockBackend()

MockBackend ( )
default

◆ ~MockBackend()

~MockBackend ( )
default

Member Function Documentation

◆ CreateBackendContext()

IBackendInternal::IBackendContextPtr CreateBackendContext ( const IRuntime::CreationOptions ) const
overridevirtual

Create the runtime context of the backend.

Implementations may return a default-constructed IBackendContextPtr if no context is needed at runtime. Implementations must throw BackendUnavailableException if the backend cannot be used (for example, necessary accelerator hardware is not present). The default implementation always returns a default-constructed pointer.

Reimplemented from IBackendInternal.

Definition at line 102 of file MockBackend.cpp.

103 {
104  return IBackendContextPtr{};
105 }
std::unique_ptr< IBackendContext > IBackendContextPtr

◆ CreateBackendProfilingContext()

IBackendInternal::IBackendProfilingContextPtr CreateBackendProfilingContext ( const IRuntime::CreationOptions creationOptions,
IBackendProfilingPtr backendProfiling 
)
overridevirtual

Create context specifically used for profiling interaction from backends.

Reimplemented from IBackendInternal.

Definition at line 107 of file MockBackend.cpp.

References armnn::IgnoreUnused(), MockBackendProfilingService::Instance(), and MockBackendProfilingService::SetProfilingContextPtr().

109 {
110  IgnoreUnused(options);
111  std::shared_ptr<armnn::MockBackendProfilingContext> context =
112  std::make_shared<MockBackendProfilingContext>(backendProfiling);
114  return context;
115 }
void SetProfilingContextPtr(std::shared_ptr< MockBackendProfilingContext > shared)
void IgnoreUnused(Ts &&...)
static MockBackendProfilingService & Instance()

◆ CreateMemoryManager()

IBackendInternal::IMemoryManagerUniquePtr CreateMemoryManager ( ) const
overridevirtual

Reimplemented from IBackendInternal.

Definition at line 117 of file MockBackend.cpp.

118 {
119  return IMemoryManagerUniquePtr{};
120 }
std::unique_ptr< IMemoryManager > IMemoryManagerUniquePtr

◆ CreateWorkloadFactory()

IBackendInternal::IWorkloadFactoryPtr CreateWorkloadFactory ( const IBackendInternal::IMemoryManagerSharedPtr memoryManager = nullptr) const
overridevirtual

Implements IBackendInternal.

Definition at line 96 of file MockBackend.cpp.

98 {
99  return IWorkloadFactoryPtr{};
100 }
std::unique_ptr< IWorkloadFactory > IWorkloadFactoryPtr

◆ GetId()

const BackendId& GetId ( ) const
inlineoverridevirtual

Implements IBackend.

Definition at line 150 of file MockBackend.hpp.

151  {
152  return GetIdStatic();
153  }
static const BackendId & GetIdStatic()
Definition: MockBackend.cpp:90

◆ GetIdStatic()

const BackendId & GetIdStatic ( )
static

Definition at line 90 of file MockBackend.cpp.

References armnn::MockBackendId().

Referenced by BOOST_AUTO_TEST_CASE(), MockBackendInitialiser::MockBackendInitialiser(), and MockBackendInitialiser::~MockBackendInitialiser().

91 {
92  static const BackendId s_Id{MockBackendId()};
93  return s_Id;
94 }
constexpr const char * MockBackendId()

◆ GetLayerSupport()

IBackendInternal::ILayerSupportSharedPtr GetLayerSupport ( ) const
overridevirtual

Implements IBackendInternal.

Definition at line 127 of file MockBackend.cpp.

128 {
129  static ILayerSupportSharedPtr layerSupport{new MockLayerSupport};
130  return layerSupport;
131 }
std::shared_ptr< ILayerSupport > ILayerSupportSharedPtr

◆ GetOptimizations()

IBackendInternal::Optimizations GetOptimizations ( ) const
overridevirtual

Reimplemented from IBackendInternal.

Definition at line 122 of file MockBackend.cpp.

123 {
124  return Optimizations{};
125 }
std::vector< OptimizationPtr > Optimizations

◆ OptimizeSubgraphView()

OptimizationViews OptimizeSubgraphView ( const SubgraphView subgraph) const
overridevirtual

Reimplemented from IBackendInternal.

Definition at line 133 of file MockBackend.cpp.

References OptimizationViews::AddFailedSubgraph(), Graph::AddLayer(), OptimizationViews::AddSubstitution(), OptimizationViews::AddUntouchedSubgraph(), ARMNN_ASSERT, OptimizationViews::GetGraph(), SubgraphView::GetLayers(), Layer::GetType(), armnn::Input, armnn::MockBackendId(), armnn::Output, SubgraphViewSelector::SelectSubgraphs(), and Layer::SetBackendId().

134 {
135  // Prepare the optimization views
136  OptimizationViews optimizationViews;
137 
138  // Get the layers of the input sub-graph
139  const SubgraphView::Layers& subgraphLayers = subgraph.GetLayers();
140 
141  // Parse the layers
142  SubgraphView::Layers supportedLayers;
143  SubgraphView::Layers unsupportedLayers;
144  SubgraphView::Layers untouchedLayers;
145  std::for_each(subgraphLayers.begin(),
146  subgraphLayers.end(),
147  [&](Layer* layer)
148  {
149  bool supported = IsLayerSupported(layer);
150  if (supported)
151  {
152  // Layer supported, check if it's optimizable
153  bool optimizable = IsLayerOptimizable(layer);
154  if (optimizable)
155  {
156  // Layer fully supported
157  supportedLayers.push_back(layer);
158  }
159  else
160  {
161  // Layer supported but not optimizable
162  untouchedLayers.push_back(layer);
163  }
164  }
165  else
166  {
167  // Layer unsupported
168  unsupportedLayers.push_back(layer);
169  }
170  });
171 
172  // Check if there are supported layers
173  if (!supportedLayers.empty())
174  {
175  // Select the layers that are neither inputs or outputs, but that are optimizable
176  auto supportedSubgraphSelector = [](const Layer& layer)
177  {
178  return layer.GetType() != LayerType::Input &&
179  layer.GetType() != LayerType::Output &&
180  IsLayerSupported(layer) &&
181  IsLayerOptimizable(layer);
182  };
183 
184  // Apply the subgraph selector to the supported layers to group them into sub-graphs were appropriate
185  SubgraphView mutableSubgraph(subgraph);
186  SubgraphViewSelector::Subgraphs supportedSubgraphs =
187  SubgraphViewSelector::SelectSubgraphs(mutableSubgraph, supportedSubgraphSelector);
188 
189  // Create a substitution pair for each supported sub-graph
190  std::for_each(supportedSubgraphs.begin(),
191  supportedSubgraphs.end(),
192  [&optimizationViews](const SubgraphView::SubgraphViewPtr& supportedSubgraph)
193  {
194  ARMNN_ASSERT(supportedSubgraph != nullptr);
195 
196  PreCompiledLayer* preCompiledLayer =
197  optimizationViews.GetGraph().AddLayer<PreCompiledLayer>(
198  PreCompiledDescriptor(supportedSubgraph->GetNumInputSlots(),
199  supportedSubgraph->GetNumOutputSlots()),
200  "pre-compiled");
201  preCompiledLayer->SetBackendId(MockBackendId());
202 
203  SubgraphView substitutionSubgraph(*supportedSubgraph);
204  SubgraphView replacementSubgraph(preCompiledLayer);
205 
206  optimizationViews.AddSubstitution({ substitutionSubgraph, replacementSubgraph });
207  });
208  }
209 
210  // Check if there are unsupported layers
211  if (!unsupportedLayers.empty())
212  {
213  // Select the layers that are neither inputs or outputs, and are not optimizable
214  auto unsupportedSubgraphSelector = [](const Layer& layer)
215  {
216  return layer.GetType() != LayerType::Input &&
217  layer.GetType() != LayerType::Output &&
218  !IsLayerSupported(layer);
219  };
220 
221  // Apply the subgraph selector to the unsupported layers to group them into sub-graphs were appropriate
222  SubgraphView mutableSubgraph(subgraph);
223  SubgraphViewSelector::Subgraphs unsupportedSubgraphs =
224  SubgraphViewSelector::SelectSubgraphs(mutableSubgraph, unsupportedSubgraphSelector);
225 
226  // Add each unsupported sub-graph to the list of failed sub-graphs in the optimizization views
227  std::for_each(unsupportedSubgraphs.begin(),
228  unsupportedSubgraphs.end(),
229  [&optimizationViews](const SubgraphView::SubgraphViewPtr& unsupportedSubgraph)
230  {
231  ARMNN_ASSERT(unsupportedSubgraph != nullptr);
232 
233  optimizationViews.AddFailedSubgraph(SubgraphView(*unsupportedSubgraph));
234  });
235  }
236 
237  // Check if there are untouched layers
238  if (!untouchedLayers.empty())
239  {
240  // Select the layers that are neither inputs or outputs, that are supported but that and are not optimizable
241  auto untouchedSubgraphSelector = [](const Layer& layer)
242  {
243  return layer.GetType() != LayerType::Input &&
244  layer.GetType() != LayerType::Output &&
245  IsLayerSupported(layer) &&
246  !IsLayerOptimizable(layer);
247  };
248 
249  // Apply the subgraph selector to the untouched layers to group them into sub-graphs were appropriate
250  SubgraphView mutableSubgraph(subgraph);
251  SubgraphViewSelector::Subgraphs untouchedSubgraphs =
252  SubgraphViewSelector::SelectSubgraphs(mutableSubgraph, untouchedSubgraphSelector);
253 
254  // Add each untouched sub-graph to the list of untouched sub-graphs in the optimizization views
255  std::for_each(untouchedSubgraphs.begin(),
256  untouchedSubgraphs.end(),
257  [&optimizationViews](const SubgraphView::SubgraphViewPtr& untouchedSubgraph)
258  {
259  ARMNN_ASSERT(untouchedSubgraph != nullptr);
260 
261  optimizationViews.AddUntouchedSubgraph(SubgraphView(*untouchedSubgraph));
262  });
263  }
264 
265  return optimizationViews;
266 }
constexpr const char * MockBackendId()
std::unique_ptr< SubgraphView > SubgraphViewPtr
std::vector< SubgraphViewPtr > Subgraphs
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
static Subgraphs SelectSubgraphs(Graph &graph, const LayerSelectorFunction &selector)
Selects subgraphs from a graph based on the selector function and the algorithm.
std::list< Layer * > Layers
std::unique_ptr< ISubGraphConverter > supported

The documentation for this class was generated from the following files: