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
8 changes: 1 addition & 7 deletions cuda_core/cuda/core/_device.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ from cuda.core._device_resources import DeviceResources
from cuda.core._event import Event, EventOptions
from cuda.core._memory._buffer import Buffer, MemoryResource
from cuda.core._stream import IsStreamType, Stream, StreamOptions
from cuda.core._utils.cuda_utils import ComputeCapability, driver
from cuda.core._utils.cuda_utils import ComputeCapability
from cuda.core.graph import GraphBuilder
from cuda.core.texture import (MipmappedArray, MipmappedArrayOptions,
OpaqueArray, OpaqueArrayOptions,
Expand Down Expand Up @@ -864,9 +864,3 @@ def _device_from_uuid(device_uuid: str) -> Device:
RuntimeError
If no device visible to this process has the UUID.
"""
def _set_device_attribute_for_testing(device: Device | int, attribute: driver.CUdevice_attribute, value: int | None) -> None:
"""Make ``Device(device).properties`` report ``value`` for ``attribute``, or read the driver again for ``None``.

Test hook: seeds the attribute cache of the device's properties. Devices
are per thread, so the override is visible only to the calling thread.
"""
14 changes: 0 additions & 14 deletions cuda_core/cuda/core/_device.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1657,20 +1657,6 @@ def _device_from_uuid(device_uuid: str) -> Device:
)


def _set_device_attribute_for_testing(
device: Device | int, attribute: driver.CUdevice_attribute, value: int | None
) -> None:
"""Make ``Device(device).properties`` report ``value`` for ``attribute``, or read the driver again for ``None``.

Test hook: seeds the attribute cache of the device's properties. Devices
are per thread, so the override is visible only to the calling thread.
"""
cdef DeviceProperties props = Device(device).properties
if value is None:
props._cache.pop(attribute, None)
else:
props._cache[attribute] = value


cdef inline int Device_ensure_cuda_initialized() except? -1:
"""Initialize CUDA driver and check version compatibility (once per process)."""
Expand Down
36 changes: 24 additions & 12 deletions cuda_core/tests/memory_ipc/test_vmm_fabric.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from cuda.bindings import driver
from cuda.core import Buffer, Device, VirtualMemoryResource, VirtualMemoryResourceOptions
from cuda.core._device import _device_from_uuid, _set_device_attribute_for_testing
from cuda.core._device import _device_from_uuid
from cuda.core._memory._ipc import VirtualMemoryFabricBufferDescriptor
from cuda.core._utils.cuda_utils import CUDAError, handle_return
from cuda_python_test_helpers import IS_WINDOWS, IS_WSL
Expand Down Expand Up @@ -350,22 +350,34 @@ def test_queued_buffer_does_not_pin(vmm_fabric_device):
assert _read(fresh) == b"\x58" * 16


class _PropertiesWithoutFabricSupport:
"""Device properties that report no fabric handle support and delegate everything else."""

handle_type_fabric_supported = False

def __init__(self, properties):
self._properties = properties

def __getattr__(self, name):
return getattr(self._properties, name)


@pytest.mark.skipif(IS_WINDOWS or IS_WSL, reason="Fabric IPC requires Linux")
@pytest.mark.thread_unsafe(reason="patches Device.properties for the whole process")
@pytest.mark.agent_authored(model="gpt-6.1-sol")
def test_unsupported_fabric_construction(init_cuda):
# Every CI GPU supports fabric handles, so fake a device without them.
# Only the attribute value is faked; the constructor's check and error run.
def test_unsupported_fabric_construction(init_cuda, monkeypatch):
# Every CI GPU supports fabric handles, so make the device report none.
# Only the property value is faked; the constructor's check and error run.
device = Device()
if not device.properties.virtual_memory_management_supported:
pytest.skip("Device does not support virtual memory management")
fabric_supported = driver.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_HANDLE_TYPE_FABRIC_SUPPORTED
_set_device_attribute_for_testing(device, fabric_supported, 0)
try:
assert not device.properties.handle_type_fabric_supported
with pytest.raises(RuntimeError) as info:
_resource(device)
finally:
_set_device_attribute_for_testing(device, fabric_supported, None)
properties = Device.properties
monkeypatch.setattr(
Device, "properties", property(lambda self: _PropertiesWithoutFabricSupport(properties.__get__(self)))
)
assert not device.properties.handle_type_fabric_supported
with pytest.raises(RuntimeError) as info:
_resource(device)
message = str(info.value)
assert "NVLink fabric" in message
assert "accessible IMEX channel (/dev/nvidia-caps-imex-channels/channel*)" in message
Expand Down
Loading