Skip to main content

cuda_pci_address

Function cuda_pci_address 

Source
pub fn cuda_pci_address(ordinal: u32) -> Result<PCIAddress>
Expand description

PCI address of the CUDA device with runtime ordinal ordinal, from the CUDA driver.

ordinal is a runtime ordinal: the numbering CUDA exposes after applying CUDA_VISIBLE_DEVICES, as reported by CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL or torch.cuda.current_device(). Asking the driver rather than reconstructing that numbering from /proc/driver/nvidia keeps it correct for every CUDA_VISIBLE_DEVICES form (indices, GPU-<uuid>, MIG-<uuid>), for any CUDA_DEVICE_ORDER, and inside a container exposing a GPU subset.

Errors when the CUDA driver is not initialized in this process, or when ordinal is not visible.

Backend-agnostic: under ROCm rdmaxcel’s wrappers resolve to hipDeviceGet / hipGetDeviceCount / hipDeviceGetAttribute, and rocm_compat aliases the CU_DEVICE_ATTRIBUTE_PCI_* constants to their HIP equivalents. TODO(slurye): validate that this actually works on ROCm.