Commit bc48811f by kun-zh Committed by Tianqi Chen

Fix a bug in inject-virtual-thread (#2039)

parent b840e960
......@@ -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);
......
......@@ -60,7 +60,26 @@ def test_vthread_extern():
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()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment