-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[TIR][Transform] Add LiftThreadBinding Pass #15207
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
jinhongyii
merged 1 commit into
apache:main
from
junrushao:feature/2023-07-02/lift-thread-binding
Jul 3, 2023
Merged
[TIR][Transform] Add LiftThreadBinding Pass #15207
jinhongyii
merged 1 commit into
apache:main
from
junrushao:feature/2023-07-02/lift-thread-binding
Jul 3, 2023
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
This PR adds a pass LiftThreadBinding to TIR.
Previously, during GPU cross-thread reduction, a temporary local buffer
will be created in the RF buffer, as a concrete example:
```python
rf_local = T.alloc_buffer(..., scope="local")
// Step 1. Data parallel RF block
for tx in T.thread_binding(..., thread="threadIdx.x")
rf_local[tx, ...] =
// Step 2. Cross-thread reduction to accumuate rf_local
for ...:
for tx' in T.thread_binding(..., thread="threadIdx.x"):
... += rf_local[tx', ...]
```
In this case, the buffer `rf_local` will only be accessed by a single
point `tx` or `tx'`, but during the pass `CompactBuffeRegion`, the two
variables as thread bindings are treated as two separate variables, i.e.
the information that `tx` and `tx'` are always identical to each other
is discarded, which means the accessed region on `rf_local` are
estimated as `Union({tx}, {tx'})` as opposed to `{tx}`, leading over
allocation of local registers.
This pass is introduced to address this issue by lifting thread bindings
to their LCAs.
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 |
3 tasks
tqchen
reviewed
Jul 3, 2023
jinhongyii
approved these changes
Jul 3, 2023
junrushao
added a commit
to junrushao/tvm
that referenced
this pull request
Jul 4, 2023
This PR enhances Decode-GEMV rule with the following changes: - Normalize the GEMV iter domain to S-R-C via transform-block-layout. This would help with further analysis and scheduling, in cases for example, when there was no spatial loop in the original reduction block. - Get rid of the ad hoc iter type analysis, including the logic calling into a TVM packed func `tir.schedule.GetLoopIterType` using `tvm._ffi.get_global_func`. - Split out the logic for two separate cases of scheduling, where the innermost dimension is spatial or reduction. - Introduces `suggest_threads_per_block` to guess the threads to be allocated each threadblock. This helps avoid the previous case where dlight allocates 256 threads for a workload whose degree of parallelism is only 128. - Misc improvements. This rest of the changes are split out to separate PRs that are already merged to main. - [x] Pass the hints to arithmetic analyzer that shape variables should be positive ones (apache#15210) - [x] Eliminate unnecessary block predicate generation - should be provable via affine analysis (apache#15193) - [x] Shrink local memory allocation if only one element `X[threadIdx.x]` is used (apache#15207)
junrushao
added a commit
to junrushao/tvm
that referenced
this pull request
Jul 4, 2023
This PR enhances Decode-GEMV rule with the following changes: - Normalize the GEMV iter domain to S-R-C via transform-block-layout. This would help with further analysis and scheduling, in cases for example, when there was no spatial loop in the original reduction block. - Get rid of the ad hoc iter type analysis, including the logic calling into a TVM packed func `tir.schedule.GetLoopIterType` using `tvm._ffi.get_global_func`. - Split out the logic for two separate cases of scheduling, where the innermost dimension is spatial or reduction. - Introduces `suggest_threads_per_block` to guess the threads to be allocated each threadblock. This helps avoid the previous case where dlight allocates 256 threads for a workload whose degree of parallelism is only 128. - Misc improvements. This rest of the changes are split out to separate PRs that are already merged to main. - [x] Pass the hints to arithmetic analyzer that shape variables should be positive ones (apache#15210) - [x] Eliminate unnecessary block predicate generation - should be provable via affine analysis (apache#15193) - [x] Shrink local memory allocation if only one element `X[threadIdx.x]` is used (apache#15207)
junrushao
added a commit
to junrushao/tvm
that referenced
this pull request
Jul 4, 2023
This PR enhances Decode-GEMV rule with the following changes: - Normalize the GEMV iter domain to S-R-C via transform-block-layout. This would help with further analysis and scheduling, in cases for example, when there was no spatial loop in the original reduction block. - Get rid of the ad hoc iter type analysis, including the logic calling into a TVM packed func `tir.schedule.GetLoopIterType` using `tvm._ffi.get_global_func`. - Split out the logic for two separate cases of scheduling, where the innermost dimension is spatial or reduction. - Introduces `suggest_threads_per_block` to guess the threads to be allocated each threadblock. This helps avoid the previous case where dlight allocates 256 threads for a workload whose degree of parallelism is only 128. - Misc improvements. This rest of the changes are split out to separate PRs that are already merged to main. - [x] Pass the hints to arithmetic analyzer that shape variables should be positive ones (apache#15210) - [x] Eliminate unnecessary block predicate generation - should be provable via affine analysis (apache#15193) - [x] Shrink local memory allocation if only one element `X[threadIdx.x]` is used (apache#15207)
junrushao
added a commit
to junrushao/tvm
that referenced
this pull request
Jul 4, 2023
This PR enhances Decode-GEMV rule with the following changes: - Normalize the GEMV iter domain to S-R-C via transform-block-layout. This would help with further analysis and scheduling, in cases for example, when there was no spatial loop in the original reduction block. - Get rid of the ad hoc iter type analysis, including the logic calling into a TVM packed func `tir.schedule.GetLoopIterType` using `tvm._ffi.get_global_func`. - Split out the logic for two separate cases of scheduling, where the innermost dimension is spatial or reduction. - Introduces `suggest_threads_per_block` to guess the threads to be allocated each threadblock. This helps avoid the previous case where dlight allocates 256 threads for a workload whose degree of parallelism is only 128. - Misc improvements. This rest of the changes are split out to separate PRs that are already merged to main. - [x] Pass the hints to arithmetic analyzer that shape variables should be positive ones (apache#15210) - [x] Eliminate unnecessary block predicate generation - should be provable via affine analysis (apache#15193) - [x] Shrink local memory allocation if only one element `X[threadIdx.x]` is used (apache#15207)
junrushao
added a commit
to junrushao/tvm
that referenced
this pull request
Jul 5, 2023
This PR enhances Decode-GEMV rule with the following changes: - Normalize the GEMV iter domain to S-R-C via transform-block-layout. This would help with further analysis and scheduling, in cases for example, when there was no spatial loop in the original reduction block. - Get rid of the ad hoc iter type analysis, including the logic calling into a TVM packed func `tir.schedule.GetLoopIterType` using `tvm._ffi.get_global_func`. - Split out the logic for two separate cases of scheduling, where the innermost dimension is spatial or reduction. - Introduces `suggest_threads_per_block` to guess the threads to be allocated each threadblock. This helps avoid the previous case where dlight allocates 256 threads for a workload whose degree of parallelism is only 128. - Misc improvements. This rest of the changes are split out to separate PRs that are already merged to main. - [x] Pass the hints to arithmetic analyzer that shape variables should be positive ones (apache#15210) - [x] Eliminate unnecessary block predicate generation - should be provable via affine analysis (apache#15193) - [x] Shrink local memory allocation if only one element `X[threadIdx.x]` is used (apache#15207)
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 adds a pass LiftThreadBinding to TIR.
Previously, during GPU cross-thread reduction, a temporary local buffer will be created in the RF buffer, as a concrete example:
In this case, the buffer
rf_localwill only be accessed by a single pointtxortx', but during the passCompactBuffeRegion, the two variables as thread bindings are treated as two separate variables, i.e. the information thattxandtx'are always identical to each other is discarded, which means the accessed region onrf_localare estimated asUnion({tx}, {tx'})as opposed to{tx}, leading over allocation of local registers.This pass is introduced to address this issue by lifting thread bindings to their LCAs.