2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
6 #include "ClBackend.hpp"
7 #include "ClBackendId.hpp"
8 #include "ClWorkloadFactory.hpp"
9 #include "ClBackendContext.hpp"
10 #include "ClLayerSupport.hpp"
11 #include "ClTensorHandleFactory.hpp"
13 #include <aclCommon/BaseMemoryManager.hpp>
15 #include <backendsCommon/BackendRegistry.hpp>
16 #include <backendsCommon/IBackendContext.hpp>
17 #include <backendsCommon/IMemoryManager.hpp>
19 #include <Optimizer.hpp>
21 #include <arm_compute/runtime/CL/CLBufferAllocator.h>
23 #include <boost/polymorphic_pointer_cast.hpp>
28 const BackendId& ClBackend::GetIdStatic()
30 static const BackendId s_Id{ClBackendId()};
34 IBackendInternal::IMemoryManagerUniquePtr ClBackend::CreateMemoryManager() const
36 return std::make_unique<ClMemoryManager>(std::make_unique<arm_compute::CLBufferAllocator>());
39 IBackendInternal::IWorkloadFactoryPtr ClBackend::CreateWorkloadFactory(
40 const IBackendInternal::IMemoryManagerSharedPtr& memoryManager) const
42 return std::make_unique<ClWorkloadFactory>(
43 boost::polymorphic_pointer_downcast<ClMemoryManager>(memoryManager));
46 IBackendInternal::IWorkloadFactoryPtr ClBackend::CreateWorkloadFactory(
47 TensorHandleFactoryRegistry& registry) const
49 auto memoryManager = std::make_shared<ClMemoryManager>(std::make_unique<arm_compute::CLBufferAllocator>());
51 registry.RegisterMemoryManager(memoryManager);
53 return std::make_unique<ClWorkloadFactory>(
54 boost::polymorphic_pointer_downcast<ClMemoryManager>(memoryManager));
57 std::vector<ITensorHandleFactory::FactoryId> ClBackend::GetHandleFactoryPreferences() const
59 return std::vector<ITensorHandleFactory::FactoryId> {ClTensorHandleFactory::GetIdStatic()};
62 void ClBackend::RegisterTensorHandleFactories(TensorHandleFactoryRegistry& registry)
64 auto mgr = std::make_shared<ClMemoryManager>(std::make_unique<arm_compute::CLBufferAllocator>());
66 registry.RegisterMemoryManager(mgr);
67 registry.RegisterFactory(std::make_unique<ClTensorHandleFactory>(mgr));
70 IBackendInternal::IBackendContextPtr
71 ClBackend::CreateBackendContext(const IRuntime::CreationOptions& options) const
73 return IBackendContextPtr{new ClBackendContext{options}};
76 IBackendInternal::Optimizations ClBackend::GetOptimizations() const
78 return Optimizations{};
81 IBackendInternal::ILayerSupportSharedPtr ClBackend::GetLayerSupport() const
83 static ILayerSupportSharedPtr layerSupport{new ClLayerSupport};
87 OptimizationViews ClBackend::OptimizeSubgraphView(const SubgraphView& subgraph) const
89 OptimizationViews optimizationViews;
91 optimizationViews.AddUntouchedSubgraph(SubgraphView(subgraph));
93 return optimizationViews;