ArmNN
 23.08
IBackendInternal Class Referenceabstract

#include <IBackendInternal.hpp>

Inheritance diagram for IBackendInternal:
[legend]
Collaboration diagram for IBackendInternal:
[legend]

Public Types

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 >
 

Public Member Functions

 ~IBackendInternal () override=default
 Allow backends created by the factory function to be destroyed through IBackendInternal. More...
 
virtual IMemoryManagerUniquePtr CreateMemoryManager () const
 
virtual IWorkloadFactoryPtr CreateWorkloadFactory (const IMemoryManagerSharedPtr &memoryManager=nullptr) const =0
 
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 IWorkloadFactoryPtr CreateWorkloadFactory (class TensorHandleFactoryRegistry &tensorHandleFactoryRegistry, const ModelOptions &modelOptions, MemorySourceFlags inputFlags, MemorySourceFlags outputFlags) const
 
virtual IBackendContextPtr CreateBackendContext (const IRuntime::CreationOptions &) const
 Create the runtime context of the backend. More...
 
virtual IBackendSpecificModelContextPtr CreateBackendSpecificModelContext (const ModelOptions &modelOptions) const
 
virtual IBackendProfilingContextPtr CreateBackendProfilingContext (const IRuntime::CreationOptions &creationOptions, IBackendProfilingPtr &backendProfiling)
 Create context specifically used for profiling interaction from backends. More...
 
virtual ILayerSupportSharedPtr GetLayerSupport () const =0
 
virtual ILayerSupportSharedPtr GetLayerSupport (const ModelOptions &modelOptions) const
 
virtual OptimizationViews OptimizeSubgraphView (const SubgraphView &subgraph) 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...
 
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 BackendCapabilities GetCapabilities () const
 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...
 
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 std::unique_ptr< ICustomAllocatorGetDefaultAllocator () const
 Returns the default memory allocator for the backend. More...
 
virtual unsigned int GetNumberOfCacheFiles () const
 Returns the number of files cached if backend supports caching. More...
 
virtual ExecutionData CreateExecutionData (WorkingMemDescriptor &workingMemDescriptor) const
 Returns ExecutionData for the backend. More...
 
virtual void UpdateExecutionData (ExecutionData &executionData, WorkingMemDescriptor &workingMemDescriptor) const
 Update the ExecutionData for a layer. More...
 
- Public Member Functions inherited from IBackend
virtual const BackendIdGetId () const =0
 

Static Public Member Functions

static constexpr BackendVersion GetApiVersion ()
 Returns the version of the Backend API. More...
 

Protected Member Functions

 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 77 of file IBackendInternal.hpp.

Member Typedef Documentation

◆ IBackendContextPtr

using IBackendContextPtr = std::unique_ptr<IBackendContext>

Definition at line 90 of file IBackendInternal.hpp.

◆ IBackendProfilingContextPtr

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.

Definition at line 92 of file IBackendInternal.hpp.

◆ IBackendProfilingPtr

using IBackendProfilingPtr = std::unique_ptr<arm::pipe::IBackendProfiling>

Definition at line 93 of file IBackendInternal.hpp.

◆ IBackendSpecificModelContextPtr

Definition at line 96 of file IBackendInternal.hpp.

◆ ILayerSupportSharedPtr

using ILayerSupportSharedPtr = std::shared_ptr<ILayerSupport>

Definition at line 94 of file IBackendInternal.hpp.

◆ IMemoryManagerSharedPtr

using IMemoryManagerSharedPtr = std::shared_ptr<IMemoryManager>

Definition at line 99 of file IBackendInternal.hpp.

◆ IMemoryManagerUniquePtr

using IMemoryManagerUniquePtr = std::unique_ptr<IMemoryManager>

Definition at line 98 of file IBackendInternal.hpp.

◆ IWorkloadFactoryPtr

using IWorkloadFactoryPtr = std::unique_ptr<IWorkloadFactory>

Definition at line 89 of file IBackendInternal.hpp.

Constructor & Destructor Documentation

◆ IBackendInternal()

IBackendInternal ( )
protecteddefault

Creation must be done through a specific backend interface.

◆ ~IBackendInternal()

~IBackendInternal ( )
overridedefault

Allow backends created by the factory function to be destroyed through IBackendInternal.

Member Function Documentation

◆ CreateBackendContext()

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

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 in ClBackend, NeonBackend, RefBackend, and TosaRefBackend.

Definition at line 71 of file IBackendInternal.cpp.

72 {
73  return IBackendContextPtr{};
74 }

◆ CreateBackendProfilingContext()

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

Create context specifically used for profiling interaction from backends.

Reimplemented in RefBackend, TosaRefBackend, ClBackend, and NeonBackend.

Definition at line 82 of file IBackendInternal.cpp.

84 {
86 }

◆ CreateBackendSpecificModelContext()

IBackendInternal::IBackendSpecificModelContextPtr CreateBackendSpecificModelContext ( const ModelOptions modelOptions) const
virtual

Reimplemented in ClBackend, and NeonBackend.

Definition at line 76 of file IBackendInternal.cpp.

78 {
80 }

◆ CreateExecutionData()

virtual ExecutionData CreateExecutionData ( WorkingMemDescriptor workingMemDescriptor) const
inlinevirtual

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 in RefBackend.

Definition at line 215 of file IBackendInternal.hpp.

216  {
217  IgnoreUnused(workingMemDescriptor);
218  throw armnn::Exception("CreateExecutionData: Function has not been implemented in backend.");
219  };

References armnn::IgnoreUnused().

◆ CreateMemoryManager()

IMemoryManagerUniquePtr CreateMemoryManager ( ) const
virtual

Reimplemented in RefBackend, ClBackend, NeonBackend, and TosaRefBackend.

Definition at line 13 of file IBackendInternal.cpp.

14 {
15  return IMemoryManagerUniquePtr();
16 }

◆ CreateWorkloadFactory() [1/5]

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

Reimplemented in ClBackend, RefBackend, NeonBackend, and TosaRefBackend.

Definition at line 18 of file IBackendInternal.cpp.

20 {
21  return IWorkloadFactoryPtr{};
22 }

◆ CreateWorkloadFactory() [2/5]

IBackendInternal::IWorkloadFactoryPtr CreateWorkloadFactory ( class TensorHandleFactoryRegistry tensorHandleFactoryRegistry,
const ModelOptions modelOptions 
) const
virtual

Reimplemented in ClBackend, and NeonBackend.

Definition at line 42 of file IBackendInternal.cpp.

45 {
46  if (!modelOptions.empty())
47  {
48  for (auto optionsGroup : modelOptions)
49  {
50  if (optionsGroup.GetBackendId() == GetId())
51  {
52  return IWorkloadFactoryPtr{};
53  }
54  }
55  }
56 
57  return CreateWorkloadFactory(tensorHandleFactoryRegistry);
58 }

References IBackendInternal::CreateWorkloadFactory(), and IBackend::GetId().

◆ CreateWorkloadFactory() [3/5]

IBackendInternal::IWorkloadFactoryPtr CreateWorkloadFactory ( class TensorHandleFactoryRegistry tensorHandleFactoryRegistry,
const ModelOptions modelOptions,
MemorySourceFlags  inputFlags,
MemorySourceFlags  outputFlags 
) const
virtual

Reimplemented in ClBackend.

Definition at line 60 of file IBackendInternal.cpp.

65 {
66  IgnoreUnused(inputFlags);
67  IgnoreUnused(outputFlags);
68  return CreateWorkloadFactory(tensorHandleFactoryRegistry, modelOptions);
69 }

References IBackendInternal::CreateWorkloadFactory(), and armnn::IgnoreUnused().

◆ CreateWorkloadFactory() [4/5]

IBackendInternal::IWorkloadFactoryPtr CreateWorkloadFactory ( const IMemoryManagerSharedPtr memoryManager,
const ModelOptions modelOptions 
) const
virtual

Reimplemented in ClBackend, and NeonBackend.

Definition at line 24 of file IBackendInternal.cpp.

27 {
28  if (!modelOptions.empty())
29  {
30  for (auto optionsGroup : modelOptions)
31  {
32  if (optionsGroup.GetBackendId() == GetId())
33  {
34  return IWorkloadFactoryPtr{};
35  }
36  }
37  }
38 
39  return CreateWorkloadFactory(memoryManager);
40 }

References IBackendInternal::CreateWorkloadFactory(), and IBackend::GetId().

◆ CreateWorkloadFactory() [5/5]

virtual IWorkloadFactoryPtr CreateWorkloadFactory ( const IMemoryManagerSharedPtr memoryManager = nullptr) const
pure virtual

◆ GetApiVersion()

static constexpr BackendVersion GetApiVersion ( )
inlinestaticconstexpr

Returns the version of the Backend API.

Definition at line 167 of file IBackendInternal.hpp.

167 { return BackendVersion(1, 0); }

Referenced by DynamicBackend::DynamicBackend(), GetVersion(), and DynamicBackendUtils::IsBackendCompatible().

◆ GetBackwardCompatibleFavoriteHandleFactory()

ITensorHandleFactory::FactoryId GetBackwardCompatibleFavoriteHandleFactory ( )

Definition at line 132 of file IBackendInternal.cpp.

133 {
134  auto favorites = GetHandleFactoryPreferences();
135  if (favorites.empty())
136  {
138  }
139 
140  return favorites[0];
141 }

References IBackendInternal::GetHandleFactoryPreferences(), and ITensorHandleFactory::LegacyFactoryId.

◆ GetCapabilities()

virtual BackendCapabilities GetCapabilities ( ) const
inlinevirtual

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 in ClBackend, NeonBackend, and RefBackend.

Definition at line 172 of file IBackendInternal.hpp.

173  {
174  return BackendCapabilities("IBackendInternal NullCapabilities");
175  };

◆ GetDefaultAllocator()

virtual std::unique_ptr<ICustomAllocator> GetDefaultAllocator ( ) const
inlinevirtual

Returns the default memory allocator for the backend.

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

Reimplemented in ClBackend, NeonBackend, RefBackend, and TosaRefBackend.

Definition at line 201 of file IBackendInternal.hpp.

202  {
203  throw armnn::Exception("GetDefaultAllocator: Function has not been implemented in backend.");
204  }

◆ GetHandleFactoryPreferences()

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

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

Reimplemented in NeonBackend, ClBackend, RefBackend, and TosaRefBackend.

Definition at line 143 of file IBackendInternal.cpp.

144 {
145  return std::vector<ITensorHandleFactory::FactoryId>();
146 }

Referenced by armnn::CalculateSlotOption(), IBackendInternal::GetBackwardCompatibleFavoriteHandleFactory(), and IBackendInternal::SupportsTensorAllocatorAPI().

◆ GetLayerSupport() [1/2]

virtual ILayerSupportSharedPtr GetLayerSupport ( ) const
pure virtual

◆ GetLayerSupport() [2/2]

IBackendInternal::ILayerSupportSharedPtr GetLayerSupport ( const ModelOptions modelOptions) const
virtual

Reimplemented in ClBackend, and NeonBackend.

Definition at line 88 of file IBackendInternal.cpp.

89 {
90  if (!modelOptions.empty())
91  {
92  for (auto optionsGroup : modelOptions)
93  {
94  if (optionsGroup.GetBackendId() == GetId())
95  {
96  return ILayerSupportSharedPtr{};
97  }
98  }
99  }
100 
101  return GetLayerSupport();
102 }

References IBackend::GetId(), and IBackendInternal::GetLayerSupport().

◆ GetNumberOfCacheFiles()

virtual unsigned int GetNumberOfCacheFiles ( ) const
inlinevirtual

Returns the number of files cached if backend supports caching.

Returns
- Returns 0 if backend does not support caching otherwise number of files cached

Reimplemented in ClBackend.

Definition at line 209 of file IBackendInternal.hpp.

209 { return 0; }

◆ OptimizeSubgraphView() [1/2]

OptimizationViews OptimizeSubgraphView ( const SubgraphView subgraph) const
virtual

Definition at line 106 of file IBackendInternal.cpp.

107 {
108  OptimizationViews result;
109  result.AddUntouchedSubgraph(SubgraphView(subgraph));
110 
111  return result;
112 }

References OptimizationViews::AddUntouchedSubgraph().

Referenced by IBackendInternal::OptimizeSubgraphView().

◆ OptimizeSubgraphView() [2/2]

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

Reimplemented in ClBackend, NeonBackend, RefBackend, and TosaRefBackend.

Definition at line 114 of file IBackendInternal.cpp.

116 {
117  return OptimizeSubgraphView(subgraph);
118 }

References IBackendInternal::OptimizeSubgraphView().

◆ RegisterTensorHandleFactories() [1/2]

virtual void RegisterTensorHandleFactories ( class TensorHandleFactoryRegistry )
inlinevirtual

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

Reimplemented in ClBackend, NeonBackend, RefBackend, and TosaRefBackend.

Definition at line 157 of file IBackendInternal.hpp.

157 {}

Referenced by IBackendInternal::RegisterTensorHandleFactories().

◆ RegisterTensorHandleFactories() [2/2]

void RegisterTensorHandleFactories ( class TensorHandleFactoryRegistry registry,
MemorySourceFlags  inputFlags,
MemorySourceFlags  outputFlags 
)
virtual

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

Reimplemented in ClBackend.

Definition at line 125 of file IBackendInternal.cpp.

128 {
129  return RegisterTensorHandleFactories(registry);
130 }

References IBackendInternal::RegisterTensorHandleFactories().

◆ SupportsTensorAllocatorAPI()

bool SupportsTensorAllocatorAPI ( ) const

Definition at line 120 of file IBackendInternal.cpp.

121 {
122  return !GetHandleFactoryPreferences().empty();
123 }

References IBackendInternal::GetHandleFactoryPreferences().

◆ UpdateExecutionData()

virtual void UpdateExecutionData ( ExecutionData executionData,
WorkingMemDescriptor workingMemDescriptor 
) const
inlinevirtual

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 in RefBackend.

Definition at line 225 of file IBackendInternal.hpp.

226  {
227  IgnoreUnused(executionData);
228  IgnoreUnused(workingMemDescriptor);
229  throw armnn::Exception("UpdateExecutionData: Function has not been implemented in backend.");
230  };

References armnn::IgnoreUnused().

◆ UseCustomMemoryAllocator()

virtual bool UseCustomMemoryAllocator ( std::shared_ptr< ICustomAllocator allocator,
armnn::Optional< std::string & >  errMsg 
)
inlinevirtual

Signals the backend to use a custom memory allocator provided by the user.

Parameters
allocator- a pointer to the provided ICustomAllocator to use with this backend
errMsg- Optional string variable to return error messages
Returns
- Returns true if switching to custom allocator was successful

Reimplemented in ClBackend.

Definition at line 182 of file IBackendInternal.hpp.

184  {
185  IgnoreUnused(allocator);
186  if (errMsg)
187  {
188  std::stringstream message;
189  message << "The backend " << GetId() << " doesn't support using a custom allocator. This error might"
190  " be related with the protected mode if the backend doesn't"
191  " fully support it.";
192 
193  errMsg.value() = message.str();
194  }
195  return false;
196  }

References IBackend::GetId(), armnn::IgnoreUnused(), and OptionalReferenceSwitch< std::is_reference< T >::value, T >::value().


The documentation for this class was generated from the following files:
armnn::BackendCapabilities
BackendOptions BackendCapabilities
Definition: BackendOptions.hpp:19
armnn::IBackendInternal::GetLayerSupport
virtual ILayerSupportSharedPtr GetLayerSupport() const =0
armnn::IBackendInternal::CreateWorkloadFactory
virtual IWorkloadFactoryPtr CreateWorkloadFactory(const IMemoryManagerSharedPtr &memoryManager=nullptr) const =0
armnn::IBackendInternal::IBackendContextPtr
std::unique_ptr< IBackendContext > IBackendContextPtr
Definition: IBackendInternal.hpp:90
armnn::ITensorHandleFactory::LegacyFactoryId
static const FactoryId LegacyFactoryId
Definition: ITensorHandleFactory.hpp:50
armnn::IBackendInternal::OptimizeSubgraphView
virtual OptimizationViews OptimizeSubgraphView(const SubgraphView &subgraph) const
Definition: IBackendInternal.cpp:106
armnn::IBackend::GetId
virtual const BackendId & GetId() const =0
armnn::Exception
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
armnn::IBackendInternal::IBackendProfilingContextPtr
std::shared_ptr< arm::pipe::IBackendProfilingContext > IBackendProfilingContextPtr
This is the bridge between backend and backend profiling we'll keep it in the backend namespace.
Definition: IBackendInternal.hpp:92
armnn::IBackendInternal::RegisterTensorHandleFactories
virtual void RegisterTensorHandleFactories(class TensorHandleFactoryRegistry &)
(Optional) Register TensorHandleFactories Either this method or CreateMemoryManager() and IWorkloadFa...
Definition: IBackendInternal.hpp:157
armnn::IBackendInternal::IMemoryManagerUniquePtr
std::unique_ptr< IMemoryManager > IMemoryManagerUniquePtr
Definition: IBackendInternal.hpp:98
armnn::IgnoreUnused
void IgnoreUnused(Ts &&...)
Definition: IgnoreUnused.hpp:14
armnn::IBackendInternal::ILayerSupportSharedPtr
std::shared_ptr< ILayerSupport > ILayerSupportSharedPtr
Definition: IBackendInternal.hpp:94
armnn::IBackendInternal::GetHandleFactoryPreferences
virtual std::vector< ITensorHandleFactory::FactoryId > GetHandleFactoryPreferences() const
(Optional) Returns a vector of supported TensorHandleFactory ids in preference order.
Definition: IBackendInternal.cpp:143
armnn::IBackendInternal::IWorkloadFactoryPtr
std::unique_ptr< IWorkloadFactory > IWorkloadFactoryPtr
Definition: IBackendInternal.hpp:89
armnn::OptionalReferenceSwitch< std::is_reference< T >::value, T >::value
const T & value() const
Definition: Optional.hpp:146
armnn::IBackendInternal::IBackendSpecificModelContextPtr
std::shared_ptr< IBackendModelContext > IBackendSpecificModelContextPtr
Definition: IBackendInternal.hpp:96