- Python CUDA set up on Windows 10 for GPU support
- Step 1: Check Configuration and Compatibility
- Step 2: Install VS2017
- Step 3: Install CUDA Toolkit
- Step 4: Install cuDNN
- Step 5: Install Tensorflow GPU
- Step 6: Install Keras
- Step 7: Install Pytorch (Optional)
- Step 8: Verify installation
- Installing PyCuda on Windows
- Windows 7 64-bit with Visual Studio Professional 2008 (no Boost!)
- Binaries
- Using Visual Studio 2008
- Another Visual Studio 2008 Win64 example (February 2012)
- Using Visual Studio 2008 (alternative on June 2010)
- Using MinGW
- Windows Vista 64-bit with Visual Studio 2008
- Windows 7 64-bit with Visual Studio Professional 2008 (no Boost!)
- Windows 7 64-bit with Visual Studio Professional 2008 (Strictly Binary Versions)
- Windows 7 64-bit with Visual Studio Express 2010 (Strictly Binary Versions)
- Windows 8 64-bit with Visual Studio Express 2010 (Strictly Binary Versions)
Python CUDA set up on Windows 10 for GPU support
Dec 30, 2019 · 3 min read
Installation of Python Deep learning on Windows 10 PC to utilise GPU may not be a straight-forward process for many people due to compatibility issues. One good and easy alternative is to use Google Collab, which is free. However, in cases where you can only use deep learning on a private PC and/or without Internet access, you can follow the steps below which I had used.
Note that after following the steps below, do not update from NVIDIA Geforce Game Ready Driver, as this will change your CUDA version, and thus mess up the compatibility issues for your deep learning setup.
- VS2017 (Visual Studio Community 2017)
- cuda_10.0.130_411.31_win10.exe
- cudnn_10.0-windows-x64-v7.4.2.24
Step 1: Check Configuration and Compatibility
- Refer to the GPU section from https://www.tensorflow.org/install/source_windows. It shows the compatibility between Tensorflow, Python, CUDA and CUDNN version.
Step 2: Install VS2017
- Download and install Microsoft Visual Studio Community 2017 from www.visualstudio.com/vs/older-downloads.
- Note that the downloaded version is for web-installation only. If you need to create an offline installation, run the following command from your download directory:
Copy the folder to the remote computer and install by double-clicking on vs_setup.exe in the folder.
Step 3: Install CUDA Toolkit
- Download CUDA from https://developer.nvidia.com/cuda-10.0-download-archive.
- Choose the following target platform:
— Operating System: Windows
— Architecture: x86_64
— Version: 10
— Installation Type: exe (local)
- Copy and install it in your remote computer. Note that after installation, environment variables (i.e. CUDA_PATH and CUDA_PATH_V10_0) will be created automatically.
Step 4: Install cuDNN
- Download from https://developer.nvidia.com/rdp/cudnn-archive. Choose “Download cuDNN v7.4.2 (Dec 14, 2018) for CUDA 10.0” followed by “cuDNN Library for Windows 10”.
- Unzip and copy the folder to your remote computer.
- Go to your Environment Variables and search the path of CUDA_PATH from System variables. In my case, it is in C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0 . Go to this CUDA installation folder.
- Copy the content inside bin , include and lib of the cuDNN folder to the CUDA installation folder (i.e. bin\cudnn64_7.dll to the bin\ , include\cudnn.h to the include\ folder and lib\x64\cudnn.lib to the lib\x64\ folder).
From step 5 onwards, I will recommend doing them in virtual conda environment, so that in cases where there are multiple project environments, modifying Python libraries in a conda environment will not affect other projects. The conda environment can also be easily portable (copy-and-paste) to remote computers.
Step 5: Install Tensorflow GPU
Step 6: Install Keras
Step 7: Install Pytorch (Optional)
- Run the following command:
- Alternatively, you can find the command from Pytorch website: https://pytorch.org/get-started/locally. Choose the following (as at time of writing):
— Pytorch Build: Stable (1.3)
— Your OS: Windows
— Package: PIP
— Language: Python 3.6
— CUDA: 10.1 (v10.0 no longer available at time of writing)
Once done, the c o mmand will be given at “Run this command”. Copy and paste in your terminal to run.
Step 8: Verify installation
You can verify if the installation is correct by running the following Python script.
Installing PyCuda on Windows
Windows 7 64-bit with Visual Studio Professional 2008 (no Boost!)
- 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.
- Edit nvcc.profile (in CUDA\3.2\bin) and set INCLUDES flag to this:
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
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
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):
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
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.
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:
This is a working siteconf.py (created first by running configure.py):
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:
You now need to add the Boost library directory (including stage\lib) by adding something like the following:
(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:
If you see this then add the following to the path (for Visual Studio 2008 / VC9):
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:
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:
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.
- 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
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.
- 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.
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
«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\v2 txt
using python : 2.6 : C:/Python26/python # cmd : C:/Python26/Include # include : C:/Python26/libs ; # libraries
- 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’]
- Make sure that the boost lib directory, C:\boost\boost_1_39\stage\lib. is in the PATH.
- Create a dummy HOME environment variable to 123456
- 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!)
- 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.
- Edit nvcc.profile (in CUDA\3.2\bin) and set INCLUDES flag to this:
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.
- Installation
- for Windows Vista Professional, 64 bit
- I prefer using Eclipse and so PyDev is useful (http://pydev.org/)
- Warning
- install everything in its 64 bit version; otherwise it will not work
- Python
- from http://www.python.org/download/releases/2.7/
- get Windows X86-64 MSI Installer (2.7)
- install
- PyCUDA
- from http://www.lfd.uci.edu/
gohlke/pythonlibs/
- 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.
- Installation
- for Windows 8 64 bit
- Warning
- install everything in its 64 bit version; otherwise it will not work
- Python
- Download Python 3.3 for x86-64 here: http://www.python.org/ftp/python/3.3.0/python-3.3.0.amd64.msi
- install
- PyCUDA
- from http://www.lfd.uci.edu/
gohlke/pythonlibs/#numpy
- nvcc.profile
- Edit nvcc.profile (in CUDA\v5.0\bin) 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)
- Fix vcvars64.bat
- Follow this stackoverflow answer by Amitabh Mritunjai http://stackoverflow.com/questions/2970493/cuda-linking-error-visual-express-2008-nvcc-fatal-due-to-null-configuratio:
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»)’)