Repository navigation
fix: missing PDL wait on main_sf_load in sm103 blockscaled GEMM - #3279
Open
tianyuxbear wants to merge 1 commit into
Open
tianyuxbear wants to merge 1 commit into
tianyuxbear wants to merge 1 commit into
Conversation
|
This PR has been labeled |
|
This PR has been labeled |
5 of 11 tasks
feih-nv
added a commit
to feih-nv/flashinfer
that referenced
this pull request
Nov 13, 2026
…the duplicate mxfp8 zero-row test The barrier and fence before griddepcontrol.launch_dependents protect one consumer: CUTLASS's SM103 block-scaled GEMM, whose main_sf_load warp loads scale factors before its own wait_on_dependent_grids (NVIDIA/cutlass#3279). Review measured the barrier at +14-19% on fp4_quantize (k=7168, m <= 128, B200) and the partial shuffle mask at +14-15% on MXFP8 m=16/128, with no consumer that needs either there. Both are now compiled for __CUDA_ARCH__ == 1030 only (QUANT_PDL_TRIGGER_CTA_FENCE); elsewhere the kernels are main's. mxfp8_quantize returns before the launch for zero rows on the Python side since flashinfer-ai#8576 (test_mxfp8_quantize_empty), so test_mxfp8_quantize_zero_rows duplicated it; the launcher's early return and launch check stay for the other C++ callers.
feih-nv
added a commit
to feih-nv/flashinfer
that referenced
this pull request
Nov 13, 2026
The CTA barrier before griddepcontrol.launch_dependents and the group shuffle masks exist for one consumer, CUTLASS's SM103 block-scaled GEMM (NVIDIA/cutlass#3279), and cost every other architecture. They move to a separate PR gated to SM103; this one keeps the zero-row early returns and the launch checks, whose kernels are main's.
4 of 11 tasks
feih-nv
added a commit
to flashinfer-ai/flashinfer
that referenced
this pull request
Nov 16, 2026
…e checked (fp4_quantize, mxfp8_quantize) (#9377) <!-- .github/pull_request_template.md --> ## 📌 Description Launcher fixes for the TRT-LLM block-scale quantization kernels (`fp4_quantize`, `mxfp8_quantize`), from upstream TensorRT-LLM: the launcher hunks of [NVIDIA/TensorRT-LLM#19727](NVIDIA/TensorRT-LLM#19727) and [NVIDIA/TensorRT-LLM#19988](NVIDIA/TensorRT-LLM#19988). The kernels themselves are main's. The CTA barrier before the PDL trigger (NVIDIA/TensorRT-LLM#14668) was split out at review into #9445, gated to SM103, because it guards one consumer (CUTLASS's SM103 block-scaled GEMM, NVIDIA/cutlass#3279) and costs every other architecture. - **Zero-sized inputs return early and launches are checked.** `invokeFP4Quantization` and `invokeMxFP8Quantization` launched a zero-sized grid for `m == 0`, which fails with `cudaErrorInvalidValue` that the next CUDA call reports (`fp4_quantize(torch.empty(0, 64))` followed by any kernel raised `CUDA error: invalid argument` on main; the Python `mxfp8_quantize` entry already guards this since #8576). The launchers return before configuring the launch when `b`, `m` or `n` is 0, and the three `cudaLaunchKernelEx` calls are wrapped in `TLLM_CUDA_CHECK`. Output is unchanged for non-empty inputs. ## 🔍 Related Issues [NVIDIA/TensorRT-LLM#19727](NVIDIA/TensorRT-LLM#19727), [NVIDIA/TensorRT-LLM#19988](NVIDIA/TensorRT-LLM#19988). ## 🚀 Pull Request Checklist Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete. ### ✅ Pre-commit Checks - [x] I have installed `pre-commit` by running `pip install pre-commit` (or used your preferred method). - [x] I have installed the hooks with `pre-commit install`. - [x] I have run the hooks manually with `pre-commit run --all-files` and fixed any reported issues. > If you are unsure about how to set up `pre-commit`, see [the pre-commit documentation](https://pre-commit.com/). ## 🧪 Tests - [x] Tests have been added or updated as needed. - [x] All tests are passing (`unittest`, etc.). New: `test_fp4_quantize_zero_rows` (both scale-factor sizes, both layouts); it fails on main with `CUDA error: invalid argument` and passes here. `mxfp8_quantize` already returns before the launch for zero rows on the Python side (#8576, covered by `test_mxfp8_quantize_empty`), so no new test for it; the launcher's early return and launch check stay for the other C++ callers. `SHAPES` gains `(8, 4800)`: 600 column threads, so the 512-thread block finishes the row in a second pass of 88 threads and the scale-factor shuffle runs in a partially active warp; it is checked against the PyTorch reference like the other shapes and also exercises #9445's masks on SM103. Run on B200 (CUDA 13.0 CI container): `tests/utils/test_fp4_quantize.py -k "test_fp4_quantization or test_scale_swizzling or test_e2m1_dequantization or zero_rows"` and `tests/utils/test_fp8_quantize.py -k "test_mxfp8_quantize_torch or zero_rows"`: 502 passed, 168 skipped (CuTe-DSL / CPU variants), at FlashInfer `e3ebb9e7dd` + this commit. ## 🔬 Experimental Track <!-- Only for PRs submitted under the experimental policy (CONTRIBUTING.md → "Experimental APIs and Backends"). Leave this section untouched for normal PRs. --> - [ ] This PR is **experimental**: it adds or changes code under `flashinfer/experimental/` and/or an `@flashinfer_experimental_api`. Tracking issue: # - [ ] The tracking issue names an owner, the reason for the experimental path, and a graduation plan with a target release. - [ ] Core changes are limited to a thin entry point (signature, shared validation, feature-gate check, backend selection, handoff). - [ ] Tests live in `tests/experimental/` and were validated on the intended hardware; a runnable example is included. - [ ] Nothing is registered in `flashinfer/aot.py`, and no experimental backend is reachable from `backend="auto"` without `FLASHINFER_ALLOW_EXPERIMENTAL_AUTO_BACKENDS=1`. (Calling an `@flashinfer_experimental_api` or naming a backend explicitly is itself the opt-in and needs no environment variable.) - [ ] **Test scope declared below.** The experimental CI lane runs exactly these targets, so keep them as narrow as the change allows. <!-- Required for experimental PRs. Replace the commented lines below with your targets. Do not delete the fence or change its `experimental-tests` tag — the experimental-track watcher reads it verbatim to decide which targets to ask CI for. --> ```experimental-tests # One target per line: a directory or a file. (A pytest ::selector is not # supported -- the sharding runner cannot consume one.) Must be under # tests/experimental/ and must exist. Delete these comment lines and add yours, e.g. # # tests/experimental/test_my_backend.py # tests/experimental/my_backend/ # # Declaring the whole tree (tests/experimental/) is allowed but means every # experimental PR pays for every other feature's tests, in every matrix cell. ``` ## Reviewer Notes Kernel code is untouched; no perf effect. Review on the earlier revision measured its barrier at +14-19% on `fp4_quantize` and the partial mask at +14-15% on MXFP8 (B200); both now live in #9445 behind an SM103 gate.
kahyunnam
pushed a commit
to flashinfer-ai/flashinfer
that referenced
this pull request
Nov 17, 2026
…e checked (fp4_quantize, mxfp8_quantize) (#9377) <!-- .github/pull_request_template.md --> ## 📌 Description Launcher fixes for the TRT-LLM block-scale quantization kernels (`fp4_quantize`, `mxfp8_quantize`), from upstream TensorRT-LLM: the launcher hunks of [NVIDIA/TensorRT-LLM#19727](NVIDIA/TensorRT-LLM#19727) and [NVIDIA/TensorRT-LLM#19988](NVIDIA/TensorRT-LLM#19988). The kernels themselves are main's. The CTA barrier before the PDL trigger (NVIDIA/TensorRT-LLM#14668) was split out at review into #9445, gated to SM103, because it guards one consumer (CUTLASS's SM103 block-scaled GEMM, NVIDIA/cutlass#3279) and costs every other architecture. - **Zero-sized inputs return early and launches are checked.** `invokeFP4Quantization` and `invokeMxFP8Quantization` launched a zero-sized grid for `m == 0`, which fails with `cudaErrorInvalidValue` that the next CUDA call reports (`fp4_quantize(torch.empty(0, 64))` followed by any kernel raised `CUDA error: invalid argument` on main; the Python `mxfp8_quantize` entry already guards this since #8576). The launchers return before configuring the launch when `b`, `m` or `n` is 0, and the three `cudaLaunchKernelEx` calls are wrapped in `TLLM_CUDA_CHECK`. Output is unchanged for non-empty inputs. ## 🔍 Related Issues [NVIDIA/TensorRT-LLM#19727](NVIDIA/TensorRT-LLM#19727), [NVIDIA/TensorRT-LLM#19988](NVIDIA/TensorRT-LLM#19988). ## 🚀 Pull Request Checklist Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete. ### ✅ Pre-commit Checks - [x] I have installed `pre-commit` by running `pip install pre-commit` (or used your preferred method). - [x] I have installed the hooks with `pre-commit install`. - [x] I have run the hooks manually with `pre-commit run --all-files` and fixed any reported issues. > If you are unsure about how to set up `pre-commit`, see [the pre-commit documentation](https://pre-commit.com/). ## 🧪 Tests - [x] Tests have been added or updated as needed. - [x] All tests are passing (`unittest`, etc.). New: `test_fp4_quantize_zero_rows` (both scale-factor sizes, both layouts); it fails on main with `CUDA error: invalid argument` and passes here. `mxfp8_quantize` already returns before the launch for zero rows on the Python side (#8576, covered by `test_mxfp8_quantize_empty`), so no new test for it; the launcher's early return and launch check stay for the other C++ callers. `SHAPES` gains `(8, 4800)`: 600 column threads, so the 512-thread block finishes the row in a second pass of 88 threads and the scale-factor shuffle runs in a partially active warp; it is checked against the PyTorch reference like the other shapes and also exercises #9445's masks on SM103. Run on B200 (CUDA 13.0 CI container): `tests/utils/test_fp4_quantize.py -k "test_fp4_quantization or test_scale_swizzling or test_e2m1_dequantization or zero_rows"` and `tests/utils/test_fp8_quantize.py -k "test_mxfp8_quantize_torch or zero_rows"`: 502 passed, 168 skipped (CuTe-DSL / CPU variants), at FlashInfer `e3ebb9e7dd` + this commit. ## 🔬 Experimental Track <!-- Only for PRs submitted under the experimental policy (CONTRIBUTING.md → "Experimental APIs and Backends"). Leave this section untouched for normal PRs. --> - [ ] This PR is **experimental**: it adds or changes code under `flashinfer/experimental/` and/or an `@flashinfer_experimental_api`. Tracking issue: # - [ ] The tracking issue names an owner, the reason for the experimental path, and a graduation plan with a target release. - [ ] Core changes are limited to a thin entry point (signature, shared validation, feature-gate check, backend selection, handoff). - [ ] Tests live in `tests/experimental/` and were validated on the intended hardware; a runnable example is included. - [ ] Nothing is registered in `flashinfer/aot.py`, and no experimental backend is reachable from `backend="auto"` without `FLASHINFER_ALLOW_EXPERIMENTAL_AUTO_BACKENDS=1`. (Calling an `@flashinfer_experimental_api` or naming a backend explicitly is itself the opt-in and needs no environment variable.) - [ ] **Test scope declared below.** The experimental CI lane runs exactly these targets, so keep them as narrow as the change allows. <!-- Required for experimental PRs. Replace the commented lines below with your targets. Do not delete the fence or change its `experimental-tests` tag — the experimental-track watcher reads it verbatim to decide which targets to ask CI for. --> ```experimental-tests # One target per line: a directory or a file. (A pytest ::selector is not # supported -- the sharding runner cannot consume one.) Must be under # tests/experimental/ and must exist. Delete these comment lines and add yours, e.g. # # tests/experimental/test_my_backend.py # tests/experimental/my_backend/ # # Declaring the whole tree (tests/experimental/) is allowed but means every # experimental PR pays for every other feature's tests, in every matrix cell. ``` ## Reviewer Notes Kernel code is untouched; no perf effect. Review on the earlier revision measured its barrier at +14-19% on `fp4_quantize` and the partial mask at +14-15% on MXFP8 (B200); both now live in #9445 behind an SM103 gate. (cherry picked from commit cf8e7ab)
This branch has not been deployed
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.
Summary
main_sf_loadwas the only load-capable warp branch insm103_blockscaled_gemm_tma_warpspecialized.hppwithout a precedingcutlass::arch::wait_on_dependent_grids(). With PDL enabled,collective_mainloop.load_sf(...)issues TMA reads of scale-factor (SF) data before the producer kernel's writes are guaranteed flushed to global memory.wait_on_dependent_grids()above the warp specialization region so it covers all warp branches (includingmain_sf_load), and remove the now-redundant inner waits inmain_ab_load/sched/epi_load. This matches the cleaned-up pattern already insm90_gemm_array_tma_warpspecialized_{pingpong,cooperative}.hpp(1 outer wait, 0 inner).wait_on_dependent_grids()#2962, but in a kernel that wasn't covered by that fix.Why this matters
Observed in TensorRT-LLM on GB300 + DeepSeek-R1 NVFP4 forward (kernel:
DeviceGemmFp4GemmSm103_..._KernelTmaWarpSpecializedBlockScaledSm103). With a diagnostic probe (ld.global.cv.u8reads of the SF buffer inmain_sf_load):main_sf_loadwaitTwo independent runs, 0 poison events across 6.4M probe samples — the race is fully eliminated on the CUTLASS side without any modification to the producer kernel.
Related
wait_on_dependent_grids()#2962 — same class of bug fixed for sm90/sm100 array variants; this PR addresses the sm103 non-array blockscaled variant not covered by that fix.sm100_*_array_tma_warpspecialized*.hppandsm103_blockscaled_gemm_array_tma_warpspecialized.hpp(which still retain redundant inner waits compared to the cleaned sm90 array variants).