ArmNN
 22.11
BaseMemoryManager.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 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 #endif
13 
14 #if defined(ARMCOMPUTENEON_ENABLED) || defined(ARMCOMPUTECL_ENABLED)
15 #include <arm_compute/runtime/IAllocator.h>
16 #include <arm_compute/runtime/IMemoryGroup.h>
17 #include <arm_compute/runtime/MemoryManagerOnDemand.h>
18 #endif
19 
20 #if defined(ARMCOMPUTECL_ENABLED)
21 #include <arm_compute/runtime/CL/CLTensorAllocator.h>
22 #endif
23 
24 namespace armnn
25 {
26 
28 {
29 public:
30  enum class MemoryAffinity
31  {
32  Buffer,
33  Offset
34  };
35 
37  virtual ~BaseMemoryManager() { }
38 
39  void Acquire() override;
40  void Release() override;
41 
42 #if defined(ARMCOMPUTENEON_ENABLED) || defined(ARMCOMPUTECL_ENABLED)
43  BaseMemoryManager(std::shared_ptr<arm_compute::IAllocator> alloc, MemoryAffinity memoryAffinity);
44 
45  std::shared_ptr<arm_compute::MemoryManagerOnDemand>& GetIntraLayerManager() { return m_IntraLayerMemoryMgr; }
46  std::shared_ptr<arm_compute::MemoryManagerOnDemand>& GetInterLayerManager() { return m_InterLayerMemoryMgr; }
47  std::shared_ptr<arm_compute::IMemoryGroup>& GetInterLayerMemoryGroup() { return m_InterLayerMemoryGroup; }
48 
49 protected:
50  std::shared_ptr<arm_compute::IAllocator> m_Allocator;
51  std::shared_ptr<arm_compute::MemoryManagerOnDemand> m_IntraLayerMemoryMgr;
52  std::shared_ptr<arm_compute::MemoryManagerOnDemand> m_InterLayerMemoryMgr;
53  std::shared_ptr<arm_compute::IMemoryGroup> m_InterLayerMemoryGroup;
54 
55  std::shared_ptr<arm_compute::MemoryManagerOnDemand> CreateArmComputeMemoryManager(MemoryAffinity memoryAffinity);
56 
57  virtual std::shared_ptr<arm_compute::IMemoryGroup>
58  CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) = 0;
59 #endif
60 };
61 
62 #if defined(ARMCOMPUTENEON_ENABLED)
64 {
65 public:
67  virtual ~NeonMemoryManager() {}
68 
69  NeonMemoryManager(std::unique_ptr<arm_compute::IAllocator> alloc, MemoryAffinity memoryAffinity)
70  : BaseMemoryManager(std::move(alloc), memoryAffinity)
71  {
73  }
74 
75 protected:
76  std::shared_ptr<arm_compute::IMemoryGroup>
77  CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) override;
78 };
79 #endif
80 
81 #if defined(ARMCOMPUTECL_ENABLED)
83 {
84 public:
86  virtual ~ClMemoryManager() {}
87 
88  ClMemoryManager(std::shared_ptr<arm_compute::IAllocator> alloc)
89  : BaseMemoryManager(std::move(alloc), MemoryAffinity::Buffer)
90  {
91  arm_compute::CLTensorAllocator::set_global_allocator(alloc.get());
93  }
94 
95 protected:
96  std::shared_ptr<arm_compute::IMemoryGroup>
97  CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) override;
98 };
99 #endif
100 
101 } //namespace armnn
std::shared_ptr< arm_compute::MemoryManagerOnDemand > CreateArmComputeMemoryManager(MemoryAffinity memoryAffinity)
ClMemoryManager(std::shared_ptr< arm_compute::IAllocator > alloc)
std::shared_ptr< arm_compute::MemoryManagerOnDemand > m_InterLayerMemoryMgr
std::shared_ptr< arm_compute::MemoryManagerOnDemand > m_IntraLayerMemoryMgr
Copyright (c) 2021 ARM Limited and Contributors.
std::shared_ptr< arm_compute::MemoryManagerOnDemand > & GetInterLayerManager()
NeonMemoryManager(std::unique_ptr< arm_compute::IAllocator > alloc, MemoryAffinity memoryAffinity)
std::shared_ptr< arm_compute::IMemoryGroup > m_InterLayerMemoryGroup
std::shared_ptr< arm_compute::MemoryManagerOnDemand > & GetIntraLayerManager()
std::shared_ptr< arm_compute::IAllocator > m_Allocator
std::shared_ptr< arm_compute::IMemoryGroup > & GetInterLayerMemoryGroup()
virtual std::shared_ptr< arm_compute::IMemoryGroup > CreateMemoryGroup(const std::shared_ptr< arm_compute::MemoryManagerOnDemand > &memoryManager)=0