Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure loop count is a constant before trying to unroll. #2797

Merged
merged 1 commit into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pass/unroll_loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class LoopUnroller : public IRMutator {

if ((auto_unroll && explicit_unroll_) ||
// unroll loops with extent = 1, no matter how many steps in body
(value <= auto_max_extent_ && auto_max_extent_ == 1)) {
(0 <= value && value <= auto_max_extent_ && auto_max_extent_ == 1)) {
return Unroll(op);
} else {
if (auto_unroll) {
Expand Down
13 changes: 13 additions & 0 deletions tests/python/unittest/test_pass_unroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,20 @@ def test_unroll_fake_loop():
ret = tvm.ir_pass.UnrollLoop(stmt, 8, 0, 1, True)
assert isinstance(ret.first, tvm.stmt.Store)

def test_unroll_single_count_loops():
n = tvm.var('n')
A = tvm.placeholder((n,), name='A')
B = tvm.compute((n,), lambda *i: A(*i), name='B')
s = tvm.create_schedule(B.op)
s = s.normalize()
dom_map = tvm.schedule.InferBound(s)
stmt = tvm.schedule.ScheduleOps(s, dom_map)
# all parameters to UnrolLoops are default values except for
# auto_unroll_max_extent which has been set to 1 (default:0)
after_unroll_stmt = tvm.ir_pass.UnrollLoop(stmt, 0, 8, 1, True)
assert after_unroll_stmt == stmt

if __name__ == "__main__":
test_unroll_loop()
test_unroll_fake_loop()
test_unroll_single_count_loops()