diff --git a/cuda_core/cuda/core/_device.pyi b/cuda_core/cuda/core/_device.pyi index cf8e1e18667..b2f4aa06f81 100644 --- a/cuda_core/cuda/core/_device.pyi +++ b/cuda_core/cuda/core/_device.pyi @@ -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 +from cuda.core._utils.cuda_utils import ComputeCapability, driver from cuda.core.graph import GraphBuilder from cuda.core.texture import (MipmappedArray, MipmappedArrayOptions, OpaqueArray, OpaqueArrayOptions, @@ -864,3 +864,9 @@ 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. + """ diff --git a/cuda_core/cuda/core/_device.pyx b/cuda_core/cuda/core/_device.pyx index 5ce22959e98..2e4d37da1d9 100644 --- a/cuda_core/cuda/core/_device.pyx +++ b/cuda_core/cuda/core/_device.pyx @@ -1657,6 +1657,21 @@ 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).""" global _is_cuInit diff --git a/cuda_core/tests/memory_ipc/test_vmm_fabric.py b/cuda_core/tests/memory_ipc/test_vmm_fabric.py index f3b444c0955..a01b12da2b9 100644 --- a/cuda_core/tests/memory_ipc/test_vmm_fabric.py +++ b/cuda_core/tests/memory_ipc/test_vmm_fabric.py @@ -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 +from cuda.core._device import _device_from_uuid, _set_device_attribute_for_testing 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 @@ -350,21 +350,23 @@ def test_queued_buffer_does_not_pin(vmm_fabric_device): assert _read(fresh) == b"\x58" * 16 -# This test is not currently run in any CI job @pytest.mark.skipif(IS_WINDOWS or IS_WSL, reason="Fabric IPC requires Linux") @pytest.mark.agent_authored(model="gpt-6.1-sol") def test_unsupported_fabric_construction(init_cuda): - unsupported = [ - device - for device in Device.get_all_devices() - if device.properties.virtual_memory_management_supported and not device.properties.handle_type_fabric_supported - ] - if not unsupported: - pytest.skip("No visible VMM device without fabric handle support") - for device in unsupported: + # 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. + 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) - message = str(info.value) - assert "NVLink fabric" in message - assert "accessible IMEX channel (/dev/nvidia-caps-imex-channels/channel*)" in message - assert f"device {device.device_id} reports no fabric handle support" in message + finally: + _set_device_attribute_for_testing(device, fabric_supported, None) + message = str(info.value) + assert "NVLink fabric" in message + assert "accessible IMEX channel (/dev/nvidia-caps-imex-channels/channel*)" in message + assert f"device {device.device_id} reports no fabric handle support" in message