Skip to content

Commit 620afec

Browse files
Andy-Jostclaude
andcommitted
cuda.core: address the review of the register() UUID check
- test_register_rejects_mismatched_uuid skips non-pool resources: VirtualMemoryResource joined the ipc_memory_resource fixture and has no register(). - The internal-invariant error uses the "internal cuda.core error, please report" wording. - register() on DeviceMemoryResource and PinnedMemoryResource documents its RuntimeError and ValueError, and the 1.3.0 release notes record the fix. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 13a5c85 commit 620afec

7 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎cuda_core/cuda/core/_memory/_device_memory_resource.pyi‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ class DeviceMemoryResource(_MemPool):
137137
-------
138138
The registered mapped memory resource. If one was previously registered
139139
with the given key, it is returned.
140+
141+
Raises
142+
------
143+
RuntimeError
144+
If the memory resource is not IPC-enabled.
145+
ValueError
146+
If the memory resource already has a different UUID.
140147
"""
141148
@classmethod
142149
def from_allocation_handle(cls, device_id: Device | int, alloc_handle: int | IPCAllocationHandle) -> DeviceMemoryResource:

‎cuda_core/cuda/core/_memory/_device_memory_resource.pyx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ cdef class DeviceMemoryResource(_MemPool):
176176
-------
177177
The registered mapped memory resource. If one was previously registered
178178
with the given key, it is returned.
179+
180+
Raises
181+
------
182+
RuntimeError
183+
If the memory resource is not IPC-enabled.
184+
ValueError
185+
If the memory resource already has a different UUID.
179186
"""
180187
return <DeviceMemoryResource>(_ipc.MP_register(self, uuid))
181188

‎cuda_core/cuda/core/_memory/_ipc.pyx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ cdef _MemPool MP_from_allocation_handle(cls, alloc_handle):
455455
registered = self.register(uuid)
456456
if registered is not self:
457457
raise RuntimeError(
458-
"Internal error: register() returned a different memory "
459-
"resource than the one being registered"
458+
"internal cuda.core error, please report: register() returned a "
459+
"different memory resource than the one being registered"
460460
)
461461

462462
return self

‎cuda_core/cuda/core/_memory/_pinned_memory_resource.pyi‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ class PinnedMemoryResource(_MemPool):
126126
-------
127127
The registered mapped memory resource. If one was previously registered
128128
with the given key, it is returned.
129+
130+
Raises
131+
------
132+
RuntimeError
133+
If the memory resource is not IPC-enabled.
134+
ValueError
135+
If the memory resource already has a different UUID.
129136
"""
130137
@classmethod
131138
def from_allocation_handle(cls, alloc_handle: int | IPCAllocationHandle) -> PinnedMemoryResource:

‎cuda_core/cuda/core/_memory/_pinned_memory_resource.pyx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ cdef class PinnedMemoryResource(_MemPool):
179179
-------
180180
The registered mapped memory resource. If one was previously registered
181181
with the given key, it is returned.
182+
183+
Raises
184+
------
185+
RuntimeError
186+
If the memory resource is not IPC-enabled.
187+
ValueError
188+
If the memory resource already has a different UUID.
182189
"""
183190
return <PinnedMemoryResource>(_ipc.MP_register(self, uuid))
184191

‎cuda_core/docs/source/release/1.3.0-notes.rst‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ New features
104104
Fixes and enhancements
105105
----------------------
106106

107+
- ``register()`` on a :class:`~_memory.DeviceMemoryResource` or a
108+
:class:`PinnedMemoryResource` now raises ``ValueError`` when the resource
109+
already has a different UUID. The check used to be an ``assert``, so under
110+
``python -O`` a mismatched UUID silently rewrote the resource's UUID and
111+
corrupted the IPC registry.
112+
(`#2697 <https://github.com/NVIDIA/cuda-python/issues/2697>`__)
113+
107114
- A :class:`~_memory.DeviceMemoryResource` or a :class:`VirtualMemoryResource`
108115
sent through ``multiprocessing`` now names its device, and the
109116
``VirtualMemoryResource`` ``peers``, by UUID. The receiving process maps

‎cuda_core/tests/memory_ipc/test_errors.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ def test_register_rejects_mismatched_uuid(ipc_memory_resource):
100100
resource's UUID and silently corrupt the IPC registry.
101101
"""
102102
mr = ipc_memory_resource
103+
if not is_pool_resource(mr):
104+
pytest.skip("allocation handles and the registry are pool-only")
103105
assert mr.is_ipc_enabled
104106

105107
# The resource must already carry its own UUID (assigned on creation).

0 commit comments

Comments
 (0)