cuda.core: transfer VMM IPC allocations one at a time
维护者通常 1 天内回复
@Andy-Jost 已经在做这个了。
开始于 2026年10月14日。
评估
这个 Issue 还没有评估数据。
描述
Summary
#3028 shares VirtualMemoryResource buffers across processes with one POSIX file descriptor per physical allocation. A descriptor holds all N descriptors at once, and each transport multiplies that count. With chunks of a few MB, a buffer of several GB holds several hundred allocations, so 2N reaches the default limit of 1024 at about 500 chunks. When the receiver is the side at its limit, the kernel drops descriptors from the message and multiprocessing reports only received 0 items of ancdata (pytorch/pytorch#34768).
Analysis by @juenglin in https://github.com/NVIDIA/cuda-python/pull/3028#pullrequestreview-5523099776 and https://github.com/NVIDIA/cuda-python/pull/3028#issuecomment-6176167324.
Where the count scales
- Export:
ipc_descriptoropens one descriptor per chunk before it returns. Queue,Pipe,Pool: pickling runsDupFdonce per handle, andresource_sharerholds each copy until the receiver fetches it. The sender holds up to 2N during the transfer.- Receive: unpickling fetches all N before the import starts.
from_fds: it duplicates every integer it is given, so the receiver holds 2N until the caller closes the originals.- Raw socket: one
SCM_RIGHTSmessage carries at most 253 descriptors (SCM_MAX_FD), so the documented one-callsend_fdspattern fails above 253 chunks.
Proposed design
- Pickling registers one callback per chunk with a sender-side server and sends only chunk ids and sizes. No descriptor is opened yet.
- Each callback exports its chunk when the receiver asks, sends that single descriptor, and closes it.
- Unpickling reserves the whole address range first, then fetches, imports, maps, and closes one chunk at a time. If a chunk fails, it releases everything mapped so far.
Prior art: NCCL moves cuMem handles one at a time through a proxy thread over a Unix socket (p2p.cc, proxy.cc). PyTorch expandable segments pull each descriptor with pidfd_getfd, which needs ptrace permission and fails in containers (pytorch/pytorch#165685), so that part should not be copied. CPython's resource_sharer already sends one descriptor per connection; all N pile up only because one unpickle fetches every one.
Consequences
queue.put(buf)keeps working unchanged, and each side holds about one descriptor at a time.- A spawned child fetches its chunks from the parent's sharer like any other receiver, so the
get_spawning_popen()stash inVirtualMemoryBuffer.__reduce__becomes unnecessary. The rule that the memory stays pinned until theProcessobject is released goes with it. VirtualMemoryIPCBufferDescriptor.from_fds()already takes anIterable, so it can consume a generator and close each descriptor after its import without a signature change. The export side needs a new generator that yields one handle per chunk next tofds.- Fabric handles are 64 bytes of plain data and do not have this problem. The design stays specific to
posix_fd.
- 主要语言
- Cython
- 星标
- 3.4k
- 派生
- 353
- 平均合并
- 2 天 3 小时
- 30 天内合并 PR
- 163
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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 个 reaction · 已指派 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 天前认领,目前没有进行中的 PR。 未关闭
难度 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 个 reaction ·
维护者通常 1 天内回复