Search code examples
cudapycuda

How can i tell PyCUDA which GPU to use?


I have two NVidia cards in my machine, and both are CUDA capable. When I run the example script to get started with PyCUDA seen here: http://documen.tician.de/pycuda/ i get the error

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

My computing GPU is compute capability 3.0, so sm_30 should be the right option for the nvcc compiler. My graphics GPU is only CC 1.2, so i thought maybe that's the problem. I've installed the CUDA 5.0 release for linux with no errors, and all the compiler components and python components.

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


Solution

  • nvcc isn't going to complain based on the specific GPUs you have installed. It will compile for whatever GPU type you tell it to compile for. The problem is you are specifying sm_30 which is not a valid option for --gpu-architecture when a --gpu-code option is also specified.

    You should be passing compute_30 for --gpu-architecture and sm_30 for --gpu-code

    Also be sure you have the correct nvcc in use and are not inadvertently using some old version of the CUDA toolkit.

    Once you have the compile problem sorted out, there is an environment variable CUDA_DEVICE that pycuda will observe to select a particular installed GPU.

    From here:

    CUDA_DEVICE=2 python my-script.py
    

    By the way someone else had your problem. Are you sure you don't have an old version of the CUDA toolkit laying around that PyCUDA is using?