-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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] Use tir::Evaluate if expression is in statement context #13396
[TVMScript] Use tir::Evaluate if expression is in statement context #13396
Conversation
For the previous version of the parser, this was special-cased for some intrinsic operators. After the new TVMScript was enabled in apache#12496, any `PrimExpr` that appears in the body of a statement is silently ignored. This commit updates the parser to instead wrap the bare `PrimExpr` in a `tir::Evaluate` node. This change effectively allows [expression statements](https://docs.python.org/3/reference/simple_stmts.html#expression-statements) in TVMScript, which are converted to `tir::Evaluate` nodes during parsing.
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 |
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 |
This PR is in response to CI failures found in #13130, when writing TVMScript that used the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I was thinking about the same thing but holding back a bit because I dont want to change TIR too often, but it is definitely a positive change and I really love it
elif isinstance(res, (int, bool)): | ||
T.evaluate(tvm.tir.const(res)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey i was wondering if we want to explicitly print T.evaluate(0)
vs 0
? The former one might look a bit clearer from my perspective
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going back and forth on it, and I like the idea of printing T.evaluate()
except in the case of CallNode. The more aggressive sugaring would be to render tir::Evaluate(0)
as pass
, which would be even clearer to read from a casual Python reader.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good idea!
@T.prim_func | ||
def func(A: T.Buffer[1, "int32"]): | ||
T.evaluate(T.assume(A[0] == 5)) | ||
A[0] = 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious what's this line for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly because T.assume
doesn't have any effect, and I was pulling this in from a failing case of T.assume
in a separate PR. This was from a unit test that validated a pass that removed T.assume
calls from a primfunc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. Thanks for the clarification!
src/printer/tvmscript_printer.cc
Outdated
Doc doc; | ||
doc << tir_prefix_ << ".evaluate(" << Print(op->value) << ")"; | ||
doc << Print(op->value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we only sugar CallNode
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that idea for the printing. Maybe best of both worlds, to have the sugar apply all the time when parsing, but only CallNode
drops the printing of T.evaluate(...)
when generating TVMScript.
Thank you! It's definitely a lot easier to add parsing/printing sugar to TVMScript than to change the TIR in C++. |
Thanks for the great update! This helps a lot with the usability of TVMScript :-) Let's get it in ASAP! |
…pache#13396) * [TVMScript] Use tir::Evaluate if expression is in statement context For the previous version of the parser, this was special-cased for some intrinsic operators. After the new TVMScript was enabled in apache#12496, any `PrimExpr` that appears in the body of a statement is silently ignored. This commit updates the parser to instead wrap the bare `PrimExpr` in a `tir::Evaluate` node. This change effectively allows [expression statements](https://docs.python.org/3/reference/simple_stmts.html#expression-statements) in TVMScript, which are converted to `tir::Evaluate` nodes during parsing. * Update to print T.evaluate() for readability, except for CallNode
For the previous version of the parser, this was special-cased for some intrinsic operators. After the new TVMScript was enabled in #12496, any
PrimExpr
that appears in the body of a statement is silently ignored. This commit updates the parser to instead wrap the barePrimExpr
in atir::Evaluate
node.This change effectively allows expression statements in TVMScript, which are converted to
tir::Evaluate
nodes during parsing.