ArmNN
 24.08
SampleDynamicBackend.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
11 
16 
17 namespace sdb // sample dynamic backend
18 {
19 
20 constexpr const char * SampleDynamicBackendId() { return "SampleDynamic"; }
21 
22 class SampleDynamicBackend : public armnn::IBackendInternal
23 {
24 public:
25  SampleDynamicBackend() = default;
26  ~SampleDynamicBackend() = default;
27 
28  static const armnn::BackendId& GetIdStatic()
29  {
30  static const armnn::BackendId s_Id{SampleDynamicBackendId()};
31  return s_Id;
32  }
33 
34  const armnn::BackendId& GetId() const override { return GetIdStatic(); }
35 
36  IBackendInternal::IMemoryManagerUniquePtr CreateMemoryManager() const override
37  {
38  return std::make_unique<SampleMemoryManager>();
39  }
40 
41  IBackendInternal::IWorkloadFactoryPtr CreateWorkloadFactory(
42  const IMemoryManagerSharedPtr& memoryManager) const override
43  {
44  return std::make_unique<SampleDynamicWorkloadFactory>(
45  armnn::PolymorphicPointerDowncast<SampleMemoryManager>(memoryManager));
46  }
47 
48  IBackendInternal::IWorkloadFactoryPtr CreateWorkloadFactory(
49  class armnn::TensorHandleFactoryRegistry& tensorHandleFactoryRegistry) const override
50  {
51  auto memoryManager = std::make_shared<SampleMemoryManager>();
52 
53  tensorHandleFactoryRegistry.RegisterMemoryManager(memoryManager);
54  tensorHandleFactoryRegistry.RegisterFactory(std::make_unique<SampleDynamicTensorHandleFactory>(memoryManager));
55 
56  return std::make_unique<SampleDynamicWorkloadFactory>(
57  armnn::PolymorphicPointerDowncast<SampleMemoryManager>(memoryManager));
58  }
59 
60  IBackendInternal::IBackendProfilingContextPtr CreateBackendProfilingContext(
61  const armnn::IRuntime::CreationOptions&, IBackendProfilingPtr&) override
62  {
64  }
65 
67  {
68  static ILayerSupportSharedPtr layerSupport{new SampleDynamicLayerSupport};
69  return layerSupport;
70  }
71 
72  std::vector<armnn::ITensorHandleFactory::FactoryId> GetHandleFactoryPreferences() const override
73  {
74  return std::vector<armnn::ITensorHandleFactory::FactoryId> { SampleDynamicTensorHandleFactory::GetIdStatic() };
75  }
76 
77  IBackendInternal::IBackendContextPtr CreateBackendContext(const armnn::IRuntime::CreationOptions&) const override
78  {
79  return IBackendContextPtr{};
80  }
81 
83  {
84  armnn::OptimizationViews optimizationViews;
85 
86  optimizationViews.AddUntouchedSubgraph(armnn::SubgraphView(subgraph));
87 
88  return optimizationViews;
89  }
90 
92  {
93  auto memoryManager = std::make_shared<SampleMemoryManager>();
94 
95  registry.RegisterMemoryManager(memoryManager);
96  registry.RegisterFactory(std::make_unique<SampleDynamicTensorHandleFactory>(memoryManager));
97  }
98 
99 };
100 
101 } // namespace sdb
102 
103 const char* GetBackendId()
104 {
105  return sdb::SampleDynamicBackend::GetIdStatic().Get().c_str();
106 }
107 
108 void GetVersion(uint32_t* outMajor, uint32_t* outMinor)
109 {
110  if (!outMajor || !outMinor)
111  {
112  return;
113  }
114 
116 
117  *outMajor = apiVersion.m_Major;
118  *outMinor = apiVersion.m_Minor;
119 }
120 
122 {
123  return new sdb::SampleDynamicBackend();
124 }
125 
126 
armnn::BackendVersion::m_Minor
uint32_t m_Minor
Definition: IBackendInternal.hpp:37
armnn::OptimizationViews::AddUntouchedSubgraph
void AddUntouchedSubgraph(SubgraphView &&subgraph)
Definition: OptimizationViews.hpp:48
sdb::SampleDynamicBackendId
constexpr const char * SampleDynamicBackendId()
Definition: SampleDynamicBackend.cpp:20
SampleDynamicTensorHandleFactory.hpp
BackendFactory
void * BackendFactory()
Definition: SampleDynamicBackend.cpp:121
armnn::IMemoryManagerUniquePtr
std::unique_ptr< IMemoryManager > IMemoryManagerUniquePtr
Definition: IMemoryManager.hpp:24
SampleDynamicLayerSupport.hpp
armnn::TensorHandleFactoryRegistry
Definition: TensorHandleFactoryRegistry.hpp:23
SampleMemoryManager.hpp
armnn::TensorHandleFactoryRegistry::RegisterMemoryManager
void RegisterMemoryManager(std::shared_ptr< IMemoryManager > memoryManger)
Register a memory manager with shared ownership.
Definition: TensorHandleFactoryRegistry.cpp:34
armnn::IBackendInternal::OptimizeSubgraphView
virtual OptimizationViews OptimizeSubgraphView(const SubgraphView &subgraph, const ModelOptions &modelOptions) const
Definition: IBackendInternal.cpp:114
armnn::IBackendInternal
Definition: IBackendInternal.hpp:77
armnn::IBackendInternal::IBackendContextPtr
std::unique_ptr< IBackendContext > IBackendContextPtr
Definition: IBackendInternal.hpp:90
SampleDynamicWorkloadFactory.hpp
TensorHandleFactoryRegistry.hpp
SampleDynamicBackend.hpp
sdb
Definition: SampleDynamicAdditionWorkload.cpp:11
OptimizationViews.hpp
armnn::IBackendInternal::CreateWorkloadFactory
virtual IWorkloadFactoryPtr CreateWorkloadFactory(const IMemoryManagerSharedPtr &memoryManager, const ModelOptions &modelOptions) const
Definition: IBackendInternal.cpp:24
PolymorphicDowncast.hpp
IBackendInternal.hpp
GetVersion
void GetVersion(uint32_t *outMajor, uint32_t *outMinor)
Definition: SampleDynamicBackend.cpp:108
armnn::SubgraphView
The SubgraphView class represents a subgraph of a Graph.
Definition: SubgraphView.hpp:31
armnn::IBackendInternal::RegisterTensorHandleFactories
virtual void RegisterTensorHandleFactories(class TensorHandleFactoryRegistry &registry, MemorySourceFlags inputFlags, MemorySourceFlags outputFlags)
(Optional) Register TensorHandleFactories Either this method or CreateMemoryManager() and IWorkloadFa...
Definition: IBackendInternal.cpp:125
armnn::OptimizationViews
Definition: OptimizationViews.hpp:17
armnn::IBackendInternal::GetApiVersion
static constexpr BackendVersion GetApiVersion()
Returns the version of the Backend API.
Definition: IBackendInternal.hpp:167
armnn::IBackendInternal::IBackendProfilingContextPtr
std::shared_ptr< arm::pipe::IBackendProfilingContext > IBackendProfilingContextPtr
This is the bridge between backend and backend profiling we'll keep it in the backend namespace.
Definition: IBackendInternal.hpp:92
sdb::SampleDynamicTensorHandleFactory::GetIdStatic
static const FactoryId & GetIdStatic()
Definition: SampleDynamicTensorHandleFactory.cpp:16
armnn::IRuntime::CreationOptions
Definition: IRuntime.hpp:78
armnn::BackendVersion
Definition: IBackendInternal.hpp:34
armnn::BackendId
Definition: BackendId.hpp:75
armnn::TensorHandleFactoryRegistry::RegisterFactory
void RegisterFactory(std::unique_ptr< ITensorHandleFactory > allocator)
Register a TensorHandleFactory and transfer ownership.
Definition: TensorHandleFactoryRegistry.cpp:12
armnn::ILayerSupportSharedPtr
std::shared_ptr< ILayerSupport > ILayerSupportSharedPtr
Definition: ILayerSupport.hpp:40
GetBackendId
const char * GetBackendId()
Definition: SampleDynamicBackend.cpp:103
armnn::BackendVersion::m_Major
uint32_t m_Major
Definition: IBackendInternal.hpp:36
armnn::IBackendInternal::GetLayerSupport
virtual ILayerSupportSharedPtr GetLayerSupport(const ModelOptions &modelOptions) const
Definition: IBackendInternal.cpp:88