2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
7 #include <backendsCommon/IMemoryManager.hpp>
8 #include <backendsCommon/WorkloadFactory.hpp>
10 #if defined(ARMCOMPUTENEON_ENABLED)
11 #include <arm_compute/runtime/MemoryGroup.h>
14 #if defined(ARMCOMPUTECL_ENABLED)
15 #include <arm_compute/runtime/CL/CLMemoryGroup.h>
18 #if defined(ARMCOMPUTENEON_ENABLED) || defined(ARMCOMPUTECL_ENABLED)
19 #include <arm_compute/runtime/IAllocator.h>
20 #include <arm_compute/runtime/IMemoryGroup.h>
21 #include <arm_compute/runtime/MemoryManagerOnDemand.h>
27 class BaseMemoryManager : public IMemoryManager
30 enum class MemoryAffinity
36 BaseMemoryManager() { }
37 virtual ~BaseMemoryManager() { }
39 void Acquire() override;
40 void Release() override;
42 #if defined(ARMCOMPUTENEON_ENABLED) || defined(ARMCOMPUTECL_ENABLED)
43 BaseMemoryManager(std::unique_ptr<arm_compute::IAllocator> alloc, MemoryAffinity memoryAffinity);
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; }
50 std::unique_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;
55 std::shared_ptr<arm_compute::MemoryManagerOnDemand> CreateArmComputeMemoryManager(MemoryAffinity memoryAffinity);
57 virtual std::shared_ptr<arm_compute::IMemoryGroup>
58 CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) = 0;
62 #if defined(ARMCOMPUTENEON_ENABLED)
63 class NeonMemoryManager : public BaseMemoryManager
66 NeonMemoryManager() {}
67 virtual ~NeonMemoryManager() {}
69 NeonMemoryManager(std::unique_ptr<arm_compute::IAllocator> alloc, MemoryAffinity memoryAffinity)
70 : BaseMemoryManager(std::move(alloc), memoryAffinity)
72 m_InterLayerMemoryGroup = CreateMemoryGroup(m_InterLayerMemoryMgr);
76 std::shared_ptr<arm_compute::IMemoryGroup>
77 CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) override;
81 #if defined(ARMCOMPUTECL_ENABLED)
82 class ClMemoryManager : public BaseMemoryManager
86 virtual ~ClMemoryManager() {}
88 ClMemoryManager(std::unique_ptr<arm_compute::IAllocator> alloc)
89 : BaseMemoryManager(std::move(alloc), MemoryAffinity::Buffer)
91 m_InterLayerMemoryGroup = CreateMemoryGroup(m_InterLayerMemoryMgr);
95 std::shared_ptr<arm_compute::IMemoryGroup>
96 CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) override;