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

Commit 2a76ece

Browse files
author
Sven Verdoolaege
committed
makeScheduleTree: keep track of loop iterator names per statement
Some parts of the code assume that isl will preserve the identifiers of set variables, while it does not (and cannot) do so in all cases. Keep track of the loop iterator names separately so that they can be used instead.
1 parent 767eba6 commit 2a76ece

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

include/tc/core/halide2isl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ isl::aff makeIslAffFromInt(isl::space space, int64_t i);
5151
// does not correspond to a parameter or set dimension of the space.
5252
isl::aff makeIslAffFromExpr(isl::space space, const Halide::Expr& e);
5353

54+
typedef std::unordered_map<isl::id, std::vector<std::string>, isl::IslIdIslHash>
55+
IteratorMap;
5456
typedef std::unordered_map<isl::id, Halide::Internal::Stmt, isl::IslIdIslHash>
5557
StatementMap;
5658
typedef std::unordered_map<const Halide::Internal::IRNode*, isl::id> AccessMap;
@@ -73,6 +75,10 @@ struct ScheduleTreeAndAccesses {
7375
/// The correspondence between leaf Stmts and the statement ids
7476
/// refered to above.
7577
StatementMap statements;
78+
79+
/// The correspondence between statement ids and the outer loop iterators
80+
/// of the corresponding leaf Stmt.
81+
IteratorMap iterators;
7682
};
7783

7884
/// Make a schedule tree from a Halide Stmt, along with auxiliary data

include/tc/core/polyhedral/scop.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ struct Scop {
419419
std::unordered_map<isl::id, Halide::Internal::Stmt, isl::IslIdIslHash>
420420
statements;
421421
std::unordered_map<const Halide::Internal::IRNode*, isl::id> accesses;
422+
halide2isl::IteratorMap iterators;
422423
} halide;
423424

424425
// Polyhedral IR

src/core/halide2isl.cc

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ struct ScheduleTreeAndDomain {
321321
* recursively descending over the Stmt.
322322
* "s" is the current position in the recursive descent.
323323
* "set" describes the bounds on the outer loop iterators.
324+
* "outer" contains the names of the outer loop iterators
325+
* from outermost to innermost.
324326
* Return the schedule tree corresponding to the subtree at "s",
325327
* along with a separated out domain.
326328
*
@@ -329,14 +331,18 @@ struct ScheduleTreeAndDomain {
329331
* (for the writes) to the corresponding tag in the access relations.
330332
* "statements" collects the mapping from instance set tuple identifiers
331333
* to the corresponding Provide node.
334+
* "iterators" collects the mapping from instance set tuple identifiers
335+
* to the corresponding outer loop iterator names, from outermost to innermost.
332336
*/
333337
ScheduleTreeAndDomain makeScheduleTreeHelper(
334338
const Stmt& s,
335339
isl::set set,
340+
std::vector<std::string>& outer,
336341
isl::union_map* reads,
337342
isl::union_map* writes,
338343
AccessMap* accesses,
339-
StatementMap* statements) {
344+
StatementMap* statements,
345+
IteratorMap* iterators) {
340346
ScheduleTreeAndDomain result;
341347
if (auto op = s.as<For>()) {
342348
// Add one additional dimension to our set of loop variables
@@ -372,8 +378,17 @@ ScheduleTreeAndDomain makeScheduleTreeHelper(
372378
}
373379

374380
// Recursively descend.
381+
auto outerNext = outer;
382+
outerNext.push_back(op->name);
375383
auto body = makeScheduleTreeHelper(
376-
op->body, set, reads, writes, accesses, statements);
384+
op->body,
385+
set,
386+
outerNext,
387+
reads,
388+
writes,
389+
accesses,
390+
statements,
391+
iterators);
377392

378393
// Create an affine function that defines an ordering for all
379394
// the statements in the body of this loop over the values of
@@ -419,8 +434,8 @@ ScheduleTreeAndDomain makeScheduleTreeHelper(
419434
// children.
420435
std::vector<ScheduleTreeUPtr> trees;
421436
for (Stmt s : stmts) {
422-
auto mem =
423-
makeScheduleTreeHelper(s, set, reads, writes, accesses, statements);
437+
auto mem = makeScheduleTreeHelper(
438+
s, set, outer, reads, writes, accesses, statements, iterators);
424439
ScheduleTreeUPtr filter;
425440
if (mem.tree) {
426441
// No statement instances are shared between the blocks, so we
@@ -452,6 +467,7 @@ ScheduleTreeAndDomain makeScheduleTreeHelper(
452467
size_t stmtIndex = statements->size();
453468
isl::id id(set.get_ctx(), kStatementLabel + std::to_string(stmtIndex));
454469
statements->emplace(id, op);
470+
iterators->emplace(id, outer);
455471
isl::set domain = set.set_tuple_id(id);
456472
result.domain = domain;
457473

@@ -474,13 +490,16 @@ ScheduleTreeAndAccesses makeScheduleTree(isl::space paramSpace, const Stmt& s) {
474490
result.writes = result.reads = isl::union_map::empty(paramSpace);
475491

476492
// Walk the IR building a schedule tree
493+
std::vector<std::string> outer;
477494
auto treeAndDomain = makeScheduleTreeHelper(
478495
s,
479496
isl::set::universe(paramSpace),
497+
outer,
480498
&result.reads,
481499
&result.writes,
482500
&result.accesses,
483-
&result.statements);
501+
&result.statements,
502+
&result.iterators);
484503

485504
// TODO: This fails if the stmt is just a Provide node, I'm not sure
486505
// what the schedule tree should look like in that case.

src/core/polyhedral/scop.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ ScopUPtr Scop::makeScop(
7070
scop->halide.statements = std::move(tree.statements);
7171
scop->halide.accesses = std::move(tree.accesses);
7272
scop->halide.reductions = halide2isl::findReductions(components.stmt);
73+
scop->halide.iterators = std::move(tree.iterators);
7374

7475
// Set partial schedule tuples for proper comparison with ISL
7576
// schedules (needs DFSPreorder numbering). Just for testing.

0 commit comments

Comments
 (0)