Skip to content
Open
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 not self.is_ipc_enabled:
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
8 changes: 8 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 @@ -73,6 +73,14 @@ Fixes and enhancements
Windows, both ``ctypes.CFUNCTYPE`` and ``ctypes.WINFUNCTYPE`` are accepted.
(`#2439 <https://github.com/NVIDIA/cuda-python/issues/2439>`__)

- :meth:`DeviceMemoryResource.register` and
:meth:`PinnedMemoryResource.register` now raise ``RuntimeError`` when the
memory resource does not have IPC enabled. Previously they dereferenced a
``None`` attribute and terminated the process with a segmentation fault, so
the call could not be guarded with ``try``. A rejected registration no longer
leaves an entry in the memory resource registry.
(`#2568 <https://github.com/NVIDIA/cuda-python/issues/2568>`__)

Deprecation Notices
-------------------

Expand Down
18 changes: 18 additions & 0 deletions cuda_core/tests/memory_ipc/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import multiprocessing
import pickle
import re
import uuid

import pytest
from helpers.child_processes import child_timeout_sec, kill_subprocesses
Expand Down Expand Up @@ -51,6 +52,23 @@ def test_ipc_allocation_handle_rejects_negative_fd():
IPCAllocationHandle._init(-1, None)


@pytest.mark.human_authored
def test_register_rejects_non_ipc_memory_resource():
"""register() on a resource without IPC enabled raises instead of dereferencing None."""
device = Device()
device.set_current()
mr = DeviceMemoryResource(device)
assert not mr.is_ipc_enabled

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

# The rejected registration must not leave the resource in the registry.
with pytest.raises(RuntimeError, match=r"Memory resource [a-z0-9-]+ was not found"):
DeviceMemoryResource.from_registry(key)


class ChildErrorHarness:
"""Test harness for checking errors in child processes. Subclasses override
PARENT_ACTION, CHILD_ACTION, and ASSERT (see below for examples)."""
Expand Down
Loading