From 0c5dea9a13cdc4c54784ea726357e37d54db7f65 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 30 Nov 2026 16:49:01 -0500 Subject: [PATCH] test(cuda.core): fake no fabric support without a production test hook test_unsupported_fabric_construction used _set_device_attribute_for_testing, a test-only function in cuda.core._device. Monkeypatch Device.properties with a proxy that reports no fabric handle support instead, and remove the hook. The constructor's real check and error still run. Co-Authored-By: Claude Opus 5.5 --- cuda_core/cuda/core/_device.pyi | 8 +---- cuda_core/cuda/core/_device.pyx | 14 -------- cuda_core/tests/memory_ipc/test_vmm_fabric.py | 36 ++++++++++++------- 3 files changed, 25 insertions(+), 33 deletions(-) diff --git a/cuda_core/cuda/core/_device.pyi b/cuda_core/cuda/core/_device.pyi index b2f4aa06f813..cf8e1e186671 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, driver +from cuda.core._utils.cuda_utils import ComputeCapability from cuda.core.graph import GraphBuilder from cuda.core.texture import (MipmappedArray, MipmappedArrayOptions, OpaqueArray, OpaqueArrayOptions, @@ -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. - """ diff --git a/cuda_core/cuda/core/_device.pyx b/cuda_core/cuda/core/_device.pyx index 2e4d37da1d90..1a1a6ce007c2 100644 --- a/cuda_core/cuda/core/_device.pyx +++ b/cuda_core/cuda/core/_device.pyx @@ -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).""" diff --git a/cuda_core/tests/memory_ipc/test_vmm_fabric.py b/cuda_core/tests/memory_ipc/test_vmm_fabric.py index a01b12da2b9e..ef43ef410938 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, _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 @@ -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