ArmNN
 20.02
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 
20 #include <Optimizer.hpp>
21 
22 #include <arm_compute/runtime/CL/CLBufferAllocator.h>
23 
24 #include <boost/polymorphic_pointer_cast.hpp>
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  boost::polymorphic_pointer_downcast<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 
54  return std::make_unique<ClWorkloadFactory>(
55  boost::polymorphic_pointer_downcast<ClMemoryManager>(memoryManager));
56 }
57 
58 std::vector<ITensorHandleFactory::FactoryId> ClBackend::GetHandleFactoryPreferences() const
59 {
60  return std::vector<ITensorHandleFactory::FactoryId> {ClTensorHandleFactory::GetIdStatic()};
61 }
62 
64 {
65  auto mgr = std::make_shared<ClMemoryManager>(std::make_unique<arm_compute::CLBufferAllocator>());
66 
67  registry.RegisterMemoryManager(mgr);
68  registry.RegisterFactory(std::make_unique<ClTensorHandleFactory>(mgr));
69 }
70 
73 {
74  return IBackendContextPtr{new ClBackendContext{options}};
75 }
76 
79 {
81 }
82 
84 {
85  return Optimizations{};
86 }
87 
89 {
90  static ILayerSupportSharedPtr layerSupport{new ClLayerSupport};
91  return layerSupport;
92 }
93 
95 {
96  OptimizationViews optimizationViews;
97 
98  optimizationViews.AddUntouchedSubgraph(SubgraphView(subgraph));
99 
100  return optimizationViews;
101 }
102 
103 } // 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:63
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:72
std::vector< ITensorHandleFactory::FactoryId > GetHandleFactoryPreferences() const override
(Optional) Returns a vector of supported TensorHandleFactory ids in preference order.
Definition: ClBackend.cpp:58
void AddUntouchedSubgraph(SubgraphView &&subgraph)
OptimizationViews OptimizeSubgraphView(const SubgraphView &subgraph) const override
Definition: ClBackend.cpp:94
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:88
IBackendInternal::IBackendProfilingContextPtr CreateBackendProfilingContext(const IRuntime::CreationOptions &, IBackendProfilingPtr &backendProfiling) override
Create context specifically used for profiling interaction from backends.
Definition: ClBackend.cpp:77
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
IBackendInternal::Optimizations GetOptimizations() const override
Definition: ClBackend.cpp:83
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