IVGCVSW-1946: Remove armnn/src from the include paths
[platform/upstream/armnn.git] / src / backends / aclCommon / memory / BaseMemoryManager.hpp
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6
7 #include <backendsCommon/WorkloadFactory.hpp>
8
9 #ifdef ARMCOMPUTENEON_ENABLED
10 #include <arm_compute/runtime/MemoryGroup.h>
11 #endif
12
13 #ifdef ARMCOMPUTECL_ENABLED
14 #include <arm_compute/runtime/CL/CLMemoryGroup.h>
15 #endif
16
17 #if defined(ARMCOMPUTENEON_ENABLED) || defined(ARMCOMPUTECL_ENABLED)
18 #include <arm_compute/runtime/IAllocator.h>
19 #include <arm_compute/runtime/IMemoryGroup.h>
20 #include <arm_compute/runtime/MemoryManagerOnDemand.h>
21 #endif
22
23 namespace armnn
24 {
25
26 class BaseMemoryManager
27 {
28 public:
29     enum class MemoryAffinity
30     {
31         Buffer,
32         Offset
33     };
34
35     BaseMemoryManager() { }
36     virtual ~BaseMemoryManager() { }
37
38 #if defined(ARMCOMPUTENEON_ENABLED) || defined(ARMCOMPUTECL_ENABLED)
39
40     BaseMemoryManager(std::unique_ptr<arm_compute::IAllocator> alloc, MemoryAffinity memoryAffinity);
41
42     std::shared_ptr<arm_compute::MemoryManagerOnDemand>& GetIntraLayerManager() { return m_IntraLayerMemoryMgr; }
43     std::shared_ptr<arm_compute::MemoryManagerOnDemand>& GetInterLayerManager() { return m_InterLayerMemoryMgr; }
44     std::shared_ptr<arm_compute::IMemoryGroup>& GetInterLayerMemoryGroup()      { return m_InterLayerMemoryGroup; }
45
46     void Finalize();
47     void Acquire();
48     void Release();
49
50 protected:
51
52     std::unique_ptr<arm_compute::IAllocator>            m_Allocator;
53     std::shared_ptr<arm_compute::MemoryManagerOnDemand> m_IntraLayerMemoryMgr;
54     std::shared_ptr<arm_compute::MemoryManagerOnDemand> m_InterLayerMemoryMgr;
55     std::shared_ptr<arm_compute::IMemoryGroup>          m_InterLayerMemoryGroup;
56
57     std::shared_ptr<arm_compute::MemoryManagerOnDemand> CreateArmComputeMemoryManager(MemoryAffinity memoryAffinity);
58
59     virtual std::shared_ptr<arm_compute::IMemoryGroup>
60     CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) = 0;
61
62     void FinalizeMemoryManager(arm_compute::MemoryManagerOnDemand& memoryManager);
63 #endif
64 };
65
66 class NeonMemoryManager : public BaseMemoryManager
67 {
68 public:
69     NeonMemoryManager() {}
70     virtual ~NeonMemoryManager() {}
71
72 #ifdef ARMCOMPUTENEON_ENABLED
73     NeonMemoryManager(std::unique_ptr<arm_compute::IAllocator> alloc, MemoryAffinity memoryAffinity)
74     : BaseMemoryManager(std::move(alloc), memoryAffinity)
75     {
76         m_InterLayerMemoryGroup = CreateMemoryGroup(m_InterLayerMemoryMgr);
77     }
78
79 protected:
80     virtual std::shared_ptr<arm_compute::IMemoryGroup>
81     CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) override;
82 #endif
83 };
84
85 class ClMemoryManager : public BaseMemoryManager
86 {
87 public:
88     ClMemoryManager() {}
89     virtual ~ClMemoryManager() {}
90
91 #ifdef ARMCOMPUTECL_ENABLED
92     ClMemoryManager(std::unique_ptr<arm_compute::IAllocator> alloc)
93     : BaseMemoryManager(std::move(alloc), MemoryAffinity::Buffer)
94     {
95         m_InterLayerMemoryGroup = CreateMemoryGroup(m_InterLayerMemoryMgr);
96     }
97
98 protected:
99     virtual std::shared_ptr<arm_compute::IMemoryGroup>
100     CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) override;
101 #endif
102 };
103
104 } //namespace armnn