Any introduction to TIR?

# from tvm.script import ir as I
# from tvm.script import tir as T

@I.ir_module
class Module:
    @T.prim_func
    def main(A: T.Buffer((64,), "float32"), B: T.Buffer((64,), "float32"), C: T.Buffer((64,), "float32")):
        T.func_attr({"from_legacy_te_schedule": True, "global_symbol": "main", "tir.noalias": True})
        for i in range(64):
            C_1 = T.Buffer((64,), data=C.data)
            A_1 = T.Buffer((64,), data=A.data)
            B_1 = T.Buffer((64,), data=B.data)
            C_1[i] = A_1[i] + B_1[i]

Is this tir? or it’s tvm script?

I didn’t find some introduction documents about tir, any help? thank you!

Highly recommended Section 2 of the MLC course: 2. Tensor Program Abstraction — Machine Learing Compilation 0.0.1 documentation

thank you for quick reply. Seems I have read the course before. So the TIR = Tensor IR = Tensor Program ? I thought the TIR was short for target ir

Yes. TIR is short for TensorIR

1 Like

TVMScript is a general term to describe the Python interface of TVM IR family (TensorIR/Relax/etc).

A TensorIR program can be constructed from TVMScript, or converted from TE, or constructed manually with IR builders.

As @junrushao mentioned, TIR is short for TensorIR, not target ir. Tensor program is more general term, Tensor Expression is also tensor program, TensorIR is another abstraction for tensor programs.

1 Like

Got it. Seems TVMScript or TE or IR Builders make the same AST representation, they are just in different formats.

TE is a higher-level abstraction (it has its own data structure, which is not TensorIR AST) that still need to be lowered to TensorIR. TVMScript can parsed to TensorIR directly, like a 1-to-1 mapping.

Thank you! We must create schedule for TE compute and lower the schedule to stmt. so stmt is the ast form of tir, is that right?

No, you don’t need a schedule for lowering TE to TIR, just use create_prim_func function. The schedule is used to describe how to optimize programs, in TensorIR, all schedules are compiler passes.

1 Like

ok, seems my understanding has a lot of error, I still needs to go deeper.I’ll try this function, thank you!