Skip to content

Add opt-in NRL_CUDA_BLOCKING_SYNC so GPU actors sleep instead of spin while waiting on the GPU - #2818

Closed
jioffe502 wants to merge 6 commits into
mainfrom
devin/1793411235-cuda-blocking-sync
Closed

jioffe502 wants to merge 6 commits into
mainfrom
devin/1793411235-cuda-blocking-sync

Conversation

@jioffe502

@jioffe502 jioffe502 commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Why it helps

By default, a GPU worker keeps one CPU core at 100% while it waits for the GPU, checking over and over whether the work is done. NRL_CUDA_BLOCKING_SYNC=1 makes the worker sleep instead and wake when the GPU finishes, which frees those cores for CPU stages such as PDF extraction. That pays off when CPU is short: 8 GPUs on 64 CPUs went from 248.2 to 259.4 pages/s (+4.5%) with fewer busy cores (inference: the freed cores are what raised throughput; where they went was not traced). When CPU is plentiful there is nothing to gain and the wake-up adds a little latency (1x H100: about -4.2% over two runs), so the flag stays off by default.

sequenceDiagram
  participant W as GPU worker on its CPU core
  participant G as GPU
  rect rgba(220, 80, 80, 0.12)
  Note over W,G: Default: spin-wait
  W->>G: launch batch
  loop until the GPU is done
    W->>W: poll, core busy at 100%
  end
  G-->>W: done
  end
  rect rgba(80, 180, 80, 0.12)
  Note over W,G: NRL_CUDA_BLOCKING_SYNC=1: blocking sync
  W->>G: launch batch
  Note over W: sleeps, core free for CPU stages
  G-->>W: done, wakes the worker after a short delay
  end
Loading

CUDA's default schedule spin-waits on the host, so each local GPU actor burns about one CPU core polling the GPU. Setting NRL_CUDA_BLOCKING_SYNC=1 sets CU_CTX_SCHED_BLOCKING_SYNC on the primary contexts. This happens once per process, after Ray assigns the GPU and before any model loads:

  • in AbstractOperator.__init__ for GPUOperator subclasses;
  • in the service pool initializer, before warmup.

Failures log a warning and retry at the next actor.

When the flag is on, NRL also defaults VLLM_WORKER_MULTIPROC_METHOD to spawn (an explicit user value is kept). A process that has called cuInit cannot start CUDA in forked children. Without this, a local vLLM embedder built in the driver process (for example, for query-time embedding) forked its engine and failed with "CUDA driver initialization failed".

Scope: the env var, a helper in operators/gpu_operator.py, the two call sites, and docs in environment-config.md.
Unchanged: when the variable is unset (the default), nothing is loaded, called, or set. vLLM EngineCore is a separate process and is not covered.

Measured, cold cache, single runs, recall@5/@10 within run-to-run noise:

host data pages/s default → =1 busy CPU cores default → =1
8x RTX PRO 6000, 64 CPUs (CPU-short) 10k PDFs 248.2 → 259.4 (+4.5%) 51.8 → 43.6
4x RTX PRO 6000, 64 CPUs 10k PDFs 175.3 → 175.4 41.0 → 23.6
8x RTX PRO 6000, 128 CPUs 10k PDFs 315.0 → 315.4 78.8 → 43.9
1x H100 NVL, 32 CPUs 767 PDFs 36.09 → 34.55 (−4.3%, repeat −4.1%) 9.7 → 6.7

When CPU is short, the cores freed from spinning go to the GPU stages' CPU work and raise throughput. On hosts with spare CPU they buy nothing, and on H100 the flag cost about 4%. Enable it only where CPU is the constraint.

Tests: tests/test_cuda_blocking_sync.py covers:

  • unset env;
  • flags set per device, once;
  • spawn default, and an explicit VLLM_WORKER_MULTIPROC_METHOD kept;
  • missing driver;
  • non-zero CUresult;
  • retry after a failure;
  • GPU vs CPU operators;
  • warmup order.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

Requested by: @jioffe502

@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@jioffe502
jioffe502 requested a review from jdye64 October 31, 2026 01:59
devin-ai-integration[bot]

This comment was marked as resolved.

@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable new issues were found.

Summary

Adds opt-in blocking CUDA waits before GPU operators load models and before service workers warm models.

  • GPU workers can sleep while waiting for CUDA work.

Reviews (6) · Last reviewed commit: "Make vLLM spawn workers when NRL_CUDA_BL..." · Reviewed by Greptile

greptile-apps[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

The flag calls cuInit in the process that builds a GPU operator. A local
query embedder built in the driver process then forked its vLLM engine,
and CUDA failed to initialize in the forked child. Default
VLLM_WORKER_MULTIPROC_METHOD to spawn when the flag is on, keep an
explicit user value, and note the throughput trade-off in the docs.

Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Closing as explored and cut. The opt-in flag only paid off on a CPU-short host (8 GPUs on 64 CPUs: +4.5%, one run). It was neutral on hosts with spare CPU and cost about 4% on 1x H100 (repeated). Since then, start-time CPU sizing (#2824) and skipping unused image crops (#2841) leave more CPU free, so the target case is rarer, and it cannot be a default because it slows hosts with spare CPU. The branch is kept; reopen if a CPU-short deployment shows CUDA spin-waits limiting throughput on current main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant