Skip to content

CUDA : fix divergent FlashAttention barrier - #27955

Open
mistrjirka wants to merge 1 commit into
ggml-org:masterfrom
mistrjirka:fix/fa-uniform-barrier
Open

CUDA : fix divergent FlashAttention barrier#27955
mistrjirka wants to merge 1 commit into
ggml-org:masterfrom
mistrjirka:fix/fa-uniform-barrier

Conversation

@mistrjirka

Copy link
Copy Markdown

Overview

Incorrect use of __syncthreads() created divergent barriers in the FlashAttention code. It produced 1024 synchronization errors reported by NVIDIA Compute Sanitizer:
compute-sanitizer --tool synccheck.
The issue is:

.... threads in the same block  ... 
if (thread_type_a) {
    .....
    __syncthreads(); // creates barrier A
} else {
   __syncthreads();  // creates barrier B
}

So the threads in the same block are running towards different barriers based on which branch they take.
This can be fixed by:

.... threads in the same block ... 
if (thread_type_a) {
    .....
}

__syncthreads();  // creates common barrier

This produces 0 errors. The numerical tests passed and after benchmarking 100k cached + 1k prompt + 256 generated tokens produced almost no performance change.
Measured change: improved prompt processing by 0.43% and token generation by 0.15%, so no measurable performance regression.

Additional information

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: yes, GPT-5.6 Sol. I was doing performance optimizations for qwen 3.8 27B and it identified this issue during some FlashAttention work.

@mistrjirka
mistrjirka requested a review from a team as a code owner August 29, 2026 11:21
@mistrjirka mistrjirka changed the title CUDA: fix divergent FlashAttention barrier CUDA : fix divergent FlashAttention barrier Aug 29, 2026
@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend labels Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA Related to the CUDA backend ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant