Repository navigation
Description
Environment
cutile/cuda-core0.5.0 (tagcutile-rs/v0.5.0), Rust 1.99.1, Linux x86_64- RTX 5090, driver 620.70.06, CUDA 13.4
- Workload: a serving engine that loads a 27B NVFP4 model. Model load captures many CUDA graphs and drops many stream-ordered buffers along the way.
Symptom
One of six server starts using 0.5.0 died with SIGSEGV during model load. The same workload on 0.4.0 has not crashed in 12+ runs (same host, same driver, same model).
#0 libcuda.so.1 + 0x350ef4
#3 cuMemFreeAsync (libcuda.so.1)
#4 cuda_core::allocation::Allocation::drop::{closure}
#5 cuda_core::completion::enqueue::{closure} thread "cuda-resource-retirement"
The free keeps its stream alive via Arc, and the pointer is freed exactly once (0.4 freed it synchronously, 0.5 frees it stream-ordered), so this does not look like a dangling stream or a double free.
What changed in 0.5, and why we suspect the retirement path
Allocation::dropnow callscompletion::deferfor stream-ordered allocations. That pending item hasevent: None, so the cleanup is not completion-bound: it runs shortly after on thecuda-resource-retirementthread and callscuMemFreeAsync(ptr, allocation_stream)(seecuda-core/src/allocation.rsdrop andcuda-core/src/completion.rs).- That path has no capture awareness: no
cuStreamIsCapturingcheck, and no coordination with capture begin/end. cuda-async'scapture_onalways begins capture inCU_STREAM_CAPTURE_MODE_RELAXED(cuda-async/src/cuda_graph.rs), which disables the driver's cross-thread interference detection. Our own AOT driver captures inCU_STREAM_CAPTURE_MODE_GLOBAL, where a call from another thread to a capturing stream is an invalid operation.
So a buffer dropped during (or just before) a capture is freed by a different thread, at an arbitrary later time, on a stream that may be mid-capture. In 0.4 the free happened synchronously on the dropping thread, at a point the application controlled and could keep outside capture windows; in 0.5 it escapes that ordering entirely. That matches an intermittent failure that only shows up in a graph-capturing load.
At minimum this should surface as CUDA_ERROR_STREAM_CAPTURE_UNSUPPORTED (or be queued), not a segfault in cuMemFreeAsync. A plausible sketch of a reproducer: thread A loops begin_capture(GLOBAL on S) -> launch noop -> end_capture, while thread B drops DeviceBuffers that were allocated on S, so some frees land inside A's capture window.
Expected
- Freeing a stream-ordered allocation while its stream is capturing is either supported and queued until the capture ends, or
- the retirement path detects capture and postpones the free (e.g.
cuStreamIsCapturing, retry afterend_capture), and - the driver reports an error instead of crashing.
Questions
- Is dropping a stream-ordered buffer while its stream is capturing supported today? If not, can
Allocation::drop/completion::deferavoid calling the driver in that state, the way other unknown-completion cases are retained/leaked instead of freed? - Would it be reasonable for
cuda-async's capture path to own a capture depth so retirement defers frees until the outermost capture ends (or to expose the capture mode so callers can useTHREAD_LOCAL)? - Is
THREAD_LOCALcapture intended to make cross-thread retirement safe here, givencuda-asynccurrently does not expose the mode?
Reproduction status
No minimal reproducer yet. The failure is intermittent (~1/6 model loads) and needs a graph-capturing load. We have a complete 0.5.0 port of the engine and a host we can run stress loops on; we can instrument completion::defer with cuStreamIsCapturing and thread-id logging to confirm the mechanism and to test a patch. If you tell us the harness shape you prefer, we will build a standalone reproducer.
Related: #1783 (Context::drop runs on the retirement thread and races exit()), #1842 (deferred frees and recorded drop errors).
Activity