ArmNN  NotReleased
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
std::unique_ptr< IWorkloadFactory > IWorkloadFactoryPtr
std::vector< OptimizationPtr > Optimizations
std::vector< ITensorHandleFactory::FactoryId > GetHandleFactoryPreferences() const override
(Optional) Returns a vector of supported TensorHandleFactory ids in preference order.
Definition: ClBackend.cpp:58
void RegisterFactory(std::unique_ptr< ITensorHandleFactory > allocator)
Register a TensorHandleFactory and transfer ownership.
IBackendInternal::IBackendProfilingContextPtr CreateBackendProfilingContext(const IRuntime::CreationOptions &, IBackendProfilingPtr &backendProfiling) override
Create context specifically used for profiling interaction from backends.
Definition: ClBackend.cpp:77
OptimizationViews OptimizeSubgraphView(const SubgraphView &subgraph) const override
Definition: ClBackend.cpp:94
IBackendInternal::ILayerSupportSharedPtr GetLayerSupport() const override
Definition: ClBackend.cpp:88
void AddUntouchedSubgraph(SubgraphView &&subgraph)
static const FactoryId & GetIdStatic()
std::unique_ptr< IBackendContext > IBackendContextPtr
std::shared_ptr< IMemoryManager > IMemoryManagerSharedPtr
void RegisterTensorHandleFactories(TensorHandleFactoryRegistry &registry) override
Definition: ClBackend.cpp:63
IBackendInternal::Optimizations GetOptimizations() const override
Definition: ClBackend.cpp:83
std::shared_ptr< armnn::profiling::IBackendProfilingContext > IBackendProfilingContextPtr
std::unique_ptr< IMemoryManager > IMemoryManagerUniquePtr
IBackendInternal::IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions &) const override
Definition: ClBackend.cpp:72
std::shared_ptr< ILayerSupport > ILayerSupportSharedPtr
IBackendInternal::IWorkloadFactoryPtr CreateWorkloadFactory(const IBackendInternal::IMemoryManagerSharedPtr &memoryManager=nullptr) const override
Definition: ClBackend.cpp:40
void RegisterMemoryManager(std::shared_ptr< IMemoryManager > memoryManger)
Register a memory manager with shared ownership.
IBackendInternal::IMemoryManagerUniquePtr CreateMemoryManager() const override
Definition: ClBackend.cpp:35
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
static const BackendId & GetIdStatic()
Definition: ClBackend.cpp:29
std::unique_ptr< armnn::profiling::IBackendProfiling > IBackendProfilingPtr
constexpr const char * ClBackendId()
Definition: ClBackendId.hpp:10