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:
- Install Visual Studio 2013 Community Edition. Straightforward…but it took the longest (around half-an-hour) of all of these steps!
- 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.
- Install Git-SCM for Windows (this will be for downloading and installing Theano from its GitHub repository)
- Install Anaconda for Python 3.4
- 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.
- 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:
- git clone git://github.com/Theano/Theano.git
- cd Theano
- python setup.py develop
- 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:
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!