How does CUDA assign device IDs to GPUs?

后端 未结 4 647
我在风中等你
我在风中等你 2020-11-30 07:41

When a computer has multiple CUDA-capable GPUs, each GPU is assigned a device ID. By default, CUDA kernels execute on device ID 0. You can use

4条回答
  •  渐次进展
    2020-11-30 07:48

    CUDA picks the fastest device as device 0. So when you swap GPUs in and out the ordering might change completely. It might be better to pick GPUs based on their PCI bus id using:

    cudaError_t cudaDeviceGetByPCIBusId ( int* device, char* pciBusId )
       Returns a handle to a compute device.
    
    cudaError_t cudaDeviceGetPCIBusId ( char* pciBusId, int  len, int  device )
       Returns a PCI Bus Id string for the device.
    

    or CUDA Driver API cuDeviceGetByPCIBusId cuDeviceGetPCIBusId.

    But IMO the most reliable way to know which device is which would be to use NVML or nvidia-smi to get each device's unique identifier (UUID) using nvmlDeviceGetUUID and then match it do CUDA device with pciBusId using nvmlDeviceGetPciInfo.

提交回复
热议问题