2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
7 #include <backendsCommon/WorkloadFactory.hpp>
9 #ifdef ARMCOMPUTENEON_ENABLED
10 #include <arm_compute/runtime/MemoryGroup.h>
13 #ifdef ARMCOMPUTECL_ENABLED
14 #include <arm_compute/runtime/CL/CLMemoryGroup.h>
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>
26 class BaseMemoryManager
29 enum class MemoryAffinity
35 BaseMemoryManager() { }
36 virtual ~BaseMemoryManager() { }
38 #if defined(ARMCOMPUTENEON_ENABLED) || defined(ARMCOMPUTECL_ENABLED)
40 BaseMemoryManager(std::unique_ptr<arm_compute::IAllocator> alloc, MemoryAffinity memoryAffinity);
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; }
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;
57 std::shared_ptr<arm_compute::MemoryManagerOnDemand> CreateArmComputeMemoryManager(MemoryAffinity memoryAffinity);
59 virtual std::shared_ptr<arm_compute::IMemoryGroup>
60 CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) = 0;
62 void FinalizeMemoryManager(arm_compute::MemoryManagerOnDemand& memoryManager);
66 class NeonMemoryManager : public BaseMemoryManager
69 NeonMemoryManager() {}
70 virtual ~NeonMemoryManager() {}
72 #ifdef ARMCOMPUTENEON_ENABLED
73 NeonMemoryManager(std::unique_ptr<arm_compute::IAllocator> alloc, MemoryAffinity memoryAffinity)
74 : BaseMemoryManager(std::move(alloc), memoryAffinity)
76 m_InterLayerMemoryGroup = CreateMemoryGroup(m_InterLayerMemoryMgr);
80 virtual std::shared_ptr<arm_compute::IMemoryGroup>
81 CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) override;
85 class ClMemoryManager : public BaseMemoryManager
89 virtual ~ClMemoryManager() {}
91 #ifdef ARMCOMPUTECL_ENABLED
92 ClMemoryManager(std::unique_ptr<arm_compute::IAllocator> alloc)
93 : BaseMemoryManager(std::move(alloc), MemoryAffinity::Buffer)
95 m_InterLayerMemoryGroup = CreateMemoryGroup(m_InterLayerMemoryMgr);
99 virtual std::shared_ptr<arm_compute::IMemoryGroup>
100 CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) override;