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:

[global]

floatX = float32

device = gpu

[nvcc]

flags=-LC:\Anaconda3\libs

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…

Theano-Import-Success

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!

Advertisements

6 thoughts on “Theano on Windows 8.1…GPU Computing here I come!

  1. naveen DN

    Wow! This looks simple! [ I have gone mad from last 4 days trying to install Theano to use gpu .. 😦 😦 ]

    In step 7 .theanorc.text file,
    at , flags=-LC:\Anaconda3\libs
    what is the reason for using ‘-L’ before the path(C:\Anaconda3\libs) ?

    Thanks

    Like

    Reply
  2. naveen DN

    Hi
    i followed your instructions as above,
    but ‘ipython check_blas.py’ gave me this error

    nvcc fatal : cannot find compiler cl.exe in the PATH
    [….
    ….]
    ERROR (theano.sandbox.cuda) :Failed to compile cuda_ndarray.cu : (
    .
    .
    )

    Thanks

    Like

    Reply
  3. naveen DN

    First of all, thank you so much!
    Actually that path was already added to the compiler_bindir as part of .theanorc file , i guess no need to add again to the PATH.
    I noticed that there was no compiler cl.exe in that path so i tried running the batch file vcvarsall.bat(or vcvars32.bat? i forgot!) present in that location,
    It generated some files including cl.exe! ( I installed visual studio offline, that may be the reason cl.exe was not there by default?)
    then i tried running ipython check_blas.py
    and ….
    SUCCESS!! 🙂 🙂 its using the gpu!

    PS: i named the theanorc file as ‘.theanorc.text’ which was saved as ‘.theanorc.text.txt’ and i wasted 2 days for that mistake.

    Like

    Reply
    1. brianthomas621

      Glad to have helped!
      After a couple of weeks playing with both Theano and PyCUDA, everything seems to be running very well on my end.
      …now let’s hope that continues to be the case after upgrading to Windows 10!

      Like

      Reply

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