Repository navigation
fix(cuda-core): quiesce background resource retirement before process exit - #1831
nihalpasham wants to merge 2 commits into
Conversation
… exit `cuda-core::completion` spawns a detached `"cuda-resource-retirement"` thread backed by a static queue that never closed. When a binary drops a `DeviceBuffer` right before returning from `main()` (such as `barrier` under `compute-sanitizer --tool synccheck`), CRT `exit()` runs `atexit` and `.fini_array` destructors in `libsanitizer-public.so` and `libcuda.so` concurrently with the worker waking up on another core and calling `cuEventQuery`, `cuMemFree`, and `cuEventDestroy` against tearing-down driver and sanitizer state. Register an ISO C `atexit` handler after `cuInit` and sanitizer startup so LIFO exit ordering invokes it before `libcuda` and Compute Sanitizer destructors. Under a worker driver gate, drain already-completed cleanups (including cascading buffer frees so `--leak-check full` reports zero leaked allocations), mark the queue exiting, and leak any genuinely unfinished GPU leases without joining the worker thread (avoiding Windows DLL loader-lock deadlocks). Also park the idle worker on a `Condvar` instead of polling every 1 ms when the queue is empty. Resolves NVBug 7090395. Signed-off-by: nihalpasham <[email protected]>
|
@nihalpasham thanks! The approach looks reasonable. I found two things we ought to fix before merging:
I reproduced both locally, using controlled scheduling for the initialization race. Could we address these and add regression tests? |
… items Address two review findings in `cuda-core::completion` exit quiescence: 1. Allocate the shared `RetirementQueue` inside `RetirementRuntime` ahead of `atexit` registration and worker creation so `on_process_exit()` observes and records shutdown state even if invoked while first-use initialization is still in flight, preventing worker startup after exit teardown begins. 2. Poll existing `in_flight` items in `shutdown_for_exit()` even when `inbox` is empty so GPU events that completed since the worker's last poll (and any cascading buffer frees they enqueue) are drained instead of leaked. Add unit regression tests for both scenarios. Signed-off-by: nihalpasham <[email protected]>
|
@elibol addressed both in |
What This PR Does
Quiesces
cuda-core's detached"cuda-resource-retirement"worker thread beforelibcudaand Compute Sanitizer (libsanitizer-public.so) tear down global state during processexit(), resolving NVBug 7090395:1. Scoped
RetirementQueueExit Fence & Idle ParkingRTX 5080,sm_120a): Undercargo oxide sanitize barrier --tool synccheck(andracecheck), all three barrier checks printedSUCCESSbefore crashing at exit (segfault at 0xaa48inlibcuda.so.620.70.08oncuda_13.5, andcuda-resource-rsegfaulting inlibsanitizer-public.so/ glibcfastbinscorruption indmesg.logoncuda_ext).enqueuelocks onlyInbox(queue), never waiting ondriver_gateor driver calls.recv_timeoutloop when empty withCondvar::wait, polling at 1 ms only while in-flight GPU events remain queued.cuda-core/src/completion.rsRetirementQueuedriver_gate,atexitdrain/fence, unit testcuda-core/tests/shared_allocation.rssynccheckexit-after-buffer-drop regression testVerification
RTX 5090,sm_120a):cargo test -p cuda-core(all unit, integration, trybuild, and doc tests +gpu_fence_tests --ignored): PASScargo test -p cuda-async -- --test-threads=1: PASScargo oxide sanitize vecadd --tool memcheck,barrier --tool racecheck,barrier --tool synccheck: PASS (0errors)compute-sanitizer --tool memcheck --leak-check full .../barrier: PASS (0 bytes leaked in 0 allocations)Test plan
cargo fmt --all -- --checkcargo clippy --workspace --all-targets -- -D warningsRUSTDOCFLAGS="-D warnings" cargo doc -p cuda-core --no-depscargo test -p cuda-core&cargo test -p cuda-core --lib gpu_fence_tests -- --ignoredcargo test -p cuda-async -- --test-threads=1just -f cuda-oxide/Justfile check-guards