ArmNN
 22.05.01
RefBackend.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "RefBackend.hpp"
7 #include "RefBackendId.hpp"
8 #include "RefWorkloadFactory.hpp"
9 #include "RefLayerSupport.hpp"
11 
17 
18 #include <Optimizer.hpp>
19 
20 namespace armnn
21 {
22 
24 {
25  static const BackendId s_Id{RefBackendId()};
26  return s_Id;
27 }
28 
30  const IBackendInternal::IMemoryManagerSharedPtr& memoryManager) const
31 {
32  return std::make_unique<RefWorkloadFactory>(PolymorphicPointerDowncast<RefMemoryManager>(memoryManager));
33 }
34 
36  class TensorHandleFactoryRegistry& tensorHandleFactoryRegistry) const
37 {
38  auto memoryManager = std::make_shared<RefMemoryManager>();
39 
40  tensorHandleFactoryRegistry.RegisterMemoryManager(memoryManager);
41 
42  std::unique_ptr<RefTensorHandleFactory> factory = std::make_unique<RefTensorHandleFactory>(memoryManager);
43  // Register copy and import factory pair
44  tensorHandleFactoryRegistry.RegisterCopyAndImportFactoryPair(factory->GetId(), factory->GetId());
45  // Register the factory
46  tensorHandleFactoryRegistry.RegisterFactory(std::move(factory));
47 
48  return std::make_unique<RefWorkloadFactory>(PolymorphicPointerDowncast<RefMemoryManager>(memoryManager));
49 }
50 
52 {
53  return IBackendContextPtr{};
54 }
55 
58 {
60 }
61 
63 {
64  return std::make_unique<RefMemoryManager>();
65 }
66 
68 {
69  static ILayerSupportSharedPtr layerSupport{new RefLayerSupport};
70  return layerSupport;
71 }
72 
74 {
75  OptimizationViews optimizationViews;
76 
77  optimizationViews.AddUntouchedSubgraph(SubgraphView(subgraph));
78 
79  return optimizationViews;
80 }
81 
82 std::vector<ITensorHandleFactory::FactoryId> RefBackend::GetHandleFactoryPreferences() const
83 {
84  return std::vector<ITensorHandleFactory::FactoryId> { RefTensorHandleFactory::GetIdStatic() };
85 }
86 
88 {
89  auto memoryManager = std::make_shared<RefMemoryManager>();
90 
91  registry.RegisterMemoryManager(memoryManager);
92 
93  std::unique_ptr<RefTensorHandleFactory> factory = std::make_unique<RefTensorHandleFactory>(memoryManager);
94 
95  // Register copy and import factory pair
96  registry.RegisterCopyAndImportFactoryPair(factory->GetId(), factory->GetId());
97  // Register the factory
98  registry.RegisterFactory(std::move(factory));
99 }
100 
101 std::unique_ptr<ICustomAllocator> RefBackend::GetDefaultAllocator() const
102 {
103  return std::make_unique<DefaultAllocator>();
104 }
105 
106 } // namespace armnn
void RegisterMemoryManager(std::shared_ptr< IMemoryManager > memoryManger)
Register a memory manager with shared ownership.
static const FactoryId & GetIdStatic()
std::unique_ptr< IWorkloadFactory > IWorkloadFactoryPtr
IBackendInternal::IMemoryManagerUniquePtr CreateMemoryManager() const override
Definition: RefBackend.cpp:62
constexpr const char * RefBackendId()
void RegisterFactory(std::unique_ptr< ITensorHandleFactory > allocator)
Register a TensorHandleFactory and transfer ownership.
IBackendInternal::ILayerSupportSharedPtr GetLayerSupport() const override
Definition: RefBackend.cpp:67
static const BackendId & GetIdStatic()
Definition: RefBackend.cpp:23
void RegisterTensorHandleFactories(class TensorHandleFactoryRegistry &registry) override
(Optional) Register TensorHandleFactories Either this method or CreateMemoryManager() and IWorkloadFa...
Definition: RefBackend.cpp:87
Copyright (c) 2021 ARM Limited and Contributors.
std::unique_ptr< IMemoryManager > IMemoryManagerUniquePtr
IBackendInternal::IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions &) const override
Create the runtime context of the backend.
Definition: RefBackend.cpp:51
IBackendInternal::IBackendProfilingContextPtr CreateBackendProfilingContext(const IRuntime::CreationOptions &creationOptions, IBackendProfilingPtr &backendProfiling) override
Create context specifically used for profiling interaction from backends.
Definition: RefBackend.cpp:56
The SubgraphView class represents a subgraph of a Graph.
OptimizationViews OptimizeSubgraphView(const SubgraphView &subgraph) const override
Definition: RefBackend.cpp:73
void RegisterCopyAndImportFactoryPair(ITensorHandleFactory::FactoryId copyFactoryId, ITensorHandleFactory::FactoryId importFactoryId)
Register a pair of TensorHandleFactory Id for Memory Copy and TensorHandleFactory Id for Memory Impor...
std::shared_ptr< IMemoryManager > IMemoryManagerSharedPtr
IBackendInternal::IWorkloadFactoryPtr CreateWorkloadFactory(const IBackendInternal::IMemoryManagerSharedPtr &memoryManager=nullptr) const override
Definition: RefBackend.cpp:29
void AddUntouchedSubgraph(SubgraphView &&subgraph)
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...
std::unique_ptr< ICustomAllocator > GetDefaultAllocator() const override
Returns the default memory allocator for the backend.
Definition: RefBackend.cpp:101
std::shared_ptr< ILayerSupport > ILayerSupportSharedPtr
std::unique_ptr< arm::pipe::IBackendProfiling > IBackendProfilingPtr
std::vector< ITensorHandleFactory::FactoryId > GetHandleFactoryPreferences() const override
(Optional) Returns a vector of supported TensorHandleFactory ids in preference order.
Definition: RefBackend.cpp:82
std::unique_ptr< IBackendContext > IBackendContextPtr