ArmNN
 22.08
RefBackend Class Reference

#include <RefBackend.hpp>

Inheritance diagram for RefBackend:
IBackendInternal IBackend

Public Member Functions

 RefBackend ()=default
 
 ~RefBackend ()=default
 
const BackendIdGetId () const override
 
IBackendInternal::IMemoryManagerUniquePtr CreateMemoryManager () const override
 
IBackendInternal::IWorkloadFactoryPtr CreateWorkloadFactory (const IBackendInternal::IMemoryManagerSharedPtr &memoryManager=nullptr) const override
 
IBackendInternal::IWorkloadFactoryPtr CreateWorkloadFactory (class TensorHandleFactoryRegistry &tensorHandleFactoryRegistry) 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::ILayerSupportSharedPtr GetLayerSupport () const override
 
OptimizationViews OptimizeSubgraphView (const SubgraphView &subgraph, const ModelOptions &modelOptions) const override
 
std::vector< ITensorHandleFactory::FactoryIdGetHandleFactoryPreferences () const override
 (Optional) Returns a vector of supported TensorHandleFactory ids in preference order. More...
 
void RegisterTensorHandleFactories (class TensorHandleFactoryRegistry &registry) override
 (Optional) Register TensorHandleFactories Either this method or CreateMemoryManager() and IWorkloadFactory::CreateTensor()/IWorkloadFactory::CreateSubtensor() methods must be implemented. More...
 
BackendCapabilities GetCapabilities () const override
 Returns a BackendCapability if the backend lists the capability The BackendCapability must then be inspected to check whether or not that BackendCapability is supported Otherwise returns an EmptyOptional if the BackendCapability is unlisted. More...
 
std::unique_ptr< ICustomAllocatorGetDefaultAllocator () const override
 Returns the default memory allocator for the backend. More...
 
ExecutionData CreateExecutionData (WorkingMemDescriptor &workingMemDescriptor) const override
 Returns ExecutionData for the backend. More...
 
void UpdateExecutionData (ExecutionData &executionData, WorkingMemDescriptor &workingMemDescriptor) const override
 Update the ExecutionData for a layer. More...
 
- Public Member Functions inherited from IBackendInternal
 ~IBackendInternal () override=default
 Allow backends created by the factory function to be destroyed through IBackendInternal. More...
 
virtual IWorkloadFactoryPtr CreateWorkloadFactory (const IMemoryManagerSharedPtr &memoryManager, const ModelOptions &modelOptions) const
 
virtual IWorkloadFactoryPtr CreateWorkloadFactory (class TensorHandleFactoryRegistry &tensorHandleFactoryRegistry, const ModelOptions &modelOptions) const
 
virtual IWorkloadFactoryPtr CreateWorkloadFactory (class TensorHandleFactoryRegistry &tensorHandleFactoryRegistry, const ModelOptions &modelOptions, MemorySourceFlags inputFlags, MemorySourceFlags outputFlags) const
 
virtual IBackendSpecificModelContextPtr CreateBackendSpecificModelContext (const ModelOptions &modelOptions) const
 
virtual ILayerSupportSharedPtr GetLayerSupport (const ModelOptions &modelOptions) const
 
virtual OptimizationViews OptimizeSubgraphView (const SubgraphView &subgraph) const
 
bool SupportsTensorAllocatorAPI () const
 
ITensorHandleFactory::FactoryId GetBackwardCompatibleFavoriteHandleFactory ()
 
virtual void RegisterTensorHandleFactories (class TensorHandleFactoryRegistry &registry, MemorySourceFlags inputFlags, MemorySourceFlags outputFlags)
 (Optional) Register TensorHandleFactories Either this method or CreateMemoryManager() and IWorkloadFactory::CreateTensor()/IWorkloadFactory::CreateSubtensor() methods must be implemented. More...
 
virtual bool UseCustomMemoryAllocator (std::shared_ptr< ICustomAllocator > allocator, armnn::Optional< std::string &> errMsg)
 Signals the backend to use a custom memory allocator provided by the user. More...
 
virtual unsigned int GetNumberOfCacheFiles () const
 Returns the number of files cached if backend supports caching. 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< arm::pipe::IBackendProfilingContext >
 This is the bridge between backend and backend profiling we'll keep it in the backend namespace. More...
 
using IBackendProfilingPtr = std::unique_ptr< arm::pipe::IBackendProfiling >
 
using ILayerSupportSharedPtr = std::shared_ptr< ILayerSupport >
 
using IBackendSpecificModelContextPtr = std::shared_ptr< IBackendModelContext >
 
using IMemoryManagerUniquePtr = std::unique_ptr< IMemoryManager >
 
using IMemoryManagerSharedPtr = std::shared_ptr< IMemoryManager >
 
- 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 29 of file RefBackend.hpp.

Constructor & Destructor Documentation

◆ RefBackend()

RefBackend ( )
default

◆ ~RefBackend()

~RefBackend ( )
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 52 of file RefBackend.cpp.

Referenced by RefBackend::GetId().

53 {
54  return IBackendContextPtr{};
55 }
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 57 of file RefBackend.cpp.

Referenced by RefBackend::GetId().

59 {
61 }
std::shared_ptr< arm::pipe::IBackendProfilingContext > IBackendProfilingContextPtr
This is the bridge between backend and backend profiling we&#39;ll keep it in the backend namespace...

◆ CreateExecutionData()

ExecutionData CreateExecutionData ( WorkingMemDescriptor workingMemDescriptor) const
overridevirtual

Returns ExecutionData for the backend.

Parameters
workingMemDescriptor- Vectors of input and output TensorHandles for a layer
Returns
- Returns backend specific ExecutionData generated for a layer

Reimplemented from IBackendInternal.

Definition at line 157 of file RefBackend.cpp.

References ExecutionData::m_Data.

Referenced by RefBackend::GetCapabilities().

158 {
159  ExecutionData executionData;
160  executionData.m_Data = &workingMemDescriptor;
161  return executionData;
162 }

◆ CreateMemoryManager()

IBackendInternal::IMemoryManagerUniquePtr CreateMemoryManager ( ) const
overridevirtual

Reimplemented from IBackendInternal.

Definition at line 63 of file RefBackend.cpp.

Referenced by RefBackend::GetId().

64 {
65  return std::make_unique<RefMemoryManager>();
66 }

◆ CreateWorkloadFactory() [1/2]

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

Implements IBackendInternal.

Definition at line 30 of file RefBackend.cpp.

Referenced by RefBackend::GetId().

32 {
33  return std::make_unique<RefWorkloadFactory>(PolymorphicPointerDowncast<RefMemoryManager>(memoryManager));
34 }

◆ CreateWorkloadFactory() [2/2]

IBackendInternal::IWorkloadFactoryPtr CreateWorkloadFactory ( class TensorHandleFactoryRegistry tensorHandleFactoryRegistry) const
overridevirtual

Reimplemented from IBackendInternal.

Definition at line 36 of file RefBackend.cpp.

References TensorHandleFactoryRegistry::RegisterCopyAndImportFactoryPair(), TensorHandleFactoryRegistry::RegisterFactory(), and TensorHandleFactoryRegistry::RegisterMemoryManager().

38 {
39  auto memoryManager = std::make_shared<RefMemoryManager>();
40 
41  tensorHandleFactoryRegistry.RegisterMemoryManager(memoryManager);
42 
43  std::unique_ptr<RefTensorHandleFactory> factory = std::make_unique<RefTensorHandleFactory>(memoryManager);
44  // Register copy and import factory pair
45  tensorHandleFactoryRegistry.RegisterCopyAndImportFactoryPair(factory->GetId(), factory->GetId());
46  // Register the factory
47  tensorHandleFactoryRegistry.RegisterFactory(std::move(factory));
48 
49  return std::make_unique<RefWorkloadFactory>(PolymorphicPointerDowncast<RefMemoryManager>(memoryManager));
50 }

◆ GetCapabilities()

BackendCapabilities GetCapabilities ( ) const
inlineoverridevirtual

Returns a BackendCapability if the backend lists the capability The BackendCapability must then be inspected to check whether or not that BackendCapability is supported Otherwise returns an EmptyOptional if the BackendCapability is unlisted.

Reimplemented from IBackendInternal.

Definition at line 60 of file RefBackend.hpp.

References armnn::cpuRefCapabilities, RefBackend::CreateExecutionData(), RefBackend::GetDefaultAllocator(), and RefBackend::UpdateExecutionData().

61  {
62  return cpuRefCapabilities;
63  };
const BackendCapabilities cpuRefCapabilities("CpuRef", { {"NonConstWeights", true}, {"AsyncExecution", true}, {"ProtectedContentAllocation", false}, {"ConstantTensorsAsInputs", true}, {"PreImportIOTensors", true}, {"ExternallyManagedMemory", true}, {"MultiAxisPacking", false}, {"SingleAxisPacking", true} })

◆ GetDefaultAllocator()

std::unique_ptr< ICustomAllocator > GetDefaultAllocator ( ) const
overridevirtual

Returns the default memory allocator for the backend.

Returns
- Returns unique pointer to the Default Allocator of the Backend

Reimplemented from IBackendInternal.

Definition at line 152 of file RefBackend.cpp.

Referenced by RefBackend::GetCapabilities().

153 {
154  return std::make_unique<DefaultAllocator>();
155 }

◆ GetHandleFactoryPreferences()

std::vector< ITensorHandleFactory::FactoryId > GetHandleFactoryPreferences ( ) const
overridevirtual

(Optional) Returns a vector of supported TensorHandleFactory ids in preference order.

Reimplemented from IBackendInternal.

Definition at line 133 of file RefBackend.cpp.

References RefTensorHandleFactory::GetIdStatic().

Referenced by RefBackend::GetId().

134 {
135  return std::vector<ITensorHandleFactory::FactoryId> { RefTensorHandleFactory::GetIdStatic() };
136 }
static const FactoryId & GetIdStatic()

◆ GetId()

◆ GetIdStatic()

const BackendId & GetIdStatic ( )
static

Definition at line 24 of file RefBackend.cpp.

References armnn::RefBackendId().

Referenced by GetBackendId(), and RefBackend::GetId().

25 {
26  static const BackendId s_Id{RefBackendId()};
27  return s_Id;
28 }
constexpr const char * RefBackendId()

◆ GetLayerSupport()

IBackendInternal::ILayerSupportSharedPtr GetLayerSupport ( ) const
overridevirtual

Implements IBackendInternal.

Definition at line 68 of file RefBackend.cpp.

Referenced by RefBackend::GetId().

69 {
70  static ILayerSupportSharedPtr layerSupport{new RefLayerSupport};
71  return layerSupport;
72 }
std::shared_ptr< ILayerSupport > ILayerSupportSharedPtr

◆ OptimizeSubgraphView()

OptimizationViews OptimizeSubgraphView ( const SubgraphView subgraph,
const ModelOptions modelOptions 
) const
overridevirtual

Reimplemented from IBackendInternal.

Definition at line 74 of file RefBackend.cpp.

References OptimizationViews::AddUntouchedSubgraph(), SubgraphView::beginIConnectable(), SubgraphView::endIConnectable(), InputSlot::GetConnectedOutputSlot(), Layer::GetGuid(), Layer::GetInputSlot(), OutputSlot::GetNumConnections(), Layer::GetOutputSlot(), OutputSlot::GetOwningLayer(), LayerWithParameters< Parameters >::GetParameters(), OptimizationViews::GetSubstitutions(), OutputSlot::GetTensorInfo(), Layer::GetType(), armnn::Pad, armnn::Pooling2d, armnn::ReportUntouchedLayers(), and armnn::optimizations::pad_fold::TryFoldPadIntoLayer2d().

Referenced by RefBackend::GetId().

76 {
77  OptimizationViews optimizationViews(modelOptions);
78 
79  auto it = subgraph.endIConnectable();
80  std::map<LayerGuid, Layer*> untouched;
81 
82  while (it != subgraph.beginIConnectable())
83  {
84  --it;
85  Layer& base = *(PolymorphicDowncast<Layer*>(*it));
86  untouched.insert({base.GetGuid(), &base});
87  }
88 
89  it = subgraph.endIConnectable();
90  while (it != subgraph.beginIConnectable())
91  {
92  --it;
93  Layer& base = *(PolymorphicDowncast<Layer*>(*it));
94 
95  // Special case to fuse padding into average pooling 2d for quantized datatype.
96  // Required to be done as a backend specific optimization as Neon does not support this special case.
97  if (base.GetType() == LayerType::Pooling2d)
98  {
99  Pooling2dLayer* baseLayer = PolymorphicDowncast<Pooling2dLayer*>(&base);
100  Pooling2dDescriptor poolingDescriptor = baseLayer->GetParameters();
101 
102  if (baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetOwningLayer().GetType() == LayerType::Pad)
103  {
104  PadLayer* padLayer = PolymorphicDowncast<PadLayer*>(
105  &baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetOwningLayer());
106  if (padLayer->GetOutputSlot(0).GetNumConnections() == 1 &&
107  optimizations::pad_fold::TryFoldPadIntoLayer2d(padLayer->GetParameters(),
108  poolingDescriptor,
109  padLayer->GetOutputSlot().GetTensorInfo(),
110  true))
111  {
112  FoldPadIntoAveragePool2d<Pooling2dLayer>(optimizationViews, baseLayer,
113  poolingDescriptor, padLayer);
114  untouched.erase(baseLayer->GetGuid());
115  untouched.erase(padLayer->GetGuid());
116  }
117  }
118  }
119  }
120 
121  if (optimizationViews.GetSubstitutions().empty())
122  {
123  optimizationViews.AddUntouchedSubgraph(SubgraphView(subgraph));
124  }
125  else
126  {
127  ReportUntouchedLayers(optimizationViews, untouched);
128  }
129 
130  return optimizationViews;
131 }
void ReportUntouchedLayers(OptimizationViews &optimizationViews, std::map< LayerGuid, Layer *> untouched)
const armnnSerializer::Pooling2dDescriptor * Pooling2dDescriptor
bool TryFoldPadIntoLayer2d(const PadDescriptor &padDescriptor, Descriptor &layerDescriptor, const TensorInfo &tensorInfo)

◆ RegisterTensorHandleFactories()

void RegisterTensorHandleFactories ( class TensorHandleFactoryRegistry )
overridevirtual

(Optional) Register TensorHandleFactories Either this method or CreateMemoryManager() and IWorkloadFactory::CreateTensor()/IWorkloadFactory::CreateSubtensor() methods must be implemented.

Reimplemented from IBackendInternal.

Definition at line 138 of file RefBackend.cpp.

References TensorHandleFactoryRegistry::RegisterCopyAndImportFactoryPair(), TensorHandleFactoryRegistry::RegisterFactory(), and TensorHandleFactoryRegistry::RegisterMemoryManager().

Referenced by RefBackend::GetId().

139 {
140  auto memoryManager = std::make_shared<RefMemoryManager>();
141 
142  registry.RegisterMemoryManager(memoryManager);
143 
144  std::unique_ptr<RefTensorHandleFactory> factory = std::make_unique<RefTensorHandleFactory>(memoryManager);
145 
146  // Register copy and import factory pair
147  registry.RegisterCopyAndImportFactoryPair(factory->GetId(), factory->GetId());
148  // Register the factory
149  registry.RegisterFactory(std::move(factory));
150 }

◆ UpdateExecutionData()

void UpdateExecutionData ( ExecutionData executionData,
WorkingMemDescriptor workingMemDescriptor 
) const
overridevirtual

Update the ExecutionData for a layer.

It is used to swap in pre-imported tensor handles

Parameters
executionData- Backend specific ExecutionData generated for a layer
workingMemDescriptor- Vectors of input and output TensorHandles for a layer

Reimplemented from IBackendInternal.

Definition at line 164 of file RefBackend.cpp.

References ExecutionData::m_Data.

Referenced by RefBackend::GetCapabilities().

165 {
166  executionData.m_Data = &workingMemDescriptor;
167 }

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