Tag Archives: Python

PyCUDA on Windows 8.1

After I had successfully installed Theano, about a week later (see my previous post), I went ahead and installed PyCUDA on my Windows 8.1 laptop.

To make this happen, I went to Christoph Gohlke’s “Unofficial Windows Binaries for Python Extension Packages” website.

Christoph noted that there are a few prerequisite Python packages for PyCUDA…however, all but two of these were already a part of the Anaconda distribution, so there were only 2 that I needed to download/install before installing PyCUDA:

  • appdirs-1.4.0-py2.py3-none-any.whl
  • pytools‑2015.1.1‑py2.py3‑none‑any.whl

…then I downloaded:

  • pycuda‑2015.1.2+cuda7028‑cp34‑none‑win_amd64.whl

[NOTE: very shortly after I did this, Gohlke updated his site and now (8/1) only lists “pytools” as the prerequisite Python package you will need to download…so whether or not I needed appdirs is an unknown!]

After downloading these three wheel files, I fired up a Windows Command Prompt, navigated to the Downloads folder, and installed all three sequentially via “pip install”:

  • pip install appdirs-1.4.0-py2.py3-none-any.whl
  • pip install pytools‑2015.1.1‑py2.py3‑none‑any.whl
  • pip install pycuda‑2015.1.2+cuda7028‑cp34‑none‑win_amd64.whl

After these three files were installed, I went to Will Landau’s excellent collection of PyCUDA code examples (which also has a nice accompanying video and slides) and downloaded them onto my machine. Of the dozen files, all but one worked (after making some minor Python3 tweaks here and there…). The only one that did not work was a file called “scan.py” which threw an import error telling me that I needed to install the Mako templating engine.

Outside of this very minor issue (which I may go ahead and correct here shortly by installing Mako), everything went pretty well.

NOTE: if you get an nvcc fatal error : cannot find compiler c1.exe in PATH, note the location of c1.exe in your Visual Studio installation (mine is 2013, so it lives in C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin). Just add this to your PATH variable, restart your machine and try again!!


Theano on Windows 8.1…GPU Computing here I come!

I just purchased an ASUS K501LX Windows 8.1 laptop, with an NVIDIA GeForce GTX 950M GPU. Now I can start looking at GPU computing in Python…notably with the Theano package!

First things first…I will say upfront that I had some trepidation going into this. In doing some preliminary research over the past couple of months, I had come across more than a few cases where people had extreme difficulty, if not outright failure, when trying to get Theano to work with their GPUs on their Windows machines. Luckily, a couple of weeks ago, I came across this helpful blog post which cleared away a lot of the conflicting and negative information I was getting out there.

I largely followed his instructions with a couple of modifications. Here is what I did to get it all up and running:

  1. Install Visual Studio 2013 Community Edition. Straightforward…but it took the longest (around half-an-hour) of all of these steps!
  2. Install the NVIDIA CUDA 7.0 Toolkit. Now let’s talk about this for a second, because this gave me a bit of a scare. Upon running the installation, I got the following message: “This graphics driver could not find compatible graphics hardware.” After checking the NVIDIA site however, I found out that all I needed to do is hit “Continue” and choose “Custom (Advanced)” installation, and uncheck the Graphics Driver (the GPU Deployment Kit also becomes unchecked!) All we really need is the CUDA Toolkit! After this, I chose the default installation locations and the CUDA Toolkit installed flawlessly.
  3. Install Git-SCM for Windows (this will be for downloading and installing Theano from its GitHub repository)
  4. Install Anaconda for Python 3.4
  5. Once Anaconda was installed and configured on my machine, I installed the mingw package by entering the following command at the Anaconda command prompt: conda install mingw libpython.
  6. Next I created a folder called “theano-download” off of my C drive. From the Windows Command Prompt, I navigated to this folder and entered the following commands:
    1. git clone git://github.com/Theano/Theano.git
    2. cd Theano
    3. python setup.py develop
  7. This successfully installed Theano, but now comes the hard part: getting Theano to utilize my GPU! To do this, I created a file named .theanorc.txt (note the period in front of the file name!), saved it to my home directory (C:\Users\Brian) and entered the following text:


floatX = float32

device = gpu



compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin

Before creating this, I verified that those two paths actually existed! It was a good thing I did because I realized that I needed to change the flags parameter to point to C:\Anaconda3\libs since I am running Python 3!

OK…so I took a deep breath as the moment of truth was upon me! Were my efforts in vain or were they successful?

I eagerly fired up IPython and typed in import theano to find out…


Great success! It’s using my GPU device!

The last step: run a test! From the Windows Command Prompt, I navigated to the C:\theano-download\Theano\theano\misc folder and typed in the following command to run a test of the Theano installation: 

ipython check_blas.py

Would it work? Importing was one thing…but testing it is quite another! Needless to say success was to be had! I got a message stating that 10 calls were executed to gemm with a and b matrices of shapes (2000,2000) and (2000,2000)…Total execution time: 0.25s on GPU.

Happy times! Now it’s time to start exploring Theano and deep learning!