test_gpu_visible.py
Go to the documentation of this file.
1 from theano import function, config, shared, sandbox
2 import theano.tensor as T
3 import numpy
4 import time
5 
6 vlen = 10 * 30 * 768 # 10 x #cores x # threads per core
7 iters = 1000
8 
9 rng = numpy.random.RandomState(22)
10 x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
11 f = function([], T.exp(x))
12 print(f.maker.fgraph.toposort())
13 t0 = time.time()
14 for i in range(iters):
15  r = f()
16 t1 = time.time()
17 print("Looping %d times took %f seconds" % (iters, t1 - t0))
18 print("Result is %s" % (r,))
19 if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]):
20  print('Used the cpu')
21 else:
22  print('Used the gpu')
23 
void function(int client, int *resource, int parblock, int *test, int p)