Installing PyCuda on Windows

Windows 7 64-bit with Visual Studio Professional 2008 (no Boost!)

Software required:

  • Python 2.7, using the amd64 installer on the web site
  • Numpy 1.5.1, using amd64 installer
  • pycuda 0.94 amd64 binary installer from Christopher Gohlke (see binaries section)
  • CUDA 3.2 Toolkit
  • Visual Studio Professional 2008 These here are the steps to follow:

  • Install Python, Numpy, pycuda and CUDA toolkit to default dirs.

  • VS 2008 only needs custom install - just C++ tools incl x64 compilers.
  • Add the following to PATH (case sensitive) environment variable:

C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\;C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\amd64;C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE

  1. Edit nvcc.profile (in CUDA\3.2\bin) and set INCLUDES flag to this:

INCLUDES                +=  "-I$(TOP)/include" "-I$(TOP)/include/cudart" "-IC:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/include" $(_SPACE_)

Note this method will probably also work for 32 bit - just substitute 32 bit versions of software. Also, for 32 bit can probably use VS 2008 Express Edition plus relevant Windows SDK. I had problems with this because it didn't seem to install the x64 compilers.

Instructions by Sam Adams

Please don't forget that this is a Wiki. If you feel like you can improve these instructions, please don't hesitate to do so. There's an edit button in the header, and you won't even need an account or any such nonsense.

Binaries

Christoph Gohlke at UC Irvine has made binary packages of PyCUDA that might be able to save you the trouble of building PyCUDA yourself. You can find them on his page of Python packges.

Using Visual Studio 2008

/!\ This set of instructions has not been updated for the removal of the Boost dependency in 0.94. If you use these instructions, please perform the necessary updates (and remove this note)! Thanks! -- AndreasKloeckner 2010-09-21 00:22:05

The following software was used here:

  • Python 2.6
  • NumPy 1.3.0 and Scipy 0.7.1
  • pycuda version 0.94beta (i.e. from git)
  • Visual Studio 2008
  • boost 1.38: I suggest using BoostPro installer as that enables you to just install the Boost libraries you need (much faster than compiling all of Boost!)
  • CUDA 2.2 (185.xx driver)
  • Windows XP 32-bit First of all - you need git version for Windows (git is a version control system). Then get (with git) a fresh copy of PyCUDA. To do this open GitBash and type in the command line

git clone http://git.tiker.net/trees/pycuda.git

You need to have and use Visual Studio 2008 (previous version does not seem to work).

I recommend to use BoostPro installer, boost 1.38, which can interactively install binary dlls and libs. You need only the ones for Version 9 of MSVC, and make sure you get a DLL variant. Also make sure you install the Boost Python, Boost DateTime, and BoostThread libraries, otherwise the PyCUDA setup won't work.

Then put this text into PyCUDA's source directory as siteconf.py (potentially with adapted paths):


BOOST_INC_DIR = [r'C:/boost']
BOOST_LIB_DIR = [r'C:/boost/lib']
BOOST_PYTHON_LIBNAME = ['boost_python-vc90-mt-1_38']
BOOST_THREAD_LIBNAME = ['boost_thread-vc90-mt-1_38']
CUDA_ROOT = r'C:\CUDA'
CUDADRV_LIB_DIR = [r'C:/CUDA/lib']
CUDADRV_LIBNAME = ['cuda']
CXXFLAGS = ['/EHsc']
LDFLAGS = ['/FORCE']

After driver installation (python setup.py install), copy all boost dlls into windows/system32 directory or add the path to it. You minimally need boost_python-vc90-mt-1_38.dll and boost_thread-vc90-mt-1_38.dll.

Finally, add a HOME environment variable in Windows: it doesn't matter what it is, so you can make it "123456" or your My Documents directory, etc.

(Instructions by {loginovdv, wuzzyview} at gmail com. Instead of emailing him directly, please go to the PyCuda/MailingList for support.)

Another Visual Studio 2008 Win64 example (February 2012)

This example of a siteconf.py uses a custom-built boost, and is using the boost auto-link capability to choose the Python and Thread libnames. It's also linking with the boost libraries statically, so you don't have to fiddle with boost DLLs.


BOOST_INC_DIR = ['D:\\Libraries\\Boost-VC9-64\\include\\boost-1_48']
BOOST_LIB_DIR = ['D:\\Libraries\\Boost-VC9-64\\lib']
BOOST_COMPILER = 'msvc'
USE_SHIPPED_BOOST = False
BOOST_PYTHON_LIBNAME = []
BOOST_THREAD_LIBNAME = []
CUDA_TRACE = False
CUDA_ROOT = 'C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v4.1'
CUDA_ENABLE_GL = True
CUDA_ENABLE_CURAND = True
CUDADRV_LIB_DIR = ['${CUDA_ROOT}/lib/x64']
CUDADRV_LIBNAME = ['cuda']
CUDART_LIB_DIR = ['${CUDA_ROOT}/lib/x64']
CUDART_LIBNAME = ['cudart']
CURAND_LIB_DIR = ['${CUDA_ROOT}/lib/x64']
CURAND_LIBNAME = ['curand']
CXXFLAGS = ['/DBOOST_PYTHON_STATIC_LIB', '/EHsc']
LDFLAGS = ['/LIBPATH:D:\\Libraries\\Boost-VC9-64\\lib']

This was not documented, but I found it necessary to also install compyte. Installing compyte was also undocumented, but what seems to work is cloning the repository at https://github.com/inducer/compyte/, then simply copying the cloned compyte folder into the pycuda installation directory. In my case, this created the folder C:\Python27\Lib\site-packages\pycuda-2011.2.2-py2.7-win-amd64.egg\pycuda\compyte.

After building with the above siteconf.py and installing compyte (which didn't seem to require any C++ building), I was able to run the 3 test files in pycuda/test successfully (except for a complaint about needing the Mako template system, which I then proceeded to install).

For examples with dynamic compilations, you'll want to run the appropriate vcvars32.bat/vcvars64.bat before running the Python interpreter.

Using Visual Studio 2008 (alternative on June 2010)

/!\ This set of instructions has not been updated for the removal of the Boost dependency in 0.94. If you use these instructions, please perform the necessary updates (and remove this note)! Thanks! -- AndreasKloeckner 2010-09-21 00:22:05

The following software was used here:

  • Python 2.6
  • NumPy 1.4.0 (update - works with 1.4.1 too)
  • pycuda version 0.94beta (i.e. from git)
  • Visual Studio 2008
  • boost 1.38 from source, note that 1.41 did not work on Windows (details below)
  • CUDA 2.3 (update - works with 3.0 too)
  • Windows XP 32-bit Follow the above instructions for Visual Studio 2008. The only difference is the use of boost from source.

Get Boost v1.38 source and the pre-compiled bjam via the Sourceforge Boost page. Note that v1.41 (latest when written in Jan 2010) did not work for pyCUDA. When compiling the python Boost library it insisted on linking to PYTHON25.DLL which does not exist on my machine. Switching back to v1.38 and compiling from source worked first time, it correctly linked to PYTHON26.DLL. Details in this thread includes references to DependencyWalker for debugging.

I used boost-jam-3.1.18-1-ntx86.zip and boost_1_38_0.7z.

Read the index.html file and then compile Boost v1.38 using:


bjam --build-type=complete stage # complete means build all the libs/dlls, stage puts the libs into ./stage/lib
# note you can add --debug-configuration to get debug info for details of e.g. the compiler and Python version it finds

This is a working siteconf.py (created first by running configure.py):


BOOST_INC_DIR = ['C:\\Program Files\\boost\\boost_1_38_0']
BOOST_LIB_DIR = ['C:\\Program Files\\boost\\boost_1_38_0\\stage\\lib']
BOOST_COMPILER = 'msvc'
BOOST_PYTHON_LIBNAME = ['boost_python-vc90-mt-1_38']
BOOST_THREAD_LIBNAME = ['boost_thread-vc90-mt-1_38']
CUDA_TRACE = False
CUDA_ROOT = 'c:\\cuda'
CUDA_ENABLE_GL = False
CUDADRV_LIB_DIR = [r'C:/CUDA/lib']
CUDADRV_LIBNAME = ['cuda']
CXXFLAGS = ['/EHsc']
LDFLAGS = ['/FORCE']

Compile using:


python setup.py build
python setup.py install

and you'll have a working pyCUDA (check that your build/install process finishes without any errors).

Next you have to setup your PATH, go to the Start menu, Settings, Control Panel, choose System, go to the Advanced tab, select Environment Variables. Under System Variables you'll find "Path". Copy all of it into a text editor and take a look at it.

You'll almost certainly see existing references to CUDA (from the CUDA package) and Python in the path looking like:


C:\CUDA\bin;
C:\Python26;

You now need to add the Boost library directory (including stage\lib) by adding something like the following:


C:\Program Files\boost\boost_1_38_0\stage\lib;

(this library contains files like boost_python-vc90-1_38.dll boost_python-vc90-1_38.lib)

When you run the pyCUDA demo files you might find that "nvcc" (NVidia's compiler) fails because it can't find the Visual Studio "cl.exe" compiler. The error is:


nvcc fatal   : Cannot find compiler 'cl.exe' in PATH

If you see this then add the following to the path (for Visual Studio 2008 / VC9):


C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\;C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE

The \bin directory contains "cl.exe", the "Common7\IDE" contains necessary DLLs you'll get an error on screen telling you the DLLs it can't find - you just need to locate them and add the right directory. The easiest way to test this is to open a new Command Prompt and type "cl.exe" - if it isn't found then your path isn't configured. If it runs OK then "cl.exe" will be seen by nvcc.

You should also add "HOME" as an environment variable, it isn't used but it is required (if you don't add it you'll get an obvious error message saying it needs to know where HOME is), I used:


HOME=pycuda;

You add it by adding a New environment variable on the same screen where you can edit the PATH.

To test first open a new Command Prompt (so you get the new PATH info you configured above) and try:


cd examples
python measure_gpuarray_speed_random.py

and you should see a simple memory benchmark running, you will see that your GPU outperforms your CPU for the larger memory transfers.

Using MinGW

/!\ This set of instructions has not been updated for the removal of the Boost dependency in 0.94. If you use these instructions, please perform the necessary updates (and remove this note)! Thanks! -- AndreasKloeckner 2010-09-21 00:22:05

The following instructions can be used to install PyCUDA on a Windows machine with Visual Studio 2005. The issue that this solves is related to building python extensions when python was built with Visual Studio 2003. The MinGW compiler can be used to work around this issue.

  1. PyCUDA can be built and installed using the MinGW compiler. You can use MinGW which is installed with python(x,y), which is a nice Python development environment. The python(x,y) installer places the MinGW compiler into the PATH variable. I used python(x,y) 2.1.14. ```txt

!note

For all of the commands that require a command prompt, I used the ‘open console here’ option in the Windows Explorer context menu that is created when python(x,y) is installed.

1. Build the Boost thread and python libraries using the MinGW compiler and the toolset=gcc command line argument with bjam. For example, assuming boost is installed in C:\boost_1_39_0: ```txt

  cd c:\boost_1_39_0
  bjam --toolset=gcc --with-python --build-type=complete stage

  • This should create libs in the stage\lib directory prefixed with boost_python-mgw34.
  • Use the same command for --with-thread.
  • Python needs to be told to build extensions using the MinGW compiler. Otherwise, when you build PyCUDA you will receive an error message that Python was built with Visual Studio 2003.
  • Create or open the file \Lib\distutils\distutils.cfg.
  • Add the following entry:
  • [build]
  • compiler=mingw32
  • Get the latest version of PyCUDA using git.
  • Change to the directory where PyCUDA was downloaded and install PyCUDA. You can use a commands similar to:
  • configure.py --boost-inc-dir=c:\boost_1_39_0 --boost-lib-dir=c:\boost_1_39_0\stage\lib --boost-python-libname=boost_python-mgw34-mt-1_39 --boost-thread-libname=boost_thread-mgw34-mt-1_39 --cuda-root=c:\cuda
  • Issue the command setup.py build -c mingw32
  • Issue the command setup.py install
  • Make sure that the Visual Studio cl.exe compiler is in the PATH. For example, C:\Program Files\Microsoft Visual Studio 8\VC\bin.
  • Make sure that the boost libs are in the PATH. For example, C:\boost_1_39_0\stage\lib.
  • Change to the PyCUDA examples directory and run demo.py after setting the HOME environment variable to 123456. The demo should run without error. (Instructions by Frank Buckle, fbuckle at gmail com. Instead of emailing him directly, please go to the PyCuda/MailingList for support.)

Windows Vista 64-bit with Visual Studio 2008

/!\ This set of instructions has not been updated for the removal of the Boost dependency in 0.94. If you use these instructions, please perform the necessary updates (and remove this note)! Thanks! -- AndreasKloeckner 2010-09-21 00:22:05

(see also this blog post) (the following instructions seems to work on Windows 7(x64) too. Test.py passes) I successfully built and passed the test_driver.py script on Windows Vista 64-bit (x64, amd64) with Visual Studio 2008. My configuration:

  • Python 2.6, using the amd64 installer on the web site
  • Numpy 1.3.0 built from source. The 1.3.0 amd64 installer on their web site seems to be compiled with something other than Visual Studio 2008 and, after installation, it crashes when I import numpy. Building from source with Visual Studio 2008 seems to make it more stable, despite the warning that support is not perfect on 64 bit Windows.
  • pycuda from git (I used 0.94 beta)
  • boost 1.39: As above, I suggest using BoostPro installer, but only you only need the Boost header files, Source and Documentation and Tools.
  • CUDA 2.3 These here are the steps to follow:

  • Open a Visual Studio 2008 x64 Win64 Command Prompt (Start -> Programs -> Microsoft Visual Studio 2008 -> Visual Studio Tools) as administrator

  • In the prompt, navigate to your boost directory (The example assumes C:\boost\boost_1_39). You need to compile the python, thread and date_time libraries. This should create dll's and libraries in the stage directory under your boost unzip. ```txt

"C:\boost\boost_1_39\bin\bjam.exe" toolset=msvc --with-python --build-type=complete address-model=64 embed-manifest=off stage "C:\boost\boost_1_39\bin\bjam.exe" toolset=msvc --with-thread --build-type=complete address-model=64 embed-manifest=off stage "C:\boost\boost_1_39\bin\bjam.exe" toolset=msvc --with-date_time --build-type=complete address-model=64 embed-manifest=off stage

bjam.exe is the boost jam executable. On other versions(such as 1.40) this file may be located in another path. You may need to add extra information into the user-config.jam located in C:\boost\boost_1_39\tools\build\v2txt

using python : 2.6 : C:/Python26/python # cmd : C:/Python26/Include # include : C:/Python26/libs ; # libraries

1. Get the latest version of pycuda using git: ```txt

 git clone http://git.tiker.net/trees/pycuda.git

  1. In pycuda's source directory, create siteconf.py: ```txt

BOOST_INC_DIR = [r'C:\boost\boost_1_39'] BOOST_LIB_DIR = [r'C:\boost\boost_1_39\stage\lib'] BOOST_COMPILER = 'msvc' BOOST_PYTHON_LIBNAME = ['boost_python-vc90-mt-1_39'] BOOST_THREAD_LIBNAME = ['boost_thread-vc90-mt-1_39'] CUDA_TRACE = False CUDA_ENABLE_GL = False CUDADRV_LIB_DIR = [r'C:\CUDA\lib64'] CUDADRV_LIBNAME = ['cuda'] CXXFLAGS = ['/EHsc'] LDFLAGS = ['/FORCE']

1. In pycuda's source directory edit setup.py, find ```txt

     # CUDA_ROOT/bin/nvcc(.exe)?
     if 'CUDA_ROOT' in sc_vars:
         verify_path(
             description="CUDA toolkit",
             paths=[sc_vars['CUDA_ROOT']],
             subpaths=['/bin/'],
             names=['nvcc'],
             extensions=APP_EXTS,
             )
     else:

```change /bin/ into  /bin64/ 
1. Build and install pycuda ```txt

 python setup.py install

  1. Make sure that the boost lib directory, C:\boost\boost_1_39\stage\lib. is in the PATH.
  2. Create a dummy HOME environment variable to 123456
  3. Run test_driver.py in the test directory under the git checkout. (Instructions by Bill Blinn, bblinn at gmail com. Instead of emailing him directly, please go to the PyCuda/MailingList for support.)

Windows 7 64-bit with Visual Studio Professional 2008 (no Boost!)

Software required:

  • Python 2.7, using the amd64 installer on the web site
  • Numpy 1.5.1, using amd64 installer
  • pycuda 0.94 amd64 binary installer from Christopher Gohlke (see binaries section)
  • CUDA 3.2 Toolkit
  • Visual Studio Professional 2008 These here are the steps to follow:

  • Install Python, Numpy, pycuda and CUDA toolkit to default dirs.

  • VS 2008 only needs custom install - just C++ tools incl x64 compilers.
  • Add the following to PATH environment variable:

C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\;C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\amd64;C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE

  1. Edit nvcc.profile (in CUDA\3.2\bin) and set INCLUDES flag to this:

INCLUDES                +=  "-I$(TOP)/include" "-I$(TOP)/include/cudart" "-IC:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/include" $(_SPACE_)

Note this method will probably also work for 32 bit - just substitute 32 bit versions of software. Also, for 32 bit can probably use VS 2008 Express Edition plus relevant Windows SDK. I had problems with this because it didn't seem to install the x64 compilers.

Instructions by Sam Adams

Windows 7 64-bit with Visual Studio Professional 2008 (Strictly Binary Versions)

Here the step-by-step installation I had to do using binaries only. Every installation step is required and most I found out by run time errors.


  C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin;C:\Program Files (x86)\Microsoft Visual Studio9.0\VC\bin\amd64;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE;

  • nvcc.profile
  • Edit nvcc.profile (in CUDA\3.2\bin) and set INCLUDES flag to this:
  • INCLUDES += "-I$(TOP)/include" "-I$(TOP)/include/cudart" "-IC:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/include" $(SPACE) Christoph Bussler

Windows 7 64-bit with Visual Studio Express 2010 (Strictly Binary Versions)

Following the instructions below (Windows 8 64-bit) worked for me for Windows 7 with the following caveats:

  • Did not need to call setEnv.cmd
  • Had to edit pycuda\compiler.py to add "--use-local-env" and "--cl-version 2010"
  • Set compiler-bindir to 64-bit version of cl.exe in nvcc.profile
  • Performed the above successfully with:
  • Windows 7
  • Visual Studio Express 2010
  • CUDA 5.5

Windows 8 64-bit with Visual Studio Express 2010 (Strictly Binary Versions)

Here is my step-by-step adaptation of Christoph Bussler's directions to Windows 8 64 bit. May also work on windows 7, but I haven't tested it. If you can't find any of the specific package versions, then install the latest x64 build for your version of python.


  C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE;


I solved the problem by 1. installing Windows SDK (don't forget to choose all x64 options for 64 bit OS) 2. include "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64" in PATH 3. create file vcvars64.bat inside directory "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64" with following content: call "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64

Note: I did this because: 1. I am using VC++ Express 2010 2. I dont have "vcvars64.bat" in any directory ??

If all went well, you should be able to run some of the example code after minor adaptations for python 3.3 (like changing 'print "HI"' to 'print ("HI")')

Christopher Hopwood