27 _mem_plans[ind] = blk;
30 VERBOSE(BP_PLANNER) <<
"CLAIM(" << ind <<
"): " << blk.offset <<
", " << blk.size << std::endl;
35 VERBOSE(BP_PLANNER) <<
"RELEASE(" << ind <<
"): "
36 <<
"NOTHING does" << std::endl;
56 uint32_t next_offset = 0;
57 for (
const auto &[claimed_base_offset, claimed_operand_idx] : _claim_table)
59 auto claimed_size = _mem_plans[claimed_operand_idx].size;
60 if (next_offset +
size <= claimed_base_offset)
66 next_offset = claimed_base_offset + claimed_size;
71 _claim_table[next_offset] = ind;
72 _mem_plans[ind] = {next_offset,
size};
74 VERBOSE(FF_PLANNER) <<
"claim(" << ind <<
"): [+" << next_offset <<
", " <<
size <<
"sz]"
77 if (_capacity < next_offset +
size)
79 _capacity = next_offset +
size;
85 for (
auto it = _claim_table.cbegin(); it != _claim_table.cend(); ++it)
87 if (it->second == ind)
89 uint32_t
offset = it->first;
90 uint32_t index = ind.
value();
91 uint32_t
size = _mem_plans[ind].size;
93 _claim_table.erase(it);
95 VERBOSE(FF_PLANNER) <<
"release(" << index <<
"): [+" <<
offset <<
", " <<
size <<
"sz]"
100 assert(!
"Cannot release for given index. It has been not claimed or released already.");
104 : _initialized(false), _capacity(0), _mem_plans(), _live_operands(), _interference_graph(),
112 _operands.emplace(
size, ind);
113 _interference_graph[ind].insert(_interference_graph[ind].end(), _live_operands.cbegin(),
114 _live_operands.cend());
115 for (
const auto &live_operand : _live_operands)
117 _interference_graph[live_operand].emplace_back(ind);
119 _live_operands.emplace(ind);
121 VERBOSE(WIC_PLANNER) <<
"claim(" << ind <<
"): [" <<
size <<
"sz]" << std::endl;
126 _live_operands.erase(ind);
127 VERBOSE(WIC_PLANNER) <<
"release(" << ind <<
")" << std::endl;
139void WICPlanner::buildMemoryPlans()
141 for (
const auto &[
size, ind] : _operands)
143 VERBOSE(WIC_PLANNER) <<
"build_plan(" << ind <<
"): [" <<
size <<
"sz]" << std::endl;
145 uint32_t next_offset = 0;
146 if (_interference_graph.count(ind))
149 std::multimap<uint32_t, uint32_t> interfered_plans;
150 for (
const auto &interference : _interference_graph[ind])
152 if (_mem_plans.count(interference))
153 interfered_plans.emplace(_mem_plans[interference].
offset, _mem_plans[interference].
size);
157 for (
const auto &[claimed_base_offset, claimed_size] : interfered_plans)
159 VERBOSE(WIC_PLANNER) <<
"interfere : [+" << claimed_base_offset <<
", " << claimed_size
160 <<
"sz]" << std::endl;
161 if (next_offset +
size <= claimed_base_offset)
165 else if (next_offset < claimed_base_offset + claimed_size)
167 next_offset = claimed_base_offset + claimed_size;
173 VERBOSE(WIC_PLANNER) <<
"No interference" << std::endl;
176 _mem_plans[ind] = {next_offset,
size};
177 VERBOSE(WIC_PLANNER) <<
"alloc(" << ind <<
"): [+" << next_offset <<
", " <<
size <<
"sz]"
180 if (_capacity < next_offset +
size)
182 _capacity = next_offset +
size;
186 _interference_graph.clear();
void release(const ir::OperandIndex &) override
Release memory for operand by bump way.
void claim(const ir::OperandIndex &, size_t) override
Claim memory for operand by bump way.
void claim(const ir::OperandIndex &, size_t) override
Claim memory for operand by firstfit way.
void release(const ir::OperandIndex &) override
Release memory for operand by firstfit way.
void claim(const ir::OperandIndex &, size_t) override
Claim memory for operand by WIC algorithm.
MemoryPlans & memory_plans() override
Get MemoryPlans.
void release(const ir::OperandIndex &) override
Release memory for operand by WIC algorithm.
T value() const
Return underlying value.
__global uchar * offset(const Image *img, int x, int y)
#define VERBOSE(name, lv)
Structure to have memory offset and size.
std::unordered_map< ir::OperandIndex, Block > MemoryPlans