31 _mem_plans[ind] = blk;
34 VERBOSE(BP_PLANNER) <<
"CLAIM(" << ind <<
"): " << blk.offset <<
", " << blk.size << std::endl;
39 VERBOSE(BP_PLANNER) <<
"RELEASE(" << ind <<
"): "
40 <<
"NOTHING does" << std::endl;
60 uint32_t next_offset = 0;
61 for (
const auto &[claimed_base_offset, claimed_operand_idx] : _claim_table)
63 auto claimed_size = _mem_plans[claimed_operand_idx].size;
64 if (next_offset +
size <= claimed_base_offset)
70 next_offset = claimed_base_offset + claimed_size;
75 _claim_table[next_offset] = ind;
76 _mem_plans[ind] = {next_offset,
size};
78 VERBOSE(FF_PLANNER) <<
"claim(" << ind <<
"): [+" << next_offset <<
", " <<
size <<
"sz]"
81 if (_capacity < next_offset +
size)
83 _capacity = next_offset +
size;
89 for (
auto it = _claim_table.cbegin(); it != _claim_table.cend(); ++it)
91 if (it->second == ind)
93 uint32_t
offset = it->first;
94 uint32_t index = ind.
value();
95 uint32_t
size = _mem_plans[ind].size;
97 _claim_table.erase(it);
99 VERBOSE(FF_PLANNER) <<
"release(" << index <<
"): [+" <<
offset <<
", " <<
size <<
"sz]"
104 assert(!
"Cannot release for given index. It has been not claimed or released already.");
108 : _initialized(false), _capacity(0), _mem_plans(), _live_operands(), _interference_graph(),
116 _operands.emplace(
size, ind);
117 _interference_graph[ind].insert(_interference_graph[ind].end(), _live_operands.cbegin(),
118 _live_operands.cend());
119 for (
const auto &live_operand : _live_operands)
121 _interference_graph[live_operand].emplace_back(ind);
123 _live_operands.emplace(ind);
125 VERBOSE(WIC_PLANNER) <<
"claim(" << ind <<
"): [" <<
size <<
"sz]" << std::endl;
130 _live_operands.erase(ind);
131 VERBOSE(WIC_PLANNER) <<
"release(" << ind <<
")" << std::endl;
143void WICPlanner::buildMemoryPlans()
145 for (
const auto &[
size, ind] : _operands)
147 VERBOSE(WIC_PLANNER) <<
"build_plan(" << ind <<
"): [" <<
size <<
"sz]" << std::endl;
149 uint32_t next_offset = 0;
150 if (_interference_graph.count(ind))
153 std::multimap<uint32_t, uint32_t> interfered_plans;
154 for (
const auto &interference : _interference_graph[ind])
156 if (_mem_plans.count(interference))
157 interfered_plans.emplace(_mem_plans[interference].
offset, _mem_plans[interference].
size);
161 for (
const auto &[claimed_base_offset, claimed_size] : interfered_plans)
163 VERBOSE(WIC_PLANNER) <<
"interfere : [+" << claimed_base_offset <<
", " << claimed_size
164 <<
"sz]" << std::endl;
165 if (next_offset +
size <= claimed_base_offset)
169 else if (next_offset < claimed_base_offset + claimed_size)
171 next_offset = claimed_base_offset + claimed_size;
177 VERBOSE(WIC_PLANNER) <<
"No interference" << std::endl;
180 _mem_plans[ind] = {next_offset,
size};
181 VERBOSE(WIC_PLANNER) <<
"alloc(" << ind <<
"): [+" << next_offset <<
", " <<
size <<
"sz]"
184 if (_capacity < next_offset +
size)
186 _capacity = next_offset +
size;
190 _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