#include <BuddyMemoryManager.h>
Definition at line 24 of file BuddyMemoryManager.h.
◆ BuddyMemoryManager()
luci_interpreter::BuddyMemoryManager::BuddyMemoryManager |
( |
uint8_t * |
memory_start, |
|
|
int32_t |
memSize |
|
) |
| |
Definition at line 22 of file BuddyMemoryManager.cpp.
23{
24 int32_t p = lowerLog2(memSize);
25
26
27 assert(p < 32);
28 memSize = 1 << p;
29
30 _start_block = reinterpret_cast<Block *>(memory_start);
31 _start_block->size = memSize - sizeof(Block);
32 _start_block->is_free = true;
33 _start_block->self = _start_block;
34 _num_blocks = 0;
35 _size = _start_block->size;
36
37 for (auto &_free_block : _free_blocks)
38 _free_block = nullptr;
39
40 addToBlocks(_start_block, p);
41}
◆ allocate_memory()
Implements luci_interpreter::IMemoryManager.
Definition at line 43 of file BuddyMemoryManager.cpp.
44{
48 auto footprint =
size +
sizeof(Block);
49 auto l = (footprint & (footprint - 1)) == 0
50 ? lowerLog2(footprint)
51 : lowerLog2(footprint) + 1;
52
53 while (l < 32 && !_free_blocks[l])
55
56 if (l >= 32)
57 {
58 throw std::runtime_error{"Memory limit exceeded"};
59 }
60
61 Block *tmp;
62 tmp = _free_blocks[
l];
63 removeFromBlocks(tmp, l);
64
65 while ((tmp->size +
sizeof(Block)) / 2 >=
size +
sizeof(Block))
66 {
67 divideBlock(tmp, l);
69 }
70
71 tmp->is_free = false;
72 tmp->self = tmp;
73 _num_blocks++;
74
75 auto *
data = (uint8_t *)(tmp + 1);
77}
const T * data(const std::vector< T, Alloc > &v)
size_t getDataTypeSize(DataType data_type)
uint32_t num_elements(const Shape &shape)
The number of elements of a feature map of a given shape.
References flatbuffers::data(), luci_interpreter::getDataTypeSize(), and size.
◆ release_memory()
Implements luci_interpreter::IMemoryManager.
Definition at line 79 of file BuddyMemoryManager.cpp.
80{
82 auto *tmp = (Block *)((uint8_t *)
data -
sizeof(Block));
83
84 assert(tmp->self == tmp);
85
86 tmp->is_free = true;
87 addToBlocks(tmp, lowerLog2(tmp->size + sizeof(Block)));
88
89 while (tmp)
90 if (tmp->size == _size)
91 break;
92 else
93 tmp = mergeBlock(tmp);
94
95 _num_blocks--;
96 tensor.set_data_buffer(
nullptr);
97}
References flatbuffers::data().
The documentation for this class was generated from the following files: