cuda: fix self-recursive static init in ggml_cuda_tq_mmq_enabled() (hangs every AMD prefill) - #348
Merged
TheTom merged 1 commit intoSep 5, 2026
Conversation
…ed() The cached GGML_TQ_MMQ lookup initialized its static from a call to itself, so the first call on the AMD MMQ path (a TQ mul_mat with n >= 8, i.e. any prefill) re-entered the static's guard from the same thread and waited on it forever. NVIDIA builds short-circuit the getenv away and never call the function, which is why the CUDA gates stayed green. Read the environment variable directly. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NxP6x5bmUDYFvmouceN2mR
TheTom
merged commit Sep 5, 2026
27d17bd
into
TheTom:feature/turboquant-kv-cache
7 of 21 checks passed
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.
What
One-line fix:
ggml_cuda_tq_mmq_enabled()initialized its cachedstatic const boolfrom a call to itself.Why it matters
The first call re-enters the static's initialization guard from the same thread and waits on it forever: the process sits in
futex_waitwith the GPU idle. The function is only reached on the AMD MMQ path (a TQmul_matwith n >= 8 andGGML_TQ_MMQ=1), so on RDNA and CDNA any prefill hangs. NVIDIA builds short-circuit the environment lookup away and never call the function, which is why the GB10 gates, CI and theMUL_MAT 1697/1697sweep stayed green.This came in with #337 (commit 439fe67, mine): the review asked for the
getenv()to be read once instead of per node, and the cached version called the wrong thing. Sorry about that.How it showed up
test-backend-ops -o MUL_MAT -p type_a=tq4_1son an MI210 stops at the eighth case,m=16,n=8,k=256(the first with n >= 8), every time; the earlier cases are below the MMQ threshold. Backtrace of the stuck thread:Test
MI210 (gfx90a),
GGML_TQ_MMQ=1 GGML_TQ_NATIVE=1:-o MUL_MAT -p type_a=tq4_1sm=16,n=8,k=256)-o MUL_MAT_ID -p type_a=tq4_1s-o MUL_MAT -p type_a=tq3_1s-o MUL_MAT_ID -p type_a=tq3_1s🤖 Generated with Claude Code
https://claude.ai/code/session_01NxP6x5bmUDYFvmouceN2mR