Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TVMScript] Create loop var with min_val dtype in for frame #15547

Merged
merged 1 commit into from Aug 15, 2023

Conversation

Lucien0
Copy link
Contributor

@Lucien0 Lucien0 commented Aug 14, 2023

Currently, int is always used when creating loop var in a for frame. So if the iteration variable is uint when creating the for frame, it will fail.

The explicit type brings great convenience to subsequent analysis. So I think it's better to create explicit variables rather than convert to int.

@tvm-bot
Copy link
Collaborator

tvm-bot commented Aug 14, 2023

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

Generated by tvm-bot

Copy link
Member

@Hzfengsy Hzfengsy left a comment

Choose a reason for hiding this comment

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

LGTM. There are two questions beyond this PR:

  1. What's the purpose of using uint in loops? For arithmetic analysis or it's related to the hardware backend.
  2. What's the Script syntax when we use uint, i.e., you've added a test case for the ir_builder, which is great. But I wonder how it can be used in the parser

@Lucien0
Copy link
Contributor Author

Lucien0 commented Aug 14, 2023

Thanks for reply. I think these two problems can be shown in one example:

uint_var = T.call_extern("uint32", "some_function")
divided_var = T.truncdiv(128, uint_var)
for i in range(divided_var):
    xxx

if divided_var % 4 == 0:
    xxx
  1. Our hardware has an architecture like OpenCL, here this function may like get_local_id. I used the divided_var after the for loop in mod, which will analysis its min_val in pass lower intrin. If set to int, its min_val will be -128 rather than 0.
    Actually, I can indeed cast like for i in range(T.int32(divided_var)), but it is horrible to add this in every for statement and is unnecessary. Just let the variable adapt to the later type.

  2. I just create uint var through call_extern.

BTW, I come from Arm China. And we discovered this issue when utilizing TVM Script to create a DSL for our custom operators during the process of writing the actual operators. cc @Johnson9009

@Hzfengsy Hzfengsy merged commit 208e01f into apache:main Aug 15, 2023
18 checks passed
@Lucien0 Lucien0 deleted the adaptive_for_loop_var branch August 15, 2023 01:25
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.

None yet

3 participants