24.08
GpuFsaMemoryManager.cpp
Go to the documentation of this file.
1
//
2
// Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved.
3
// SPDX-License-Identifier: MIT
4
//
5
#include "
GpuFsaMemoryManager.hpp
"
6
#include "
Exceptions.hpp
"
7
8
#include <algorithm>
9
10
namespace
armnn
11
{
12
13
GpuFsaMemoryManager::GpuFsaMemoryManager
()
14
{}
15
16
GpuFsaMemoryManager::~GpuFsaMemoryManager
()
17
{}
18
19
GpuFsaMemoryManager::Pool
*
GpuFsaMemoryManager::Manage
(
unsigned
int
numBytes)
20
{
21
if
(!m_FreePools.empty())
22
{
23
Pool
* res = m_FreePools.back();
24
m_FreePools.pop_back();
25
res->
Reserve
(numBytes);
26
return
res;
27
}
28
else
29
{
30
m_Pools.push_front(
Pool
(numBytes));
31
return
&m_Pools.front();
32
}
33
}
34
35
void
GpuFsaMemoryManager::Allocate
(
GpuFsaMemoryManager::Pool
* pool)
36
{
37
if
(pool ==
nullptr
)
38
{
39
throw
armnn::MemoryValidationException
(
40
"GpuFsaMemoryManager: Allocate: Attempting to allocate a null memory pool ptr"
);
41
}
42
m_FreePools.push_back(pool);
43
}
44
45
void
*
GpuFsaMemoryManager::GetPointer
(
GpuFsaMemoryManager::Pool
* pool)
46
{
47
return
pool->
GetPointer
();
48
}
49
50
void
GpuFsaMemoryManager::Acquire
()
51
{
52
for
(
Pool
&pool: m_Pools)
53
{
54
pool.Acquire();
55
}
56
}
57
58
void
GpuFsaMemoryManager::Release
()
59
{
60
for
(
Pool
&pool: m_Pools)
61
{
62
pool.Release();
63
}
64
}
65
66
GpuFsaMemoryManager::Pool::Pool
(
unsigned
int
numBytes)
67
: m_Size(numBytes),
68
m_Pointer(nullptr)
69
{}
70
71
GpuFsaMemoryManager::Pool::~Pool
()
72
{
73
if
(m_Pointer)
74
{
75
Release
();
76
}
77
}
78
79
void
*
GpuFsaMemoryManager::Pool::GetPointer
()
80
{
81
if
(m_Pointer ==
nullptr
)
82
{
83
throw
armnn::MemoryValidationException
(
84
"GpuFsaMemoryManager::Pool::GetPointer() called when memory not acquired"
);
85
}
86
return
m_Pointer;
87
}
88
89
void
GpuFsaMemoryManager::Pool::Reserve
(
unsigned
int
numBytes)
90
{
91
if
(m_Pointer !=
nullptr
)
92
{
93
throw
armnn::MemoryValidationException
(
94
"GpuFsaMemoryManager::Pool::Reserve() cannot be called after memory acquired"
);
95
}
96
m_Size = std::max(m_Size, numBytes);
97
}
98
99
void
GpuFsaMemoryManager::Pool::Acquire
()
100
{
101
if
(m_Pointer !=
nullptr
)
102
{
103
throw
armnn::MemoryValidationException
(
104
"GpuFsaMemoryManager::Pool::Acquire() called when memory already acquired"
);
105
}
106
m_Pointer = ::operator
new
(size_t(m_Size));
107
}
108
109
void
GpuFsaMemoryManager::Pool::Release
()
110
{
111
if
(m_Pointer ==
nullptr
)
112
{
113
throw
armnn::MemoryValidationException
(
114
"GpuFsaMemoryManager::Pool::Release() called when memory not acquired"
);
115
}
116
::operator
delete
(m_Pointer);
117
m_Pointer =
nullptr
;
118
}
119
120
}
GpuFsaMemoryManager.hpp
armnn::GpuFsaMemoryManager::Acquire
void Acquire() override
Definition:
GpuFsaMemoryManager.cpp:50
armnn::GpuFsaMemoryManager::Manage
Pool * Manage(unsigned int numBytes)
Definition:
GpuFsaMemoryManager.cpp:19
armnn::GpuFsaMemoryManager::~GpuFsaMemoryManager
virtual ~GpuFsaMemoryManager()
Definition:
GpuFsaMemoryManager.cpp:16
armnn::GpuFsaMemoryManager::Pool::Release
void Release()
Definition:
GpuFsaMemoryManager.cpp:109
armnn::GpuFsaMemoryManager::Pool
Definition:
GpuFsaMemoryManager.hpp:33
armnn::GpuFsaMemoryManager::GetPointer
void * GetPointer(Pool *pool)
Definition:
GpuFsaMemoryManager.cpp:45
armnn::MemoryValidationException
Definition:
Exceptions.hpp:158
armnn::GpuFsaMemoryManager::GpuFsaMemoryManager
GpuFsaMemoryManager()
Definition:
GpuFsaMemoryManager.cpp:13
armnn::GpuFsaMemoryManager::Pool::~Pool
~Pool()
Definition:
GpuFsaMemoryManager.cpp:71
armnn::GpuFsaMemoryManager::Allocate
void Allocate(Pool *pool)
Definition:
GpuFsaMemoryManager.cpp:35
armnn::GpuFsaMemoryManager::Pool::Reserve
void Reserve(unsigned int numBytes)
Definition:
GpuFsaMemoryManager.cpp:89
Exceptions.hpp
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition:
01_00_quick_start.dox:6
armnn::GpuFsaMemoryManager::Pool::Pool
Pool(unsigned int numBytes)
Definition:
GpuFsaMemoryManager.cpp:66
armnn::GpuFsaMemoryManager::Pool::GetPointer
void * GetPointer()
Definition:
GpuFsaMemoryManager.cpp:79
armnn::GpuFsaMemoryManager::Release
void Release() override
Definition:
GpuFsaMemoryManager.cpp:58
armnn::GpuFsaMemoryManager::Pool::Acquire
void Acquire()
Definition:
GpuFsaMemoryManager.cpp:99
src
backends
gpuFsa
GpuFsaMemoryManager.cpp
Generated on Wed Aug 28 2024 14:31:50 for Arm NN by
1.8.17