PyCUDA Windows Installation (Offline)

PyCUDA
PyCUDA is a Python extension for CUDA which is useful for prototyping GPU solutions with Python. Here are some things it is being used for. http://wiki.tiker.net/PyCuda/ShowCase It isn’t officially supported by NVIDIA though.
Because my environment is offline, many of the things I mention here may be extraneous.

First, install CUDA Toolkit for windows – I assume that you have done so or you probably wouldn’t be here.

There is the official installation page for Windows here : http://wiki.tiker.net/PyCuda/Installation/Windows , which you really should follow if you have internet access on your installation computer. If you follow that and you still have trouble, come back here to see if the rest of this helps.

You need Microsoft Visual Studio 2010 for this installation. Or at least, the correct cl.exe compiler and any other dependencies it may need. I have not tested with later versions. If you have a 64-bit system and Python installation, make sure that you are using the 64-bit compiler and not the 32-bit one. The 64-bit cl.exe is located here :

c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\

You can run cl.exe to check whether you are using the 32 or 64 bit version.

Offline Installation

In the case that you are as unfortunate as me to have to install this stuff offline, here are the various files that I used to install pycuda. https://onedrive.live.com/redir?resid=692F268A60881F2D!15820&authkey=!AJpd-O9yUi_O_1w&ithint=file%2czip

In the case you need any other additional wheel files, download them here: http://www.lfd.uci.edu/~gohlke/pythonlibs/

Do note that you should download the correct wheel file for your python distribution.

For example,

boost_python-1.59-cp27-none-win_amd64.whl

cp27 means Python 2.7. For my installation I downloaded those with cp34 as I had a Python 3.4 installation.

You can use pip, located under ‘scripts’ in the Python directory to install whl (known as wheel) files.

pip install pathandfilenamewhatever.whl

Boost Libraries Installation

After the various installations, I was not able to find the boost thread library when I tried to compile PyCUDA. Hence, I had to compile the boost libraries manually.

Refer to section 5.1 here http://www.boost.org/doc/libs/1_55_0/more/getting_started/windows.html

for the easiest method to compile the boost libraries.

After the boost libraries were compiled, I went to the ‘boost/lib’ directory and manually copied out the files I wanted to the python installation\libs directory :

  • libboost-thread-vc100-mt-1_59
  • libboost_thread-vc100-mt-gd-1_59

PyCUDA Compilation

Now, we can start compiling PyCUDA.

Unzip the PyCUDA source files, and at the command prompt inside the PyCUDA directory, type this:
configure

This will create a siteconf.py at your directory which houses the information required by PyCUDA for installation.

Here’s how my siteconf.py looks like:

BOOST_INC_DIR = ['']
BOOST_LIB_DIR = ['']
BOOST_COMPILER = 'msvc'
USE_SHIPPED_BOOST = True
BOOST_PYTHON_LIBNAME = ['libboost_python3-vc100-mt-1_59']
BOOST_THREAD_LIBNAME = ['libboost_thread-vc100-mt-1_59']
CUDA_TRACE = False
CUDA_ROOT = 'C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v7.5'
CUDA_ENABLE_GL = False
CUDA_ENABLE_CURAND = True
CUDADRV_LIB_DIR = ['${CUDA_ROOT}/lib', '${CUDA_ROOT}/lib/x64']
CUDADRV_LIBNAME = ['cuda']
CUDART_LIB_DIR = ['${CUDA_ROOT}/lib', '${CUDA_ROOT}/lib/x64']
CUDART_LIBNAME = ['cudart']
CURAND_LIB_DIR = ['${CUDA_ROOT}/lib', '${CUDA_ROOT}/lib/x64']
CURAND_LIBNAME = ['curand']
CXXFLAGS = ['/EHsc']
LDFLAGS = ['/FORCE']

Set USE_SHIPPED_BOOST to true so that it will look for the boost libraries inside the python directory. I had to set the CXXFLAGS and LDFLAGS as such so that the code would compile. Sounds not so good, I know, but what the heck, it compiles.
Then type,
python setup.py install

It should compile at this stage. Hooray!!!

After the installation:

Edit nvcc.profile (in CUDA\v7.5\bin) (or whereever you installed the Cuda GPU Computing toolkit) and set INCLUDES flag to this:
INCLUDES += "-I$(TOP)/include" "-I$(TOP)/include/cudart" "-IC:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/include" $(_SPACE_)

 

And that is my personal, painful story of PyCUDA Windows Installation.

This page helped me a lot! Thanks Marty! I didn’t need to install the Windows SDK for this installation though.

Advertisements

2 thoughts on “PyCUDA Windows Installation (Offline)

Add yours

  1. Hello Pier,

    I tried you method but it seems, compilation failed with the message:

    LINK : fatal error LNK1181: cannot open input file ‘cuda.lib’
    error: command ‘D:\\_app\\visualstudio13\\VC\\BIN\\link.exe’ failed with exit status 1181

    I have the cuda.lib defined in the cudatoolkit…

    Do you have any idea ?
    Kind regards

    Like

    1. Just a wild guess : Have you set up the CUDA_PATH under System Properties->Advanced->Environment Variables? Make sure CUDA_LIB_PATH is also set and it points to the correct place where cuda.lib is found. Mine is %CUDA_PATH%\lib\x64 and CUDA_PATH is c:\Program files\NVIDIA GPU Computing Toolkit\CUDA\v7.5 . The locations of the cuda files on your PC is probably different.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: