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

[usmp] Also remap VarNode to USMP-allocated buffer #12880

Merged
merged 3 commits into from
Sep 27, 2022

Conversation

areusch
Copy link
Contributor

@areusch areusch commented Sep 23, 2022

This PR fixes cases where a USMP buffer is used with tensorization intrinsics. In these cases, it is common to
write schedules that pass Buffers to extern functions using access_ptr(). When transforming tir.allocate into
offsets into global_workspace buffers, USMP inserts a let expression that replaces the old Buffer var with a new
var named "<buffer_var>_let." It then attempts to replace all references to the old var with the new one. When
a Buffer was passed via access_ptr, USMP would would previously ignore such instances, producing this error
later on in codegen (dense being the name of the Buffer in use):

  "src/target/source/codegen_source_base.cc", line 67
  Check failed: (it != var_idmap_.end()) is false: Find undefined
    Variable dense

This patch fixes the problem by replacing the old VarNode with the new one.

cc @lhutton1 @Mousius @leandron @manupak @mehrdadh

 * Fixes cases where a USMP buffer is used with tensorization
   intrinsics. In these cases, the buffer data var is referenced
   directly in the call_extern args.

Before this patch, ConvertPoolAllocationsToOffsets would generate TIR
like the following:

  let dense_let: Pointer(global int32) = @tir.address_of(global_workspace_37_buffer_var[69952], dtype=handle)
  for (k.outer: int32, 0, 64) {
    @tir.call_extern("gemm_1x1x1_update_UKVNAEBL", ..., dense, ...)
  }

  T_multiply[ax1] = @tir.q_multiply_shift(((dense: Buffer(dense_let,
      int32, [10], [], align=32)[ax1], ...)

This caused CodegenSourceBase to later fail with this error:
  "src/target/source/codegen_source_base.cc", line 67
  Check failed: (it != var_idmap_.end()) is false: Find undefined
    Variable dense

After this patch, "dense" in the call_extern is changed to read "dense_let."
@areusch
Copy link
Contributor Author

areusch commented Sep 23, 2022

NOTE: sending this through CI to see what I broke, then will add tests.

@github-actions
Copy link
Contributor

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.

  • No users to tag found in teams See #10317 for details
  • No additional skipped tests found in this branch for commit 98798c7.
  • Built docs for commit 98798c7 can be found here.

Generated by tvm-bot

@lhutton1
Copy link
Contributor

also cc @d-smirnov

@manupak
Copy link
Contributor

manupak commented Sep 23, 2022

Hmmmm... I suppose this scenario want to pass a buffer itself to the call (as opposed to a BufferLoad) ?

@areusch
Copy link
Contributor Author

areusch commented Sep 24, 2022

@manupak I think it's ok to pass the buffer's data var, since the receiving function expects T.handle and will build its own Buffer around it, no? wdyt?

edit: I suppose I should test the call_packed case, though...

@manupak
Copy link
Contributor

manupak commented Sep 26, 2022

Thanks for the fix -- yea I double checked whether buffer info extraction captures this scenario as well -- it seems so. If we can get the tests and LOG(INFO)s removed -- I think we can get this in...

@areusch areusch mentioned this pull request Sep 26, 2022
7 tasks
@areusch areusch marked this pull request as ready for review September 26, 2022 22:24
@areusch
Copy link
Contributor Author

areusch commented Sep 26, 2022

@manupak great, deleted the LOG lines and added a test. please take a look!

Copy link
Contributor

@lhutton1 lhutton1 left a comment

Choose a reason for hiding this comment

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

Thanks @areusch, LGTM! Will leave for @manupak to take another look :)

Copy link
Contributor

@manupak manupak left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @areusch and @lhutton1

@manupak
Copy link
Contributor

manupak commented Sep 27, 2022

I think we need a commit message that is bit plain text and describes the changes.

@manupak
Copy link
Contributor

manupak commented Sep 27, 2022

to clarify a bit more -- I just meant to say, according to https://github.com/apache/tvm/blob/main/docs/contribute/pull_request.rst, we might want to put a textual description in here in the body as the test in the PR shows what is being fixed. Also I think we can remove the first bullet point too (just the bullet and replace it with a text describing the change).

I m happy merge this by taking that body in -- it felt odd to have a code example as a commit in the tree.

@areusch
Copy link
Contributor Author

areusch commented Sep 27, 2022

gotcha, updated the message.

@areusch areusch merged commit c89a8ba into apache:main Sep 27, 2022
AndrewZhaoLuo pushed a commit that referenced this pull request Sep 28, 2022
Before this patch, ConvertPoolAllocationsToOffsets would generate TIR
like the following:

  let dense_let: Pointer(global int32) = @tir.address_of(global_workspace_37_buffer_var[69952], dtype=handle)
  for (k.outer: int32, 0, 64) {
    @tir.call_extern("gemm_1x1x1_update_UKVNAEBL", ..., dense, ...)
  }

  T_multiply[ax1] = @tir.q_multiply_shift(((dense: Buffer(dense_let,
      int32, [10], [], align=32)[ax1], ...)

This caused CodegenSourceBase to later fail with this error:
  "src/target/source/codegen_source_base.cc", line 67
  Check failed: (it != var_idmap_.end()) is false: Find undefined
    Variable dense

After this patch, "dense" in the call_extern is changed to read "dense_let."
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
Before this patch, ConvertPoolAllocationsToOffsets would generate TIR
like the following:

  let dense_let: Pointer(global int32) = @tir.address_of(global_workspace_37_buffer_var[69952], dtype=handle)
  for (k.outer: int32, 0, 64) {
    @tir.call_extern("gemm_1x1x1_update_UKVNAEBL", ..., dense, ...)
  }

  T_multiply[ax1] = @tir.q_multiply_shift(((dense: Buffer(dense_let,
      int32, [10], [], align=32)[ax1], ...)

This caused CodegenSourceBase to later fail with this error:
  "src/target/source/codegen_source_base.cc", line 67
  Check failed: (it != var_idmap_.end()) is false: Find undefined
    Variable dense

After this patch, "dense" in the call_extern is changed to read "dense_let."
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