Repository navigation
[Codegen][GPU] Sort intrinsic according to k alignment - Step 1 of 2- Track MmaInterfaceAttr via field instead of index - #21103
Merged
Conversation
jerryyin
requested review from
Groverkss,
MaheshRavishankar,
antiagainst,
kuhar and
qedawkins
as code owners
June 16, 2025 17:08
jerryyin
force-pushed
the
users/zyin/refactor-create-gpu-intrinsic-type
branch
from
June 16, 2025 17:30
3c6158d to
750081f
Compare
kuhar
approved these changes
Jun 17, 2025
kuhar
left a comment
Member
There was a problem hiding this comment.
LGTM % nit. Maybe wait for @qedawkins to stamp too before landing.
qedawkins
approved these changes
Jun 17, 2025
qedawkins
left a comment
Contributor
There was a problem hiding this comment.
I'm worried about how painful it is to follow this code, but that's eternally been the case with heuristic code. Looks like an improvement to me.
Signed-off-by: jerryyin <[email protected]>
jerryyin
force-pushed
the
users/zyin/refactor-create-gpu-intrinsic-type
branch
3 times, most recently
from
June 18, 2025 14:26
bf1ea95 to
866c222
Compare
Signed-off-by: jerryyin <[email protected]>
Member
Author
|
@qedawkins I hear you! The heuristic code has been a bit spaghetti like and looks like this is a common infra supporting a wide range of different pipelines. I tried hard to narrow the feature into a small scope (i.e. adding an argument with default parameter) and only to find that makes the situation worse. This PR ended to become the minimal refactor that hopefully makes this common infra slightly cleaner and more generic. |
Signed-off-by: jerryyin <[email protected]>
jerryyin
added a commit
that referenced
this pull request
Jun 20, 2025
…- Creating intrinsic sort routine (#21128) This is a follow-up of #21103. This intrinsic sorting routine will sort the MMA intrinsics by following precedence rules: 1) K-alignment. We prefer intrinsics that can evenly divide the K dimension of the problem. 2) M/N-alignment. We prefer intrinsics that can evenly divide the M and N dimensions of the problem. 3) Intrinsic with larger gemm size. 4) Intrinsic with larger K size. Scope of the impact is igemm and matmul problems. Other pipelines can choose to adopt this if the sorting turns out to be useful. ### Motivation: convolution configuration with > BOO_CACHE_ON=0 python boo_driver.py convbfp16 -n 16 -c 40 -H 192 -W 128 -k 40 -y 3 -x 3 -p 1 -q 1 -u 2 -v 2 -l 1 -j 1 -m conv -g 1 -F 1 -t 1 --in_layout NHWC --out_layout NHWC --fil_layout NHWC --iter 50 Since the gemmK size is 360, the best intrinsic is 32x32x8xbf16, not 16x16x16xbf16, as the former will end in aligned K. Before this PR: `362.06 us`. After this PR: `44.74 us`. Note that due to limitation of the tuner, this combination won't be covered by typical tuning run with 2k trials. So it is essential we bridge the gap through heuristic first before tuner is more capable of searching through different heuristics. --------- Signed-off-by: jerryyin <[email protected]>
AWoloszyn
pushed a commit
that referenced
this pull request
Dec 1, 2025
… Track MmaInterfaceAttr via field instead of index (#21103) This PR is NFC. This PR simplified the intrinsic derive process via: - Created a dedicated `GPUIntrinsicType` to differentiate from a `GPUMatmulShapeType` - This newly created `GPUIntrinsicType` inherits from `GPUMatmulShapeType` - It keep track of the `MmaInterfaceAttr` directly in a field - Removed the need to track the intrinsic separately through a index like `intrinsicIndex` - The separately maintained index used reference only to the position of intrinsic, making it error prone. To sort and prioritize the intrinsic will have to keep track of the intrinsic before and after sorting. - Keeping track of intrinsic instead of index makes tracking much easier - Replaced the index field from `GPUMMASchedule` to `MmaInterfaceAttr` for the same reasoning Sort intrinsic according to K alignment is dependent on this change to land. I break the NFC aspect of the feature into this PR so it is easier to do code reviews. For the convolution configurations that are not k-aligned by 16x16x16 intrinsic (but aligned with 32x32x8), this together with next PR will bring 5-10x perf lift. --------- Signed-off-by: jerryyin <[email protected]>
AWoloszyn
pushed a commit
that referenced
this pull request
Dec 1, 2025
…- Creating intrinsic sort routine (#21128) This is a follow-up of #21103. This intrinsic sorting routine will sort the MMA intrinsics by following precedence rules: 1) K-alignment. We prefer intrinsics that can evenly divide the K dimension of the problem. 2) M/N-alignment. We prefer intrinsics that can evenly divide the M and N dimensions of the problem. 3) Intrinsic with larger gemm size. 4) Intrinsic with larger K size. Scope of the impact is igemm and matmul problems. Other pipelines can choose to adopt this if the sorting turns out to be useful. ### Motivation: convolution configuration with > BOO_CACHE_ON=0 python boo_driver.py convbfp16 -n 16 -c 40 -H 192 -W 128 -k 40 -y 3 -x 3 -p 1 -q 1 -u 2 -v 2 -l 1 -j 1 -m conv -g 1 -F 1 -t 1 --in_layout NHWC --out_layout NHWC --fil_layout NHWC --iter 50 Since the gemmK size is 360, the best intrinsic is 32x32x8xbf16, not 16x16x16xbf16, as the former will end in aligned K. Before this PR: `362.06 us`. After this PR: `44.74 us`. Note that due to limitation of the tuner, this combination won't be covered by typical tuning run with 2k trials. So it is essential we bridge the gap through heuristic first before tuner is more capable of searching through different heuristics. --------- Signed-off-by: jerryyin <[email protected]>
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.
This PR is NFC. This PR simplified the intrinsic derive process via:
GPUIntrinsicTypeto differentiate from aGPUMatmulShapeTypeGPUIntrinsicTypeinherits fromGPUMatmulShapeTypeMmaInterfaceAttrdirectly in a fieldintrinsicIndexGPUMMAScheduletoMmaInterfaceAttrfor the same reasoningSort intrinsic according to K alignment is dependent on this change to land. I break the NFC aspect of the feature into this PR so it is easier to do code reviews. For the convolution configurations that are not k-aligned by 16x16x16 intrinsic (but aligned with 32x32x8), this together with next PR will bring 5-10x perf lift.