Fix IMA caused by OOB lanes in varlen indexer top-k - #410
Conversation
Signed-off-by: Hongxiao Bai <hongxiaob@nvidia.com>
📝 WalkthroughWalkthroughThe varlen top-k kernel now excludes vector-tail padding from histogram construction, index collection, and refinement. A CUDA regression test verifies that negative-infinity padding does not affect returned indices or selected values. ChangesVarlen top-k padding handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@cudnn-ci-bot run |
|
@cudnn-ci-bot run |
|
🚀 Running mirror pipeline Branch: cudnn-gh/pr-410-782c445 |
|
We independently hit this exact bug in production and can confirm the diagnosis — thanks for fixing it. Our data point: a GLM-5.2 context-parallel (CP32) training run on B200s crashed with Xid 43 ( One extra trigger route worth noting alongside yours: our rows had plenty of finite values — the threshold landed in the We verified an equivalent patch on our side: previously-crashing inputs pass with exact |
…y MIT) Rebased onto current develop (4f75b1f). Relicenses NVIDIA-authored code from MIT to Apache-2.0 using the exact NVIDIA OSS SPDX header, while keeping under MIT every file that carries non-NVIDIA contributions, so no third party's code is relicensed without consent. License assignment (per-file SPDX tag on every source file): - Apache-2.0: 515 files authored solely by NVIDIA (incl. the new Rubin/BF16 grouped GEMM kernels and gemm_proj_rope_mxfp8 variants). - MIT (67): files with surviving lines from external contributors in the issue NVIDIA#431 sign-off list, determined by git blame on develop. - MIT (29): FlashAttention/QuACK-derived files carrying external authors' copyright; pinned to MIT so the Apache-2.0 root does not absorb them. New since the previous revision of this PR (develop 3a9ed3f -> 4f75b1f): - 26 new files headered; 63 modified files re-analyzed. - Two new external contributors, adding 4 files to the MIT set: DrDirk (NVIDIA#423) -> conv_dgrad.h, conv_fprop.h, conv_wgrad.h Hongxiao (NVIDIA#410) -> test/python/fe_api/dsa/test_DSA_indexer_top_k.py Both must be added to the issue NVIDIA#431 consent list. - rmhaskar (NVIDIA#432) verified NVIDIA-affiliated; Chase Block now commits from an NVIDIA address. Neither adds MIT files. - PR NVIDIA#434 removed the Jerry Chen personal copyright from bwd_barriers.py; 6 other DSA files still carry it and remain Category 2. Licensing files: LICENSE.txt (Apache-2.0), LICENSE-MIT.txt, LICENSING.md (dual-license manifest with per-file introducing-commit links), THIRD_PARTY_LICENSES.txt, NOTICE, pyproject ('Apache-2.0 AND MIT'), README. Every change is comment/header-only; all Python compiles. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…MIT) Rebased onto current develop (b950af1). Relicenses NVIDIA-authored code from MIT to Apache-2.0 using the exact NVIDIA OSS SPDX header, keeping under MIT only files that still carry contributions from external contributors whose permission has not been established. License assignment (per-file SPDX tag on every source file): - Apache-2.0: 541 files - MIT (50): surviving lines from external contributors, consent pending - MIT (29): FlashAttention/QuACK-derived files carrying external authors' copyright Cleared, freeing 16 files to Apache-2.0: - Written consent on issue NVIDIA#431 (10): take-cheeze, fallintoplace, zianglih, JackRao123, zkyue, Hyaloid, haowen-han, junaire, szluyu99, dimitar-asenov. - NVIDIA employment (2), commits under personal email addresses: HollowMan6, and hxbai (Hongxiao Bai, PR NVIDIA#410) -- frees .../indexer_top_k/indexer_top_k_varlen_util.py and test/python/fe_api/dsa/test_DSA_indexer_top_k.py. Files touched by both a cleared and a still-pending contributor remain MIT. PR NVIDIA#427 (CSA fused Compressor kernels ported from Megatron-LM, author @zkyue who consented): its 13 files had no license header at all; they now carry the NVIDIA Apache-2.0 SPDX header. Megatron-LM added to THIRD_PARTY_LICENSES.txt as an NVIDIA Apache-2.0 provenance note. Still pending (7): ConnorBaker, DrDirk, EmilienM, jyknight, sbcd90, valgur, and co-author Benjamin Leff. Every change is comment/header-only; all Python compiles. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…MIT) (#408) Rebased onto current develop (b950af1). Relicenses NVIDIA-authored code from MIT to Apache-2.0 using the exact NVIDIA OSS SPDX header, keeping under MIT only files that still carry contributions from external contributors whose permission has not been established. License assignment (per-file SPDX tag on every source file): - Apache-2.0: 541 files - MIT (50): surviving lines from external contributors, consent pending - MIT (29): FlashAttention/QuACK-derived files carrying external authors' copyright Cleared, freeing 16 files to Apache-2.0: - Written consent on issue #431 (10): take-cheeze, fallintoplace, zianglih, JackRao123, zkyue, Hyaloid, haowen-han, junaire, szluyu99, dimitar-asenov. - NVIDIA employment (2), commits under personal email addresses: HollowMan6, and hxbai (Hongxiao Bai, PR #410) -- frees .../indexer_top_k/indexer_top_k_varlen_util.py and test/python/fe_api/dsa/test_DSA_indexer_top_k.py. Files touched by both a cleared and a still-pending contributor remain MIT. PR #427 (CSA fused Compressor kernels ported from Megatron-LM, author @zkyue who consented): its 13 files had no license header at all; they now carry the NVIDIA Apache-2.0 SPDX header. Megatron-LM added to THIRD_PARTY_LICENSES.txt as an NVIDIA Apache-2.0 provenance note. Still pending (7): ConnorBaker, DrDirk, EmilienM, jyknight, sbcd90, valgur, and co-author Benjamin Leff. Every change is comment/header-only; all Python compiles. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Before submitting
pre-commit runand committed any formatting changes.Affected area
Summary
Fix the varlen indexer top-k kernel so that out-of-bounds lanes from predicated vector loads do not participate in radix histogram construction or candidate collection.
The change applies the existing vector-lane bounds predicate during:
A regression test covers rows where the valid input prefix contains fewer finite values than
top_k, making the top-k threshold-inf.Why
The kernel uses predicated vector loads and fills out-of-bounds register lanes with
-inf. However, those lanes were still counted in the radix histogram and could subsequently be collected as top-k candidates.When the real top-k threshold was also
-inf, the kernel could not distinguish valid in-range-infvalues from the synthetic OOB values. This produced thousands of invalid candidates, overflowed the per-row extra buffer, and resulted in an illegal memory access.Filtering candidates by their logical input index fixes the issue while preserving valid top-k semantics for real in-range
-infvalues.Related issues
None.
API and compatibility impact
None. There are no public API or input-contract changes.
The kernel now excludes internal OOB vector lanes from top-k selection. Valid in-range values, including
-inf, retain their existing top-k semantics.Testing
Tested on an NVIDIA B200 (SM100) with CUDA launch blocking enabled.
python -m pytest -q --tb=short fe_api/dsa/test_DSA_indexer_top_k.py5 passed(633, 768)float32seq_lens=633top_k=512git diff --checkSummary by CodeRabbit
Bug Fixes
Tests