[TIR] Keep trivial LetStmt in tir.Simplify when used in buffer decl#14951
Merged
masahi merged 1 commit intoapache:mainfrom Jun 4, 2023
Merged
Conversation
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 |
Lunderberg
added a commit
to Lunderberg/tvm
that referenced
this pull request
May 25, 2023
Prior to this commit, `ArgBinder` would always introduce a new variable to represent the input argument, even if the argument already a primitive type. This introduces trivial let bindings that are expected to be simplified out, but which can produce dangling `tir::Var` usage in some cases (see apache#14951). This commit updates `ArgBinder` to prefer using the original `tir::Var` when possible. That is, when a function takes `n: T.int32` as input, the packed function should produce a binding `n: T.int32 = T.tvm_struct_get(...)`, rather than producing a binding `arg_n = T.tvm_struct_get(...)` followed by `n = arg_n`.
Contributor
Author
|
@tvm-bot rerun |
masahi
pushed a commit
that referenced
this pull request
May 28, 2023
Prior to this commit, `ArgBinder` would always introduce a new variable to represent the input argument, even if the argument already a primitive type. This introduces trivial let bindings that are expected to be simplified out, but which can produce dangling `tir::Var` usage in some cases (see #14951). This commit updates `ArgBinder` to prefer using the original `tir::Var` when possible. That is, when a function takes `n: T.int32` as input, the packed function should produce a binding `n: T.int32 = T.tvm_struct_get(...)`, rather than producing a binding `arg_n = T.tvm_struct_get(...)` followed by `n = arg_n`.
c62c8cf to
6dce15b
Compare
Lunderberg
added a commit
to Lunderberg/tvm
that referenced
this pull request
May 30, 2023
The functionality tested in this commit was added across several recent PRs, each of which tested their features in isolation. This PR adds unit tests to validate the end-to-end behavior of TIR subroutine calls. PRs building up to this point: - TVMScript - apache#14889 - apache#14915 - apache#14919 - apache#14941 - Functionality improvements of existing TIR passes - apache#14913 - apache#14914 - apache#14918 - apache#14951 - Changes to the TIR lowering flow - apache#14942 - apache#14985 - Codegen updates - apache#14958 - apache#14901 - Compatibility updates/fixes - apache#14892 - apache#14950 - apache#14943 - apache#14944 - apache#14945 - apache#14952 - apache#14982 - apache#14949
mei-ye
pushed a commit
to mei-ye/tvm
that referenced
this pull request
Jun 1, 2023
Prior to this commit, `ArgBinder` would always introduce a new variable to represent the input argument, even if the argument already a primitive type. This introduces trivial let bindings that are expected to be simplified out, but which can produce dangling `tir::Var` usage in some cases (see apache#14951). This commit updates `ArgBinder` to prefer using the original `tir::Var` when possible. That is, when a function takes `n: T.int32` as input, the packed function should produce a binding `n: T.int32 = T.tvm_struct_get(...)`, rather than producing a binding `arg_n = T.tvm_struct_get(...)` followed by `n = arg_n`.
Lunderberg
added a commit
to Lunderberg/tvm
that referenced
this pull request
Jun 2, 2023
Prior to apache#14951, these can have erroneous simplifications when used in buffer definitions.
masahi
approved these changes
Jun 2, 2023
| return mod | ||
|
|
||
|
|
||
| class TestSplitHostDevice(BaseCompare): |
Contributor
Author
There was a problem hiding this comment.
Hmm, it was a dup from #14982, which I had based this PR on top of to make allow the CI to use that bugfix. I think the "squash and merge" should remove it from this PR as part of merging, but just to be on the safe side, rebasing onto main.
Contributor
Author
There was a problem hiding this comment.
And after rebase, no changes remain in test_tir_transform_split_host_device.py.
Prior to this commit, any trivial let binding of `var1 = var2` is
inlined. However, buffer definitions are not updated, so this can
result in dangling `tir::Var` instances. This commit updates the
`tir.Simplify` pass to keep trivial let bindings if they are used as
part of a buffer definition.
Ideally, the trivial `LetStmt` variable would be inlined into the
buffer definition as well as other expressions. However, because a
buffer may be implicitly declared, the first usage may be within a
constrained context. If that happens, the simplified shape/strides
expression cannot be used to update the buffer definition, as that
simplification is not valid at all possible usage points of the
buffer.
```python
for i in range(n):
elem_offset = i
view = T.Buffer(1, data=buf, elem_offset = elem_offset)
if i == 0:
# First occurrence in TIR is here, where elem_offset would
# simplify to zero.
view[0] = 1
else:
# But the same buffer is used here, where elem_offset doesn't
# simplify to zero.
view[0] = 2
```
This will be resolvable after apache#14778
lands, requiring all buffers to be declared with `DeclBuffer` prior to
usage.
```python
for i in range(n):
elem_offset = i
# All variables used by the DeclBuffer are valid across the entire
# body of the DeclBuffer.
view = T.decl_buffer(1, data=buf, elem_offset = elem_offset)
if i == 0:
view[0] = 1
else:
view[0] = 2
```
6dce15b to
d0c9df2
Compare
Lunderberg
added a commit
to Lunderberg/tvm
that referenced
this pull request
Jun 3, 2023
Prior to apache#14951, these can have erroneous simplifications when used in buffer definitions.
Lunderberg
added a commit
to Lunderberg/tvm
that referenced
this pull request
Jun 5, 2023
Prior to apache#14951, these can have erroneous simplifications when used in buffer definitions.
Lunderberg
added a commit
to Lunderberg/tvm
that referenced
this pull request
Jun 6, 2023
Prior to apache#14951, these can have erroneous simplifications when used in buffer definitions. While they no longer cause issues with correct-ness, they are unnecessary in this case.
Lunderberg
added a commit
to Lunderberg/tvm
that referenced
this pull request
Jun 10, 2023
The functionality tested in this commit was added across several recent PRs, each of which tested their features in isolation. This PR adds unit tests to validate the end-to-end behavior of TIR subroutine calls. PRs building up to this point: - TVMScript - apache#14889 - apache#14915 - apache#14919 - apache#14941 - Functionality improvements of existing TIR passes - apache#14913 - apache#14914 - apache#14918 - apache#14951 - Changes to the TIR lowering flow - apache#14942 - apache#14985 - Codegen updates - apache#14958 - apache#14901 - Compatibility updates/fixes - apache#14892 - apache#14950 - apache#14943 - apache#14944 - apache#14945 - apache#14952 - apache#14982 - apache#14949
csullivan
pushed a commit
that referenced
this pull request
Jun 15, 2023
Prior to #14951, these can have erroneous simplifications when used in buffer definitions. While they no longer cause issues with correct-ness, they are unnecessary in this case.
Lunderberg
added a commit
to Lunderberg/tvm
that referenced
this pull request
Jun 16, 2023
The functionality tested in this commit was added across several recent PRs, each of which tested their features in isolation. This PR adds unit tests to validate the end-to-end behavior of TIR subroutine calls. PRs building up to this point: - TVMScript - apache#14889 - apache#14915 - apache#14919 - apache#14941 - Functionality improvements of existing TIR passes - apache#14913 - apache#14914 - apache#14918 - apache#14951 - Changes to the TIR lowering flow - apache#14942 - apache#14985 - Codegen updates - apache#14958 - apache#14901 - Compatibility updates/fixes - apache#14892 - apache#14950 - apache#14943 - apache#14944 - apache#14945 - apache#14952 - apache#14982 - apache#14949
Lunderberg
added a commit
to Lunderberg/tvm
that referenced
this pull request
Jun 16, 2023
The functionality tested in this commit was added across several recent PRs, each of which tested their features in isolation. This PR adds unit tests to validate the end-to-end behavior of TIR subroutine calls. PRs building up to this point: - TVMScript - apache#14889 - apache#14915 - apache#14919 - apache#14941 - Functionality improvements of existing TIR passes - apache#14913 - apache#14914 - apache#14918 - apache#14951 - Changes to the TIR lowering flow - apache#14942 - apache#14985 - Codegen updates - apache#14958 - apache#14901 - Compatibility updates/fixes - apache#14892 - apache#14950 - apache#14943 - apache#14944 - apache#14945 - apache#14952 - apache#14982 - apache#14949
Lunderberg
added a commit
to Lunderberg/tvm
that referenced
this pull request
Jun 21, 2023
The functionality tested in this commit was added across several recent PRs, each of which tested their features in isolation. This PR adds unit tests to validate the end-to-end behavior of TIR subroutine calls. PRs building up to this point: - TVMScript - apache#14889 - apache#14915 - apache#14919 - apache#14941 - Functionality improvements of existing TIR passes - apache#14913 - apache#14914 - apache#14918 - apache#14951 - Changes to the TIR lowering flow - apache#14942 - apache#14985 - Codegen updates - apache#14958 - apache#14901 - Compatibility updates/fixes - apache#14892 - apache#14950 - apache#14943 - apache#14944 - apache#14945 - apache#14952 - apache#14982 - apache#14949
junrushao
pushed a commit
to junrushao/tvm
that referenced
this pull request
Jun 22, 2023
…pache#14951) Prior to this commit, any trivial let binding of `var1 = var2` is inlined. However, buffer definitions are not updated, so this can result in dangling `tir::Var` instances. This commit updates the `tir.Simplify` pass to keep trivial let bindings if they are used as part of a buffer definition. Ideally, the trivial `LetStmt` variable would be inlined into the buffer definition as well as other expressions. However, because a buffer may be implicitly declared, the first usage may be within a constrained context. If that happens, the simplified shape/strides expression cannot be used to update the buffer definition, as that simplification is not valid at all possible usage points of the buffer. ```python for i in range(n): elem_offset = i view = T.Buffer(1, data=buf, elem_offset = elem_offset) if i == 0: # First occurrence in TIR is here, where elem_offset would # simplify to zero. view[0] = 1 else: # But the same buffer is used here, where elem_offset doesn't # simplify to zero. view[0] = 2 ``` This will be resolvable after apache#14778 lands, requiring all buffers to be declared with `DeclBuffer` prior to usage. ```python for i in range(n): elem_offset = i # All variables used by the DeclBuffer are valid across the entire # body of the DeclBuffer. view = T.decl_buffer(1, data=buf, elem_offset = elem_offset) if i == 0: view[0] = 1 else: view[0] = 2 ```
Lunderberg
added a commit
to Lunderberg/tvm
that referenced
this pull request
Jul 3, 2023
The functionality tested in this commit was added across several recent PRs, each of which tested their features in isolation. This PR adds unit tests to validate the end-to-end behavior of TIR subroutine calls. PRs building up to this point: - TVMScript - apache#14889 - apache#14915 - apache#14919 - apache#14941 - Functionality improvements of existing TIR passes - apache#14913 - apache#14914 - apache#14918 - apache#14951 - Changes to the TIR lowering flow - apache#14942 - apache#14985 - Codegen updates - apache#14958 - apache#14901 - Compatibility updates/fixes - apache#14892 - apache#14950 - apache#14943 - apache#14944 - apache#14945 - apache#14952 - apache#14982 - apache#14949
Lunderberg
added a commit
to Lunderberg/tvm
that referenced
this pull request
Jul 4, 2023
The functionality tested in this commit was added across several recent PRs, each of which tested their features in isolation. This PR adds unit tests to validate the end-to-end behavior of TIR subroutine calls. PRs building up to this point: - TVMScript - apache#14889 - apache#14915 - apache#14919 - apache#14941 - Functionality improvements of existing TIR passes - apache#14913 - apache#14914 - apache#14918 - apache#14951 - Changes to the TIR lowering flow - apache#14942 - apache#14985 - Codegen updates - apache#14958 - apache#14901 - Compatibility updates/fixes - apache#14892 - apache#14950 - apache#14943 - apache#14944 - apache#14945 - apache#14952 - apache#14982 - apache#14949
Lunderberg
added a commit
to Lunderberg/tvm
that referenced
this pull request
Jul 5, 2023
The functionality tested in this commit was added across several recent PRs, each of which tested their features in isolation. This PR adds unit tests to validate the end-to-end behavior of TIR subroutine calls. PRs building up to this point: - TVMScript - apache#14889 - apache#14915 - apache#14919 - apache#14941 - Functionality improvements of existing TIR passes - apache#14913 - apache#14914 - apache#14918 - apache#14951 - Changes to the TIR lowering flow - apache#14942 - apache#14985 - Codegen updates - apache#14958 - apache#14901 - Compatibility updates/fixes - apache#14892 - apache#14950 - apache#14943 - apache#14944 - apache#14945 - apache#14952 - apache#14982 - apache#14949
Lunderberg
added a commit
to Lunderberg/tvm
that referenced
this pull request
Jul 6, 2023
The functionality tested in this commit was added across several recent PRs, each of which tested their features in isolation. This PR adds unit tests to validate the end-to-end behavior of TIR subroutine calls. PRs building up to this point: - TVMScript - apache#14889 - apache#14915 - apache#14919 - apache#14941 - Functionality improvements of existing TIR passes - apache#14913 - apache#14914 - apache#14918 - apache#14951 - Changes to the TIR lowering flow - apache#14942 - apache#14985 - Codegen updates - apache#14958 - apache#14901 - Compatibility updates/fixes - apache#14892 - apache#14950 - apache#14943 - apache#14944 - apache#14945 - apache#14952 - apache#14982 - apache#14949
Lunderberg
added a commit
to Lunderberg/tvm
that referenced
this pull request
Jul 7, 2023
The functionality tested in this commit was added across several recent PRs, each of which tested their features in isolation. This PR adds unit tests to validate the end-to-end behavior of TIR subroutine calls. PRs building up to this point: - TVMScript - apache#14889 - apache#14915 - apache#14919 - apache#14941 - Functionality improvements of existing TIR passes - apache#14913 - apache#14914 - apache#14918 - apache#14951 - Changes to the TIR lowering flow - apache#14942 - apache#14985 - Codegen updates - apache#14958 - apache#14901 - Compatibility updates/fixes - apache#14892 - apache#14950 - apache#14943 - apache#14944 - apache#14945 - apache#14952 - apache#14982 - apache#14949
Lunderberg
added a commit
to Lunderberg/tvm
that referenced
this pull request
Aug 8, 2023
The functionality tested in this commit was added across several recent PRs, each of which tested their features in isolation. This PR adds unit tests to validate the end-to-end behavior of TIR subroutine calls. PRs building up to this point: - TVMScript - apache#14889 - apache#14915 - apache#14919 - apache#14941 - Functionality improvements of existing TIR passes - apache#14913 - apache#14914 - apache#14918 - apache#14951 - Changes to the TIR lowering flow - apache#14942 - apache#14985 - Codegen updates - apache#14958 - apache#14901 - Compatibility updates/fixes - apache#14892 - apache#14950 - apache#14943 - apache#14944 - apache#14945 - apache#14952 - apache#14982 - apache#14949
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
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.
Prior to this commit, any trivial let binding of
var1 = var2is inlined. However, buffer definitions are not updated, so this can result in danglingtir::Varinstances. This commit updates thetir.Simplifypass to keep trivial let bindings if they are used as part of a buffer definition.Ideally, the trivial
LetStmtvariable would be inlined into the buffer definition as well as other expressions. However, because a buffer may be implicitly declared, the first usage may be within a constrained context. If that happens, the simplified shape/strides expression cannot be used to update the buffer definition, as that simplification is not valid at all possible usage points of the buffer.This will be resolvable after #14778 lands, requiring all buffers to be declared with
DeclBufferprior to usage.