Installing Theano on Windows 10 + Anaconda with GPU Support – A Full Guide

So I decided to try to get Theano to recognize the GPU in my laptop just to see how feasible/ difficult it would be. I’m using a Dell Precision 5510 with the NVIDIA Quadro M1000M GPU. This is the order I installed everything, there might be some redundancies but after trying a hodgepodge of tutorials this is what got it working for me. Please let me know if there is any unnecessary information here.

  • Install TDM-GCC x64
  • Install Anaconda for python 2.7 x64
  • Run the following commands to install a compiler for windows allowing Theano to run:
    • conda install mingw libpython
  • Run the following commands inside the anaconda prompt in order to get the latest versions of Theano and Lasagne:
  • You can test your installation by downloading the file and running from the anaconda prompt. Just navigate to the folder where the file is stored and type:
    • python mlp 3
  • If this ran correctly you should get a trained network over 3 epochs and should take a couple minutes.
  • Next you need to get a BLAS library working (Basic Linear Algebra Subprograms). The Intel MKL version bundled with Anaconda can’t be used by Theano so we have to install OpenBLAS
  • Open the folder and extract the three subfolders (bin, include. lib) to somewhere on your directory and note the location. For me this was:
    • C:\Lasagne\OpenBLAS
  • Go to
    • C:\Lasagne\OpenBLAS\bin\libopenblas.dll
  • Move this libopenblas.dll file to where the path is. For me it is in Anaconda2 at:
    • C:\Users\Sarick\Anaconda2
  • For the second file, extract the three .dll files (libgcc_s_seh-1.dll, libgfortran-3.dll, libquadmath-0.dll)  to the same place where libopenblas.dll was moved to.
  • Now in the command prompt, cd to your User folder and create a .theanorc settings file:
    • cd C:\Users\Sarick
    • notepad .theanorc
  • In the new notepad file, paste these lines and save. If you saved your OpenBLAS folders to somewhere other than I did, just replace the paths appropriately
    • [blas]
    • [gcc]
      cxxflags=-IC:\Lasagne\OpenBLAS\include -LC:\Lasagne\OpenBLAS\lib
  • This might be a good time to test BLAS by downloading the file, cd’ing to the directory it is stored in and running as:
    • python
  • If everything is running smoothly, you should get an output that includes the phrase “with direct Theano binding to blas”.

  • Now time for GPU support! This part hopefully causes you less headaches than it caused me!
  • FIRST install Visual Studio Ultimate 2013 I installed the compilers (32 and 64 bit) and did not install any of the phone stuff that comes with it. You also do not have to install the IDE if you get that as an option to uncheck. We only care about the compilers.
  • Download and install Microsoft SDK and .NET framework 4 and make sure these components are selected. If any are grayed out, install .NET Framework 4 fist:
    • Windows Headers
    • x64 Libraries
    • Visual C++ Compilers
  • Now enter these commands in the command prompt:
    • cd C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64
    • notepad vcvars64.bat
  • IF this opens and there is already stuff here, you DO NOT need to change anything! For me that file was was there, if it didn’t exist you should look around to see how to remedy this, some examples include adding one of these lines:
    • CALL setenv /x64
    • CALL “C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1\Bin\SetEnv” /x64

  • Go to NVIDIA’s website and upgrade your drivers here.
  • Next downloat CUDA Toolkit (I used version 8) here and install everything. Be sure you get the NVIDIA Nsight Visual Studio Edition installed from this toolkit as well.
  • Make sure you do this after downloading Visual Studio so that the toolkit installer knows which is the right version of NVCC to install.
  • Go back to the .theanorc file you saved (mine was at C:\Users\Sarick) and add the following lines:
    • [nvcc]
      fastmath = True
      compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\cl.exe
    • [cuda]
      C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0
    • [dnn.conv]
      algo_fwd = time_once
      algo_bwd_data = time_once
      algo_bwd_filter = time_once
    • [lib]
      cnmem = .80
  • After saving this, run the file again and now it should say that it ran on the GPU. If this DOESN’T work, try this:
    • Download cuda_check.c and save it to a folder.
    • From the command prompt, cd to the folder that the file is contained in and type
      • nvcc -o cuda_check.exe cuda_check.c –compiler-bindir=”C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64″ –cl-version=2013 -lcuda -lcudart -lcublas
    • This should create a check_cuda.exe file. Run this from the command prompt and see if your GPU is showing up. It should! If you have to tweak the path in this command to make it work, make the corresponding change in the path in the .theanorc file.
  • Download cuDNN and open the director. Copy the contents of the bin, include, and lib directories to the directories of the same names within the following path:
    • C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0
  • If you run this command. you should now see that CNMeM has a value of .8 and CuDNN has a value as well.
    • python -c “from theano.sandbox.cuda.dnn import dnn_available as da; print(da() or da.msg)”
  • Now you should be able to run a NN off your GPU!

A lot of the instructions I followed came from this guide and this one and another one.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your 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 )

Connecting to %s