19#include "BuddyMemoryManager.h"
26 int32_t p = lowerLog2(memSize);
32 _start_block =
reinterpret_cast<Block *
>(memory_start);
33 _start_block->size = memSize -
sizeof(Block);
34 _start_block->is_free =
true;
35 _start_block->self = _start_block;
37 _size = _start_block->size;
39 for (
auto &_free_block : _free_blocks)
40 _free_block = nullptr;
42 addToBlocks(_start_block, p);
50 auto footprint =
size +
sizeof(Block);
51 auto l = (footprint & (footprint - 1)) == 0
52 ? lowerLog2(footprint)
53 : lowerLog2(footprint) + 1;
55 while (l < 32 && !_free_blocks[l])
61 tmp = _free_blocks[
l];
62 removeFromBlocks(tmp, l);
64 while ((tmp->size +
sizeof(Block)) / 2 >=
size +
sizeof(Block))
74 auto *
data = (uint8_t *)(tmp + 1);
81 auto *tmp = (Block *)((uint8_t *)
data -
sizeof(Block));
83 assert(tmp->self == tmp);
86 addToBlocks(tmp, lowerLog2(tmp->size +
sizeof(Block)));
89 if (tmp->size == _size)
92 tmp = mergeBlock(tmp);
95 tensor.set_data_buffer(
nullptr);
void allocate_memory(luci_interpreter::Tensor &tensor) final
void release_memory(luci_interpreter::Tensor &tensor) final
BuddyMemoryManager(uint8_t *memory_start, int32_t memSize)
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.