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

Commit 94c1141

Browse files
author
Sven Verdoolaege
committed
makeScheduleTreeHelper: create iteration domain in parameter space first
The function makeIslAffBoundsFromExpr currently relies on the names of the set dimensions in a space. Even though the dependence is very localized and it is unlikely that those names would get dropped, it is better to not rely on them at all. Start by collecting the constraints on the outer loop iterators in terms of parameters and only convert them into set dimensions at the point where the iteration domain is constructed. This means that at least during this part of the construction, makeIslAffBoundsFromExpr only gets called on parameter spaces. Treating the outer loop iterators as parameters at first makes sense because they have a fixed value at the point where the statement is executed. It is only at the point where the iteration domain is constructed that the loop iterators should no longer be considered as parameters. Since the current loop index can no longer be extracted from the set dimension, it is obtained from the number of outer loop iterators instead.
1 parent 60f6a2f commit 94c1141

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

tc/core/halide2isl.cc

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -361,32 +361,25 @@ isl::schedule makeScheduleTreeHelper(
361361
IterationDomainMap* domains) {
362362
isl::schedule schedule;
363363
if (auto op = s.as<For>()) {
364-
// Add one additional dimension to our set of loop variables
365-
int thisLoopIdx = set.dim(isl::dim_type::set);
366-
set = set.add_dims(isl::dim_type::set, 1);
367-
368-
// Make an id for this loop var. For set dimensions this is
369-
// really just for pretty-printing.
364+
// Make an id for this loop var. It starts out as a parameter.
370365
isl::id id(set.get_ctx(), op->name);
371-
set = set.set_dim_id(isl::dim_type::set, thisLoopIdx, id);
366+
auto space = set.get_space().add_param(id);
372367

373-
// Construct a variable (affine function) that indexes the new dimension of
374-
// this space.
375-
isl::aff loopVar(
376-
isl::local_space(set.get_space()), isl::dim_type::set, thisLoopIdx);
368+
// Construct a variable (affine function) that references
369+
// the new parameter.
370+
auto loopVar = isl::aff::param_on_domain_space(space, id);
377371

378372
// Then we add our new loop bound constraints.
379-
auto lbs = halide2isl::makeIslAffBoundsFromExpr(
380-
set.get_space(), op->min, false, true);
373+
auto lbs =
374+
halide2isl::makeIslAffBoundsFromExpr(space, op->min, false, true);
381375
TC_CHECK_GT(lbs.size(), 0u)
382376
<< "could not obtain polyhedral lower bounds from " << op->min;
383377
for (auto lb : lbs) {
384378
set = set.intersect(loopVar.ge_set(lb));
385379
}
386380

387381
Expr max = simplify(op->min + op->extent - 1);
388-
auto ubs =
389-
halide2isl::makeIslAffBoundsFromExpr(set.get_space(), max, true, false);
382+
auto ubs = halide2isl::makeIslAffBoundsFromExpr(space, max, true, false);
390383
TC_CHECK_GT(ubs.size(), 0u)
391384
<< "could not obtain polyhedral upper bounds from " << max;
392385
for (auto ub : ubs) {
@@ -407,7 +400,7 @@ isl::schedule makeScheduleTreeHelper(
407400
isl::multi_union_pw_aff mupa;
408401
body.get_domain().foreach_set([&](isl::set s) {
409402
isl::aff newLoopVar(
410-
isl::local_space(s.get_space()), isl::dim_type::set, thisLoopIdx);
403+
isl::local_space(s.get_space()), isl::dim_type::set, outer.n());
411404
if (mupa) {
412405
mupa = mupa.union_add(isl::union_pw_aff(isl::pw_aff(newLoopVar)));
413406
} else {
@@ -442,7 +435,7 @@ isl::schedule makeScheduleTreeHelper(
442435
IterationDomain iterationDomain;
443436
iterationDomain.tuple = isl::multi_id(tupleSpace, outer);
444437
domains->emplace(id, iterationDomain);
445-
isl::set domain = set.set_tuple_id(id);
438+
auto domain = set.unbind_params(iterationDomain.tuple);
446439
schedule = isl::schedule::from_domain(domain);
447440

448441
isl::union_map newReads, newWrites;

0 commit comments

Comments
 (0)