Sunday, 21 April 2013

CUDA: multiple GPU setting (Ubuntu)

CUDA: multiple GPU setting (Ubuntu)

I have multiple GPUs are installed on a computer and want to make one of them do computing and another do displaying. This blog is going to tell how to set Ubuntu and code your CUDA.

Firstly, check the display devices by using a command /usr/bin/nvidia-settings. You will see installed GPUs. You can set display option here or edit a config file /etc/X11/xorg.config.

And then, we code a program to count the GPU, get info and set computing GPU by folowing command:

1. cudaGetDeviceCount(int* NumberOfGPUs); to count nymber of GPUs
2. cudaGetDeviceProperties(&deviceProp,GPU_ID);
3. cudaSetDevice(GPU_ID);

Example code:

int deviceNum;
cudaError error;
cudaDeviceProp deviceProp; //struct used to keep a GPU info
for(int i=0;i<deviceNum;i++){
    if(error)printf("Error:getting property DeviceID:%d ErrorCode:%d\n",i,error);
    printf("Device %d: %s\n",i,;