cuda.core: release synchronous allocations in stream order through a host callback instead of blocking
メンテナーはふだん 1 日以内に返信
@Andy-Jost がすでに取り組んでいます。
2026年10月1日 から。
評価
この issue はまだ評価されていません。
説明
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.
- 主要言語
- Cython
- スター
- 3.4k
- フォーク
- 353
- 平均マージ
- 2日 3時間
- マージ済み PR(30日)
- 163
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
NVIDIA/cuda-python のほかの issue
-
[BUG]: the `__cuda_stream__` deprecation warning points to `Stream(obj)`, which always raises対応中かも @Iamsohungrynow が 5 日前に担当しました。 オープンbug cuda.core P1
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
NVIDIA/cuda-python#3505 · コメント 3 件 · リアクション 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
[BUG]: ProcessInfo.used_gpu_memory returns the NVML_VALUE_NOT_AVAILABLE sentinel as a byte countオープンtriage
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
NVIDIA/cuda-python#3468 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
triage
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
NVIDIA/cuda-python#3409 ·
メンテナーはふだん 1 日以内に返信
-
[BUG]: cleanup-pr-previews never removes previews of deleted PRs再び着手できるかも @rwgk が 48 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
NVIDIA/cuda-python#2952 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
[BUG]: LocatedHeaderDir is mutable, so callers can poison the cached header-directory lookup対応中かも @rwgk が 62 日前に担当しました。 オープンtriage
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
NVIDIA/cuda-python#2646 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信