본문 바로가기
언어/ㄴTheano

pycuda install problem

by 공대우냉이 2016. 1. 11.

Problem

  • I tried to install PyCUDA using pip:
1
$ sudo pip install pycuda
  • The installation tries to compile a few C++ files and it failed on the very first file with this error:
1
2
3
4
5
6
In file included from src/cpp/cuda.cpp:1:0:
src/cpp/cuda.hpp:14:18: fatal error: cuda.h: No such file or directory
#include <cuda.h>
                ^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

Investigation

  • This error was strange because I had set CUDA_ROOT and had added the bin path of CUDA installation to PATH environment variable. So, the installer should have found cuda.h which I could see was present in $CUDA_ROOT/include

  • To see what was happening, I tried the same command with verbosity:

1
$ sudo pip -vvv install pycuda
  • Now I could see that it was failing to find nvcc.

  • On downloading the source code of PyCUDA and checking setup.py, I saw that the check for nvcc was used to figure out the CUDA_ROOT and CUDA_INC_DIR.

  • The reason nvcc was not visible was that CUDA_ROOT was set for my user, but this PATH is not visible when a command is run under sudo, as described here. The solution was to make the CUDA bin path visible to sudo.

Solution

To make the $CUDA_ROOT/bin available in PATH for sudo, we can follow the steps described here. For example, on my system with CUDA 7.0 I followed these steps:

  • Created a new file /etc/profile.d/cuda.sh and added this line:
1
export PATH=/usr/local/cuda-7.0/bin:$PATH
  • Opened root shell without resetting PATH and ran the pip installation:
1
2
$ sudo su -
$ pip install pycuda

This worked and PyCUDA was installed successfully! :-)

Tried with: PyCUDA 2015.1.2, CUDA 7.0 and Ubuntu 14.04


========================================================================================================================================

reference

http://codeyarns.com/tag/pycuda/