Skip to content

Commit

Permalink
Duplicate likely nodes added when loop axis split unevenly (#5084)
Browse files Browse the repository at this point in the history
* [TE][Schedule] Duplicate likely nodes removed

* [1] Test case added

* [2] Lint error fixed

* [3] Review comments handled

* [4] Review comments handled
  • Loading branch information
ANSHUMAN TRIPATHY authored Mar 25, 2020
1 parent 3aabbd9 commit 0c38b91
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/te/schedule/message_passing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,14 @@ void PassUpBoundCheck(const Stage& s,
}
}

bool IsRangeSame(const Range input_1, const Range input_2) {
arith::Analyzer analyzer;
if (input_1.same_as(input_2)) return true;

return (analyzer.CanProve(input_1->min == input_2->min)
&& analyzer.CanProve(input_1->extent == input_2->extent));
}

std::vector<PrimExpr> MakeBoundCheck(
const Stage& stage,
const Map<IterVar, Range>& dom_map,
Expand Down Expand Up @@ -593,7 +601,7 @@ std::vector<PrimExpr> MakeBoundCheck(
if (skip_iter.count(iv) || iv->iter_type == kOpaque) continue;
Range dom = dom_map.at(iv);
CHECK(iv->dom.defined());
if (!skip_ivar_domain && !iv->dom.same_as(dom)) {
if (!skip_ivar_domain && !IsRangeSame(iv->dom, dom)) {
PrimExpr value = value_map.at(iv) - iv->dom->min;
IntSet s = EvalSet(value, iset_dmap);
PrimExpr vmin = s.min();
Expand Down
13 changes: 13 additions & 0 deletions tests/python/unittest/test_te_build_lower.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ def test_dependent_output_shape():
s = te.create_schedule(B.op)
mod = tvm.build(s, [A, B, x])

def test_split_uneven_unique_likely():
a = te.placeholder((16, 16),)
b = te.placeholder((16, 16),)
c = te.compute((16, 16), lambda x, y: a[x, y] + b[x, y])

x, y = c.op.axis
sch = te.create_schedule(c.op)
xo, xi = sch[c].split(x, 5)
stmt = tvm.lower(sch, [a, b, c], simple_mode=True)
assert isinstance(stmt.body.body.body.body, tvm.tir.stmt.IfThenElse)
assert str(stmt.body.body.body.body).count("likely") == 1

if __name__ == "__main__":
test_lower_rfactor()
test_dependent_output_shape()
test_split_uneven_unique_likely()

0 comments on commit 0c38b91

Please sign in to comment.