Repository navigation
Description
Description
pending_copy_excludes_other_stream_and_outlives_dropped_buffer in cuda-core/tests/shared_allocation.rs fails intermittently when the test binary runs its tests on parallel threads. It passes every time with --test-threads=1 and when run alone.
Error / actual behavior
thread 'pending_copy_excludes_other_stream_and_outlives_dropped_buffer' panicked at cuda-core/tests/shared_allocation.rs:84:5:
assertion failed: storage.acquire(&other, false, false).is_err()
Line 84 is the first check after zero_async. A read lease on other succeeds while the zero fill on stream sits behind the Gate host function. The write lease from enqueue_access has therefore left active before its completion event fired, or never conflicted.
Over 40 runs each of the built test binary at 8d8254869:
| Mode | Failures |
|---|---|
| default (parallel threads) | 8 / 40 |
--test-threads=1 |
0 / 40 |
--exact pending_copy_excludes_other_stream_and_outlives_dropped_buffer |
0 / 40 |
Expected behavior
The acquire on other returns CUDA_ERROR_NOT_READY until drop(gate), regardless of which tests share the process.
Minimal reproduction example
cargo test -p cuda-core --test shared_allocation --no-run
BIN=$(ls -t target/debug/deps/shared_allocation-* | grep -v '\.d$' | head -1)
fails=0; for i in $(seq 40); do "$BIN" -q >/dev/null 2>&1 || fails=$((fails+1)); done; echo "parallel: $fails/40"
fails=0; for i in $(seq 40); do "$BIN" -q --test-threads=1 >/dev/null 2>&1 || fails=$((fails+1)); done; echo "serial: $fails/40"Operating System
Fedora 44, Linux 7.2.13
GPU and GPU Architecture
NVIDIA GeForce RTX 5060 Laptop GPU, sm_120
CUDA driver version
615.78.08 (CUDA 13.4 UMD), toolkit 13.3
cargo oxide doctor
All checks pass.
rustc version
1.98.0 (root workspace pin)
llc version
Not applicable (host workspace test).
Additional context
The other tests in the file create their own Context::new(0) and streams, and stream_drop_is_nonblocking_and_holds_context_until_completion also blocks its stream with a Gate host function. The interaction with those concurrent tests is the likely trigger. The full host workspace otherwise passes (264 tests).
Activity
build4me2 commentedon Nov 15, 2026
I reproduced and traced this on a GB10 (sm_121, CUDA 13.0, driver 610.57.04). The cause matches the one named in #1782's concurrency audit (context-synchronizing setup overlapping gated work), and on current
main(348895e42) the test passes: 0/200 parallel runs.The specific trigger is
fresh_thread_allocation_binds_its_context. Dropping itsfrom_hostbuffer deferscuMemFree_v2to thecuda-resource-retirementthread. That call doesn't return until the gated stream drains, and while it waits, the test thread'scuMemsetD8Async(fromzero_async) is blocked too, so nothing moves until the gate's 10 s timeout. At6156bed1d, running just those two tests 30 times gave 9 failures, each one a run wherezero_asynctook 10 s. Leaking the buffer instead of freeing it gave 0/30.The test lock doesn't cover the underlying problem: the same stall is reachable through the public API. On
main, dropping afrom_hostbuffer while another stream in the context has pending work blocks other threads' driver calls, including on an unrelated idle stream, until that work finishes.Reproduction (4.8 s stall, 3/3 runs)
With raw driver calls the result is the same: the memset takes 4.8 s behind a pending
cuMemFree, and 0.0 ms with no free or withcuMemFreeAsync.I think the fix is to move
from_hostandzeroedonto the stream-ordered allocation path (Owner::StreamOrdered, freed withcuMemFreeAsync), which doesn't stall. #89 moved them tomalloc_syncto fix mismatched alloc/free pairing, so this needs the matched stream-ordered path rather than swapping the call back. I'll open a separate issue to track it unless you'd rather handle it here.