How can I tell PyCUDA which GPU to use?

I have two NVidia cards on my machine, and both are CUDA. When I run the sample script to get started with PyCUDA, presented here: http://documen.tician.de/pycuda/ , I get an error

nvcc fatal : Value 'sm_30' is not defined for option 'gpu-architecture' 

My computing GPU is the computing power of 3.0, so sm_30 should be the right option for the nvcc compiler. My GPU is only CC 1.2, so I thought maybe the problem. I installed CUDA version 5.0 for Linux without errors, as well as all compiler components and python components.

Is there a way to explicitly tell PyCUDA which GPU to use?

+4
source share
2 answers

nvcc not going to complain based on the specific GPUs you installed. It will be compiled for any type of GPU that you tell it to compile. The problem is that you specify sm_30 , which is not a valid option for --gpu-architecture , when the --gpu-code option is also specified.

You must pass compute_30 for --gpu-architecture and sm_30 for --gpu-code

Also make sure that you have the correct nvcc to use and it is no coincidence that you are using any old version of the CUDA toolkit.

After fixing the compilation problem, there is a CUDA_DEVICE environment variable that pycuda will observe to select the specific GPU installed.

From here :

 CUDA_DEVICE=2 python my-script.py 

By the way, someone else had your problem. Are you sure that you do not have an old version of the CUDA toolkit lying around what PyCUDA uses?

+1
source

I don’t know about the Python shell (or Python in general), but in C ++ you have the WGL_NV_gpu_affinity NVidia extension that allows you to target a specific GPU. You can probably write a wrapper for it in Python.

EDIT:

Now that I see that you are actually running Linux, the solution is simpler (C ++). You just need to list XDisplay before the init context.

Thus, basically the default GPU is usually aimed at the display bar "0.0"

To open a display with a second GPU, you can do something like this:

  const char* gpuNum = "0:1"; if (!(_display = XOpenDisplay(gpuNum ))) { printf("error: %s\n", "failed to open display"); } else { printf("message: %s\n", "display created"); } ////here comes the rest of context setup.... 
0
source

Source: https://habr.com/ru/post/1494303/


All Articles