Repository navigation
Thin N GEMM kernels - #4640
Merged
Merged
Thin N GEMM kernels#4640
Conversation
zcbenz
approved these changes
Oct 8, 2026
zcbenz
left a comment
Member
There was a problem hiding this comment.
This is a really nice optimization, thanks!
This was referenced Oct 8, 2026
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.
GEMMs with small count of N and large M are bound by reading A. On main, the kernel uses 64x128 NAX tiles which waste most of the columns. For the kernel added in this PR, each simdgroup computes a 32x32 block of output matrix.
A matrix tile stays in registers and B matrix is read from device memory with mpp. K is split across simdgroups per output block, if M is <2048 then K is split across 4 simdgroups in quarters of K. If M is >=2048 then K is split in 2 main parts with 4 simdgroups while tile size used to write to output being bigger, so 4 simdgroups cover 64 columns instead of 32 columns
bf16 perf on M5 Pro with macOS 27:
in_proj_a/bweights_projproj_out, biasI don't have base m5 so would be nice to benchmark for it as well (M5 base is also included in the dispatch for this kernel).
AI was used to port kernels from my repo https://github.com/Isalia20/metalBLAS to here.