arovir01 | 4424b0a | 2018-10-04 10:46:04 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "NeonBackend.hpp" |
David Beck | 3e9e115 | 2018-10-17 14:17:50 +0100 | [diff] [blame] | 7 | #include "NeonBackendId.hpp" |
arovir01 | a094479 | 2018-10-11 15:00:58 +0100 | [diff] [blame] | 8 | #include "NeonWorkloadFactory.hpp" |
David Beck | 111b5d9 | 2018-11-12 14:59:37 +0000 | [diff] [blame] | 9 | #include "NeonLayerSupport.hpp" |
Narumol Prangnawarat | 4e3e818 | 2019-08-14 12:25:50 +0100 | [diff] [blame] | 10 | #include "NeonTensorHandleFactory.hpp" |
arovir01 | a094479 | 2018-10-11 15:00:58 +0100 | [diff] [blame] | 11 | |
Aron Virginas-Tar | 5605519 | 2018-11-12 18:10:43 +0000 | [diff] [blame] | 12 | #include <aclCommon/BaseMemoryManager.hpp> |
| 13 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 14 | #include <backendsCommon/BackendRegistry.hpp> |
Aron Virginas-Tar | 5605519 | 2018-11-12 18:10:43 +0000 | [diff] [blame] | 15 | #include <backendsCommon/IBackendContext.hpp> |
| 16 | #include <backendsCommon/IMemoryManager.hpp> |
| 17 | |
David Beck | 263e349 | 2018-11-09 14:46:40 +0000 | [diff] [blame] | 18 | #include <Optimizer.hpp> |
arovir01 | a094479 | 2018-10-11 15:00:58 +0100 | [diff] [blame] | 19 | |
Aron Virginas-Tar | 5605519 | 2018-11-12 18:10:43 +0000 | [diff] [blame] | 20 | #include <arm_compute/runtime/Allocator.h> |
| 21 | |
David Beck | 9efb57d | 2018-11-05 13:40:33 +0000 | [diff] [blame] | 22 | #include <boost/cast.hpp> |
Aron Virginas-Tar | 5605519 | 2018-11-12 18:10:43 +0000 | [diff] [blame] | 23 | #include <boost/polymorphic_pointer_cast.hpp> |
David Beck | 9efb57d | 2018-11-05 13:40:33 +0000 | [diff] [blame] | 24 | |
arovir01 | 4424b0a | 2018-10-04 10:46:04 +0100 | [diff] [blame] | 25 | namespace armnn |
| 26 | { |
| 27 | |
David Beck | 3cc9a62 | 2018-10-12 10:38:31 +0100 | [diff] [blame] | 28 | const BackendId& NeonBackend::GetIdStatic() |
arovir01 | 4424b0a | 2018-10-04 10:46:04 +0100 | [diff] [blame] | 29 | { |
David Beck | 3e9e115 | 2018-10-17 14:17:50 +0100 | [diff] [blame] | 30 | static const BackendId s_Id{NeonBackendId()}; |
arovir01 | 4424b0a | 2018-10-04 10:46:04 +0100 | [diff] [blame] | 31 | return s_Id; |
| 32 | } |
| 33 | |
Aron Virginas-Tar | 5605519 | 2018-11-12 18:10:43 +0000 | [diff] [blame] | 34 | IBackendInternal::IMemoryManagerUniquePtr NeonBackend::CreateMemoryManager() const |
arovir01 | 4424b0a | 2018-10-04 10:46:04 +0100 | [diff] [blame] | 35 | { |
Aron Virginas-Tar | 5605519 | 2018-11-12 18:10:43 +0000 | [diff] [blame] | 36 | return std::make_unique<NeonMemoryManager>(std::make_unique<arm_compute::Allocator>(), |
Sadik Armagan | 13a9fa6 | 2019-04-26 16:04:34 +0100 | [diff] [blame] | 37 | BaseMemoryManager::MemoryAffinity::Offset); |
Aron Virginas-Tar | 5605519 | 2018-11-12 18:10:43 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | IBackendInternal::IWorkloadFactoryPtr NeonBackend::CreateWorkloadFactory( |
| 41 | const IBackendInternal::IMemoryManagerSharedPtr& memoryManager) const |
| 42 | { |
| 43 | return std::make_unique<NeonWorkloadFactory>( |
| 44 | boost::polymorphic_pointer_downcast<NeonMemoryManager>(memoryManager)); |
arovir01 | 4424b0a | 2018-10-04 10:46:04 +0100 | [diff] [blame] | 45 | } |
| 46 | |
Narumol Prangnawarat | 4e3e818 | 2019-08-14 12:25:50 +0100 | [diff] [blame] | 47 | IBackendInternal::IWorkloadFactoryPtr NeonBackend::CreateWorkloadFactory( |
| 48 | class TensorHandleFactoryRegistry& tensorHandleFactoryRegistry) const |
| 49 | { |
| 50 | auto memoryManager = std::make_shared<NeonMemoryManager>(std::make_unique<arm_compute::Allocator>(), |
| 51 | BaseMemoryManager::MemoryAffinity::Offset); |
| 52 | |
| 53 | tensorHandleFactoryRegistry.RegisterMemoryManager(memoryManager); |
| 54 | return std::make_unique<NeonWorkloadFactory>( |
| 55 | boost::polymorphic_pointer_downcast<NeonMemoryManager>(memoryManager)); |
| 56 | } |
| 57 | |
David Beck | 263e349 | 2018-11-09 14:46:40 +0000 | [diff] [blame] | 58 | IBackendInternal::IBackendContextPtr NeonBackend::CreateBackendContext(const IRuntime::CreationOptions&) const |
| 59 | { |
| 60 | return IBackendContextPtr{}; |
| 61 | } |
| 62 | |
| 63 | IBackendInternal::Optimizations NeonBackend::GetOptimizations() const |
| 64 | { |
| 65 | return Optimizations{}; |
| 66 | } |
| 67 | |
David Beck | 111b5d9 | 2018-11-12 14:59:37 +0000 | [diff] [blame] | 68 | IBackendInternal::ILayerSupportSharedPtr NeonBackend::GetLayerSupport() const |
| 69 | { |
| 70 | static ILayerSupportSharedPtr layerSupport{new NeonLayerSupport}; |
| 71 | return layerSupport; |
| 72 | } |
| 73 | |
Matteo Martincigh | c3ba50e | 2019-05-22 14:28:16 +0100 | [diff] [blame] | 74 | OptimizationViews NeonBackend::OptimizeSubgraphView(const SubgraphView& subgraph) const |
Matteo Martincigh | adddddb | 2019-01-24 14:06:23 +0000 | [diff] [blame] | 75 | { |
Matteo Martincigh | c3ba50e | 2019-05-22 14:28:16 +0100 | [diff] [blame] | 76 | OptimizationViews optimizationViews; |
Matteo Martincigh | adddddb | 2019-01-24 14:06:23 +0000 | [diff] [blame] | 77 | |
Matteo Martincigh | c3ba50e | 2019-05-22 14:28:16 +0100 | [diff] [blame] | 78 | optimizationViews.AddUntouchedSubgraph(SubgraphView(subgraph)); |
| 79 | |
| 80 | return optimizationViews; |
Matteo Martincigh | adddddb | 2019-01-24 14:06:23 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Narumol Prangnawarat | 4e3e818 | 2019-08-14 12:25:50 +0100 | [diff] [blame] | 83 | std::vector<ITensorHandleFactory::FactoryId> NeonBackend::GetHandleFactoryPreferences() const |
| 84 | { |
Jan Eilers | 146b2e1 | 2019-08-16 10:45:30 +0100 | [diff] [blame] | 85 | return std::vector<ITensorHandleFactory::FactoryId>() = {"Arm/Neon/TensorHandleFactory", |
| 86 | "Arm/Cl/TensorHandleFactory"}; |
Narumol Prangnawarat | 4e3e818 | 2019-08-14 12:25:50 +0100 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | void NeonBackend::RegisterTensorHandleFactories(class TensorHandleFactoryRegistry& registry) |
| 90 | { |
| 91 | auto memoryManager = std::make_shared<NeonMemoryManager>(std::make_unique<arm_compute::Allocator>(), |
| 92 | BaseMemoryManager::MemoryAffinity::Offset); |
| 93 | |
| 94 | registry.RegisterMemoryManager(memoryManager); |
Jan Eilers | e9f0f0f | 2019-08-16 10:28:37 +0100 | [diff] [blame] | 95 | registry.RegisterFactory(std::make_unique<NeonTensorHandleFactory>(memoryManager)); |
Narumol Prangnawarat | 4e3e818 | 2019-08-14 12:25:50 +0100 | [diff] [blame] | 96 | } |
| 97 | |
Matthew Bentham | 42bad95 | 2018-12-17 09:23:36 +0000 | [diff] [blame] | 98 | } // namespace armnn |