Haha TTpro Haha TTpro - 1 month ago 30
Python Question

Command to run Theano on GPU (windows)

I talk about the tutorial here http://deeplearning.net/software/theano/tutorial/using_gpu.html

The code I use

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')


At section Testing Theano with GPU:
There are some command line which set Theano flag to run on cpu or gpu. The problem is I have no idea to put these command in.

I have try on windows cmd

THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python theanogpu_example.py


then I get

'THEANO_FLAGS' is not recognized as an internal or external command,
operable program or batch file.


t1

However, I am able to run the code, on cpu using the command

python theanogpu_example.py


t2

I want to run the code on GPU, what should I do (with these command in the tutorial)?

Answer

From the docs, THEANO_FLAGS is an environment variable. So as you're on Windows, you might want to change

THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python theanogpu_example.py

into

set THEANO_FLAGS="mode=FAST_RUN,device=gpu,floatX=float32" & python theanogpu_example.py