[BUG]: Imported memory resources should take their location from the driver, not the caller
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 8/100
Hướng nghiên cứu
Start with _DMR_init_imported in cuda_core/cuda/core/_memory/_device_memory_resource.pyx and _ipc.MP_check_import_location, then _PMR_check_numa_id from the open PR #3530. Done means the driver-reported location is authoritative and a conflicting device_id raises ValueError, verified by a two-GPU test. The issue requires multi-GPU hardware and a driver 13.2+ to confirm the numbering assumption before any fix.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Is this a duplicate?
- I confirmed there appear to be no duplicate issues for this bug and that I agree to the Code of Conduct
Type of Bug
Silent Failure
Component
cuda.core
Describe the bug
When a memory pool is imported from an allocation handle, the pool's location is a property of the pool: it is fixed by the exporter's cuMemPoolCreate, and cuMemPoolImportFromShareableHandle takes no device or location argument. On a CUDA 13 build with a 13.2+ driver, the driver reports that location for an imported pool through CU_MEMPOOL_ATTR_LOCATION_TYPE and CU_MEMPOOL_ATTR_LOCATION_ID. cuda.core already queries both attributes on import (_ipc.MP_check_import_location), but the two resource classes use the result differently, and neither treats it as the only source of truth.
DeviceMemoryResource ignores the queried ID. _DMR_init_imported in cuda_core/cuda/core/_memory/_device_memory_resource.pyx uses only the location type (to reject a host pool, #3502) and then assigns the caller's value unconditionally:
(<DeviceMemoryResource>mr)._dev_id = dev_id
The docstring of from_allocation_handle states: "The pool's device is not checked against device_id." A caller that passes the device it intends to use rather than the pool's owner gets a resource that reports the wrong device. For example, a process whose primary device is B imports a pool that lives on device A with DeviceMemoryResource.from_allocation_handle(B, handle). The docstring's description of device_id ("the device ... for which the memory resource is created") reasonably invites this. The resulting resource reports device_id == B, and the code that treats _dev_id as the pool's owner acts on the wrong GPU:
_peer_access_utils.pyxusesmr._dev_idas the owner (owner_id,owner_device_id=mr._dev_id), sopeer_accessible_by = {B}is skipped as "owner always has access", although B is exactly the device that needs remote access granted.- The peer check
Device(mr._dev_id).can_access_peer(dev_id)asks about B instead of A. Buffer.device_idand anything derived from it name the wrong GPU.Buffer._reduce_helperin_buffer.pyxcallsDevice(mr.device_id).set_current()when the unpickling process has no current context, so it creates a context on the wrong GPU.
PinnedMemoryResource takes numa_id from the queried loc.id (_PMR_init_imported in _pinned_memory_resource.pyx), which is correct. #3530 (open, fixing #3508) adds an optional numa_id parameter to from_allocation_handle and, when the driver reports the node, raises ValueError if the caller's value disagrees (_PMR_check_numa_id).
The pickle paths are not affected by the device bug: _deep_reduce_device_memory_resource sends the owner's UUID (#3097) and the receiver maps it to its own ordinal.
The device check was deferred in #3502 ("A device ID mismatch on DeviceMemoryResource.from_allocation_handle is not checked. It needs a two-GPU machine to verify how the driver reports the pool's device in the importing process"), but no issue was filed for it. #3508 also describes the device path as already solved because from_allocation_handle "takes the device explicitly"; the caller-supplied device is the problem described here.
How to Reproduce
Requires two GPUs. I have not run this; the description above comes from reading the code.
- Process 1: create
DeviceMemoryResource(0, DeviceMemoryResourceOptions(ipc_enabled=True, max_size=1 << 21))and sendmr.allocation_handleto process 2 (for example withmultiprocessing, spawn start method). - Process 2: call
DeviceMemoryResource.from_allocation_handle(1, handle). - Observe that the import succeeds with
device_id == 1, whilecuMemPoolGetAttribute(..., CU_MEMPOOL_ATTR_LOCATION_ID)on the imported pool is expected to report device 0 in process 2's numbering. - Repeat with process 2 under a reordered
CUDA_VISIBLE_DEVICES(for example1,0) and check which ordinalCU_MEMPOOL_ATTR_LOCATION_IDreports. This verifies the assumption that the driver reports the owner in the importer's numbering. For an independent reference, process 1, which created the pool, also sendsDevice(0).uuid, as themultiprocessingreduction of aDeviceMemoryResourcedoes. The reported ordinal must equal_device_from_uuid(uuid).device_idin process 2. - Repeat with process 2 under
CUDA_VISIBLE_DEVICESrestricted to the non-owner device and record whatCU_MEMPOOL_ATTR_LOCATION_TYPEandCU_MEMPOOL_ATTR_LOCATION_IDreport. The header documentsCU_MEM_LOCATION_TYPE_INVISIBLEwithCU_DEVICE_INVALIDfor this case. Then grant the visible device access withcuMemPoolSetAccess, import an allocation withcuMemPoolImportPointer, and read and write it from the visible device. This determines whether a pool with an invisible owner is usable at all. Also record whatcuPointerGetAttributereturns forCU_POINTER_ATTRIBUTE_DEVICE_ORDINALon the imported pointer.
Expected behavior
Scope: the case where the driver reports the pool's location (CUDA 13 build, 13.2+ driver), for both DeviceMemoryResource and PinnedMemoryResource. The case without the query is tracked in #3508 / #3530 for pinned resources; for device resources the caller's device_id remains the only source there.
Prerequisite: the proposal assumes that CU_MEMPOOL_ATTR_LOCATION_ID on an imported device pool is a device ordinal in the importing process's numbering. This must be confirmed on a two-GPU machine (step 4 above) before the fix is merged. If the driver reports the ID in any other numbering, it cannot be used as device_id and the proposal needs rework. The check also matters for the multiprocessing path: _reconstruct_device_memory_resource passes the device it finds by UUID to from_allocation_handle, so with the conflict check below, a numbering mismatch would make every such transfer under a reordered CUDA_VISIBLE_DEVICES raise ValueError.
Proposal:
- The driver's value is authoritative.
DeviceMemoryResourcetakes its device fromCU_MEMPOOL_ATTR_LOCATION_ID, andPinnedMemoryResourcekeeps taking its node from it. - The caller's value must match the driver's value. When the driver reports the location, a
device_id/numa_idthat disagrees with it raisesValueError, for both classes. This keeps the conflict check that #3530 adds fornuma_idand adds the same check fordevice_id. The argument then has one meaning in every configuration: it names the pool's owner, and it is verified whenever the driver can verify it. Ignoring a conflicting value instead would let a caller's mistake pass on a 13.2+ driver and produce a wrong owner on an older driver or a CUDA 12 build, where the caller's value is the only source. - A registry hit applies the same check. Today a registry hit returns the registered resource with its original device and ignores a different
device_idargument. It should compare the argument with the resource's device and raise on a mismatch, as #3530 does fornuma_id. device_id=Noneis accepted byDeviceMemoryResource.from_allocation_handle. The resource then takes its device from the driver. When the driver cannot report the location (a CUDA 12 build ofcuda.core, or a driver older than 13.2),Noneraises, because nothing else determines the device.- Locality-domain pools take the device from
localized.deviceId. ForCU_MEM_LOCATION_TYPE_DEVICE_LOCALITY_DOMAIN,CUmemLocationis a union ofidwithlocalized.deviceIdandlocalized.localityDomainId, and the documentation does not say whatCU_MEMPOOL_ATTR_LOCATION_IDreturns for such a pool. The low byte,localized.deviceId, is the device ordinal whether the attribute returns the plain ordinal or the union's value. The locality domain is available separately asCU_MEMPOOL_ATTR_LOCALITY_DOMAIN_ID. A device with a single locality domain reports such a pool asCU_MEM_LOCATION_TYPE_DEVICE, so this needs hardware with more than one locality domain to verify. - Docs for both
from_allocation_handlemethods state that the argument must name the pool's owning device or node, not the device that will access the memory, and that it is checked against the pool when the driver reports the pool's location. - Tests include a permanent multi-GPU test, skipped on machines with fewer than two GPUs. It sends a
DeviceMemoryResourcethroughmultiprocessingfrom the process that created the pool to a process under a reorderedCUDA_VISIBLE_DEVICES, and asserts that the imported resource'sdevice_idequals_device_from_uuid(uuid).device_idfor the exporter's device UUID.
Pools whose owner is not visible:
An imported device pool whose device is not visible to the importer reports CU_MEM_LOCATION_TYPE_INVISIBLE with CU_DEVICE_INVALID. No ordinal in the importing process names that device. Today the import accepts the caller's ordinal, which is necessarily wrong. The header describes the type as "Location is not visible but device is accessible", so the memory is expected to be usable from a visible device that has been granted access. Step 5 above must confirm this. If it does:
- The import succeeds with
device_id=None. Any ordinal the caller passes conflicts with the pool and raisesValueError, like every other mismatch. DeviceMemoryResource.device_idraisesRuntimeErrorfor such a resource, with a message that the owning device is not visible to this process. A sentinel value is not used:-1isCU_DEVICE_CPUand means host inBuffer.device_id.peer_accessible_byworks without an owner. No device is skipped as the owner, and theDevice.can_access_peercheck is omitted because it needs the owner's ordinal. An error fromcuMemPoolSetAccesspropagates.Buffer._reduce_helperuses the default device when the process has no current context, as it already does for a negativedevice_id.Buffer.device_idand the DLPack device ask the driver per pointer. A buffer from such a resource usesCU_POINTER_ATTRIBUTE_DEVICE_ORDINAL, the path that buffers without a memory resource already take, instead of the resource'sdevice_id. If step 5 shows that the driver returns no usable ordinal for such a pointer,Buffer.device_idraisesRuntimeErrorlike the resource.- Receiving through
multiprocessing:_reconstruct_device_memory_resourcepassesdevice_id=Nonewhen no visible device has the exporter's UUID, instead of raising in_device_from_uuid. Without the driver query it keeps raisingRuntimeError. - Sending on through
multiprocessing: a process that imported such a pool cannot query the owner's UUID. When it sends the resource, or aBufferfrom it, to a third process, the reduction sendsNonein place of the UUID. The receiver then imports withdevice_id=Noneand determines the device with its own driver query. A receiver without the driver query raisesRuntimeError. The receiver may see the owning device even though the sender does not. Forwarding an imported pool through a third process is not covered by a test today, also not for a visible owner, so the fix adds one.
If step 5 shows that the memory is not usable, DeviceMemoryResource.from_allocation_handle raises RuntimeError at import for such a pool instead.
Callers that pass a non-owner device_id today get a ValueError on 13.2+ drivers. The error is raised without a release that warns first, as #3530 does for numa_id: the affected calls already report the wrong device and break peer access. The release note should call the change out.
- 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
Tất cả issue của NVIDIA/cuda-python
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area: ui-kit type: chore
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
schlessera/brain-kit#4598 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
mloda-ai/mloda-plugin-template#206 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Beginner Enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
JSPrismarine/JSPrismarine#3740 ·
Maintainer thường phản hồi trong vòng 1 ngày