[AMD][Draft] Implement implicit layout conversion for DotOp to enable direct GMEM to reg loads #8450
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.
Related RFC
[RFC][AMD] Optimizations for Paged Attention: Proposal with Multiple Features(#8281)
[Feature 2] Implicit Layout Conversion
Problem
We found that partitioning the
seq_lendimension of matrix K and thehead_dimdimension of matrix V across different wavefronts yields significant benefits (because loading matrices K and V does not require shared memory).However, the AMD backend pass of the Triton compiler does not support directly loading data from global memory into registers and completing a
DotOpwithDotOperandEncodingAttr. Instead, it requires an intermediate transfer through shared memory usingConvertLayoutOp.The goal of implicit layout conversion is to directly load data in a layout that matches matrix multiplication requirements, eliminating unnecessary conversions.
Core Process
DotOpis matched.DotOp, trace backward until aLoadOpis matched, and determine whether implicit layout conversion is feasible based on the types of operations along the path (essentially, implicit conversion cannot be applied if data copying occurs).ConvertLayoutOpandLocalLoadOp-like operations, check whether data copying occurs. If so, implicit conversion is not allowed.TransOp,ReshapeOp,LoadOp, andElementwiseOpare supported.vecSize) from theLayoutAttrof the matchedLoadOp, and update thekWidthin theLayoutAttrof theDotOpoperands.vecSize.LayoutAttrfrom theDotOpoperands to all operations along the path to theLoadOp.LayoutAttrto all subsequent operations.ConvertLayoutOpexists, remove it (Step 4 ensures that all operations along the path have consistent layouts).ConvertLayoutOpbefore and after each operation to ensure legality; these will be removed later byRemoveLayoutConversions.