Skip to content

cuda: add GGML_CUDA_BLOCKING_SYNC to eliminate 100% CPU busy-wait on full GPU offload - #26487

Open
hksk wants to merge 1 commit into
ggml-org:masterfrom
hksk:cuda-blocking-sync
Open

cuda: add GGML_CUDA_BLOCKING_SYNC to eliminate 100% CPU busy-wait on full GPU offload#26487
hksk wants to merge 1 commit into
ggml-org:masterfrom
hksk:cuda-blocking-sync

Conversation

@hksk

@hksk hksk commented Aug 3, 2026

Copy link
Copy Markdown

Overview

When running llama-server with full GPU offload (--n-gpu-layers 99), the host thread that drives decoding ends up busy-waiting inside cudaStreamSynchronize. This makes one CPU core sit at 100% even though the GPU is doing all the work.

This PR adds an opt-in environment variable GGML_CUDA_BLOCKING_SYNC. When set to a non-zero value, llama.cpp calls cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync) before the CUDA primary context is created, turning the busy-poll into a blocking sleep and dropping host CPU usage to near zero during decode. Throughput stays essentially the same; the only expected cost is a small increase in host-GPU synchronization latency.

Additional information

Requirements

  • I have read and agree with the contributing guidelines.
  • AI usage disclosure: YES — I used an AI assistant to help draft the PR description and the initial patch. I reviewed, tested, and verified the changes on my own hardware.

@hksk
hksk requested a review from a team as a code owner August 3, 2026 03:08
@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 3, 2026
@ggml-gh-bot

ggml-gh-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown

Hi @hksk, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • PR Template not respected: Please respect the template when creating a new pull request. Make sure to fill out all required sections.

  • AI-generated content: While code is allowed to be generated by AI, please write the PR description and commit messages on your own without the help of AI.


Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

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