Skip to content

[Codegen][GPU] Sort intrinsic according to k alignment - Step 2 of 2 - Creating intrinsic sort routine - #21128

Merged
jerryyin merged 4 commits into
mainfrom
users/zyin/sort-intrinsics-according-to-k-aligned
Jun 20, 2025
Merged

jerryyin merged 4 commits into
mainfrom
users/zyin/sort-intrinsics-according-to-k-aligned

Conversation

@jerryyin

@jerryyin jerryyin commented Jun 18, 2025 •

Copy link
Copy Markdown
Member

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.

@jerryyin
jerryyin requested review from Max191 and krzysz00 June 18, 2025 16:41
@jerryyin
jerryyin force-pushed the users/zyin/sort-intrinsics-according-to-k-aligned branch from b9fadc6 to efbfe7e Compare June 18, 2025 16:42
@jerryyin
jerryyin force-pushed the users/zyin/sort-intrinsics-according-to-k-aligned branch from 5fa470a to f43b430 Compare June 18, 2025 19:53
@jerryyin
jerryyin requested a review from krzysz00 June 18, 2025 20:13
@jerryyin
jerryyin force-pushed the users/zyin/sort-intrinsics-according-to-k-aligned branch 2 times, most recently from 066a94f to 51bf5d4 Compare June 19, 2025 20:17
@jerryyin
jerryyin requested a review from kuhar June 19, 2025 21:01

@krzysz00 krzysz00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a reasonable set of tests for this code

Thanks for following up on this!

@jerryyin
jerryyin enabled auto-merge (squash) June 20, 2025 19:15
@jerryyin
jerryyin merged commit 03f3094 into main Jun 20, 2025
@jerryyin
jerryyin deleted the users/zyin/sort-intrinsics-according-to-k-aligned branch June 20, 2025 19:38
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants