test_pass_virtual_thread.py 905 Bytes
Newer Older
1 2 3
import tvm

def test_virtual_thread():
4
    m = tvm.var('m')
5 6 7 8
    A = tvm.placeholder((m, ), name='A')
    A1 = tvm.compute((m,), lambda i: A[i], name='A1')
    A2 = tvm.compute((m,), lambda i: A1[i] + 3, name='A2')

9
    s = tvm.create_schedule(A2.op)
10 11 12
    vx = tvm.thread_axis("vthread", name="vx")
    xo, xi = s[A2].split(A2.op.axis[0], nparts=2)
    s[A2].bind(xo, vx)
13 14 15 16
    xo, xi = s[A2].split(xi, 8)
    s[A1].compute_at(s[A2], xo)

    bounds = tvm.schedule.InferBound(s)
17
    assert isinstance(bounds, tvm.container.Map)
18 19
    stmt = tvm.schedule.ScheduleOps(s, bounds)

20 21
    Ab = tvm.decl_buffer(A.shape, A.dtype, name='A')
    A2b = tvm.decl_buffer(A2.shape, A2.dtype, name='A2')
22
    stmt = tvm.ir_pass.StorageFlatten(stmt, {A: Ab, A2: A2b}, 64)
23 24 25 26 27 28
    stmt = tvm.ir_pass.Simplify(stmt)
    stmt = tvm.ir_pass.InjectVirtualThread(stmt)
    print(stmt)

if __name__ == "__main__":
    test_virtual_thread()