vulkan: clamp l_/m_ warptile WM to <= BM (fix wrong matmul on subgroupSize > 64) - #25735
Closed
lkazarin wants to merge 1 commit into
Closed
vulkan: clamp l_/m_ warptile WM to <= BM (fix wrong matmul on subgroupSize > 64)#25735lkazarin wants to merge 1 commit into
lkazarin wants to merge 1 commit into
Conversation
…pSize > 64)
The l_/m_ warptiles set WM (and WARP) to subgroup_size_8, encoding an implicit
WM <= BM invariant. It holds for subgroupSize in {8,16,32,64} but breaks at 128
(Adreno reports subgroupSize=128 under double threadsize): m_warptile gets
WM=128 > BM=64, l_warptile gets WM=256 > BM=128. In mul_mm.comp this makes BM/WM
fold to 0, buf_a indexing overrun into buf_b, and half the output columns go
unwritten -> silently wrong results (test-backend-ops MUL_MAT f16 fails on
batched+broadcast+partial-tile shapes; whisper.cpp outputs garbage on GPU).
Clamp the tiling WARP for the l_/m_ warptiles to 64. s_warptile keeps the
unclamped value (its BLOCK_SIZE is subgroup_size_32 and it needs NUM_WARPS==1).
The min is a no-op on subgroupSize <= 64 devices.
Fixes ggml-org#25734
|
Hi @lkazarin, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
Contributor
|
Superseded by #27726 |
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.
Overview
The
l_/m_warptiles setWM(andWARP) tosubgroup_size_8 = max(device->subgroup_size, 8), which encodes an implicitWM <= BMinvariant. That invariant holds forsubgroupSize ∈ {8,16,32,64}but breaks at 128 — Adreno (Mesa Turnip) reportssubgroupSize = 128under double threadsize, som_warptilegetsWM=128 > BM=64andl_warptilegetsWM=256 > BM=128.In
mul_mm.compthe degenerate tile causes:BM / WMto fold to0→warp_r = warp_i % (BM/WM)/warp_c = warp_i / (BM/WM)are udiv/umod by zero;buf_ashared-memory indexing (rows0..WM-1) to overrun itsBM * SHMEM_STRIDEallocation intobuf_b, so the A operands become B data;WN..BN-1of every output tile to be never computed or stored.Result: silently wrong matmul results.
s_warptileis unaffected (BM = WM = 32), which is why only medium/large tiles fail.This PR clamps the tiling
WARPfor thel_/m_warptiles to 64.s_warptiledeliberately keeps the unclamped value (itsBLOCK_SIZEissubgroup_size_32and it needsNUM_WARPS == 1; clamping it regressesm=1). Theminis a no-op onsubgroupSize <= 64, so NVIDIA/AMD/Intel are unaffected.Additional information
Reported in #25734.
Tested on Adreno 650 / Mesa Turnip (SM8250, mainline Linux / postmarketOS),
test-backend-ops -b Vulkan0 -o MUL_MAT:m=64,n=45,k=128,bs=[8,1],nr=[4,1]ERR≈0.41,m=128,n=45,k=64ERR≈1.08)Note: this device also needs a separate Mesa/Turnip fix to avoid a GPU hang, filed at https://gitlab.freedesktop.org/mesa/mesa/-/work_items/15881 — that one is a driver bug, unrelated to this change.
Requirements
I have read and agree with the contributing guidelines
AI usage disclosure: YES — and it exceeds what CONTRIBUTING.md permits. Disclosing in full so maintainers can decide.
This work was done with an AI assistant (Claude, via Claude Code) operating under my direction on my hardware. Specifically:
WM <= BMinvariant violated for subgroupSize > 64) #25734 text, and the commit message were also written by the AI, which CONTRIBUTING.md point 4 explicitly prohibits.What is mine: I directed the whole investigation, supplied and operated the device, and made the decisions; the bug was found and the fix verified through live debugging on real hardware, not generated speculatively. The underlying finding is genuine and reproducible.
I did not know about the AI policy when this was opened — that is on me, and I am not going to dress the text up to look otherwise. If this is not acceptable in its current form, please say so and I will either close it or resubmit the change authored by me in my own words. Happy to answer questions about any line of it.