blob: 4fe1a917a639ee5565a450ced0bb282d2e3e94e2 [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 Monahan2ef4a2b2023-12-11 10:35:30 +000011#include <arm_compute/runtime/MemoryGroup.h>
David Beckac42efd2018-09-26 17:41:13 +010012#include <arm_compute/runtime/IAllocator.h>
13#include <arm_compute/runtime/IMemoryGroup.h>
14#include <arm_compute/runtime/MemoryManagerOnDemand.h>
David Monahan75b981d2021-08-11 10:22:35 +010015#endif
16
David Monahan8a570462023-11-22 13:24:25 +000017#if defined(ARMCOMPUTECL_ENABLED) || defined(ARMCOMPUTEGPUFSA_ENABLED)
Jan Eilersc1c872f2021-07-22 13:17:04 +010018#include <arm_compute/runtime/CL/CLTensorAllocator.h>
telsoa01c577f2c2018-08-31 09:22:23 +010019#endif
20
21namespace armnn
22{
23
Aron Virginas-Tar56055192018-11-12 18:10:43 +000024class BaseMemoryManager : public IMemoryManager
telsoa01c577f2c2018-08-31 09:22:23 +010025{
26public:
27 enum class MemoryAffinity
28 {
29 Buffer,
30 Offset
31 };
32
33 BaseMemoryManager() { }
34 virtual ~BaseMemoryManager() { }
35
Aron Virginas-Tar56055192018-11-12 18:10:43 +000036 void Acquire() override;
37 void Release() override;
38
David Monahan8a570462023-11-22 13:24:25 +000039#if defined(ARMCOMPUTENEON_ENABLED) || defined(ARMCOMPUTECL_ENABLED) || defined(ARMCOMPUTEGPUFSA_ENABLED)
Jan Eilersc1c872f2021-07-22 13:17:04 +010040 BaseMemoryManager(std::shared_ptr<arm_compute::IAllocator> alloc, MemoryAffinity memoryAffinity);
telsoa01c577f2c2018-08-31 09:22:23 +010041
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
telsoa01c577f2c2018-08-31 09:22:23 +010046protected:
Jan Eilersc1c872f2021-07-22 13:17:04 +010047 std::shared_ptr<arm_compute::IAllocator> m_Allocator;
telsoa01c577f2c2018-08-31 09:22:23 +010048 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;
telsoa01c577f2c2018-08-31 09:22:23 +010056#endif
57};
58
Matteo Martincighd95e9062019-01-31 15:35:59 +000059#if defined(ARMCOMPUTENEON_ENABLED)
telsoa01c577f2c2018-08-31 09:22:23 +010060class NeonMemoryManager : public BaseMemoryManager
61{
62public:
63 NeonMemoryManager() {}
64 virtual ~NeonMemoryManager() {}
65
telsoa01c577f2c2018-08-31 09:22:23 +010066 NeonMemoryManager(std::unique_ptr<arm_compute::IAllocator> alloc, MemoryAffinity memoryAffinity)
67 : BaseMemoryManager(std::move(alloc), memoryAffinity)
68 {
69 m_InterLayerMemoryGroup = CreateMemoryGroup(m_InterLayerMemoryMgr);
70 }
71
72protected:
Matteo Martincighd95e9062019-01-31 15:35:59 +000073 std::shared_ptr<arm_compute::IMemoryGroup>
telsoa01c577f2c2018-08-31 09:22:23 +010074 CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) override;
telsoa01c577f2c2018-08-31 09:22:23 +010075};
Matteo Martincighd95e9062019-01-31 15:35:59 +000076#endif
telsoa01c577f2c2018-08-31 09:22:23 +010077
Matteo Martincighd95e9062019-01-31 15:35:59 +000078#if defined(ARMCOMPUTECL_ENABLED)
telsoa01c577f2c2018-08-31 09:22:23 +010079class ClMemoryManager : public BaseMemoryManager
80{
81public:
82 ClMemoryManager() {}
83 virtual ~ClMemoryManager() {}
84
Jan Eilersc1c872f2021-07-22 13:17:04 +010085 ClMemoryManager(std::shared_ptr<arm_compute::IAllocator> alloc)
telsoa01c577f2c2018-08-31 09:22:23 +010086 : BaseMemoryManager(std::move(alloc), MemoryAffinity::Buffer)
87 {
Jan Eilersc1c872f2021-07-22 13:17:04 +010088 arm_compute::CLTensorAllocator::set_global_allocator(alloc.get());
telsoa01c577f2c2018-08-31 09:22:23 +010089 m_InterLayerMemoryGroup = CreateMemoryGroup(m_InterLayerMemoryMgr);
90 }
91
92protected:
Matteo Martincighd95e9062019-01-31 15:35:59 +000093 std::shared_ptr<arm_compute::IMemoryGroup>
telsoa01c577f2c2018-08-31 09:22:23 +010094 CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) override;
telsoa01c577f2c2018-08-31 09:22:23 +010095};
Matteo Martincighd95e9062019-01-31 15:35:59 +000096#endif
telsoa01c577f2c2018-08-31 09:22:23 +010097
David Monahan8a570462023-11-22 13:24:25 +000098#if defined(ARMCOMPUTEGPUFSA_ENABLED)
99class GpuFsaMemoryManager : public BaseMemoryManager
100{
101public:
102 GpuFsaMemoryManager() {}
103 virtual ~GpuFsaMemoryManager() {}
104
105 GpuFsaMemoryManager(std::shared_ptr<arm_compute::IAllocator> alloc)
106 : BaseMemoryManager(std::move(alloc), MemoryAffinity::Buffer)
107 {
108 arm_compute::CLTensorAllocator::set_global_allocator(alloc.get());
109 m_InterLayerMemoryGroup = CreateMemoryGroup(m_InterLayerMemoryMgr);
110 }
111
112protected:
113 std::shared_ptr<arm_compute::IMemoryGroup>
114 CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) override;
115};
116#endif
117
Aron Virginas-Tarf9aeef02018-10-12 15:18:03 +0100118} //namespace armnn