ArmNN
 25.02
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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)
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)
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)
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 
99 } //namespace armnn
std::shared_ptr< arm_compute::MemoryManagerOnDemand > m_InterLayerMemoryMgr
std::shared_ptr< arm_compute::IMemoryGroup > m_InterLayerMemoryGroup
std::shared_ptr< arm_compute::MemoryManagerOnDemand > & GetInterLayerManager()
std::shared_ptr< arm_compute::IMemoryGroup > & GetInterLayerMemoryGroup()
std::shared_ptr< arm_compute::MemoryManagerOnDemand > & GetIntraLayerManager()
virtual std::shared_ptr< arm_compute::IMemoryGroup > CreateMemoryGroup(const std::shared_ptr< arm_compute::MemoryManagerOnDemand > &memoryManager)=0
std::shared_ptr< arm_compute::MemoryManagerOnDemand > CreateArmComputeMemoryManager(MemoryAffinity memoryAffinity)
std::shared_ptr< arm_compute::IAllocator > m_Allocator
std::shared_ptr< arm_compute::MemoryManagerOnDemand > m_IntraLayerMemoryMgr
ClMemoryManager(std::shared_ptr< arm_compute::IAllocator > alloc)
std::shared_ptr< arm_compute::IMemoryGroup > CreateMemoryGroup(const std::shared_ptr< arm_compute::MemoryManagerOnDemand > &memoryManager) override
std::shared_ptr< arm_compute::IMemoryGroup > CreateMemoryGroup(const std::shared_ptr< arm_compute::MemoryManagerOnDemand > &memoryManager) override
NeonMemoryManager(std::unique_ptr< arm_compute::IAllocator > alloc, MemoryAffinity memoryAffinity)
Copyright (c) 2021 ARM Limited and Contributors.