Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cuda_core/cuda/core/_memory/_ipc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ cdef _MemPool MP_register(_MemPool self, uuid):
existing = registry.get(uuid)
if existing is not None:
return existing
if self._ipc_data is None:
raise RuntimeError("Memory resource is not IPC-enabled")
assert self.uuid is None or self.uuid == uuid
registry[uuid] = self
self._ipc_data._alloc_handle._uuid = uuid
Expand Down
4 changes: 4 additions & 0 deletions cuda_core/docs/source/release/1.2.0-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
Fixes and enhancements
----------------------

- ``DeviceMemoryResource.register()`` and ``PinnedMemoryResource.register()``
now raise ``RuntimeError`` when called on a resource without IPC enabled,
instead of dereferencing missing IPC state.

- Graph node resources are now retained independently across graph clones,
executable graphs, updates, node deletion, and in-flight launches. Previously,
modifying a graph definition could release resources still used by an
Expand Down
19 changes: 19 additions & 0 deletions cuda_core/tests/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import ctypes
import sys
import uuid

from cuda.bindings import driver

Expand Down Expand Up @@ -570,6 +571,24 @@ def test_memory_resource_and_owner_disallowed():
Buffer.from_handle(ptr, 20, mr=DummyDeviceMemoryResource(Device()), owner=a)


@pytest.mark.parametrize("resource_type", [DeviceMemoryResource, PinnedMemoryResource])
def test_register_without_ipc_raises(init_cuda, resource_type):
device = Device()
device.set_current()

if resource_type is DeviceMemoryResource:
mr = resource_type(device)
else:
skip_if_pinned_memory_unsupported(device)
mr = create_pinned_memory_resource_or_xfail(xfail_device=device)

try:
with pytest.raises(RuntimeError, match="Memory resource is not IPC-enabled"):
mr.register(uuid.uuid4())
finally:
mr.close()


def test_owner_close():
a = (ctypes.c_byte * 20)()
ptr = ctypes.addressof(a)
Expand Down
Loading