Quality: u32 overflow in CUDA grid dimension calculation silently truncates large tensor indices#2417
Open
kumburovicbranko682-boop wants to merge 1 commit into
Conversation
…uncates large tensor indices For rank 5 and 6, intermediate multiplications are performed in u32 arithmetic before the result is assigned to the grid dimension. If the product of shape dimensions exceeds u32::MAX (4,294,967,295), the result wraps around silently, producing a grid that is too small. CUDA threads beyond the wrapped grid will never launch, causing silent data corruption (uninitialized portions of the output tensor). For example, shape = [2, 3, 4096, 4096, 1] for rank 5 computes `4096u32 * 4096u32` = 16,777,216 which fits, but shape = [2, 3, 65536, 65536, 1] computes `65536u32 * 65536u32` which overflows u32. Affected files: utils.rs Signed-off-by: kumburovicbranko682-boop <295886834+kumburovicbranko682-boop@users.noreply.github.com>
Collaborator
|
Do we have actual models where it manifested ? or is it static analysis ? |
Collaborator
|
/ci llm |
|
✅ Bench vs main — no regressions Reference: main nightly, latest 2026-06-27 (0d old) · PR Speed — evaltime · prefill · decode no inference-speed regressions 🟢 7 improvement(s)
lower is better except prefill/decode (tok/s) · adaptive thresholds (max(floor, k×noise) vs the series' own history) · single-shot vs nightly reference · full report → run |
✅ CI / large-models: success
|
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.
Problem
For rank 5 and 6, intermediate multiplications are performed in u32 arithmetic before the result is assigned to the grid dimension. If the product of shape dimensions exceeds u32::MAX (4,294,967,295), the result wraps around silently, producing a grid that is too small. CUDA threads beyond the wrapped grid will never launch, causing silent data corruption (uninitialized portions of the output tensor). For example, shape = [2, 3, 4096, 4096, 1] for rank 5 computes
4096u32 * 4096u32= 16,777,216 which fits, but shape = [2, 3, 65536, 65536, 1] computes65536u32 * 65536u32which overflows u32.Severity:
highFile:
cuda/src/kernels/utils.rsSolution
Perform intermediate multiplication in usize (or u64), then saturating-cast or validate before assigning to u32:
Changes
cuda/src/kernels/utils.rs(modified)Testing