Theano运行GPU配置

pip install theano

之后并不是就能用GPU跑程序了


不信你写个脚本

check_GPU.py

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


运行下看看。。


开头有这个命令就行了


THEANO_FLAGS='floatX=float32,device=gpu0,lib.cnmem=1'  python check_GPU.py


gpu0是你要用的gpu,要是多个gpu那就好几个号码啦~

官方的说明在这里哦:http://deeplearning.net/software/theano/library/config.html#envvar-THEANORC


嫌麻烦可以这样子

 $vim HOME/.theanorc


把文件改成如下(就是官网说明啦~)

[global]
floatX = float32
device = gpu0

[lib]
cnmem = 1


你可能感兴趣的:(深度学习,linux)