Only add one LDS Barrier for one wave blockSizes#2253
Open
umangyadav wants to merge 3 commits intobarrierFixfrom
Open
Only add one LDS Barrier for one wave blockSizes#2253umangyadav wants to merge 3 commits intobarrierFixfrom
umangyadav wants to merge 3 commits intobarrierFixfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements an optimization that skips backward LDS barriers for single-wave GPU kernels with specific schedule versions (1 and 3) during loop pipelining. The motivation is that when a workgroup consists of only one wave (blockSize ≤ waveSize), the GPU's in-order instruction execution within the wave eliminates the need for explicit synchronization barriers between iterations.
Changes:
- Added
canSkipBackwardBarrierForOneWave()function to determine when backward barriers can be safely skipped - Modified
placeBarriers()to accept the parent function and conditionally skip backward barriers for single-wave cases - Added comprehensive test coverage including unit tests and end-to-end tests for various scheduleVersions and data types
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| mlir/lib/Dialect/Rock/Transforms/RockPipeline.cpp | Core implementation: added barrier optimization logic and modified placeBarriers signature |
| mlir/test/Dialect/Rock/test_rock_pipeline_wave_barrier.mlir | Unit tests covering single-wave (scheduleVersion 1,3), multi-wave, and different scheduleVersions |
| mlir/test/Dialect/Rock/rock-pipeline-early-exit.mlir | Added arch attribute to existing test function to ensure compatibility |
| mlir/test/e2e/GemmOneWaveBarrier.toml | E2E test for single-wave GEMM with scheduleVersion=1 |
| mlir/test/e2e/GemmOneWaveBarrierDirectToLDS.toml | E2E test for single-wave GEMM with scheduleVersion=3 (DirectToLDS) |
| mlir/test/e2e/GemmOneWaveBarrierFp8.toml | E2E test for single-wave GEMM with fp8 data types |
| mlir/test/e2e/PrGemmOneWaveBarrier.toml | PR-specific test for single-wave GEMM optimization |
| mlir/test/e2e/PrGemmOneWaveBarrierDirectToLDS.toml | PR-specific test for DirectToLDS variant |
| mlir/test/e2e/*.cfg | Configuration files specifying hardware requirements for each test |
| mlir/test/e2e/CMakeLists.txt | Added new test suites to the build system |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Motivation
Depends on #2250
For schedule=1 after loop pipelining, it generates following program after barrier placement and before loop pipelining
After loop pipelining and pushDownBarrier it becomes this
In here it requires bwd_barrier for loop carried dependency which makes sure that all waves within workgroup have finished issuing and reading from LDS buffers before continuing to next iteration of for loop which again writes to same LDS buffer. Waves can be out of sync therefore this barrier ensures the Reads from all waves have finished before writing into same buffer.
For the special case of
blockSize = 1xWaveSize, we don't need to wait for all the waves as there is only one wave. Just issuing DSReads is enough and we don't have to wait it to finish before proceeding to next iteration.Therefore for that case we can skip adding
__bwd_barrier__Technical Details
Currently this is only enabled for single For loop and therefore only GEMMs and Convs. Nested for loop may require additional analysis across the loops.
Test Plan
Added new tests with blockSize = 1xWaveSize