blob: 04e0d640ab7d6508d57d61eea4b6fe6e8fcf0f5e [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
David Monahan8a570462023-11-22 13:24:25 +00002// Copyright © 2017-2023 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa01c577f2c2018-08-31 09:22:23 +01004//
5#pragma once
6
Matteo Martincighe5b8eb92019-11-28 15:45:42 +00007#include <armnn/backends/IMemoryManager.hpp>
Colm Donelan0c479742021-12-10 12:43:54 +00008#include <armnn/backends/WorkloadFactory.hpp>
telsoa01c577f2c2018-08-31 09:22:23 +01009
David Monahan8a570462023-11-22 13:24:25 +000010#if defined(ARMCOMPUTENEON_ENABLED) || defined(ARMCOMPUTECL_ENABLED) || defined(ARMCOMPUTEGPUFSA_ENABLED)
David Beckac42efd2018-09-26 17:41:13 +010011#include <arm_compute/runtime/IAllocator.h>
12#include <arm_compute/runtime/IMemoryGroup.h>
13#include <arm_compute/runtime/MemoryManagerOnDemand.h>
David Monahan75b981d2021-08-11 10:22:35 +010014#endif
15
David Monahan8a570462023-11-22 13:24:25 +000016#if defined(ARMCOMPUTECL_ENABLED) || defined(ARMCOMPUTEGPUFSA_ENABLED)
Jan Eilersc1c872f2021-07-22 13:17:04 +010017#include <arm_compute/runtime/CL/CLTensorAllocator.h>
telsoa01c577f2c2018-08-31 09:22:23 +010018#endif
19
20namespace armnn
21{
22
Aron Virginas-Tar56055192018-11-12 18:10:43 +000023class BaseMemoryManager : public IMemoryManager
telsoa01c577f2c2018-08-31 09:22:23 +010024{
25public:
26 enum class MemoryAffinity
27 {
28 Buffer,
29 Offset
30 };
31
32 BaseMemoryManager() { }
33 virtual ~BaseMemoryManager() { }
34
Aron Virginas-Tar56055192018-11-12 18:10:43 +000035 void Acquire() override;
36 void Release() override;
37
David Monahan8a570462023-11-22 13:24:25 +000038#if defined(ARMCOMPUTENEON_ENABLED) || defined(ARMCOMPUTECL_ENABLED) || defined(ARMCOMPUTEGPUFSA_ENABLED)
Jan Eilersc1c872f2021-07-22 13:17:04 +010039 BaseMemoryManager(std::shared_ptr<arm_compute::IAllocator> alloc, MemoryAffinity memoryAffinity);
telsoa01c577f2c2018-08-31 09:22:23 +010040
41 std::shared_ptr<arm_compute::MemoryManagerOnDemand>& GetIntraLayerManager() { return m_IntraLayerMemoryMgr; }
42 std::shared_ptr<arm_compute::MemoryManagerOnDemand>& GetInterLayerManager() { return m_InterLayerMemoryMgr; }
43 std::shared_ptr<arm_compute::IMemoryGroup>& GetInterLayerMemoryGroup() { return m_InterLayerMemoryGroup; }
44
telsoa01c577f2c2018-08-31 09:22:23 +010045protected:
Jan Eilersc1c872f2021-07-22 13:17:04 +010046 std::shared_ptr<arm_compute::IAllocator> m_Allocator;
telsoa01c577f2c2018-08-31 09:22:23 +010047 std::shared_ptr<arm_compute::MemoryManagerOnDemand> m_IntraLayerMemoryMgr;
48 std::shared_ptr<arm_compute::MemoryManagerOnDemand> m_InterLayerMemoryMgr;
49 std::shared_ptr<arm_compute::IMemoryGroup> m_InterLayerMemoryGroup;
50
51 std::shared_ptr<arm_compute::MemoryManagerOnDemand> CreateArmComputeMemoryManager(MemoryAffinity memoryAffinity);
52
53 virtual std::shared_ptr<arm_compute::IMemoryGroup>
54 CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) = 0;
telsoa01c577f2c2018-08-31 09:22:23 +010055#endif
56};
57
Matteo Martincighd95e9062019-01-31 15:35:59 +000058#if defined(ARMCOMPUTENEON_ENABLED)
telsoa01c577f2c2018-08-31 09:22:23 +010059class NeonMemoryManager : public BaseMemoryManager
60{
61public:
62 NeonMemoryManager() {}
63 virtual ~NeonMemoryManager() {}
64
telsoa01c577f2c2018-08-31 09:22:23 +010065 NeonMemoryManager(std::unique_ptr<arm_compute::IAllocator> alloc, MemoryAffinity memoryAffinity)
66 : BaseMemoryManager(std::move(alloc), memoryAffinity)
67 {
68 m_InterLayerMemoryGroup = CreateMemoryGroup(m_InterLayerMemoryMgr);
69 }
70
71protected:
Matteo Martincighd95e9062019-01-31 15:35:59 +000072 std::shared_ptr<arm_compute::IMemoryGroup>
telsoa01c577f2c2018-08-31 09:22:23 +010073 CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) override;
telsoa01c577f2c2018-08-31 09:22:23 +010074};
Matteo Martincighd95e9062019-01-31 15:35:59 +000075#endif
telsoa01c577f2c2018-08-31 09:22:23 +010076
Matteo Martincighd95e9062019-01-31 15:35:59 +000077#if defined(ARMCOMPUTECL_ENABLED)
telsoa01c577f2c2018-08-31 09:22:23 +010078class ClMemoryManager : public BaseMemoryManager
79{
80public:
81 ClMemoryManager() {}
82 virtual ~ClMemoryManager() {}
83
Jan Eilersc1c872f2021-07-22 13:17:04 +010084 ClMemoryManager(std::shared_ptr<arm_compute::IAllocator> alloc)
telsoa01c577f2c2018-08-31 09:22:23 +010085 : BaseMemoryManager(std::move(alloc), MemoryAffinity::Buffer)
86 {
Jan Eilersc1c872f2021-07-22 13:17:04 +010087 arm_compute::CLTensorAllocator::set_global_allocator(alloc.get());
telsoa01c577f2c2018-08-31 09:22:23 +010088 m_InterLayerMemoryGroup = CreateMemoryGroup(m_InterLayerMemoryMgr);
89 }
90
91protected:
Matteo Martincighd95e9062019-01-31 15:35:59 +000092 std::shared_ptr<arm_compute::IMemoryGroup>
telsoa01c577f2c2018-08-31 09:22:23 +010093 CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) override;
telsoa01c577f2c2018-08-31 09:22:23 +010094};
Matteo Martincighd95e9062019-01-31 15:35:59 +000095#endif
telsoa01c577f2c2018-08-31 09:22:23 +010096
David Monahan8a570462023-11-22 13:24:25 +000097#if defined(ARMCOMPUTEGPUFSA_ENABLED)
98class GpuFsaMemoryManager : public BaseMemoryManager
99{
100public:
101 GpuFsaMemoryManager() {}
102 virtual ~GpuFsaMemoryManager() {}
103
104 GpuFsaMemoryManager(std::shared_ptr<arm_compute::IAllocator> alloc)
105 : BaseMemoryManager(std::move(alloc), MemoryAffinity::Buffer)
106 {
107 arm_compute::CLTensorAllocator::set_global_allocator(alloc.get());
108 m_InterLayerMemoryGroup = CreateMemoryGroup(m_InterLayerMemoryMgr);
109 }
110
111protected:
112 std::shared_ptr<arm_compute::IMemoryGroup>
113 CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) override;
114};
115#endif
116
Aron Virginas-Tarf9aeef02018-10-12 15:18:03 +0100117} //namespace armnn