Commit 9a796de23083a6342a24f8280c5fe22a2b7b24e3
1 parent
2bf33465
Exists in
master
and in
1 other branch
staged.
Showing
1 changed file
with
24 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,24 @@ | @@ -0,0 +1,24 @@ | ||
1 | +__author__ = 'chunk' | ||
2 | + | ||
3 | +from theano import function, config, shared, sandbox | ||
4 | +import theano.tensor as T | ||
5 | +import numpy | ||
6 | +import time | ||
7 | + | ||
8 | +vlen = 10 * 30 * 768 # 10 x #cores x # threads per core | ||
9 | +iters = 1000 | ||
10 | + | ||
11 | +rng = numpy.random.RandomState(22) | ||
12 | +x = shared(numpy.asarray(rng.rand(vlen), config.floatX)) | ||
13 | +f = function([], T.exp(x)) | ||
14 | +print f.maker.fgraph.toposort() | ||
15 | +t0 = time.time() | ||
16 | +for i in xrange(iters): | ||
17 | + r = f() | ||
18 | +t1 = time.time() | ||
19 | +print 'Looping %d times took' % iters, t1 - t0, 'seconds' | ||
20 | +print 'Result is', r | ||
21 | +if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]): | ||
22 | + print 'Used the cpu' | ||
23 | +else: | ||
24 | + print 'Used the gpu' |