ArmNN
 21.02
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
 
virtual IWorkloadFactoryPtr CreateWorkloadFactory (const IMemoryManagerSharedPtr &memoryManager, const ModelOptions &modelOptions) const
 
virtual IWorkloadFactoryPtr CreateWorkloadFactory (class TensorHandleFactoryRegistry &tensorHandleFactoryRegistry, const ModelOptions &modelOptions) const
 
virtual IBackendSpecificModelContextPtr CreateBackendSpecificModelContext (const ModelOptions &modelOptions) const
 
virtual ILayerSupportSharedPtr GetLayerSupport (const ModelOptions &modelOptions) const
 
virtual OptimizationViews OptimizeSubgraphView (const SubgraphView &subgraph, const ModelOptions &modelOptions) 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 IBackendSpecificModelContextPtr = std::shared_ptr< IBackendModelContext >
 
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 100 of file MockBackend.cpp.

101 {
102  return IBackendContextPtr{};
103 }
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 105 of file MockBackend.cpp.

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

107 {
108  IgnoreUnused(options);
109  std::shared_ptr<armnn::MockBackendProfilingContext> context =
110  std::make_shared<MockBackendProfilingContext>(backendProfiling);
112  return context;
113 }
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 115 of file MockBackend.cpp.

116 {
117  return IMemoryManagerUniquePtr{};
118 }
std::unique_ptr< IMemoryManager > IMemoryManagerUniquePtr

◆ CreateWorkloadFactory()

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

Implements IBackendInternal.

Definition at line 94 of file MockBackend.cpp.

96 {
97  return IWorkloadFactoryPtr{};
98 }
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:88

◆ GetIdStatic()

const BackendId & GetIdStatic ( )
static

Definition at line 88 of file MockBackend.cpp.

References armnn::MockBackendId().

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

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

◆ GetLayerSupport()

IBackendInternal::ILayerSupportSharedPtr GetLayerSupport ( ) const
overridevirtual

Implements IBackendInternal.

Definition at line 125 of file MockBackend.cpp.

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

◆ GetOptimizations()

IBackendInternal::Optimizations GetOptimizations ( ) const
overridevirtual

Reimplemented from IBackendInternal.

Definition at line 120 of file MockBackend.cpp.

121 {
122  return Optimizations{};
123 }
std::vector< OptimizationPtr > Optimizations

◆ OptimizeSubgraphView()

OptimizationViews OptimizeSubgraphView ( const SubgraphView subgraph) const
overridevirtual

Reimplemented from IBackendInternal.

Definition at line 131 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().

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