Configure Theano GPU Support

If you followed the steps on how to install theano on windows in my previous blogpost, you are ready to configure GPU Acceleration. Telling theano to use the GPU on a windows machine is quite simple:

1) Intall Visual Studio 2013 Enterprise Edition. (not express as it does not install some x64.bat files) and also not Visual Studio 2015 as it is still not supported! )
2) Install Cuda 7.5 Toolkit (you have to get registered in the Nvidia community to get the download)
3) Create a File in your User Home directory(For me this is C:\Users\Lukas) named .theanorc.txt with the following text:

#!sh

[global]

device = gpu

floatX = float32

[nvcc]

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

 

4) Test your configuration using the following python script: (you can save it to a file e.g testgpu.py and run it by open a commandshell in elevated mode and run python testgpu.py) (Script taken from deeplearning.net)

##see if gpu is used

from theano import function, config, shared, sandbox

import theano.tensor as T

import numpy

import time

 

vlen = 10 * 30 * 768  # 10 x #cores x # threads per core

iters = 1000

 

rng = numpy.random.RandomState(22)

x = shared(numpy.asarray(rng.rand(vlen), config.floatX))

f = function([], T.exp(x))

print(f.maker.fgraph.toposort())

t0 = time.time()

for i in range(iters):

    r = f()

t1 = time.time()

print(„Looping %d times took %f seconds“ % (iters, t1 t0))

print(„Result is %s“ % (r,))

if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]):

    print(‚Used the cpu‘)

else:

    print(‚Used the gpu‘)

Titel Picture from Larry Browns Blogpost on “How to accelerate Machine Learning with GPUs”

Advertisements