cuda.core: release synchronous allocations in stream order through a host callback instead of blocking
Maintainer thường phản hồi trong vòng 1 ngày
@Andy-Jost đang làm issue này rồi.
Từ ngày 1/10/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Problem
VirtualMemoryResource, _SynchronousMemoryResource and LegacyPinnedMemoryResource free memory with calls that are not stream-ordered: cuMemUnmap, cuMemFree and cuMemFreeHost. To honor the recorded deallocation stream, each one calls cuStreamSynchronize before the free, inside the deleter (_cpp/rt/virtual_memory.cpp, _memory/_synchronous_memory_resource.pyx, _memory/_legacy.py). The wait runs on whichever thread drops the last reference, which may be a garbage collection far from any CUDA code, and it holds that thread for as long as the queue on the stream is deep.
Beyond the latency, the wait has two failure modes, first described in this comment on #2906:
- It deadlocks when the host is part of the stream's dependency chain, for example a persistent kernel that waits on a host flag, or a buffer released inside a host callback.
- It cannot run during a graph capture. The release skips the wait, frees anyway, and warns.
A review comment on #2917 raised the debuggability cost: a main thread stalled for seconds at an arbitrary point in unrelated Python code, with nothing in the traceback to say why.
Proposal
Enqueue a host function on the deallocation stream with cuLaunchHostFunc. When the stream reaches it, the callback hands a preallocated item to the deferred-cleanup queue that graph user objects already use (see "Deferred cleanup" in _cpp/rt/GRAPH_ATTACHMENTS.md), and the next pending call on the main thread performs the free. Host callbacks may not call CUDA, so the callback only transfers the item, as the user-object destructor does today. The wait disappears, the ordering guarantee stays, and the memory remains allocated until the main thread next runs Python.
Alternative
PyTorch and RMM mark each pending release with an event and reap the finished ones on the next call into the resource, with an explicit flush for callers who need the memory back now. This avoids callbacks, but frees become lazy and depend on the resource being called again.
Scope
All three resources. The epic #2906 covers the VirtualMemoryResource redesign; this issue is the follow-up for every synchronous release in cuda.core.
- Ngôn ngữ chính
- Cython
- Star
- 3.4k
- Fork
- 353
- Merge trung bình
- 2 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 163
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của NVIDIA/cuda-python
-
[BUG]: the `__cuda_stream__` deprecation warning points to `Stream(obj)`, which always raisesCó thể đã có người làm @Iamsohungrynow đã nhận 5 ngày trước. Đang mởbug cuda.core P1
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
NVIDIA/cuda-python#3505 · 3 bình luận · 1 reaction · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG]: ProcessInfo.used_gpu_memory returns the NVML_VALUE_NOT_AVAILABLE sentinel as a byte countĐang mởtriage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
NVIDIA/cuda-python#3468 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
NVIDIA/cuda-python#3409 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG]: cleanup-pr-previews never removes previews of deleted PRsCó thể làm lại được @rwgk đã nhận 48 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
NVIDIA/cuda-python#2952 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG]: LocatedHeaderDir is mutable, so callers can poison the cached header-directory lookupCó thể đã có người làm @rwgk đã nhận 62 ngày trước. Đang mởtriage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
NVIDIA/cuda-python#2646 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày