-
Notifications
You must be signed in to change notification settings - Fork 637
[Ops] Fix int32 overflow in pointer arithmetic across all Triton kernels #818
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
Closed
Closed
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f0295f5
[Ops] Fix int32 overflow in pointer arithmetic across all Triton kernels
tmct 9d97e38
Address Gemini review: cast i_b to int64 before multiply in chunk_A_bwd
tmct e9515f0
AGENTS.md: clarify that int64 cast is only needed when overflow is pl…
tmct 03ab3ad
Fix autopep8 line length violations
tmct e48c608
Merge branch 'main' into fix/int32-overflow-triton-kernels
zhiyuan1i 37a4394
Add placeholder test to probe CI GPU memory availability
tmct 367844a
Merge remote-tracking branch 'upstream/main' into fix/int32-overflow-…
tmct 0743e31
Add overflow tests and temporarily revert int64 fixes to verify tests…
tmct 0781576
Revert "Add overflow tests and temporarily revert int64 fixes to veri…
tmct 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # AI Review Guidelines for flash-linear-attention | ||
|
|
||
| ## Triton Kernel Integer Overflow Prevention | ||
|
|
||
| `tl.program_id()` and `tl.load()` from `cu_seqlens` return **int32** values. When these are multiplied by strides (e.g., `T`, `H*K`, `D`), the intermediate product can exceed `INT32_MAX` (2^31) for realistic tensor sizes (e.g., `B=4096, T=576, H=8, K=128`), causing silent wrong results or illegal CUDA memory accesses. | ||
|
|
||
| **Rule**: All index arithmetic derived from `tl.program_id()` or `cu_seqlens` loads should be cast to `int64` *before* any multiplication with strides or dimensions. Results should be cast back to `int32` before passing to `tl.make_block_ptr`, which requires 32-bit shape and offset arguments. | ||
|
|
||
| ### When reviewing Triton kernels, flag: | ||
| - Any `i_b * T`, `i_n * T`, `i_b * D`, `i_n * D`, or `i_b * stride_*` without a prior `tl.cast(..., tl.int64)` **only when the product can plausibly exceed INT32_MAX** (consider the actual dimensions involved — not every int32 multiply needs promotion) | ||
| - Any `tl.load(cu_seqlens + ...).to(tl.int32)` (should be `.to(tl.int64)`) | ||
| - Any compound index expression like `(i_b * S + i_s) * D` where `i_b` or `i_s` comes from `tl.program_id()` without int64 promotion | ||
|
|
||
| See [#783](https://github.com/fla-org/flash-linear-attention/pull/783) and [#803](https://github.com/fla-org/flash-linear-attention/pull/803) for prior instances of this bug class. |
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
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
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
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
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
Oops, something went wrong.
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.