Skip to content

Commit

Permalink
Fix a bug in inject-virtual-thread (#2039)
Browse files Browse the repository at this point in the history
  • Loading branch information
kun-zh authored and tqchen committed Oct 30, 2018
1 parent b840e96 commit bc48811
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pass/inject_virtual_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class VTInjector : public IRMutator {
CHECK_EQ(max_loop_depth_, 0);
Stmt then_case = this->Mutate(op->then_case);
Stmt else_case;
if (else_case.defined()) {
if (op->else_case.defined()) {
int temp = max_loop_depth_;
max_loop_depth_ = 0;
else_case = this->Mutate(op->else_case);
Expand Down
19 changes: 19 additions & 0 deletions tests/python/unittest/test_pass_inject_vthread.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,26 @@ def get_vthread(name):
assert stmt.body.body.body.body.body.body.extents[0].value == 2
assert len(stmt.body.body.body.body.body.body.extents) == 3

def test_vthread_if_then_else():
nthread = 2
tx = tvm.thread_axis("vthread")
ib = tvm.ir_builder.create()
A = ib.pointer("float32", name="A")
with ib.for_range(0, 100) as i:
ib.scope_attr(tx, "virtual_thread", nthread)
B = ib.allocate("float32", 128, name="B", scope="shared")
with ib.if_scope(i == 0):
B[i] = A[i * nthread + tx]
with ib.else_scope():
B[i] = A[i * nthread + tx] + 1
with ib.if_scope(i == 0):
B[i] = A[i * nthread + tx] + 2
stmt = ib.get()
stmt = tvm.ir_pass.InjectVirtualThread(stmt)
assert stmt.body.body.body.first.else_case != None
assert stmt.body.body.body.rest.else_case == None

if __name__ == "__main__":
test_vthread_extern()
test_vthread()
test_vthread_if_then_else()

0 comments on commit bc48811

Please sign in to comment.