how to select the device manually

Hi Guys,

A real quick question. I have 3 GPUs installed currently in the system, how can I choose which one to execute my cuda program other than using the default device? I am assuming the default selection is “device 0”? I saw some threads talking about coding in a Multi-GPUs environment, but what I need is just one device. So any easy way to do so?


You have a couple of choices. In your code, add a call to cudaSetDevice if you are using the runtime API. Alternatively, you can use the nvidia-smi utility and mark one of the GPUs are compute exclusive, and the other compute prohibited, and the driver will “automagically” run all CUDA tasks on the correct card.

I just tried cudaSetDevice() on my codes, it works just fine. Thanks!