ArmNN
 25.11
Loading...
Searching...
No Matches
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//
6
8#include <algorithm>
9
10namespace armnn
11{
12
15
18
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
36{
37 ARMNN_THROW_INVALIDARG_MSG_IF_FALSE(pool, "Null memory manager passed to TosaRefMemoryManager.");
38 m_FreePools.push_back(pool);
39}
40
45
47{
48 for (Pool &pool: m_Pools)
49 {
50 pool.Acquire();
51 }
52}
53
55{
56 for (Pool &pool: m_Pools)
57 {
58 pool.Release();
59 }
60}
61
63 : m_Size(numBytes),
64 m_Pointer(nullptr)
65{}
66
68{
69 if (m_Pointer)
70 {
71 Release();
72 }
73}
74
76{
78 "TosaRefMemoryManager::Pool::GetPointer() called when memory not acquired");
79 return m_Pointer;
80}
81
82void TosaRefMemoryManager::Pool::Reserve(unsigned int numBytes)
83{
85 "TosaRefMemoryManager::Pool::Reserve() cannot be called after memory acquired");
86 m_Size = std::max(m_Size, numBytes);
87}
88
90{
92 "TosaRefMemoryManager::Pool::Acquire() called when memory already acquired");
93 m_Pointer = ::operator new(size_t(m_Size));
94}
95
97{
99 "TosaRefMemoryManager::Pool::Release() called when memory not acquired");
100 ::operator delete(m_Pointer);
101 m_Pointer = nullptr;
102}
103
104}
#define ARMNN_THROW_INVALIDARG_MSG_IF_FALSE(_cond, _str)
#define ARMNN_THROW_MSG_IF_FALSE(_cond, _except, _str)
void Reserve(unsigned int numBytes)
Pool * Manage(unsigned int numBytes)
Copyright (c) 2021 ARM Limited and Contributors.