test_pass_inline.py 1.05 KB
Newer Older
tqchen committed
1 2 3
import tvm

def test_inline():
4
    m = tvm.var('m')
tqchen committed
5
    A = tvm.placeholder((m,), name='A')
6 7
    T = tvm.compute((m,), lambda i,: A[i] + 10, name='T')
    stmt = tvm.make.Evaluate(T[10] + 11 * T[100])
tqchen committed
8
    stmt = tvm.ir_pass.Inline(
9
        stmt, T.op, [x.var for x in T.op.axis], T.op.body[0])
tqchen committed
10 11 12
    print(stmt)
    assert(tvm.ir_pass.VerifySSA(stmt))

13 14 15 16
    try:
        # pass in int array(wrong argument type)
        # must raise an error
        stmt = tvm.ir_pass.Inline(
17
            T.op, [1,2,3], T.op.body, stmt)
18 19 20 21
        assert False
    except tvm.TVMError:
        pass

22 23 24 25 26 27
def test_inline2():
    m = tvm.var('m')
    A = tvm.placeholder((m,), name='A')
    T = tvm.compute((m,), lambda i,: A[i] + 10, name='T')
    stmt = tvm.make.Evaluate(tvm.exp(T[10]) + 11 * T[100])
    stmt = tvm.ir_pass.Inline(
28
        stmt, T.op, [x.var for x in T.op.axis], T.op.body[0])
29 30 31 32
    def check(op):
        if isinstance(op, tvm.expr.Call):
            assert op.func != T.op
    tvm.ir_pass.PostOrderVisit(stmt, check)
33 34


tqchen committed
35
if __name__ == "__main__":
36
    test_inline2()
tqchen committed
37
    test_inline()