Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does CUDA assign device IDs to GPUs?

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 cudaSetDevice(int device) to select a different device.

Let's say I have two GPUs in my machine: a GTX 480 and a GTX 670. How does CUDA decide which GPU is device ID 0 and which GPU is device ID 1?


Ideas for how CUDA might assign device IDs (just brainstorming):

  • descending order of compute capability
  • PCI slot number
  • date/time when the device was added to system (device that was just added to computer is higher ID number)

Motivation: I'm working on some HPC algorithms, and I'm benchmarking and autotuning them for several GPUs. My processor has enough PCIe lanes to drive cudaMemcpys to 3 GPUs at full bandwidth. So, instead of constantly swapping GPUs in and out of my machine, I'm planning to just keep 3 GPUs in my computer. I'd like to be able to predict what will happen when I add or replace some GPUs in the computer.

like image 760
solvingPuzzles Avatar asked Dec 08 '12 20:12

solvingPuzzles


People also ask

How do I find Cuda device ID?

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 .

Does CUDA work with multiple GPUs?

To run multiple instances of a single-GPU application on different GPUs you could use CUDA environment variable CUDA_​VISIBLE_​DEVICES. The variable restricts execution to a specific set of devices. To use it, just set CUDA_​VISIBLE_​DEVICES to a comma-separated list of GPU IDs.

What is CUDA visible devices?

CUDA_VISIBLE_DEVICES is used by the CUDA driver to decide what devices should be visible to CUDA.

How do I choose a CUDA device?

The canonical way to select a device in the runtime API is using cudaSetDevice . That will configure the runtime to perform lazy context establishment on the nominated device. Prior to CUDA 4.0, this call didn't actually establish a context, it just told the runtime which GPU to try and use.


1 Answers

Set the environment variable CUDA_DEVICE_ORDER as:

export CUDA_DEVICE_ORDER=PCI_BUS_ID 

Then the GPU IDs will be ordered by pci bus IDs.

like image 136
Liang Xiao Avatar answered Sep 28 '22 02:09

Liang Xiao