Skip to content
Merged
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: 7 additions & 1 deletion 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
from cuda.core._utils.cuda_utils import ComputeCapability, driver
from cuda.core.graph import GraphBuilder
from cuda.core.texture import (MipmappedArray, MipmappedArrayOptions,
OpaqueArray, OpaqueArrayOptions,
Expand Down Expand Up @@ -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.
"""
15 changes: 15 additions & 0 deletions cuda_core/cuda/core/_device.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 16 additions & 14 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
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
Expand Down Expand Up @@ -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
Loading