On Linux, you can retrieve the GPU UUID or PCI domain/bus ID from a GPU index (e.g., nvidia-smi index) using the following methods:
nvidia-smiThe nvidia-smi command provides detailed information about NVIDIA GPUs, including their UUID and PCI bus ID.
bashnvidia-smi -q | grep -A 4 "Bus Id"
This will output something like:
textBus Id : 00000000:01:00.0
The format is Domain:Bus:Device.Function.
bashnvidia-smi --query-gpu=uuid --format=csv,noheader
This will list the UUIDs of all GPUs.
lspciYou can also use lspci to find the PCI domain/bus ID of NVIDIA GPUs:
bashlspci | grep -i nvidia
Example output:
text01:00.0 VGA compatible controller: NVIDIA Corporation Device 1e04 (rev a1)
The 01:00.0 is the PCI bus ID.
If you want to map the GPU index (e.g., 0, 1) to its PCI bus ID, use:
bashnvidia-smi --query-gpu=index,pci.bus_id --format=csv,noheader
Example output:
text0, 00000000:01:00.0 1, 00000000:81:00.0
Here, GPU index 0 corresponds to PCI bus ID 00000000:01:00.0.
nvml (NVIDIA Management Library)For programmatic access (e.g., in Python), you can use the pynvml library:
pythonfrom pynvml import * nvmlInit() device_count = nvmlDeviceGetCount() for i in range(device_count): handle = nvmlDeviceGetHandleByIndex(i) pci_info = nvmlDeviceGetPciInfo(handle) print(f"GPU {i}: PCI Bus ID: {pci_info.busId}") uuid = nvmlDeviceGetUUID(handle) print(f"GPU {i}: UUID: {uuid.decode('utf-8')}") nvmlShutdown()
nvidia-smi -q | grep -A 4 "Bus Id"nvidia-smi --query-gpu=uuid --format=csv,noheadernvidia-smi --query-gpu=index,pci.bus_id --format=csv,noheaderlspci | grep -i nvidia