ArmNN
 21.08
IBackendInternal Class Referenceabstract

#include <IBackendInternal.hpp>

Inheritance diagram for IBackendInternal:
IBackend ClBackend MockBackend MockImportBackend NeonBackend RefBackend

Public Types

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 >
 

Public Member Functions

 ~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 Optimizations GetOptimizations () const
 
virtual SubGraphUniquePtr OptimizeSubGraph (const SubGraph &subGraph, bool &optimizationAttempted) const
 
virtual ARMNN_NO_DEPRECATE_WARN_END 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 HasCapability (BackendCapability) const
 Returns true if backend support the capability false otherwise. 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...
 
- 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 75 of file IBackendInternal.hpp.

Member Typedef Documentation

◆ GraphUniquePtr

using GraphUniquePtr = std::unique_ptr<Graph>

Definition at line 101 of file IBackendInternal.hpp.

◆ IBackendContextPtr

using IBackendContextPtr = std::unique_ptr<IBackendContext>

Definition at line 88 of file IBackendInternal.hpp.

◆ IBackendProfilingContextPtr

This is the bridge between backend and backend profiling we'll keep it in the backend namespace.

Definition at line 90 of file IBackendInternal.hpp.

◆ IBackendProfilingPtr

Definition at line 91 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.

◆ instead

using instead = std::unique_ptr<SubGraph>

Definition at line 108 of file IBackendInternal.hpp.

◆ IWorkloadFactoryPtr

using IWorkloadFactoryPtr = std::unique_ptr<IWorkloadFactory>

Definition at line 87 of file IBackendInternal.hpp.

◆ OptimizationPtr

using OptimizationPtr = std::unique_ptr<Optimization>

Definition at line 92 of file IBackendInternal.hpp.

◆ Optimizations

using Optimizations = std::vector<OptimizationPtr>

Definition at line 93 of file IBackendInternal.hpp.

◆ SubgraphViewUniquePtr

using SubgraphViewUniquePtr = std::unique_ptr<SubgraphView>

Definition at line 102 of file IBackendInternal.hpp.

◆ supported

using supported = std::unique_ptr<ISubGraphConverter>

Definition at line 106 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 MockBackend, ClBackend, NeonBackend, RefBackend, and MockImportBackend.

Definition at line 90 of file IBackendInternal.cpp.

91 {
92  return IBackendContextPtr{};
93 }
std::unique_ptr< IBackendContext > IBackendContextPtr

◆ CreateBackendProfilingContext()

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

Create context specifically used for profiling interaction from backends.

Reimplemented in MockBackend, ClBackend, NeonBackend, RefBackend, and MockImportBackend.

Definition at line 101 of file IBackendInternal.cpp.

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

◆ CreateBackendSpecificModelContext()

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

Reimplemented in ClBackend, and NeonBackend.

Definition at line 95 of file IBackendInternal.cpp.

97 {
99 }
std::shared_ptr< IBackendModelContext > IBackendSpecificModelContextPtr

◆ CreateMemoryManager()

ARMNN_NO_DEPRECATE_WARN_END IMemoryManagerUniquePtr CreateMemoryManager ( ) const
virtual

Reimplemented in MockBackend, ClBackend, RefBackend, MockImportBackend, and NeonBackend.

Definition at line 32 of file IBackendInternal.cpp.

Referenced by LoadedNetwork::MakeLoadedNetwork().

33 {
34  return IMemoryManagerUniquePtr();
35 }
std::unique_ptr< IMemoryManager > IMemoryManagerUniquePtr

◆ CreateSubGraphConverter()

ARMNN_NO_DEPRECATE_WARN_BEGIN IBackendInternal::ISubGraphConverterPtr CreateSubGraphConverter ( const std::shared_ptr< SubGraph > &  subGraph) const
virtual

Definition at line 13 of file IBackendInternal.cpp.

15 {
16  return ISubGraphConverterPtr{};
17 }

◆ CreateWorkloadFactory() [1/5]

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

◆ CreateWorkloadFactory() [2/5]

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

Reimplemented in ClBackend, RefBackend, MockImportBackend, and NeonBackend.

Definition at line 37 of file IBackendInternal.cpp.

39 {
40  return IWorkloadFactoryPtr{};
41 }
std::unique_ptr< IWorkloadFactory > IWorkloadFactoryPtr

◆ CreateWorkloadFactory() [3/5]

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

Reimplemented in ClBackend, and NeonBackend.

Definition at line 43 of file IBackendInternal.cpp.

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

46 {
47  if (!modelOptions.empty())
48  {
49  for (auto optionsGroup : modelOptions)
50  {
51  if (optionsGroup.GetBackendId() == GetId())
52  {
53  return IWorkloadFactoryPtr{};
54  }
55  }
56  }
57 
58  return CreateWorkloadFactory(memoryManager);
59 }
std::unique_ptr< IWorkloadFactory > IWorkloadFactoryPtr
virtual const BackendId & GetId() const =0
virtual IWorkloadFactoryPtr CreateWorkloadFactory(const IMemoryManagerSharedPtr &memoryManager=nullptr) const =0

◆ CreateWorkloadFactory() [4/5]

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

Reimplemented in ClBackend, and NeonBackend.

Definition at line 61 of file IBackendInternal.cpp.

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

64 {
65  if (!modelOptions.empty())
66  {
67  for (auto optionsGroup : modelOptions)
68  {
69  if (optionsGroup.GetBackendId() == GetId())
70  {
71  return IWorkloadFactoryPtr{};
72  }
73  }
74  }
75 
76  return CreateWorkloadFactory(tensorHandleFactoryRegistry);
77 }
std::unique_ptr< IWorkloadFactory > IWorkloadFactoryPtr
virtual const BackendId & GetId() const =0
virtual IWorkloadFactoryPtr CreateWorkloadFactory(const IMemoryManagerSharedPtr &memoryManager=nullptr) const =0

◆ CreateWorkloadFactory() [5/5]

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

Reimplemented in ClBackend.

Definition at line 79 of file IBackendInternal.cpp.

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

84 {
85  IgnoreUnused(inputFlags);
86  IgnoreUnused(outputFlags);
87  return CreateWorkloadFactory(tensorHandleFactoryRegistry, modelOptions);
88 }
void IgnoreUnused(Ts &&...)
virtual IWorkloadFactoryPtr CreateWorkloadFactory(const IMemoryManagerSharedPtr &memoryManager=nullptr) const =0

◆ GetApiVersion()

static constexpr BackendVersion GetApiVersion ( )
inlinestatic

Returns the version of the Backend API.

Definition at line 186 of file IBackendInternal.hpp.

References BackendVersion::BackendVersion().

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

186 { return BackendVersion(1, 0); }

◆ GetBackwardCompatibleFavoriteHandleFactory()

ITensorHandleFactory::FactoryId GetBackwardCompatibleFavoriteHandleFactory ( )

Definition at line 168 of file IBackendInternal.cpp.

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

169 {
170  auto favorites = GetHandleFactoryPreferences();
171  if (favorites.empty())
172  {
174  }
175 
176  return favorites[0];
177 }
virtual std::vector< ITensorHandleFactory::FactoryId > GetHandleFactoryPreferences() const
(Optional) Returns a vector of supported TensorHandleFactory ids in preference order.
static const FactoryId 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 191 of file IBackendInternal.hpp.

References ARMNN_DEPRECATED_MSG.

192  {
193  return BackendCapabilities("IBackendInternal NullCapabilities");
194  };
BackendOptions BackendCapabilities

◆ GetHandleFactoryPreferences()

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

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

Reimplemented in ClBackend, NeonBackend, RefBackend, and MockImportBackend.

Definition at line 179 of file IBackendInternal.cpp.

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

180 {
181  return std::vector<ITensorHandleFactory::FactoryId>();
182 }

◆ 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 107 of file IBackendInternal.cpp.

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

108 {
109  if (!modelOptions.empty())
110  {
111  for (auto optionsGroup : modelOptions)
112  {
113  if (optionsGroup.GetBackendId() == GetId())
114  {
115  return ILayerSupportSharedPtr{};
116  }
117  }
118  }
119 
120  return GetLayerSupport();
121 }
virtual const BackendId & GetId() const =0
std::shared_ptr< ILayerSupport > ILayerSupportSharedPtr
virtual ILayerSupportSharedPtr GetLayerSupport() const =0

◆ GetOptimizations()

IBackendInternal::Optimizations GetOptimizations ( ) const
virtual

Reimplemented in MockBackend, ClBackend, NeonBackend, RefBackend, and MockImportBackend.

Definition at line 19 of file IBackendInternal.cpp.

20 {
21  return Optimizations{};
22 }
std::vector< OptimizationPtr > Optimizations

◆ HasCapability()

virtual bool HasCapability ( BackendCapability  ) const
inlinevirtual

Returns true if backend support the capability false otherwise.

Reimplemented in RefBackend.

Definition at line 198 of file IBackendInternal.hpp.

198 { return false; }

◆ OptimizeSubGraph()

IBackendInternal::SubGraphUniquePtr OptimizeSubGraph ( const SubGraph &  subGraph,
bool &  optimizationAttempted 
) const
virtual

Definition at line 24 of file IBackendInternal.cpp.

References ARMNN_NO_DEPRECATE_WARN_END.

Referenced by IBackendInternal::OptimizeSubgraphView().

26 {
27  optimizationAttempted = false;
28  return nullptr;
29 }

◆ OptimizeSubgraphView() [1/2]

OptimizationViews OptimizeSubgraphView ( const SubgraphView subgraph) const
virtual

Reimplemented in MockBackend, NeonBackend, RefBackend, and MockImportBackend.

Definition at line 125 of file IBackendInternal.cpp.

References OptimizationViews::AddUntouchedSubgraph(), ARMNN_NO_DEPRECATE_WARN_BEGIN, ARMNN_NO_DEPRECATE_WARN_END, and IBackendInternal::OptimizeSubGraph().

Referenced by IBackendInternal::OptimizeSubgraphView().

126 {
127  bool optimizationAttempted = false;
128 
130  SubGraphUniquePtr optSubgraph = OptimizeSubGraph(subgraph, optimizationAttempted);
132 
133  OptimizationViews result;
134  if (!optimizationAttempted)
135  {
136  result.AddUntouchedSubgraph(SubgraphView(subgraph));
137  }
138  else if (optSubgraph)
139  {
140  result.AddSubstitution({subgraph, SubgraphView(*optSubgraph.get())});
141  }
142  else
143  {
144  result.AddFailedSubgraph(SubgraphView(subgraph));
145  }
146 
147  return result;
148 }
#define ARMNN_NO_DEPRECATE_WARN_BEGIN
Definition: Deprecated.hpp:33
#define ARMNN_NO_DEPRECATE_WARN_END
Definition: Deprecated.hpp:34
virtual SubGraphUniquePtr OptimizeSubGraph(const SubGraph &subGraph, bool &optimizationAttempted) const

◆ OptimizeSubgraphView() [2/2]

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

Reimplemented in ClBackend.

Definition at line 150 of file IBackendInternal.cpp.

References IBackendInternal::OptimizeSubgraphView().

152 {
153  return OptimizeSubgraphView(subgraph);
154 }
virtual OptimizationViews OptimizeSubgraphView(const SubgraphView &subgraph) const

◆ 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 MockImportBackend.

Definition at line 176 of file IBackendInternal.hpp.

Referenced by IBackendInternal::RegisterTensorHandleFactories().

176 {}

◆ 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 161 of file IBackendInternal.cpp.

References IBackendInternal::RegisterTensorHandleFactories().

164 {
165  return RegisterTensorHandleFactories(registry);
166 }
virtual void RegisterTensorHandleFactories(class TensorHandleFactoryRegistry &)
(Optional) Register TensorHandleFactories Either this method or CreateMemoryManager() and IWorkloadFa...

◆ SupportsTensorAllocatorAPI()

bool SupportsTensorAllocatorAPI ( ) const

Definition at line 156 of file IBackendInternal.cpp.

References IBackendInternal::GetHandleFactoryPreferences().

Referenced by LoadedNetwork::MakeLoadedNetwork().

157 {
158  return !GetHandleFactoryPreferences().empty();
159 }
virtual std::vector< ITensorHandleFactory::FactoryId > GetHandleFactoryPreferences() const
(Optional) Returns a vector of supported TensorHandleFactory ids in preference order.

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

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

207  {
208  IgnoreUnused(allocator);
209  if (errMsg)
210  {
211  std::stringstream message;
212  message << "The backend " << GetId() << " doesn't support using a custom allocator. This error might"
213  " be related with the protected mode if the backend doesn't"
214  " fully support it.";
215 
216  errMsg.value() = message.str();
217  }
218  return false;
219  }
void IgnoreUnused(Ts &&...)
virtual const BackendId & GetId() const =0

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