36 _mem_plans[ind] = blk;
39 VERBOSE(BP_PLANNER) <<
"CLAIM(" << ind <<
"): " << blk.
offset <<
", " << blk.size << std::endl;
44 VERBOSE(BP_PLANNER) <<
"RELEASE(" << ind <<
"): "
45 <<
"NOTHING does" << std::endl;
65 uint32_t next_offset = 0;
66 for (
const auto &[claimed_base_offset, claimed_index] : _claim_table)
68 auto claimed_size = _mem_plans[claimed_index].size;
69 if (next_offset +
size <= claimed_base_offset)
75 next_offset = claimed_base_offset + claimed_size;
82 _claim_table.emplace(std::make_pair(next_offset, ind));
83 _mem_plans[ind] = {next_offset,
size};
85 VERBOSE(FF_PLANNER) <<
"claim(" << ind <<
"): [+" << next_offset <<
", " <<
size <<
"sz]"
88 if (_capacity < next_offset +
size)
90 _capacity = next_offset +
size;
96 for (
auto it = _claim_table.cbegin(); it != _claim_table.cend(); ++it)
98 if (it->second == ind)
100 uint32_t
offset = it->first;
101 uint32_t
size = _mem_plans[ind].size;
103 _claim_table.erase(it);
105 VERBOSE(FF_PLANNER) <<
"release(" << ind <<
"): [+" <<
offset <<
", " <<
size <<
"sz]"
110 assert(!
"Cannot release for given index. It has been not claimed or released already.");
113template <
typename Index>
115 : _initialized(false), _capacity(0), _mem_plans(), _live_indices(), _interference_graph(),
123 _indices.emplace(
size, ind);
124 _interference_graph[ind].insert(_interference_graph[ind].end(), _live_indices.cbegin(),
125 _live_indices.cend());
126 for (
const auto &live_operand : _live_indices)
128 _interference_graph[live_operand].emplace_back(ind);
130 _live_indices.emplace(ind);
132 VERBOSE(WIC_PLANNER) <<
"claim(" << ind <<
"): [" <<
size <<
"sz]" << std::endl;
137 _live_indices.erase(ind);
138 VERBOSE(WIC_PLANNER) <<
"release(" << ind <<
")" << std::endl;
153 for (
const auto &[
size, ind] : _indices)
155 VERBOSE(WIC_PLANNER) <<
"build_plan(" << ind <<
"): [" <<
size <<
"sz]" << std::endl;
157 uint32_t next_offset = 0;
158 if (_interference_graph.count(ind))
161 std::multimap<uint32_t, uint32_t> interfered_plans;
162 for (
const auto &interference : _interference_graph[ind])
164 if (_mem_plans.count(interference))
165 interfered_plans.emplace(_mem_plans[interference].
offset, _mem_plans[interference].
size);
169 for (
const auto &[claimed_base_offset, claimed_size] : interfered_plans)
171 VERBOSE(WIC_PLANNER) <<
"interfere : [+" << claimed_base_offset <<
", " << claimed_size
172 <<
"sz]" << std::endl;
173 if (next_offset +
size <= claimed_base_offset)
177 else if (next_offset < claimed_base_offset + claimed_size)
179 next_offset = claimed_base_offset + claimed_size;
185 VERBOSE(WIC_PLANNER) <<
"No interference" << std::endl;
188 _mem_plans[ind] = {next_offset,
size};
189 VERBOSE(WIC_PLANNER) <<
"alloc(" << ind <<
"): [+" << next_offset <<
", " <<
size <<
"sz]"
192 if (_capacity < next_offset +
size)
194 _capacity = next_offset +
size;
198 _interference_graph.clear();
Class to plan memory by bump way.
void release(const Index &) override
Release memory for tensor by bump way.
void claim(const Index &, size_t) override
Claim memory for tensor by bump way.
Class to plan memory by firstfit way.
void claim(const Index &, size_t) override
Claim memory for tensor by firstfit way.
void release(const Index &) override
Release memory for tensor by firstfit way.
Class to plan memory by Weighted Interval Color algorithm.
void release(const Index &) override
Release memory for tensor by WIC algorithm.
MemoryPlans & memory_plans() override
Get MemoryPlans.
void claim(const Index &, size_t) override
Claim memory for tensor by WIC algorithm.
__global uchar * offset(const Image *img, int x, int y)
#define VERBOSE(name, lv)
Structure to have memory offset and size.