ArmNN
 21.11
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  tensorHandleFactoryRegistry.RegisterFactory(std::make_unique<RefTensorHandleFactory>(memoryManager));
42 
43  return std::make_unique<RefWorkloadFactory>(PolymorphicPointerDowncast<RefMemoryManager>(memoryManager));
44 }
45 
47 {
48  return IBackendContextPtr{};
49 }
50 
53 {
55 }
56 
58 {
59  return std::make_unique<RefMemoryManager>();
60 }
61 
63 {
64  static ILayerSupportSharedPtr layerSupport{new RefLayerSupport};
65  return layerSupport;
66 }
67 
69 {
70  OptimizationViews optimizationViews;
71 
72  optimizationViews.AddUntouchedSubgraph(SubgraphView(subgraph));
73 
74  return optimizationViews;
75 }
76 
77 std::vector<ITensorHandleFactory::FactoryId> RefBackend::GetHandleFactoryPreferences() const
78 {
79  return std::vector<ITensorHandleFactory::FactoryId> { RefTensorHandleFactory::GetIdStatic() };
80 }
81 
83 {
84  auto memoryManager = std::make_shared<RefMemoryManager>();
85 
86  registry.RegisterMemoryManager(memoryManager);
87  registry.RegisterFactory(std::make_unique<RefTensorHandleFactory>(memoryManager));
88 }
89 
90 std::unique_ptr<ICustomAllocator> RefBackend::GetDefaultAllocator() const
91 {
92  return std::make_unique<DefaultAllocator>();
93 }
94 
95 } // 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:57
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:62
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:82
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:46
IBackendInternal::IBackendProfilingContextPtr CreateBackendProfilingContext(const IRuntime::CreationOptions &creationOptions, IBackendProfilingPtr &backendProfiling) override
Create context specifically used for profiling interaction from backends.
Definition: RefBackend.cpp:51
The SubgraphView class represents a subgraph of a Graph.
OptimizationViews OptimizeSubgraphView(const SubgraphView &subgraph) const override
Definition: RefBackend.cpp:68
std::unique_ptr< armnn::profiling::IBackendProfiling > IBackendProfilingPtr
std::shared_ptr< IMemoryManager > IMemoryManagerSharedPtr
IBackendInternal::IWorkloadFactoryPtr CreateWorkloadFactory(const IBackendInternal::IMemoryManagerSharedPtr &memoryManager=nullptr) const override
Definition: RefBackend.cpp:29
void AddUntouchedSubgraph(SubgraphView &&subgraph)
std::unique_ptr< ICustomAllocator > GetDefaultAllocator() const override
Returns the default memory allocator for the backend.
Definition: RefBackend.cpp:90
std::shared_ptr< ILayerSupport > ILayerSupportSharedPtr
std::vector< ITensorHandleFactory::FactoryId > GetHandleFactoryPreferences() const override
(Optional) Returns a vector of supported TensorHandleFactory ids in preference order.
Definition: RefBackend.cpp:77
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...
std::unique_ptr< IBackendContext > IBackendContextPtr