@@ -311,6 +311,47 @@ bool isCoalesced(
311
311
return true ;
312
312
}
313
313
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
+
314
355
/*
315
356
* For every place in the schedule tree where schedule depth (i.e., the number
316
357
* of preceding band members) is "depth", promote tensor reference groups to
@@ -336,37 +377,18 @@ void promoteToSharedGreedy(
336
377
337
378
auto root = scop.scheduleRoot ();
338
379
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);
363
385
364
- // 3 . Compute full schedule without mapping filters. The filters would make
386
+ // 2 . Compute full schedule without mapping filters. The filters would make
365
387
// it impossible to test for coalescing by incrementing a member of a band as
366
388
// only the values divisible by grid or block size pass through the filter.
367
389
auto fullSched = fullSchedule (root);
368
390
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
370
392
// immediately below it in the tree. In particular, promote if the
371
393
// approximated footprint fits into the remaining memory, and the reference
372
394
// group either features reuse or is accessed in a non-coalesced way, or
0 commit comments