On Linux how to get GPU UUID or PCI domain/bus ID from GPU index?
Feb 18, 11:28pm

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:


1. Using nvidia-smi

The nvidia-smi command provides detailed information about NVIDIA GPUs, including their UUID and PCI bus ID.

Get PCI Bus ID:

bash
nvidia-smi -q | grep -A 4 "Bus Id"

This will output something like:

text
Bus Id                     : 00000000:01:00.0

The format is Domain:Bus:Device.Function.

Get GPU UUID:

bash
nvidia-smi --query-gpu=uuid --format=csv,noheader

This will list the UUIDs of all GPUs.


2. Using lspci

You can also use lspci to find the PCI domain/bus ID of NVIDIA GPUs:

bash
lspci | grep -i nvidia

Example output:

text
01:00.0 VGA compatible controller: NVIDIA Corporation Device 1e04 (rev a1)

The 01:00.0 is the PCI bus ID.


3. Mapping GPU Index to PCI Bus ID

If you want to map the GPU index (e.g., 0, 1) to its PCI bus ID, use:

bash
nvidia-smi --query-gpu=index,pci.bus_id --format=csv,noheader

Example output:

text
0, 00000000:01:00.0
1, 00000000:81:00.0

Here, GPU index 0 corresponds to PCI bus ID 00000000:01:00.0.


4. Using nvml (NVIDIA Management Library)

For programmatic access (e.g., in Python), you can use the pynvml library:

python
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()

Summary Table

GPU Information Commands
nvidia-smi -q | grep -A 4 "Bus Id"
PCI Bus ID
nvidia-smi --query-gpu=uuid --format=csv,noheader
GPU UUID
nvidia-smi --query-gpu=index,pci.bus_id --format=csv,noheader
Map GPU index to PCI Bus ID
lspci | grep -i nvidia
PCI Bus ID (alternative)
Feb 18, 11:28pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.