Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit a1194c8

Browse files
committed
extract bandsContainingScheduleDepth and bandsSplitAfterDepth
These function will be reused for promotion to registers in the following commits.
1 parent ff4c871 commit a1194c8

File tree

1 file changed

+48
-26
lines changed

1 file changed

+48
-26
lines changed

src/core/polyhedral/memory_promotion_heuristic.cc

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,47 @@ bool isCoalesced(
311311
return true;
312312
}
313313

314+
/*
315+
* Starting from the root, find bands where depth is reached. Using
316+
* DFSPreorder to make sure order is specified and consistent for tests.
317+
*/
318+
std::vector<detail::ScheduleTree*> bandsContainingScheduleDepth(
319+
detail::ScheduleTree* root,
320+
size_t depth) {
321+
using namespace tc::polyhedral::detail;
322+
323+
auto bands =
324+
ScheduleTree::collectDFSPreorder(root, detail::ScheduleTreeType::Band);
325+
std::function<bool(ScheduleTree * st)> containsDepth = [&](ScheduleTree* st) {
326+
auto depthBefore = st->scheduleDepth(root);
327+
auto band = st->elemAs<ScheduleTreeElemBand>();
328+
auto depthAfter = depthBefore + band->nMember();
329+
return depthBefore < depth && depthAfter >= depth;
330+
};
331+
return functional::Filter(containsDepth, bands);
332+
}
333+
334+
/*
335+
* Split bands so that the "depth"-th dimension is always the last in some
336+
* band. Return such bands.
337+
*/
338+
std::vector<detail::ScheduleTree*> bandsSplitAfterDepth(
339+
const std::vector<detail::ScheduleTree*>& bands,
340+
detail::ScheduleTree* root,
341+
size_t depth) {
342+
using namespace tc::polyhedral::detail;
343+
344+
std::function<ScheduleTree*(ScheduleTree*)> splitAtDepth =
345+
[&](ScheduleTree* st) {
346+
auto nMember = st->elemAs<ScheduleTreeElemBand>()->nMember();
347+
auto scheduleDepth = st->scheduleDepth(root);
348+
auto depthAfter = scheduleDepth + nMember;
349+
return depthAfter == depth ? st
350+
: bandSplit(root, st, depth - scheduleDepth);
351+
};
352+
return functional::Map(splitAtDepth, bands);
353+
}
354+
314355
/*
315356
* For every place in the schedule tree where schedule depth (i.e., the number
316357
* of preceding band members) is "depth", promote tensor reference groups to
@@ -336,37 +377,18 @@ void promoteToSharedGreedy(
336377

337378
auto root = scop.scheduleRoot();
338379

339-
// 1. Starting from the root, find bands where depth is reached.
340-
// Using DFSPreorder to make sure order is specified and consistent for
341-
// tests.
342-
auto bands =
343-
ScheduleTree::collectDFSPreorder(root, detail::ScheduleTreeType::Band);
344-
std::function<bool(ScheduleTree * st)> containsDepth = [&](ScheduleTree* st) {
345-
auto depthBefore = st->scheduleDepth(root);
346-
auto band = st->elemAs<ScheduleTreeElemBand>();
347-
auto depthAfter = depthBefore + band->nMember();
348-
return depthBefore < depth && depthAfter >= depth;
349-
};
350-
bands = functional::Filter(containsDepth, bands);
351-
352-
// 2. Split bands so that the "depth"-th dimension is always the last in some
353-
// band. Keep such bands.
354-
std::function<ScheduleTree*(ScheduleTree*)> splitAtDepth =
355-
[&](ScheduleTree* st) {
356-
auto nMember = st->elemAs<ScheduleTreeElemBand>()->nMember();
357-
auto scheduleDepth = st->scheduleDepth(root);
358-
auto depthAfter = scheduleDepth + nMember;
359-
return depthAfter == depth ? st
360-
: bandSplit(root, st, depth - scheduleDepth);
361-
};
362-
bands = functional::Map(splitAtDepth, bands);
380+
// 1. Collect all bands with a member located at the given depth in the
381+
// overall schedule. Make sure this is the last member of the band by
382+
// splitting off the subsequent members into a different band.
383+
auto bands = bandsContainingScheduleDepth(root, depth);
384+
bands = bandsSplitAfterDepth(bands, root, depth);
363385

364-
// 3. Compute full schedule without mapping filters. The filters would make
386+
// 2. Compute full schedule without mapping filters. The filters would make
365387
// it impossible to test for coalescing by incrementing a member of a band as
366388
// only the values divisible by grid or block size pass through the filter.
367389
auto fullSched = fullSchedule(root);
368390

369-
// 4. For each band that ends at "depth", take decisions about promotion
391+
// 3. For each band that ends at "depth", take decisions about promotion
370392
// immediately below it in the tree. In particular, promote if the
371393
// approximated footprint fits into the remaining memory, and the reference
372394
// group either features reuse or is accessed in a non-coalesced way, or

0 commit comments

Comments
 (0)