MCPcopy Create free account
hub / github.com/ROCm/AMDMIGraphX / build

Method build

src/memory_coloring.cpp:215–285  ·  view source on GitHub ↗

Build the allocation_color class from the conflict_table

Source from the content-addressed store, hash-verified

213
214 // Build the allocation_color class from the conflict_table
215 static allocation_segment
216 build(const module& m, const instruction_set_map& conflict_table, std::size_t alignment)
217 {
218 allocation_segment as{};
219 std::vector<instruction_ref> conflict_queue;
220 // Add all allocations to the conflict_queue
221 std::transform(conflict_table.begin(),
222 conflict_table.end(),
223 std::back_inserter(conflict_queue),
224 [](auto&& pp) { return pp.first; });
225
226 auto alloc_index = create_allocation_index(m, conflict_table);
227
228 // Sort the conflict queue so we process the allocation with the most
229 // number of adjacent allocations first
230 std::sort(conflict_queue.begin(), conflict_queue.end(), by(std::greater<>{}, [&](auto x) {
231 return std::make_tuple(
232 conflict_table.at(x).size(), x->get_shape().bytes(), alloc_index.at(x));
233 }));
234 // Process the conflict_queue, we refer to the current allocation as
235 // the parent and the adjacent allocations as children
236 for(auto parent : conflict_queue)
237 {
238 // Sort children by size
239 std::vector<instruction_ref> children(conflict_table.at(parent).begin(),
240 conflict_table.at(parent).end());
241 std::sort(children.begin(), children.end(), by(std::less<>{}, [&](auto x) {
242 return std::make_tuple(x->get_shape().bytes(), alloc_index.at(x));
243 }));
244 assert(not contains(children, parent));
245 // This set is to track the segments already processed
246 std::set<segment> segments;
247 // Add all segments for the children to the segments already processed
248 transform_if(
249 children.begin(),
250 children.end(),
251 std::inserter(segments, segments.begin()),
252 [&](auto child) { return as.get_segment(child); },
253 [&](auto child) { return *as.get_segment(child); });
254
255 assert(as.get_segment(parent) == nullptr);
256 as.add_segment(parent, next_segment(segments, parent, alignment));
257 }
258 // Reduce the number of segments
259 for(std::size_t n = 0; n < 3; n++)
260 {
261 for(auto parent : conflict_queue)
262 {
263 auto children = conflict_table.at(parent);
264 // This set is to track the segments already processed
265 std::set<segment> segments;
266 // Add all segments for the children to the segments already processed
267 transform_if(
268 children.begin(),
269 children.end(),
270 std::inserter(segments, segments.begin()),
271 [&](auto child) { return as.get_segment(child); },
272 [&](auto child) { return *as.get_segment(child); });

Callers

nothing calls this directly

Calls 15

containsFunction · 0.85
transform_ifFunction · 0.85
atMethod · 0.80
get_segmentMethod · 0.80
add_segmentMethod · 0.80
transformFunction · 0.50
sortFunction · 0.50
byFunction · 0.50
make_tupleFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected