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] Comments and docstrings printing #13839

Merged
merged 2 commits into from
Jan 26, 2023

Conversation

cyx-6
Copy link
Contributor

@cyx-6 cyx-6 commented Jan 25, 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.

# 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,

# from tvm.script import ir as I
# from tvm.script import tir as T

@I.ir_module
class Module():
  @T.prim_func
  def func():
    ...

@tvm-bot
Copy link
Collaborator

tvm-bot commented Jan 25, 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

@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.

Thanks for brining in this change!

BTW, for IRModule and PrimFunc printing, would you like to add a couple of lines of comments for clarify:

# from tvm.script import ir as I      # if `IR(...)` is ever used
# from tvm.script import tir as T   # if `TIR(...)` is ever used

@I.ir_module
class Module()

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.

Perfect. Please address my comment above and fix the lint, and we are good to go!

@junrushao junrushao merged commit 697fdb2 into apache:main Jan 26, 2023
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants