Skip to content

CUDA: fix misaligned synchronization in FA - #13469

Merged
JohannesGaessler merged 1 commit into
ggml-org:masterfrom
JohannesGaessler:cuda-fix-fa-sync
May 12, 2025
Merged

JohannesGaessler merged 1 commit into
ggml-org:masterfrom
JohannesGaessler:cuda-fix-fa-sync

Conversation

@JohannesGaessler

Copy link
Copy Markdown
Contributor

See discussion following #13430 (comment) .

I added a __syncthreads instruction in #13438 to fix a race condition. However, this instruction is for some kernel configuration only executed for part of the warps so the points at which warps wait for each other become misaligned. On a sufficiently long context this then causes incorrect results.

@github-actions github-actions Bot added Nvidia GPU Issues specific to Nvidia GPUs ggml changes relating to the ggml tensor library for machine learning labels May 12, 2025
@JohannesGaessler
JohannesGaessler merged commit 95e1888 into ggml-org:master May 12, 2025
Nexesenex added a commit to Nexesenex/croco.cpp that referenced this pull request May 14, 2025
Nexesenex added a commit to Nexesenex/croco.cpp that referenced this pull request May 25, 2025
Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
my-other-github-account pushed a commit to my-other-github-account/llama.cpp that referenced this pull request May 15, 2026
AlexiAlp pushed a commit to minghaop/llama.cpp that referenced this pull request Jun 2, 2026
AlexiAlp pushed a commit to minghaop/llama.cpp that referenced this pull request Jun 2, 2026
fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 5, 2026
zommiommy pushed a commit to zommiommy/llama.cpp that referenced this pull request Aug 18, 2026
crusaderky added a commit to crusaderky/llama.cpp that referenced this pull request Sep 18, 2026
Port of upstream ggml-org/llama.cpp ggml-org#27870 (b74f590, PR by Siavash
Norouzi), adapted to keep the beellama 0xFFFFFFFFULL shuffle masks and
the KVarN dst_final_meta whole-tile publishing block.

The old shape (kept since ggml-org#13469) put the meta-combine __syncthreads()
inside 'if (np > 1 && threadIdx.y % np == 0)' with a separate
'else if (np > 1) __syncthreads()'. The paired barriers are formally
divergent per the CUDA spec, and in practice the if-branch's post-barrier
meta write-back races with the other warps re-entering the tile_Q reuse
loop, which corrupts attention output data- and timing-dependently.

This is the root cause of the catastrophic per-chunk KLD/PPL blowups
seen on K2-Horizon-7B (GQA ratio 4, head dim 128 -> np = 4) with f16/bf16
KV caches and any exact tail: f16/f16, kvarn4 (intrinsic f16 tail) and
bf16-tail runs collapse on whole chunks (chunk-9 PPL 5.11 -> 10.68 on
Q5_K_M|f16) while quantized-body runs without a tail stay clean because
they dispatch to fattn-vec. CPU runs of the same chunks/configs are
clean, isolating the fault to this CUDA kernel.

Restructure per upstream: all threads enter 'if (np > 1)', the combine
reads run under 'threadIdx.y % np == 0', the __syncthreads() is
unconditional, and the write-back runs after it under the same guard.
frostyautumnleaf pushed a commit to frostyautumnleaf/llama.cpp that referenced this pull request Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning Nvidia GPU Issues specific to Nvidia GPUs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants