ArmNN
 25.11
Loading...
Searching...
No Matches
TosaRefBackend Class Reference

#include <TosaRefBackend.hpp>

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

Public Member Functions

 TosaRefBackend ()=default
 ~TosaRefBackend ()=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.
IBackendInternal::IBackendProfilingContextPtr CreateBackendProfilingContext (const IRuntime::CreationOptions &creationOptions, IBackendProfilingPtr &backendProfiling) override
 Create context specifically used for profiling interaction from backends.
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.
void RegisterTensorHandleFactories (class TensorHandleFactoryRegistry &registry) override
 (Optional) Register TensorHandleFactories Either this method or CreateMemoryManager() and IWorkloadFactory::CreateTensor() IWorkloadFactory::CreateSubtensor() methods must be implemented.
std::unique_ptr< ICustomAllocatorGetDefaultAllocator () const override
 Returns the default memory allocator for the backend.
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.
Public Member Functions inherited from IBackendInternal
 ~IBackendInternal () override=default
 Allow backends created by the factory function to be destroyed through IBackendInternal.
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.
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.
virtual unsigned int GetNumberOfCacheFiles () const
 Returns the number of files cached if backend supports caching.

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.

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

Detailed Description

Definition at line 12 of file TosaRefBackend.hpp.

Constructor & Destructor Documentation

◆ TosaRefBackend()

TosaRefBackend ( )
default

◆ ~TosaRefBackend()

~TosaRefBackend ( )
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 60 of file TosaRefBackend.cpp.

61{
62 return IBackendContextPtr{};
63}
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 65 of file TosaRefBackend.cpp.

67{
69}
std::shared_ptr< arm::pipe::IBackendProfilingContext > IBackendProfilingContextPtr
This is the bridge between backend and backend profiling we'll keep it in the backend namespace.

◆ CreateMemoryManager()

IBackendInternal::IMemoryManagerUniquePtr CreateMemoryManager ( ) const
overridevirtual

Reimplemented from IBackendInternal.

Definition at line 71 of file TosaRefBackend.cpp.

72{
73 return std::make_unique<TosaRefMemoryManager>();
74}

◆ CreateWorkloadFactory() [1/2]

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

Reimplemented from IBackendInternal.

Definition at line 44 of file TosaRefBackend.cpp.

46{
47 auto memoryManager = std::make_shared<TosaRefMemoryManager>();
48
49 tensorHandleFactoryRegistry.RegisterMemoryManager(memoryManager);
50
51 auto factory = std::make_unique<TosaRefTensorHandleFactory>(memoryManager);
52 // Register copy and import factory pair
53 tensorHandleFactoryRegistry.RegisterCopyAndImportFactoryPair(factory->GetId(), factory->GetId());
54 // Register the factory
55 tensorHandleFactoryRegistry.RegisterFactory(std::move(factory));
56
57 return std::make_unique<TosaRefWorkloadFactory>(PolymorphicPointerDowncast<TosaRefMemoryManager>(memoryManager));
58}
auto PolymorphicPointerDowncast(const SourceType &value)
Polymorphic downcast for shared pointers and build in pointers.

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

◆ CreateWorkloadFactory() [2/2]

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

Implements IBackendInternal.

Definition at line 38 of file TosaRefBackend.cpp.

40{
41 return std::make_unique<TosaRefWorkloadFactory>(PolymorphicPointerDowncast<TosaRefMemoryManager>(memoryManager));
42}

References armnn::PolymorphicPointerDowncast().

◆ GetCapabilities()

BackendCapabilities GetCapabilities ( ) const
overridevirtual

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 213 of file TosaRefBackend.cpp.

214{
215 return BackendCapabilities ("TosaRef",
216 {
217 {"NonConstWeights", true},
218 {"ConstantTensorsAsInputs", true}
219 });
220}
BackendOptions BackendCapabilities

◆ 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 208 of file TosaRefBackend.cpp.

209{
210 return std::make_unique<DefaultAllocator>();
211}

◆ 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 189 of file TosaRefBackend.cpp.

190{
191 return std::vector<ITensorHandleFactory::FactoryId> { TosaRefTensorHandleFactory::GetIdStatic() };
192}

References TosaRefTensorHandleFactory::GetIdStatic().

◆ GetId()

const BackendId & GetId ( ) const
inlineoverridevirtual

Implements IBackend.

Definition at line 19 of file TosaRefBackend.hpp.

20 {
21 return GetIdStatic();
22 }

References GetIdStatic().

Referenced by OptimizeSubgraphView().

◆ GetIdStatic()

const BackendId & GetIdStatic ( )
static

Definition at line 32 of file TosaRefBackend.cpp.

33{
34 static const BackendId s_Id{TosaRefBackendId()};
35 return s_Id;
36}
constexpr const char * TosaRefBackendId()

References armnn::TosaRefBackendId().

Referenced by GetId().

◆ GetLayerSupport()

IBackendInternal::ILayerSupportSharedPtr GetLayerSupport ( ) const
overridevirtual

Implements IBackendInternal.

Definition at line 76 of file TosaRefBackend.cpp.

77{
78 static ILayerSupportSharedPtr layerSupport{new TosaRefLayerSupport};
79 return layerSupport;
80}
std::shared_ptr< ILayerSupport > ILayerSupportSharedPtr

◆ OptimizeSubgraphView()

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

Reimplemented from IBackendInternal.

Definition at line 82 of file TosaRefBackend.cpp.

84{
85 OptimizationViews optimizationViews(modelOptions);
86
87 auto handler = std::make_unique<TosaSerializationHandler>();
88
89 std::vector<std::string> graphInputs;
90 std::vector<std::string> graphOutputs;
91 std::vector<TosaSerializationOperator*> operators;
92 std::vector<TosaSerializationTensor*> tensors;
93 OpBlockSequencer<Layer, TosaSerializationBasicBlock> sequencer;
94
95 // These sets are created to check the duplication of tensor and input
96 std::unordered_set<std::string> graphInputsSet;
97 std::unordered_set<std::string> uniqueTensorNamesSet;
98
99 auto it = subgraph.begin();
100 while (it != subgraph.end())
101 {
102 Layer& base = *(PolymorphicDowncast<Layer*>(*it));
103 ++it;
104
105 if (base.GetType() == LayerType::Input ||
106 base.GetType() == LayerType::Output)
107 {
108 continue;
109 }
110
111 TosaSerializationBasicBlock* mappings = GetTosaMappingFromLayer(&base);
112
113 // Loop through inputs to see if there are any graph inputs, if so save them.
114 // If it's an input to the graph "input" can be found in the string.
115 for (const std::string& blockInputName : mappings->GetInputs())
116 {
117 if ((blockInputName.find("input") != std::string::npos) && !graphInputsSet.count(blockInputName))
118 {
119 graphInputs.push_back(blockInputName);
120 graphInputsSet.insert(blockInputName);
121 }
122 }
123
124 // Loop through outputs to see if there are any graph outputs, if so save them.
125 // If it's an output to the graph "output" can be found in the string.
126 for (const std::string& blockOutputName : mappings->GetOutputs())
127 {
128 if (blockOutputName.find("output") != std::string::npos)
129 {
130 graphOutputs.push_back(blockOutputName);
131 }
132 }
133
134 sequencer.Add(&base, mappings);
135 }
136
137 for (auto & pair : sequencer.Finish())
138 {
139 auto blockOperators = pair.block->GetOperators();
140 operators.insert(operators.end(), blockOperators.begin(), blockOperators.end());
141
142 auto blockTensors = pair.block->GetTensors();
143
144 // Checking for duplicate tensors, to handle special cases where same input is
145 // added to different layer in the architecture.
146 for (const auto& tensor : blockTensors)
147 {
148 const std::string& name = tensor->GetName();
149
150 // If the input tensor is already present, we don't need to add to the list
151 if (!uniqueTensorNamesSet.count(name))
152 {
153 uniqueTensorNamesSet.insert(name);
154 tensors.push_back(tensor);
155 }
156 }
157 }
158
159 // Add all mappings to main block.
160 auto* block = new TosaSerializationBasicBlock("main", "main", operators, tensors, graphInputs, graphOutputs);
161
162 std::vector<TosaSerializationBasicBlock*> blocks;
163 blocks.emplace_back(block);
164
165 // Add blocks to the main region.
166 auto* region = new TosaSerializationRegion("main", blocks);
167 handler->GetRegions().emplace_back(region);
168
169 auto compiledBlob =
170 std::make_unique<PreCompiledObjectPtr>(handler.release(), DeleteAsType<TosaSerializationHandler>);
171
172 IConnectableLayer* preCompiledLayer = optimizationViews.GetINetwork()->AddPrecompiledLayer(
173 PreCompiledDescriptor(subgraph.GetNumInputSlots(), subgraph.GetNumOutputSlots()),
174 std::move(*compiledBlob),
175 armnn::Optional<BackendId>(GetId()),
176 "TOSA_Pre_Compiled_Layer");
177
178 // Copy the output tensor infos from sub-graph
179 for (unsigned int i = 0; i < subgraph.GetNumOutputSlots(); i++)
180 {
181 preCompiledLayer->GetOutputSlot(i).SetTensorInfo(subgraph.GetIOutputSlot(i)->GetTensorInfo());
182 }
183
184 optimizationViews.AddSubstitution({ std::move(subgraph), SubgraphView(preCompiledLayer) });
185 return optimizationViews;
186}
TosaSerializationBasicBlock * GetTosaMappingFromLayer(const Layer *layer)
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
virtual const TensorInfo & GetTensorInfo() const =0
LayerType GetType() const override
Returns the armnn::LayerType of this layer.
Definition Layer.hpp:286
std::list< Pair > & Finish()
void Add(LayerT *layer, BlockT *block)
IConnectableLayerIterator begin()
unsigned int GetNumOutputSlots() const
unsigned int GetNumInputSlots() const
const IOutputSlot * GetIOutputSlot(unsigned int index) const
IConnectableLayerIterator end()
const BackendId & GetId() const override
void DeleteAsType(const void *const blob)
DestType PolymorphicDowncast(SourceType *value)
Polymorphic downcast for build in pointers only.

References OpBlockSequencer< LayerT, BlockT >::Add(), INetwork::AddPrecompiledLayer(), OptimizationViews::AddSubstitution(), SubgraphView::begin(), armnn::DeleteAsType(), SubgraphView::end(), OpBlockSequencer< LayerT, BlockT >::Finish(), GetId(), OptimizationViews::GetINetwork(), SubgraphView::GetIOutputSlot(), SubgraphView::GetNumInputSlots(), SubgraphView::GetNumOutputSlots(), IConnectableLayer::GetOutputSlot(), IOutputSlot::GetTensorInfo(), GetTosaMappingFromLayer(), Layer::GetType(), armnn::Input, armnn::Output, armnn::PolymorphicDowncast(), and IOutputSlot::SetTensorInfo().

◆ 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 194 of file TosaRefBackend.cpp.

195{
196 auto memoryManager = std::make_shared<TosaRefMemoryManager>();
197
198 registry.RegisterMemoryManager(memoryManager);
199
200 auto factory = std::make_unique<TosaRefTensorHandleFactory>(memoryManager);
201
202 // Register copy and import factory pair
203 registry.RegisterCopyAndImportFactoryPair(factory->GetId(), factory->GetId());
204 // Register the factory
205 registry.RegisterFactory(std::move(factory));
206}

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


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