test_pass_simplify.py 893 Bytes
Newer Older
1 2 3 4 5 6
import tvm
import numpy

def test_simplify():
    """Not yet working, mock design"""
    dtype = 'int64'
7 8 9 10
    n = tvm.var('n')
    Ab = tvm.decl_buffer((n, ), dtype)
    i = tvm.var('i')
    j = tvm.var('j')
11 12 13 14 15 16 17 18 19 20 21
    # for i in 0 to n-1:
    stmt = tvm.make.For(
        i, 2, n, 0, 0,
        tvm.make.For(j, 0, n, 0, 0,
                     tvm.make.IfThenElse(
                         tvm.make.LT(i + 2, n),
                         tvm.make.Store(Ab.data,
                                        tvm.make.Load(dtype, Ab.data, i + 4) + 1,
                                        (j + 1) * 4 - 4 * j + i),
                         None)))
    stmt = tvm.ir_pass.CanonicalSimplify(stmt)
22 23 24


def test_basic():
25
    m = tvm.var('m')
26 27 28
    ret = tvm.ir_pass.CanonicalSimplify(tvm.make.Evaluate(m-1))
    assert str(ret.value) == "(m - 1)"

29 30

if __name__ == "__main__":
31
    test_basic()
32
    test_simplify()