From d33f51c17d25f98f9edf2035b059618c721833ce Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 30 Nov 2026 11:18:37 -0500 Subject: [PATCH] test(cuda.core): run test_unsupported_fabric_construction with a faked attribute test_unsupported_fabric_construction needed a Linux device with VMM but without fabric handle support. Every CI GPU supports fabric handles, so it never ran. Add a private _set_device_attribute_for_testing hook that seeds the attribute cache DeviceProperties already keeps (None clears the entry, so the next read queries the driver). The normal attribute path is unchanged. Devices are per thread, so the override is visible only to the calling thread. The test fakes no fabric support on the current device, checks the constructor's error, and restores the cache. Remove the "not currently run in any CI job" comment. Closes #3574. Co-Authored-By: Claude Opus 5.5 --- cuda_core/cuda/core/_device.pyi | 8 ++++- cuda_core/cuda/core/_device.pyx | 15 ++++++++++ cuda_core/tests/memory_ipc/test_vmm_fabric.py | 30 ++++++++++--------- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/cuda_core/cuda/core/_device.pyi b/cuda_core/cuda/core/_device.pyi index cf8e1e186671..b2f4aa06f813 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 5ce22959e985..2e4d37da1d90 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 f3b444c09551..a01b12da2b9e 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