If_scope in ir_builder

Hi, I’m using the ir_builder to contrust a cuda kernel, but I encounter a problem of if_scope

 ib = tvm.tir.ir_builder.create()
    n = te.size_var("n")
    A = ib.pointer("float32", name="A")
    tmod = tvm.tir.truncmod
    with ib.for_range(0, n, name="i") as i:
        with ib.if_scope(tmod(i, 2) == 0):
            A[i] = A[i] + 1
            b = 100
        with ib.else_scope():
            A[0] = A[i] + 2
            b  =  200
    A[3] = b

I find some error occurred. The problem is that ir builder will fold the variable python automatically. In my case, this python code did not appeared in my if_else_scope. Is there any approach to solve this problem?

Appreciate for any explanation of this or any suggestions about this issue. Thanks in advance!

Hi @SYangDong, use b = tvm.tir.const(100, dtype="float32") instead of the assgiment directly.

Thank you @leeexyz. Yeah, we can use tvm.tir.const or a new buffer. I means, it there any mechanism to prevent users using python variables within a if_scope. For example, error message to tell users to utilize tvm.tir.const since it’s quite easy to confuse the python variable with tvm Expr. It still works sometimes event thought we define some python variables within a if_scope. That really causes me a lot of trouble.