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

[TIR, TVMScript] Update printer / parser to make T.allocate return buffer var #12412

Merged
merged 8 commits into from
Aug 31, 2022

Conversation

vinx13
Copy link
Member

@vinx13 vinx13 commented Aug 12, 2022

  • Updated TVMScript syntax of T.allocate to return buffer var.
  • Added syntax sugar for T.decl_buffer. When data field is not specified, data will be implicitly created via Allocate stmt.
  • Updated the existing test cases. Most test cases can be updated by changing T.allocate to T.decl_buffer. T.allocate in some tests are updated to T.allocate + T.buffer_decl, to maintain the legacy behavior of allocation and implicit buffer declaration (will be followed up in future PR to adopt T.decl_buffer).

Related RFC: apache/tvm-rfcs#87

cc @junrushao1994 @Lunderberg @wrongtest-intellif @cyx-6 @tqchen

@github-actions github-actions bot requested a review from Lunderberg August 12, 2022 19:53
@vinx13 vinx13 force-pushed the feat/decl-buffer-1-tvmscript branch from 628b844 to f2a0a1a Compare August 12, 2022 20:41
@vinx13 vinx13 force-pushed the feat/decl-buffer-1-tvmscript branch 8 times, most recently from 1f07d88 to 45a5ac8 Compare August 16, 2022 04:02
Copy link
Contributor

@Lunderberg Lunderberg left a comment

Choose a reason for hiding this comment

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

Looks good! I have a couple of questions on the implementation side, but overall it looks very good!

@@ -100,13 +100,21 @@ class BufferUsageFinder : public StmtExprVisitor {
StmtExprVisitor::VisitStmt_(op);
}

void VisitStmt_(const DeclBufferNode* op) final {
buffers_declared_.insert(op->buffer.get());
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also track which buffers have gone out of scope? If I'm understanding it correctly, a single DeclBufferNode would also allow for usage outside of the DeclBufferNode::body, where I'd expect it to only apply within the scope of the node.

src/printer/tvmscript_printer.cc Outdated Show resolved Hide resolved
src/printer/tvmscript_printer.cc Show resolved Hide resolved
tests/python/unittest/test_tir_renew_defs.py Show resolved Hide resolved
src/printer/tvmscript_printer.cc Outdated Show resolved Hide resolved
Copy link
Member Author

@vinx13 vinx13 left a comment

Choose a reason for hiding this comment

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

To answer the question about T.allocate vs T.decl_buffer update:
There are two ways to update the existing TVM scripts.

  1. Update T.allocate to T.allocate + T.buffer_decl. This is strictly equivalent to the TIR before.
  2. Update T.allocate to T.allocate + T.decl_buffer, (or the syntax sugar form, only a single T.decl_buffer statement without data argument). This adds a DeclBuffer node in TIR, which is not strictly equivalent to the TIR before. This is the preferred way (as it uses explicit DeclBuffer) but might require updating the existing passes. To minimize changes to existing passes in this PR, in the case this method doesn't work out-of-box, we will choose method 1 for now.

src/printer/tvmscript_printer.cc Outdated Show resolved Hide resolved
src/printer/tvmscript_printer.cc Show resolved Hide resolved
src/printer/tvmscript_printer.cc Outdated Show resolved Hide resolved
@Lunderberg
Copy link
Contributor

That makes sense for minimizing the changes to the generated TIR, so that those can be handled in an independent change. Marking all of those conversations as resolved.

@vinx13 vinx13 force-pushed the feat/decl-buffer-1-tvmscript branch from 45a5ac8 to 071b81d Compare August 30, 2022 21:54
Copy link
Contributor

@Lunderberg Lunderberg left a comment

Choose a reason for hiding this comment

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

LGTM!

xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
…ffer var (apache#12412)

* Updated TVMScript syntax of `T.allocate` to return buffer var.

* Added syntax sugar for `T.decl_buffer`. When `data` field is not
  specified, `data` will be implicitly created via `Allocate` stmt.
  
* Updated the existing test cases. Most test cases can be updated by
  changing `T.allocate` to `T.decl_buffer`. `T.allocate` in some tests
  are updated to `T.allocate` + `T.buffer_decl`, to maintain the
  legacy behavior of allocation and implicit buffer declaration (will
  be followed up in future PR to adopt `T.decl_buffer`).
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.

2 participants