ArmNN  NotReleased
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
 
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
 
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 &)
 

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 >
 
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
 
- Protected Member Functions inherited from IBackend
 IBackend ()
 
virtual ~IBackend ()
 

Detailed Description

Definition at line 124 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 103 of file MockBackend.cpp.

104 {
105  return IBackendContextPtr{};
106 }
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 108 of file MockBackend.cpp.

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

110 {
111  boost::ignore_unused(options);
112  std::shared_ptr<armnn::MockBackendProfilingContext> context =
113  std::make_shared<MockBackendProfilingContext>(backendProfiling);
115  return context;
116 }
static MockBackendProfilingService & Instance()
void SetProfilingContextPtr(std::shared_ptr< MockBackendProfilingContext > shared)
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ CreateMemoryManager()

IBackendInternal::IMemoryManagerUniquePtr CreateMemoryManager ( ) const
overridevirtual

Reimplemented from IBackendInternal.

Definition at line 118 of file MockBackend.cpp.

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

◆ CreateWorkloadFactory()

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

Implements IBackendInternal.

Definition at line 97 of file MockBackend.cpp.

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

◆ GetId()

const BackendId& GetId ( ) const
inlineoverridevirtual

Implements IBackend.

Definition at line 131 of file MockBackend.hpp.

132  {
133  return GetIdStatic();
134  }
static const BackendId & GetIdStatic()
Definition: MockBackend.cpp:91

◆ GetIdStatic()

const BackendId & GetIdStatic ( )
static

Definition at line 91 of file MockBackend.cpp.

References armnn::MockBackendId().

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

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

◆ GetLayerSupport()

IBackendInternal::ILayerSupportSharedPtr GetLayerSupport ( ) const
overridevirtual

Implements IBackendInternal.

Definition at line 128 of file MockBackend.cpp.

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

◆ GetOptimizations()

IBackendInternal::Optimizations GetOptimizations ( ) const
overridevirtual

Reimplemented from IBackendInternal.

Definition at line 123 of file MockBackend.cpp.

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

◆ OptimizeSubgraphView()

OptimizationViews OptimizeSubgraphView ( const SubgraphView subgraph) const
overridevirtual

Reimplemented from IBackendInternal.

Definition at line 134 of file MockBackend.cpp.

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

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

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