操作系统:Ubuntu 14.04LTS
语言:Python Anaconda 2.7(keras,theano)
GPU:GTX980Ti CUDA:CUDA 7.5
我想通过使用我的GPU(GTX980Ti)在IPython Notebook上运行keras python代码
但是我找不到它.
我想测试下面的代码.当我把它运行到Ubuntu终端时,我命令如下(它使用GPU很好.它没有任何问题)
首先,我设置如下的路径
export PATH=/usr/local/cuda/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
其次,我运行如下代码
THEANO_FLAGS='floatX=float32,device=gpu0,nvcc.fastmath=True' python myscript.py
它运行良好.
但是当我在pycharm(python IDE)上运行代码或者当我在Ipython Notebook上运行它时,它不使用gpu.它只使用CPU
myscript.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')
要解决它,我强制代码使用gpu如下 (在myscript.py上多插入两行)
import theano.sandbox.cuda theano.sandbox.cuda.use("gpu0")
然后它会产生如下错误
ERROR (theano.sandbox.cuda): nvcc compiler not found on $PATH. Check your nvcc installation and try again.
怎么做???我花了两天时间.
我肯定在主目录中使用'.theanorc'文件.