Open
Conversation
Member
xiaohuguo2023
commented
Mar 13, 2026
- add stream-k mxfp4 kernel
- add unit and perf tests
…te of LDS usage and filter out those tile sizes that exceed LDS compacity
…ath for padding size estimation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…ile tracing: is_compiling() returns True, so the condition is False, and we fall through to torch.empty(...) which FakeTensorMode can handle properly
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds Stream‑K load balancing support for FP4 GEMM in tritonblas, along with an expanded FP4 test/benchmark suite and a pytest marker for performance benchmarks.
Changes:
- Add a new Triton kernel implementing Stream‑K for FP4 matmul and wire it into the
matmul_fp4dispatch. - Extend FP4 tests to cover Stream‑K correctness/behavior and add Stream‑K performance benchmark tests.
- Register a
performancepytest marker inpyproject.toml.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
include/tritonblas/matmul.py |
Adds FP4 Stream‑K dispatch and scratch-buffer handling; updates Stream‑K buffer reuse logic. |
include/tritonblas/kernels/fp4_streamk_gemm.py |
New FP4 Stream‑K GEMM Triton kernel implementation. |
include/tritonblas/kernels/__init__.py |
Exports the new FP4 Stream‑K kernel symbol. |
tests/test_matmul_fp4.py |
Adds Stream‑K FP4 correctness tests and multiple Stream‑K benchmark tests. |
pyproject.toml |
Defines the performance pytest marker. |
Comments suppressed due to low confidence (1)
include/tritonblas/matmul.py:201
- Global Stream-K scratch buffers (
_global_locks/_global_P) are allocated once on the default CUDA device at import time. The reuse path here does not verify thata.devicematches those buffers, which can crash or silently misbehave when matmul runs on a non-default GPU (e.g. cuda:1). Consider gating reuse on device match (or keeping a per-device cache of scratch buffers) and falling back to per-call allocation otherwise.
# Reuse pre-allocated global buffers at runtime, but allocate fresh during
# torch.compile tracing (FakeTensorMode cannot slice real tensors).
if not torch.compiler.is_compiling() and grids <= MAX_SMS and block_size <= MAX_BLOCK_SIZE:
locks = _global_locks[:grids]
P = _global_P[:grids, :block_size]
else:
locks = torch.empty(grids, device=a.device, dtype=torch.uint8)
P = torch.empty(grids, block_size, device=a.device, dtype=torch.float32)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
568
to
576
| def matmul_fp4( | ||
| a: torch.Tensor, | ||
| b: torch.Tensor, | ||
| c: torch.Tensor, | ||
| a_scales: torch.Tensor, | ||
| b_scales: torch.Tensor, | ||
| block_m: int = None, #Overrides Origami value | ||
| block_n: int = None, #Overrides Origami value | ||
| block_k: int = None, #Overrides Origami value | ||
| group_size_m: int = 8, #Overrides Origami value | ||
| num_warps: int = 8, | ||
| num_stages: int = 2, | ||
| enable_streamk: bool = False, | ||
| sk_grid: Optional[int] = None, | ||
| ): |
Comment on lines
+531
to
+540
| grids = total_programs_streamk | ||
| block_size = BLK_M * BLK_N | ||
|
|
||
| if not torch.compiler.is_compiling() and grids <= MAX_SMS and block_size <= MAX_BLOCK_SIZE: | ||
| locks = _global_locks[:grids] | ||
| P = _global_P[:grids, :block_size] | ||
| else: | ||
| locks = torch.empty(grids, device=a.device, dtype=torch.uint8) | ||
| P = torch.empty(grids, block_size, device=a.device, dtype=torch.float32) | ||
|
|
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.