ArmNN
 25.11
Loading...
Searching...
No Matches
RefMemoryManager.cpp
Go to the documentation of this file.
1//
2// Copyright © 2017, 2024 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
6
8
9#include <algorithm>
10
11namespace armnn
12{
13
16
19
21{
22 if (!m_FreePools.empty())
23 {
24 Pool* res = m_FreePools.back();
25 m_FreePools.pop_back();
26 res->Reserve(numBytes);
27 return res;
28 }
29 else
30 {
31 m_Pools.push_front(Pool(numBytes));
32 return &m_Pools.front();
33 }
34}
35
37{
38 ARMNN_THROW_INVALIDARG_MSG_IF_FALSE(pool, "Null memory manager passed to RefMemoryManager.");
39 m_FreePools.push_back(pool);
40}
41
43{
44 return pool->GetPointer();
45}
46
48{
49 for (Pool &pool: m_Pools)
50 {
51 pool.Acquire();
52 }
53}
54
56{
57 for (Pool &pool: m_Pools)
58 {
59 pool.Release();
60 }
61}
62
63RefMemoryManager::Pool::Pool(unsigned int numBytes)
64 : m_Size(numBytes),
65 m_Pointer(nullptr)
66{}
67
69{
70 if (m_Pointer)
71 {
72 Release();
73 }
74}
75
77{
79 "RefMemoryManager::Pool::GetPointer() called when memory not acquired");
80 return m_Pointer;
81}
82
83void RefMemoryManager::Pool::Reserve(unsigned int numBytes)
84{
86 "RefMemoryManager::Pool::Reserve() cannot be called after memory acquired");
87 m_Size = std::max(m_Size, numBytes);
88}
89
91{
93 "RefMemoryManager::Pool::Acquire() called when memory already acquired");
94 m_Pointer = ::operator new(size_t(m_Size));
95}
96
98{
100 "RefMemoryManager::Pool::Release() called when memory not acquired");
101 ::operator delete(m_Pointer);
102 m_Pointer = nullptr;
103}
104
105}
#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)
void * GetPointer(Pool *pool)
Copyright (c) 2021 ARM Limited and Contributors.