24.08
TosaRefMemoryManager.cpp
Go to the documentation of this file.
1
//
2
// Copyright © 2022, 2024 Arm Ltd and Contributors. All rights reserved.
3
// SPDX-License-Identifier: MIT
4
//
5
#include "
TosaRefMemoryManager.hpp
"
6
7
#include <
armnn/Exceptions.hpp
>
8
#include <algorithm>
9
10
namespace
armnn
11
{
12
13
TosaRefMemoryManager::TosaRefMemoryManager
()
14
{}
15
16
TosaRefMemoryManager::~TosaRefMemoryManager
()
17
{}
18
19
TosaRefMemoryManager::Pool
*
TosaRefMemoryManager::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
TosaRefMemoryManager::Allocate
(
TosaRefMemoryManager::Pool
* pool)
36
{
37
ARMNN_THROW_INVALIDARG_MSG_IF_FALSE
(pool,
"Null memory manager passed to TosaRefMemoryManager."
);
38
m_FreePools.push_back(pool);
39
}
40
41
void
*
TosaRefMemoryManager::GetPointer
(
TosaRefMemoryManager::Pool
* pool)
42
{
43
return
pool->
GetPointer
();
44
}
45
46
void
TosaRefMemoryManager::Acquire
()
47
{
48
for
(
Pool
&pool: m_Pools)
49
{
50
pool.Acquire();
51
}
52
}
53
54
void
TosaRefMemoryManager::Release
()
55
{
56
for
(
Pool
&pool: m_Pools)
57
{
58
pool.Release();
59
}
60
}
61
62
TosaRefMemoryManager::Pool::Pool
(
unsigned
int
numBytes)
63
: m_Size(numBytes),
64
m_Pointer(nullptr)
65
{}
66
67
TosaRefMemoryManager::Pool::~Pool
()
68
{
69
if
(m_Pointer)
70
{
71
Release
();
72
}
73
}
74
75
void
*
TosaRefMemoryManager::Pool::GetPointer
()
76
{
77
ARMNN_THROW_MSG_IF_FALSE
(m_Pointer,
RuntimeException
,
78
"TosaRefMemoryManager::Pool::GetPointer() called when memory not acquired"
);
79
return
m_Pointer;
80
}
81
82
void
TosaRefMemoryManager::Pool::Reserve
(
unsigned
int
numBytes)
83
{
84
ARMNN_THROW_MSG_IF_FALSE
(!m_Pointer,
RuntimeException
,
85
"TosaRefMemoryManager::Pool::Reserve() cannot be called after memory acquired"
);
86
m_Size = std::max(m_Size, numBytes);
87
}
88
89
void
TosaRefMemoryManager::Pool::Acquire
()
90
{
91
ARMNN_THROW_MSG_IF_FALSE
(!m_Pointer,
RuntimeException
,
92
"TosaRefMemoryManager::Pool::Acquire() called when memory already acquired"
);
93
m_Pointer = ::operator
new
(size_t(m_Size));
94
}
95
96
void
TosaRefMemoryManager::Pool::Release
()
97
{
98
ARMNN_THROW_MSG_IF_FALSE
(m_Pointer,
RuntimeException
,
99
"TosaRefMemoryManager::Pool::Release() called when memory not acquired"
);
100
::operator
delete
(m_Pointer);
101
m_Pointer =
nullptr
;
102
}
103
104
}
armnn::TosaRefMemoryManager::TosaRefMemoryManager
TosaRefMemoryManager()
Definition:
TosaRefMemoryManager.cpp:13
armnn::TosaRefMemoryManager::~TosaRefMemoryManager
virtual ~TosaRefMemoryManager()
Definition:
TosaRefMemoryManager.cpp:16
armnn::TosaRefMemoryManager::Pool::Acquire
void Acquire()
Definition:
TosaRefMemoryManager.cpp:89
TosaRefMemoryManager.hpp
armnn::TosaRefMemoryManager::Pool
Definition:
TosaRefMemoryManager.hpp:33
armnn::TosaRefMemoryManager::Pool::GetPointer
void * GetPointer()
Definition:
TosaRefMemoryManager.cpp:75
armnn::TosaRefMemoryManager::Pool::Release
void Release()
Definition:
TosaRefMemoryManager.cpp:96
armnn::TosaRefMemoryManager::Allocate
void Allocate(Pool *pool)
Definition:
TosaRefMemoryManager.cpp:35
armnn::TosaRefMemoryManager::Pool::~Pool
~Pool()
Definition:
TosaRefMemoryManager.cpp:67
armnn::TosaRefMemoryManager::Acquire
void Acquire() override
Definition:
TosaRefMemoryManager.cpp:46
ARMNN_THROW_MSG_IF_FALSE
#define ARMNN_THROW_MSG_IF_FALSE(_cond, _except, _str)
Definition:
Exceptions.hpp:206
armnn::RuntimeException
Definition:
Exceptions.hpp:120
armnn::TosaRefMemoryManager::Pool::Pool
Pool(unsigned int numBytes)
Definition:
TosaRefMemoryManager.cpp:62
armnn::TosaRefMemoryManager::Pool::Reserve
void Reserve(unsigned int numBytes)
Definition:
TosaRefMemoryManager.cpp:82
armnn::TosaRefMemoryManager::GetPointer
void * GetPointer(Pool *pool)
Definition:
TosaRefMemoryManager.cpp:41
armnn::TosaRefMemoryManager::Manage
Pool * Manage(unsigned int numBytes)
Definition:
TosaRefMemoryManager.cpp:19
Exceptions.hpp
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition:
01_00_quick_start.dox:6
armnn::TosaRefMemoryManager::Release
void Release() override
Definition:
TosaRefMemoryManager.cpp:54
ARMNN_THROW_INVALIDARG_MSG_IF_FALSE
#define ARMNN_THROW_INVALIDARG_MSG_IF_FALSE(_cond, _str)
Definition:
Exceptions.hpp:210
src
backends
tosaReference
TosaRefMemoryManager.cpp
Generated on Wed Aug 28 2024 14:31:52 for Arm NN by
1.8.17