ArmNN
 20.08
ClBackend.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 "ClBackend.hpp"
7 #include "ClBackendId.hpp"
8 #include "ClWorkloadFactory.hpp"
9 #include "ClBackendContext.hpp"
10 #include "ClLayerSupport.hpp"
12 
14 
16 
19 
21 
22 #include <Optimizer.hpp>
23 
24 #include <arm_compute/runtime/CL/CLBufferAllocator.h>
25 
26 namespace armnn
27 {
28 
30 {
31  static const BackendId s_Id{ClBackendId()};
32  return s_Id;
33 }
34 
36 {
37  return std::make_unique<ClMemoryManager>(std::make_unique<arm_compute::CLBufferAllocator>());
38 }
39 
41  const IBackendInternal::IMemoryManagerSharedPtr& memoryManager) const
42 {
43  return std::make_unique<ClWorkloadFactory>(
44  PolymorphicPointerDowncast<ClMemoryManager>(memoryManager));
45 }
46 
48  TensorHandleFactoryRegistry& registry) const
49 {
50  auto memoryManager = std::make_shared<ClMemoryManager>(std::make_unique<arm_compute::CLBufferAllocator>());
51 
52  registry.RegisterMemoryManager(memoryManager);
53  registry.RegisterFactory(std::make_unique<ClTensorHandleFactory>(memoryManager));
54 
55  return std::make_unique<ClWorkloadFactory>(
56  PolymorphicPointerDowncast<ClMemoryManager>(memoryManager));
57 }
58 
59 std::vector<ITensorHandleFactory::FactoryId> ClBackend::GetHandleFactoryPreferences() const
60 {
61  return std::vector<ITensorHandleFactory::FactoryId> {ClTensorHandleFactory::GetIdStatic()};
62 }
63 
65 {
66  auto mgr = std::make_shared<ClMemoryManager>(std::make_unique<arm_compute::CLBufferAllocator>());
67 
68  registry.RegisterMemoryManager(mgr);
69  registry.RegisterFactory(std::make_unique<ClTensorHandleFactory>(mgr));
70 }
71 
74 {
75  return IBackendContextPtr{new ClBackendContext{options}};
76 }
77 
80 {
82 }
83 
85 {
86  return Optimizations{};
87 }
88 
90 {
91  static ILayerSupportSharedPtr layerSupport{new ClLayerSupport};
92  return layerSupport;
93 }
94 
96 {
97  OptimizationViews optimizationViews;
98 
99  optimizationViews.AddUntouchedSubgraph(SubgraphView(subgraph));
100 
101  return optimizationViews;
102 }
103 
104 } // 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
std::vector< OptimizationPtr > Optimizations
constexpr const char * ClBackendId()
Definition: ClBackendId.hpp:10
void RegisterFactory(std::unique_ptr< ITensorHandleFactory > allocator)
Register a TensorHandleFactory and transfer ownership.
Copyright (c) 2020 ARM Limited.
std::unique_ptr< IMemoryManager > IMemoryManagerUniquePtr
IBackendInternal::IMemoryManagerUniquePtr CreateMemoryManager() const override
Definition: ClBackend.cpp:35
void RegisterTensorHandleFactories(TensorHandleFactoryRegistry &registry) override
(Optional) Register TensorHandleFactories Either this method or CreateMemoryManager() and IWorkloadFa...
Definition: ClBackend.cpp:64
The SubgraphView class represents a subgraph of a Graph.
std::unique_ptr< armnn::profiling::IBackendProfiling > IBackendProfilingPtr
std::shared_ptr< IMemoryManager > IMemoryManagerSharedPtr
IBackendInternal::IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions &) const override
Create the runtime context of the backend.
Definition: ClBackend.cpp:73
std::vector< ITensorHandleFactory::FactoryId > GetHandleFactoryPreferences() const override
(Optional) Returns a vector of supported TensorHandleFactory ids in preference order.
Definition: ClBackend.cpp:59
void AddUntouchedSubgraph(SubgraphView &&subgraph)
OptimizationViews OptimizeSubgraphView(const SubgraphView &subgraph) const override
Definition: ClBackend.cpp:95
IBackendInternal::IWorkloadFactoryPtr CreateWorkloadFactory(const IBackendInternal::IMemoryManagerSharedPtr &memoryManager=nullptr) const override
Definition: ClBackend.cpp:40
std::shared_ptr< ILayerSupport > ILayerSupportSharedPtr
IBackendInternal::ILayerSupportSharedPtr GetLayerSupport() const override
Definition: ClBackend.cpp:89
IBackendInternal::IBackendProfilingContextPtr CreateBackendProfilingContext(const IRuntime::CreationOptions &, IBackendProfilingPtr &backendProfiling) override
Create context specifically used for profiling interaction from backends.
Definition: ClBackend.cpp:78
IBackendInternal::Optimizations GetOptimizations() const override
Definition: ClBackend.cpp:84
static const BackendId & GetIdStatic()
Definition: ClBackend.cpp:29
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