tvm_tirx.tirx.transform.UnrollLoop

Contents

tvm_tirx.tirx.transform.UnrollLoop#

tvm_tirx.tirx.transform.UnrollLoop()#

Unroll loops with constant extents marked T.unroll.

The tirx.UnrollLoop PassContext configuration also controls automatic unrolling and whether to expand loops or retain unroll annotations.

Returns:

fpass (tvm_tirx.ir.transform.Pass) – The result pass

Examples

import tvm_tirx as tvm
from tvm_tirx.script import ir as I, tirx as T
from tvm_tirx.tirx import transform as tr

@I.ir_module
class Before:
    @T.function(private=True)
    def main(A: T.Tensor((2,), T.int32)):
        for i in T.unroll(0, 2):
            A[i] = 1

@I.ir_module
class Expected:
    @T.function(private=True)
    def main(A: T.Tensor((2,), T.int32)):
        A[0] = 1
        A[1] = 1

def run_pass():
    return tr.UnrollLoop()(Before)

tvm.ir.assert_structural_equal(run_pass(), Expected)