ArmNN
 24.02
BaseMemoryManager.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017-2023 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
9 
10 #if defined(ARMCOMPUTENEON_ENABLED) || defined(ARMCOMPUTECL_ENABLED) || defined(ARMCOMPUTEGPUFSA_ENABLED)
11 #include <arm_compute/runtime/MemoryGroup.h>
12 #include <arm_compute/runtime/IAllocator.h>
13 #include <arm_compute/runtime/IMemoryGroup.h>
14 #include <arm_compute/runtime/MemoryManagerOnDemand.h>
15 #endif
16 
17 #if defined(ARMCOMPUTECL_ENABLED) || defined(ARMCOMPUTEGPUFSA_ENABLED)
18 #include <arm_compute/runtime/CL/CLTensorAllocator.h>
19 #endif
20 
21 namespace armnn
22 {
23 
25 {
26 public:
27  enum class MemoryAffinity
28  {
29  Buffer,
30  Offset
31  };
32 
34  virtual ~BaseMemoryManager() { }
35 
36  void Acquire() override;
37  void Release() override;
38 
39 #if defined(ARMCOMPUTENEON_ENABLED) || defined(ARMCOMPUTECL_ENABLED) || defined(ARMCOMPUTEGPUFSA_ENABLED)
40  BaseMemoryManager(std::shared_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 protected:
47  std::shared_ptr<arm_compute::IAllocator> m_Allocator;
48  std::shared_ptr<arm_compute::MemoryManagerOnDemand> m_IntraLayerMemoryMgr;
49  std::shared_ptr<arm_compute::MemoryManagerOnDemand> m_InterLayerMemoryMgr;
50  std::shared_ptr<arm_compute::IMemoryGroup> m_InterLayerMemoryGroup;
51 
52  std::shared_ptr<arm_compute::MemoryManagerOnDemand> CreateArmComputeMemoryManager(MemoryAffinity memoryAffinity);
53 
54  virtual std::shared_ptr<arm_compute::IMemoryGroup>
55  CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) = 0;
56 #endif
57 };
58 
59 #if defined(ARMCOMPUTENEON_ENABLED)
61 {
62 public:
64  virtual ~NeonMemoryManager() {}
65 
66  NeonMemoryManager(std::unique_ptr<arm_compute::IAllocator> alloc, MemoryAffinity memoryAffinity)
67  : BaseMemoryManager(std::move(alloc), memoryAffinity)
68  {
70  }
71 
72 protected:
73  std::shared_ptr<arm_compute::IMemoryGroup>
74  CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) override;
75 };
76 #endif
77 
78 #if defined(ARMCOMPUTECL_ENABLED)
80 {
81 public:
83  virtual ~ClMemoryManager() {}
84 
85  ClMemoryManager(std::shared_ptr<arm_compute::IAllocator> alloc)
86  : BaseMemoryManager(std::move(alloc), MemoryAffinity::Buffer)
87  {
88  arm_compute::CLTensorAllocator::set_global_allocator(alloc.get());
90  }
91 
92 protected:
93  std::shared_ptr<arm_compute::IMemoryGroup>
94  CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) override;
95 };
96 #endif
97 
98 #if defined(ARMCOMPUTEGPUFSA_ENABLED)
99 class GpuFsaMemoryManager : public BaseMemoryManager
100 {
101 public:
103  virtual ~GpuFsaMemoryManager() {}
104 
105  GpuFsaMemoryManager(std::shared_ptr<arm_compute::IAllocator> alloc)
106  : BaseMemoryManager(std::move(alloc), MemoryAffinity::Buffer)
107  {
108  arm_compute::CLTensorAllocator::set_global_allocator(alloc.get());
109  m_InterLayerMemoryGroup = CreateMemoryGroup(m_InterLayerMemoryMgr);
110  }
111 
112 protected:
113  std::shared_ptr<arm_compute::IMemoryGroup>
114  CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) override;
115 };
116 #endif
117 
118 } //namespace armnn
armnn::BaseMemoryManager::MemoryAffinity::Offset
@ Offset
armnn::NeonMemoryManager::~NeonMemoryManager
virtual ~NeonMemoryManager()
Definition: BaseMemoryManager.hpp:64
armnn::BaseMemoryManager::GetInterLayerManager
std::shared_ptr< arm_compute::MemoryManagerOnDemand > & GetInterLayerManager()
Definition: BaseMemoryManager.hpp:43
armnn::GpuFsaMemoryManager::~GpuFsaMemoryManager
virtual ~GpuFsaMemoryManager()
Definition: GpuFsaMemoryManager.cpp:16
armnn::BaseMemoryManager::m_InterLayerMemoryGroup
std::shared_ptr< arm_compute::IMemoryGroup > m_InterLayerMemoryGroup
Definition: BaseMemoryManager.hpp:50
armnn::BaseMemoryManager::CreateMemoryGroup
virtual std::shared_ptr< arm_compute::IMemoryGroup > CreateMemoryGroup(const std::shared_ptr< arm_compute::MemoryManagerOnDemand > &memoryManager)=0
armnn::BaseMemoryManager::m_Allocator
std::shared_ptr< arm_compute::IAllocator > m_Allocator
Definition: BaseMemoryManager.hpp:47
armnn::BaseMemoryManager::CreateArmComputeMemoryManager
std::shared_ptr< arm_compute::MemoryManagerOnDemand > CreateArmComputeMemoryManager(MemoryAffinity memoryAffinity)
Definition: BaseMemoryManager.cpp:29
armnn::NeonMemoryManager::NeonMemoryManager
NeonMemoryManager(std::unique_ptr< arm_compute::IAllocator > alloc, MemoryAffinity memoryAffinity)
Definition: BaseMemoryManager.hpp:66
armnn::BaseMemoryManager::MemoryAffinity
MemoryAffinity
Definition: BaseMemoryManager.hpp:27
WorkloadFactory.hpp
armnn::BaseMemoryManager::m_InterLayerMemoryMgr
std::shared_ptr< arm_compute::MemoryManagerOnDemand > m_InterLayerMemoryMgr
Definition: BaseMemoryManager.hpp:49
armnn::NeonMemoryManager
Definition: BaseMemoryManager.hpp:60
armnn::IMemoryManager
Definition: IMemoryManager.hpp:12
armnn::BaseMemoryManager::MemoryAffinity::Buffer
@ Buffer
armnn::NeonMemoryManager::CreateMemoryGroup
std::shared_ptr< arm_compute::IMemoryGroup > CreateMemoryGroup(const std::shared_ptr< arm_compute::MemoryManagerOnDemand > &memoryManager) override
Definition: BaseMemoryManager.cpp:93
armnn::ClMemoryManager
Definition: BaseMemoryManager.hpp:79
armnn::GpuFsaMemoryManager::GpuFsaMemoryManager
GpuFsaMemoryManager()
Definition: GpuFsaMemoryManager.cpp:13
armnn::NeonMemoryManager::NeonMemoryManager
NeonMemoryManager()
Definition: BaseMemoryManager.hpp:63
armnn::ClMemoryManager::~ClMemoryManager
virtual ~ClMemoryManager()
Definition: BaseMemoryManager.hpp:83
armnn::ClMemoryManager::CreateMemoryGroup
std::shared_ptr< arm_compute::IMemoryGroup > CreateMemoryGroup(const std::shared_ptr< arm_compute::MemoryManagerOnDemand > &memoryManager) override
Definition: BaseMemoryManager.cpp:101
armnn::BaseMemoryManager::~BaseMemoryManager
virtual ~BaseMemoryManager()
Definition: BaseMemoryManager.hpp:34
armnn::BaseMemoryManager
Definition: BaseMemoryManager.hpp:24
std
Definition: BackendId.hpp:149
armnn::BaseMemoryManager::Release
void Release() override
Definition: BaseMemoryManager.cpp:65
armnn::BaseMemoryManager::m_IntraLayerMemoryMgr
std::shared_ptr< arm_compute::MemoryManagerOnDemand > m_IntraLayerMemoryMgr
Definition: BaseMemoryManager.hpp:48
armnn::BaseMemoryManager::GetIntraLayerManager
std::shared_ptr< arm_compute::MemoryManagerOnDemand > & GetIntraLayerManager()
Definition: BaseMemoryManager.hpp:42
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::ClMemoryManager::ClMemoryManager
ClMemoryManager()
Definition: BaseMemoryManager.hpp:82
armnn::BaseMemoryManager::Acquire
void Acquire() override
Definition: BaseMemoryManager.cpp:48
armnn::BaseMemoryManager::BaseMemoryManager
BaseMemoryManager()
Definition: BaseMemoryManager.hpp:33
IMemoryManager.hpp
armnn::BaseMemoryManager::GetInterLayerMemoryGroup
std::shared_ptr< arm_compute::IMemoryGroup > & GetInterLayerMemoryGroup()
Definition: BaseMemoryManager.hpp:44
armnn::ClMemoryManager::ClMemoryManager
ClMemoryManager(std::shared_ptr< arm_compute::IAllocator > alloc)
Definition: BaseMemoryManager.hpp:85