Theano使用命令行中的gpu,但不使用PyCharm

时间:2017-05-16 20:36:14

标签: pycharm theano theano-cuda

我正在努力让Theano在我的Linux机器上使用gpu。它适用于命令行,但不适用于Pycharm。两者都在我的机器的同一文件夹中使用Python 3.5。

我正在测试这个脚本:

from theano import function, config, shared, tensor
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([], tensor.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, tensor.Elemwise) and
              ('Gpu' not in type(x.op).__name__)
              for x in f.maker.fgraph.toposort()]):
    print('Used the cpu')
else:
    print('Used the gpu')

如果我从命令行运行它,它可以正常工作:

THEANO_FLAGS=device=cuda0 /home/jon/anaconda3/bin/python check_theano_cuda.py

Looping 1000 times took 0.840969 seconds
Result is [ 1.23178032  1.61879341  1.52278065 ...,  2.20771815  2.29967753
  1.62323285]
Used the gpu

如果我从PyCharm运行它,我会收到此错误:

ERROR (theano.gpuarray): Could not initialize pygpu, support disabled
Traceback (most recent call last):
  File "/home/jon/anaconda3/lib/python3.5/site-packages/theano/gpuarray/__init__.py", line 164, in <module>
    use(config.device)
  File "/home/jon/anaconda3/lib/python3.5/site-packages/theano/gpuarray/__init__.py", line 151, in use
    init_dev(device)
  File "/home/jon/anaconda3/lib/python3.5/site-packages/theano/gpuarray/__init__.py", line 60, in init_dev
    sched=config.gpuarray.sched)
  File "pygpu/gpuarray.pyx", line 614, in pygpu.gpuarray.init (pygpu/gpuarray.c:9419)
  File "pygpu/gpuarray.pyx", line 566, in pygpu.gpuarray.pygpu_init (pygpu/gpuarray.c:9110)
  File "pygpu/gpuarray.pyx", line 1021, in pygpu.gpuarray.GpuContext.__cinit__ (pygpu/gpuarray.c:13472)
pygpu.gpuarray.GpuArrayException: Error loading library: 0

在PyCharm中,我已经将运行配置的环境变量修改为device = cuda0,我希望能够复制命令行版本中发生的事情。但这不起作用。

我尝试在〜/ .theanorc文件中创建一个文件,但它不起作用。它包含:

[全球] device = cuda0 floatX = float32

我还能尝试做些什么呢?我的安装必须正常,因为它从命令行运行。

0 个答案:

没有答案