-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[TVMScript] Implicit root block syntax sugar for TVMScript printer #13819
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Collaborator
|
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 |
junrushao
approved these changes
Jan 20, 2023
Member
junrushao
left a comment
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!
junrushao
reviewed
Jan 20, 2023
junrushao
pushed a commit
that referenced
this pull request
Jan 26, 2023
This PR introduces the `CommentDoc` for comments printing and `DocStringDoc` for docstring printing. It enables to add free comments and docstring as `stmt` in printing, e.g. ```python # comment 1 # comment 2 """ docstring 1 docstring 2 """ ``` The free here means to not be bound to any `stmt`, but acts as a single `stmt`, similar to `ExprStmtDoc` for `ExprDoc`. This PR also introduces an example for the `CommentDoc`, as follow up of #13819. In the old printer, we always print a `# with T.block("root"):`, when there is an implicit root block skipped when printing. For example, ``` @T.prim_func def main(): # with T.block("root"): a = T.alloc_buffer((128, 128)) for i, j in T.grid(128, 128): with T.block(""): ... ``` We bring this syntax reminder back in this PR. In addition, we introduce a field of `ir_usage` and `print_headers` into the printer configuration, to support the printing of headers for `IRModule` and `PrimFunc`. For example, ```python # from tvm.script import ir as I # from tvm.script import tir as T @I.ir_module class Module(): @T.prim_func def func(): ... ```
fzi-peccia
pushed a commit
to fzi-peccia/tvm
that referenced
this pull request
Mar 27, 2023
…pache#13819) This PR implements the syntax sugar of implicit root block for new TVMScript printer. This syntax sugar will skip the `T.block("root")`, when the root block realize is simple and we shall reconstruct that root block via `tvm::tir::ScriptComplete` when roundtripping. For example, it will change ```python @T.prim_func def root_block_explicitly(): with T.block("root"): a = T.alloc_buffer([128, 128]) for i, j in T.grid(128, 128): with T.block(): T.evaluate(0) ``` into ```python @T.prim_func def main(): a = T.alloc_buffer((128, 128)) for i, j in T.grid(128, 128): with T.block(""): T.evaluate(0) ```
fzi-peccia
pushed a commit
to fzi-peccia/tvm
that referenced
this pull request
Mar 27, 2023
This PR introduces the `CommentDoc` for comments printing and `DocStringDoc` for docstring printing. It enables to add free comments and docstring as `stmt` in printing, e.g. ```python # comment 1 # comment 2 """ docstring 1 docstring 2 """ ``` The free here means to not be bound to any `stmt`, but acts as a single `stmt`, similar to `ExprStmtDoc` for `ExprDoc`. This PR also introduces an example for the `CommentDoc`, as follow up of apache#13819. In the old printer, we always print a `# with T.block("root"):`, when there is an implicit root block skipped when printing. For example, ``` @T.prim_func def main(): # with T.block("root"): a = T.alloc_buffer((128, 128)) for i, j in T.grid(128, 128): with T.block(""): ... ``` We bring this syntax reminder back in this PR. In addition, we introduce a field of `ir_usage` and `print_headers` into the printer configuration, to support the printing of headers for `IRModule` and `PrimFunc`. For example, ```python # from tvm.script import ir as I # from tvm.script import tir as T @I.ir_module class Module(): @T.prim_func def func(): ... ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements the syntax sugar of implicit root block for new TVMScript printer. This syntax sugar will skip the
T.block("root"), when the root block realize is simple and we shall reconstruct that root block viatvm::tir::ScriptCompletewhen roundtripping. For example, it will changeinto