-
Notifications
You must be signed in to change notification settings - Fork 609
[Fix][Pipeline] Prevent double expansion of shared buffers across sibling pipelines #2342
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
Open
harelhuang
wants to merge
3
commits into
tile-ai:main
Choose a base branch
from
harelhuang:fix/sibling-pipeline-shared-buffer-cuda
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Copyright (c) 2025 Tile-AI Corporation. | ||
| # Licensed under the MIT License. | ||
| """Tests for sibling pipeline shared buffer handling (issue #2309). | ||
|
|
||
| When two sibling T.Pipelined loops share the same alloc_shared buffer but use | ||
| different num_stages, the first pipeline expands the buffer from 2D to 3D, and | ||
| the second pipeline must not re-expand the already-3D buffer (which would | ||
| produce a 4D buffer and crash LayoutInference). | ||
| """ | ||
|
|
||
| import tilelang | ||
| import tilelang.language as T | ||
| import tilelang.testing | ||
|
|
||
|
|
||
| def run_asymmetric_pipeline(): | ||
| """Sibling pipelines sharing alloc_shared buffers with different num_stages.""" | ||
| M, N, K = 512, 512, 512 | ||
| BM, BN, BK = 64, 64, 32 | ||
|
|
||
| @T.prim_func | ||
| def asymmetric_stages( | ||
| A: T.Tensor((M, K), T.float16), | ||
| B: T.Tensor((K, N), T.float16), | ||
| C: T.Tensor((M, N), T.float16), | ||
| ): | ||
| K_half = K // 2 | ||
| with T.Kernel(T.ceildiv(N, BN), T.ceildiv(M, BM), threads=128) as (bx, by): | ||
| A_shared = T.alloc_shared((BM, BK), T.float16) | ||
| B_shared = T.alloc_shared((BK, BN), T.float16) | ||
| C_local = T.alloc_fragment((BM, BN), T.float32) | ||
|
|
||
| T.clear(C_local) | ||
|
|
||
| for ko in T.Pipelined(T.ceildiv(K_half, BK), num_stages=2): | ||
| T.copy(A[by * BM, ko * BK], A_shared) | ||
| T.copy(B[ko * BK, bx * BN], B_shared) | ||
| T.gemm(A_shared, B_shared, C_local) | ||
|
|
||
| for ko in T.Pipelined(T.ceildiv(K_half, BK), num_stages=4): | ||
| T.copy(A[by * BM, K_half + ko * BK], A_shared) | ||
| T.copy(B[K_half + ko * BK, bx * BN], B_shared) | ||
| T.gemm(A_shared, B_shared, C_local) | ||
|
|
||
| T.copy(C_local, C[by * BM, bx * BN]) | ||
|
|
||
| kernel = tilelang.compile( | ||
| asymmetric_stages, | ||
| out_idx=[2], | ||
| pass_configs={tilelang.PassConfigKey.TL_DISABLE_WARP_SPECIALIZED: True}, | ||
| ) | ||
|
|
||
| profiler = kernel.get_profiler() | ||
|
|
||
| def ref_program(A, B): | ||
| import torch | ||
|
|
||
| C = torch.matmul(A.to(torch.float), B.to(torch.float)) | ||
| C = C.to(torch.float16) | ||
| return C | ||
|
|
||
| profiler.assert_allclose(ref_program, atol=1e-2, rtol=1e-2) | ||
|
|
||
|
|
||
| def test_sibling_pipeline_different_num_stages(): | ||
| """Reproducer for issue #2309: sibling pipelines with different num_stages | ||
| sharing alloc_shared buffers should compile and run correctly.""" | ||
| run_asymmetric_pipeline() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| tilelang.testing.main() |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.