-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSampleDynamicBackend.cpp
126 lines (96 loc) · 3.88 KB
/
SampleDynamicBackend.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//
#include "SampleDynamicBackend.hpp"
#include "SampleDynamicLayerSupport.hpp"
#include "SampleDynamicWorkloadFactory.hpp"
#include "SampleMemoryManager.hpp"
#include "SampleDynamicTensorHandleFactory.hpp"
#include <armnn/backends/IBackendInternal.hpp>
#include <armnn/backends/OptimizationViews.hpp>
#include <armnn/utility/PolymorphicDowncast.hpp>
#include <backendsCommon/TensorHandleFactoryRegistry.hpp>
namespace sdb // sample dynamic backend
{
constexpr const char * SampleDynamicBackendId() { return "SampleDynamic"; }
class SampleDynamicBackend : public armnn::IBackendInternal
{
public:
SampleDynamicBackend() = default;
~SampleDynamicBackend() = default;
static const armnn::BackendId& GetIdStatic()
{
static const armnn::BackendId s_Id{SampleDynamicBackendId()};
return s_Id;
}
const armnn::BackendId& GetId() const override { return GetIdStatic(); }
IBackendInternal::IMemoryManagerUniquePtr CreateMemoryManager() const override
{
return std::make_unique<SampleMemoryManager>();
}
IBackendInternal::IWorkloadFactoryPtr CreateWorkloadFactory(
const IMemoryManagerSharedPtr& memoryManager) const override
{
return std::make_unique<SampleDynamicWorkloadFactory>(
armnn::PolymorphicPointerDowncast<SampleMemoryManager>(memoryManager));
}
IBackendInternal::IWorkloadFactoryPtr CreateWorkloadFactory(
class armnn::TensorHandleFactoryRegistry& tensorHandleFactoryRegistry) const override
{
auto memoryManager = std::make_shared<SampleMemoryManager>();
tensorHandleFactoryRegistry.RegisterMemoryManager(memoryManager);
tensorHandleFactoryRegistry.RegisterFactory(std::make_unique<SampleDynamicTensorHandleFactory>(memoryManager));
return std::make_unique<SampleDynamicWorkloadFactory>(
armnn::PolymorphicPointerDowncast<SampleMemoryManager>(memoryManager));
}
IBackendInternal::IBackendProfilingContextPtr CreateBackendProfilingContext(
const armnn::IRuntime::CreationOptions&, IBackendProfilingPtr&) override
{
return IBackendProfilingContextPtr{};
}
IBackendInternal::ILayerSupportSharedPtr GetLayerSupport() const override
{
static ILayerSupportSharedPtr layerSupport{new SampleDynamicLayerSupport};
return layerSupport;
}
std::vector<armnn::ITensorHandleFactory::FactoryId> GetHandleFactoryPreferences() const override
{
return std::vector<armnn::ITensorHandleFactory::FactoryId> { SampleDynamicTensorHandleFactory::GetIdStatic() };
}
IBackendInternal::IBackendContextPtr CreateBackendContext(const armnn::IRuntime::CreationOptions&) const override
{
return IBackendContextPtr{};
}
armnn::OptimizationViews OptimizeSubgraphView(const armnn::SubgraphView& subgraph) const override
{
armnn::OptimizationViews optimizationViews;
optimizationViews.AddUntouchedSubgraph(armnn::SubgraphView(subgraph));
return optimizationViews;
}
void RegisterTensorHandleFactories(class armnn::TensorHandleFactoryRegistry& registry) override
{
auto memoryManager = std::make_shared<SampleMemoryManager>();
registry.RegisterMemoryManager(memoryManager);
registry.RegisterFactory(std::make_unique<SampleDynamicTensorHandleFactory>(memoryManager));
}
};
} // namespace sdb
const char* GetBackendId()
{
return sdb::SampleDynamicBackend::GetIdStatic().Get().c_str();
}
void GetVersion(uint32_t* outMajor, uint32_t* outMinor)
{
if (!outMajor || !outMinor)
{
return;
}
armnn::BackendVersion apiVersion = armnn::IBackendInternal::GetApiVersion();
*outMajor = apiVersion.m_Major;
*outMinor = apiVersion.m_Minor;
}
void* BackendFactory()
{
return new sdb::SampleDynamicBackend();
}