Avoid GPU waits when the MemoryStore evicts a GPU broadcast [databricks] #16490
All Vouch review confidence checks passed
Residual risk 0.27 = Change Risk (0.50) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 630 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.386
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #16490"
general
weight: 0.35
gerashegalov
Fixes #16460.
Description
When Spark's
MemoryStoreevicts a broadcast that the plugin has loaded onto the GPU, it serializes it while holding the memory manager lock. The old code waited for the GPU semaphore at that point, which deadlocks with GPU tasks that need the same lock. The full analysis is in https://github.com/NVIDIA/cudf-spark/issues/16460#issuecomment-6328248089.Related: #16491 models the wait order of eviction and
batchfrom an earlier revision of this PR. #15230 tracks the broader lock-ordering work.Changes:
doWriteObjectwrites a GPU-materialized broadcast as packed table bytes plus cudf unpack metadata, without the GPU semaphore or a device allocation:- Device data is copied to host through the spill bounce buffer. cudf's JNI selects the RMM device for each copy, so the evicting thread need not have acquired the semaphore.
- Spilled data is streamed from its host or disk copy.
- New helpers:
SpillableColumnarBatchFromBufferHandle.writePackedToandSpillableHostBufferHandle.writeTo.- Eviction may still wait for a spill bounce buffer and its copy. Holders of those never need the memory manager lock.
batch, which copies it to the device.batchreturns an already-loaded batch under the object's monitor alone, as before. Otherwise it builds the GPU batch (buildGpuBatch) under a separatematerializeLockand takes the monitor only to publish the result.hostBatchreads device data undermaterializeLockand insidewithRetryNoSplit, not under the object's monitor. In local mode the driver shares the executor'sMemoryStore, sohostBatchon a reloaded packed broadcast copies through the GPU, as it already does for a loaded batch.doWriteObjecttakes the monitor only to snapshot its state and reference the data it writes.Tests:
BroadcastEvictionSuite. Each eviction runs on a task thread under theSparkEnvmemory manager lock and asserts that it allocates no device memory.- Eviction while another task holds the only GPU permit:
- with the GPU batch on the device, in host memory, and on disk, asserting where the data is, re-evicting the reloaded broadcast, and evicting a GPU batch rebuilt from the packed bytes;
- for zero-row and row-count-only broadcasts. The row-count-only case is coverage: the old code also passed it.
- Eviction completes while another task waits for the GPU inside
hostBatch.- Eviction completes while another task is paused inside
buildGpuBatch, for both the original and the packed format.- Reading an unknown format tag or a truncated packed stream fails.
- a semaphore wait in eviction;
- a device allocation in the spilled write path;
- building the batch or running
hostBatchunder the object's monitor.SerializationSuitebroadcast tests pass.AI assistance: drafted with Claude Code and reviewed by the author.
Checklists
Documentation
Testing
(Please provide the names of the existing tests in the PR description.)
Performance
Microbenchmark on one Quadro RTX 6000 with Spark 3.5.0. The setup:
getColumnarBatchplus JCudf serialization) on the same build, with an uncontended semaphore. The harness was temporary and is not part of this PR.| Operation | Before | After |
|---|---|---|
| Evict, batch on device | 16.3 ms | 16.4 ms |
| Evict, batch in host memory | 27.2 ms | 5.6 ms |
| Evict, batch on disk | 120.1 ms | 88.5 ms |
| Reload evicted broadcast and call
batch| 128.1 ms | 73.6 ms |batchon a loaded broadcast takes one uncontended monitor, as before: about 20 ns per call.🤖 Generated with Claude Code