29 delete static_cast<const T*
>(blob);
41 return std::make_unique<TosaRefWorkloadFactory>(PolymorphicPointerDowncast<TosaRefMemoryManager>(memoryManager));
47 auto memoryManager = std::make_shared<TosaRefMemoryManager>();
51 auto factory = std::make_unique<TosaRefTensorHandleFactory>(memoryManager);
57 return std::make_unique<TosaRefWorkloadFactory>(PolymorphicPointerDowncast<TosaRefMemoryManager>(memoryManager));
73 return std::make_unique<TosaRefMemoryManager>();
82 static void LayerToTosaMappings(
const Layer& base,
83 std::vector<std::string>& graphInputs,
84 std::vector<std::string>& graphOutputs,
85 std::vector<TosaSerializationOperator*>& operators,
86 std::vector<TosaSerializationTensor*>& tensors)
92 for (
const std::string& blockInputName : mappings->GetInputs())
94 if (blockInputName.find(
"input") != std::string::npos)
96 graphInputs.push_back(blockInputName);
102 for (
const std::string& blockOutputName : mappings->GetOutputs())
104 if (blockOutputName.find(
"output") != std::string::npos)
106 graphOutputs.push_back(blockOutputName);
110 auto blockOperators = mappings->GetOperators();
111 operators.insert(operators.end(), blockOperators.begin(), blockOperators.end());
113 auto blockTensors = mappings->GetTensors();
114 tensors.insert(tensors.end(), blockTensors.begin(), blockTensors.end());
122 auto handler = std::make_unique<TosaSerializationHandler>();
124 std::vector<std::string> graphInputs;
125 std::vector<std::string> graphOutputs;
127 std::vector<TosaSerializationOperator*> operators;
128 std::vector<TosaSerializationTensor*> tensors;
130 auto it = subgraph.
begin();
131 while (it != subgraph.
end())
133 Layer& base = *(PolymorphicDowncast<Layer*>(*it));
142 bool baseContainsBroadcastReshape =
false;
146 if (++nextIt != subgraph.
end())
148 Layer& nextLayer = *(PolymorphicDowncast<Layer*>(*(nextIt)));
155 LayerToTosaMappings(nextLayer, graphInputs, graphOutputs, operators, tensors);
156 baseContainsBroadcastReshape =
true;
162 LayerToTosaMappings(base, graphInputs, graphOutputs, operators, tensors);
165 if (baseContainsBroadcastReshape)
171 std::sort(graphInputs.begin(), graphInputs.end());
175 auto* block =
new TosaSerializationBasicBlock(
"main",
"main", operators, tensors, graphInputs, graphOutputs);
177 std::vector<TosaSerializationBasicBlock*> blocks;
178 blocks.emplace_back(block);
181 auto* region =
new TosaSerializationRegion(
"main", blocks);
182 handler->GetRegions().emplace_back(region);
185 std::make_unique<PreCompiledObjectPtr>(handler.release(), DeleteAsType<TosaSerializationHandler>);
189 std::move(*compiledBlob),
191 "TOSA_Pre_Compiled_Layer");
200 return optimizationViews;
211 auto memoryManager = std::make_shared<TosaRefMemoryManager>();
215 auto factory = std::make_unique<TosaRefTensorHandleFactory>(memoryManager);
225 return std::make_unique<DefaultAllocator>();
TosaSerializationBasicBlock * GetTosaMappingFromLayer(const Layer *layer)
std::shared_ptr< ILayerSupport > ILayerSupportSharedPtr
std::unique_ptr< IMemoryManager > IMemoryManagerUniquePtr
std::unique_ptr< arm::pipe::IBackendProfiling > IBackendProfilingPtr
std::shared_ptr< IMemoryManager > IMemoryManagerSharedPtr
std::unique_ptr< IWorkloadFactory > IWorkloadFactoryPtr
std::unique_ptr< IBackendContext > IBackendContextPtr
std::shared_ptr< arm::pipe::IBackendProfilingContext > IBackendProfilingContextPtr
This is the bridge between backend and backend profiling we'll keep it in the backend namespace.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
IConnectableLayer * AddPrecompiledLayer(const PreCompiledDescriptor &preCompiledDescriptor, CompiledBlobPtr compiledBlobPtr, const Optional< BackendId > &backend, const char *name=nullptr)
Adds a Precompiled layer to the network.
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
virtual const TensorInfo & GetTensorInfo() const =0
unsigned int GetNumInputSlots() const override
Returns the number of connectable input slots.
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
LayerType GetType() const override
Returns the armnn::LayerType of this layer.
void AddSubstitution(SubstitutionPair &&substitution)
Layer & GetOwningLayer() const
The SubgraphView class represents a subgraph of a Graph.
IConnectableLayerIterator begin()
unsigned int GetNumOutputSlots() const
unsigned int GetNumInputSlots() const
const IOutputSlot * GetIOutputSlot(unsigned int index) const
IConnectableLayerIterator end()
void RegisterFactory(std::unique_ptr< ITensorHandleFactory > allocator)
Register a TensorHandleFactory and transfer ownership.
void RegisterMemoryManager(std::shared_ptr< IMemoryManager > memoryManger)
Register a memory manager with shared ownership.
void RegisterCopyAndImportFactoryPair(ITensorHandleFactory::FactoryId copyFactoryId, ITensorHandleFactory::FactoryId importFactoryId)
Register a pair of TensorHandleFactory Id for Memory Copy and TensorHandleFactory Id for Memory Impor...
static const BackendId & GetIdStatic()
OptimizationViews OptimizeSubgraphView(const SubgraphView &subgraph, const ModelOptions &modelOptions) const override
void RegisterTensorHandleFactories(class TensorHandleFactoryRegistry ®istry) override
(Optional) Register TensorHandleFactories Either this method or CreateMemoryManager() and IWorkloadFa...
std::vector< ITensorHandleFactory::FactoryId > GetHandleFactoryPreferences() const override
(Optional) Returns a vector of supported TensorHandleFactory ids in preference order.
const BackendId & GetId() const override
IBackendInternal::IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions &) const override
Create the runtime context of the backend.
IBackendInternal::IWorkloadFactoryPtr CreateWorkloadFactory(const IBackendInternal::IMemoryManagerSharedPtr &memoryManager=nullptr) const override
IBackendInternal::ILayerSupportSharedPtr GetLayerSupport() const override
IBackendInternal::IMemoryManagerUniquePtr CreateMemoryManager() const override
IBackendInternal::IBackendProfilingContextPtr CreateBackendProfilingContext(const IRuntime::CreationOptions &creationOptions, IBackendProfilingPtr &backendProfiling) override
Create context specifically used for profiling interaction from backends.
std::unique_ptr< ICustomAllocator > GetDefaultAllocator() const override
Returns the default memory allocator for the backend.
static const FactoryId & GetIdStatic()
Copyright (c) 2021 ARM Limited and Contributors.
constexpr const char * TosaRefBackendId()
void DeleteAsType(const void *const blob)
std::vector< BackendOptions > ModelOptions
A PreCompiledDescriptor for the PreCompiledLayer.