Saturday, August 6, 2016

Installing Theano on Windows

My build:
OS:Windows 10 x64
GPU: GTX 1060



  1. Install Visual Studio 2013 Community Edition
    • Community, because it's free
    • 2013 because 2015 is not supported by CUDA yet.
  2. Install CUDA 7.5 8.0 (Currenly only CUDA 8.0 RC is available. You have to register with NVIDIA in order to download it.) Installing and testing 8.0 is basically the same as installing 7.5.

    1. Choose Custom during the NVIDA CUDA install. Don't install drivers for the GPU, just install CUDA stuff.
      (I installed the wrong version of CUDA the first time. The GTX 1060 need CUDA 8.)

      My GPU drivers are newer than the ones packaged with this CUDA install. I can ignore this warning.
      Don't install the outdated GPU drivers.
    2. Test CUDA install. Compile one of the samples and run it.
      Open a CUDA sample project .sln, e.g. deviceQuery or bandwidthTest.

      Running the just-built device

  3. Install gcc via the TDM-GCC compiler suite.
    • Install the 64bit version.
    • TDM-GCC is a compiler suite for Windows which consists of components that are all individually available elsewhere. TDM-GCC include GCC and MinGW. TDM-GCC includes command-line tools only.
  4. Install WinPython, one of many scientific Python distributions. (WinPython-64bit-3.4.4.3Qt5.exe)
    • By design, WinPython unzips itself to a local directory but does not mess with the system environment variables.
  5. Create a startup shell script for Python.
  6. Create a link library for gcc? But there is already a .a file in the target location.
  7. Clone and install latest version of Theano. Optional, because Theano is included in WinPy.
    • pip install git+git://github.com/Theano/Theano.git
  8. Create a .theanorc (or .theanorc.txt) for GPU usage. Put it in the settings folder of the WinPython directory.

    .theanorc

    [global]
    device = gpu
    floatX = float32

    [nvcc]
    flags = -LC:\WinPython-64bit-3.4.4.3Qt5\python-3.4.4.amd64\libs
    compiler_binddir=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64
  9. Create and run theano-test.py from the command line to see if it works.

    theano-test.py

    import numpy as np
    import time
    import theano
    A = np.random.rand(1000,10000).astype(theano.config.floatX)
    B = np.random.rand(10000,1000).astype(theano.config.floatX)
    np_start = time.time()
    AB = A.dot(B)
    np_end = time.time()
    X,Y = theano.tensor.matrices('XY')
    mf = theano.function([X,Y],X.dot(Y))
    t_start = time.time()
    tAB = mf(A,B)
    t_end = time.time()
    print("NP time: %f[s], theano time: %f[s] (times should be close when run on CPU!)" %(
                                               np_end-np_start, t_end-t_start))
    print("Result difference: %f" % (np.abs(AB-tAB).max(), ))
    Note: The first time it runs, there will be a lot of debug output as theano compiles the code. Subsequent runs are much quieter.





6 comments :

  1. This comment has been removed by the author.

    ReplyDelete