Skip to content

Conversation

@MasterJH5574
Copy link
Contributor

This PR fixes a bug in TVMScript printer. Suppose we have the following script:

@T.prim_func
def func(a: T.handle) -> None:
    A = T.match_buffer(a, [], dtype="int32")
    for i in T.serial(0, 128):
        for j in T.serial(0, i):
            A[()] = A[()] + j

Before this PR, the printer prints it as

@T.prim_func
def func(a: T.handle) -> None:
    A = T.match_buffer(a, [], dtype="int32")
    # body
    for i, j in T.grid(128, i):  # <=== Invalid Python syntax!
        A[()] = A[()] + j

Note that the last but one line is erroneous. When TVMScript parser deals with the printed script, it says

error: Unknown identifier i.
 --> tensorir.py:23:29
    |  
 23 |      for i, j in T.grid(128, i):
    |                              ^  
note: run with `TVM_BACKTRACE=1` environment variable to display a backtrace.

After this PR, the printer separately prints loops with dependency. So the issue above won't show again :-)

cc @Hzfengsy @junrushao1994

Copy link
Member

@junrushao junrushao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely an interesting corner case! Thanks for spotting this!

@junrushao junrushao merged commit 13f54e0 into apache:main Nov 15, 2021
mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request Dec 1, 2021
mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request Dec 1, 2021
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 7, 2022
yangulei pushed a commit to yangulei/tvm that referenced this pull request Jan 11, 2022
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants