-
Notifications
You must be signed in to change notification settings - Fork 631
[KDA] enable TMA on some simple kernels #647
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7f41991
[KDA]: Add TMA support for chunk_kda_bwd_kernel_intra and tune BK
zhiyuan1i b40233a
[KDA] enable TMA on some simple kernels
zhiyuan1i f6edbbe
fix test
zhiyuan1i 907c31d
fixup! [KDA] enable TMA on some simple kernels
zhiyuan1i ac29748
Merge branch 'main' into kda-training-tma
zhiyuan1i 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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
TMA branch lacks boundary handling that exists in the pointer path
In the
for i_v in range(tl.cdiv(V, BV))loop and the finaldwwrite:tl.make_block_ptr(..., boundary_check=(0, 1))andmask=m_kto safely handle tail tiles whenT,V, orKare not multiples ofBT,BV, orBK.[T, V],[V, K],[T, K]with block shapes[BT, BV]/[BV, BK]/[BT, BK]) and callsdesc_*.load(...)/desc_dw.store(...)with no apparent boundary checks.Given that:
BTis a chunk size that may not divideT(e.g., tests useT=63withchunk_size=64),VandKalso aren’t guaranteed to be multiples ofBV/BK,the TMA path risks reading/writing beyond logical tensor bounds unless
make_tensor_descriptorand itsload/storeintrinsically clip partial tiles.Please either:
T % BT == 0andV % BV == 0andK % BK == 0), orThis should be validated on shapes where
T,V, andKare not multiples ofBT,BV,BK.Also applies to: 129-135
I'll verify the review comment by examining the code and checking the boundary handling claims.
🏁 Script executed:
Length of output: 7052
🏁 Script executed:
Length of output: 1011
🏁 Script executed:
Length of output: 1924
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 253
🏁 Script executed:
Length of output: 615
🏁 Script executed:
Length of output: 3714
🏁 Script executed:
Length of output: 2626
🏁 Script executed:
Length of output: 808
🏁 Script executed:
Length of output: 54
🏁 Script executed:
Length of output: 12988
🏁 Script executed:
Length of output: 607
🏁 Script executed:
Length of output: 23
🏁 Script executed:
Length of output: 2129
🏁 Script executed:
Length of output: 1434
🏁 Script executed:
Length of output: 1213
🏁 Script executed:
Length of output: 745
🏁 Script executed:
Length of output: 219
🏁 Script executed:
Length of output: 840
🏁 Script executed:
Length of output: 1716
🏁 Script executed:
Length of output: 152
🏁 Script executed:
Length of output: 2732
🏁 Script executed:
Length of output: 696
🏁 Script executed:
Length of output: 1543
🏁 Script executed:
Length of output: 386
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 56
🏁 Script executed:
Length of output: 3633
🏁 Script executed:
Length of output: 1770
🏁 Script executed:
Length of output: 392
🏁 Script executed:
Length of output: 3570
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 1860
🏁 Script executed:
Length of output: 3512
🏁 Script executed:
Length of output: 3113
🏁 Script executed:
Length of output: 1122
🏁 Script executed:
Length of output: 1267
🏁 Script executed:
Length of output: 6967
🏁 Script executed:
Length of output: 884
🏁 Script executed:
Length of output: 4791
🏁 Script executed:
Length of output: 1770
🏁 Script executed:
Length of output: 995
🏁 Script executed:
Length of output: 3
🏁 Script executed:
Length of output: 3492
🏁 Script executed:
Length of output: 40
🏁 Script executed:
Length of output: 533
🏁 Script executed:
Length of output: 63
🏁 Script executed:
Length of output: 1961
🏁 Script executed:
Length of output: 2848
🏁 Script executed:
Length of output: 2151
🏁 Script executed:
Length of output: 1027
🏁 Script executed:
Length of output: 8087
🏁 Script executed:
Length of output: 75
🏁 Script executed:
Length of output: 40
🏁 Script executed:
Length of output: 40
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 40
🏁 Script executed:
Length of output: 8087
🏁 Script executed:
Length of output: 63
🏁 Script executed:
Length of output: 178
🏁 Script executed:
Length of output: 2338
🏁 Script executed:
Length of output: 4513
🏁 Script executed:
Length of output: 28
🏁 Script executed:
Length of output: 621
🏁 Script executed:
Length of output: 193
🏁 Script executed:
Length of output: 468
🏁 Script executed:
Length of output: 75
🏁 Script executed:
Length of output: 757
🏁 Script executed:
Length of output: 992
🏁 Script executed:
Length of output: 1166
🏁 Script executed:
Length of output: 1380
🏁 Script executed:
Length of output: 679
🏁 Script executed:
Length of output: 766
🏁 Script executed:
Length of output: 1434
🏁 Script executed:
Length of output: 2238
🏁 Script executed:
Length of output: 1961
🏁 Script executed:
Length of output: 178
🏁 Script executed:
Length of output: 65
🏁 Script executed:
Length of output: 14
🏁 Script executed:
Length of output: 26
🏁 Script executed:
Length of output: 7052
🏁 Script executed:
Length of output: 402
🏁 Script executed:
Length of output: 195
🏁 Script executed:
Length of output: 18
🏁 Script executed:
Length of output: 1512
🏁 Script executed:
Length of output: 217
🏁 Script executed:
Length of output: 151
🏁 Script executed:
Length of output: 345
🏁 Script executed:
Length of output: 3
Key Finding from Web Search: TMA includes "necessarily handles predication (e.g., out-of-bounds checks)", but critically, the TMA hardware "No bounds checking. No divergence. Hardware handles it all." However, this refers to asynchronous load/store operations. The Triton documentation at index 3 does NOT mention automatic boundary clipping for partial tiles. The key documentation states "The destination tensor type and shape must match the descriptor otherwise the result is undefined."
This is the critical insight: TMA descriptors do NOT automatically clip partial tiles—they require exact shape matching.
Rewritten Review Comment:
Add boundary handling to TMA descriptor loads/stores for non-aligned tensor dimensions
The TMA code path (lines 94-121 and 129-135) is missing boundary handling that protects the non-TMA path. Specifically:
boundary_check=(0, 1)on alltl.load()andtl.store()callsmake_tensor_descriptor()with.load()and.store()but provides no boundary parametersWhen
T,V, orKare not multiples ofBT,BV, orBK(e.g., T=63 with chunk_size=64), the TMA path risks out-of-bounds memory access since TMA descriptors require "the destination tensor type and shape must match the descriptor otherwise the result is undefined."Required fixes (lines 94-121 and 129-135):
This must be validated on shapes where T, V, and K are not multiples of BT, BV, BK.
🤖 Prompt for AI Agents