24 int32_t p = lowerLog2(memSize);
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;
35 _size = _start_block->size;
37 for (
auto &_free_block : _free_blocks)
38 _free_block =
nullptr;
40 addToBlocks(_start_block, p);
46 const int32_t num_elements = tensor.shape().num_elements();
47 auto size = num_elements * element_size;
48 auto footprint =
size +
sizeof(Block);
49 auto l = (footprint & (footprint - 1)) == 0
50 ? lowerLog2(footprint)
51 : lowerLog2(footprint) + 1;
53 while (l < 32 && !_free_blocks[l])
58 throw std::runtime_error{
"Memory limit exceeded"};
62 tmp = _free_blocks[l];
63 removeFromBlocks(tmp, l);
65 while ((tmp->size +
sizeof(Block)) / 2 >=
size +
sizeof(Block))
75 auto *
data = (uint8_t *)(tmp + 1);
76 tensor.set_data_buffer(
data);