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-smi
The nvidia-smi command provides detailed information about NVIDIA GPUs, including their UUID and PCI bus ID.
nvidia-smi -q | grep -A 4 "Bus Id"
This will output something like:
Bus Id : 00000000:01:00.0
The format is Domain:Bus:Device.Function.
Domain:Bus:Device.Function
nvidia-smi --query-gpu=uuid --format=csv,noheader
This will list the UUIDs of all GPUs.
lspci
You can also use lspci to find the PCI domain/bus ID of NVIDIA GPUs:
lspci | grep -i nvidia
Example output:
01:00.0 VGA compatible controller: NVIDIA Corporation Device 1e04 (rev a1)
The 01:00.0 is the PCI bus ID.
01:00.0
If you want to map the GPU index (e.g., 0, 1) to its PCI bus ID, use:
0
1
nvidia-smi --query-gpu=index,pci.bus_id --format=csv,noheader
0, 00000000:01:00.0 1, 00000000:81:00.0
Here, GPU index 0 corresponds to PCI bus ID 00000000:01:00.0.
00000000:01:00.0
nvml
For programmatic access (e.g., in Python), you can use the pynvml library:
pynvml
from 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()
This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.
Vibe can make mistakes. Check answers. Learn more