使用非root用户

时间:2017-06-08 14:46:32

标签: python-3.x theano theano-cuda gpuarray

我按照说明在系统文件夹(不是用户)中从源(git版本)安装Theano和GPUArray。 GPUArray测试运行正常,没有错误。

问题是如果我以root身份运行,Theano仅适用于GPU。运行example to test gpu

(python35) rll@ip-30-92:~$ THEANO_FLAGS=device=cuda python temp.py 
ERROR (theano.gpuarray): Could not initialize pygpu, support disabled
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/theano/gpuarray/__init__.py", line 179, in <module>
    use(config.device)
  File "/usr/local/lib/python3.5/dist-packages/theano/gpuarray/__init__.py", line 166, in use
    init_dev(device, preallocate=preallocate)
  File "/usr/local/lib/python3.5/dist-packages/theano/gpuarray/__init__.py", line 73, in init_dev
    context.cudnn_handle = dnn._make_handle(context)
  File "/usr/local/lib/python3.5/dist-packages/theano/gpuarray/dnn.py", line 83, in _make_handle
    cudnn = _dnn_lib()
  File "/usr/local/lib/python3.5/dist-packages/theano/gpuarray/dnn.py", line 70, in _dnn_lib
    raise RuntimeError('Could not find cudnn library (looked for v5* or v6*)')
RuntimeError: Could not find cudnn library (looked for v5* or v6*)
[Elemwise{exp,no_inplace}(<TensorType(float64, vector)>)]
Looping 1000 times took 3.201078 seconds
Result is [ 1.23178032  1.61879341  1.52278065 ...,  2.20771815  2.29967753
  1.62323285]
Used the cpu

如果以root身份运行它可以工作,尽管仍然存在与cuDNN无法识别设备相关的错误:

(python35) rll@ip-30-92:~$ sudo THEANO_FLAGS=device=cuda python3 temp.py 
Can not use cuDNN on context None: cannot compile with cuDNN. We got this error:
b'/tmp/try_flags_bg7m03hd.c:4:19: fatal error: cudnn.h: No such file or directory\ncompilation terminated.\n'
Mapped name None to device cuda: TITAN X (Pascal) (0000:01:00.0)
[GpuElemwise{exp,no_inplace}(<GpuArrayType<None>(float64, vector)>), HostFromGpu(gpuarray)(GpuElemwise{exp,no_inplace}.0)]
Looping 1000 times took 0.390976 seconds
Result is [ 1.23178032  1.61879341  1.52278065 ...,  2.20771815  2.29967753
  1.62323285]
Used the gpu

这台机器上有2个Titan X.使用Tensorflow可以正常工作。我没有使用.theanorc文件,但我设置了两个:

(python35) rll@ip-30-92:~$ echo $LD_LIBRARY_PATH 
/usr/local/cuda-8.0/lib64
(python35) rll@ip-30-92:~$ echo $CUDA_ROOT
/usr/local/cuda-8.0/

我按照说明做了一切,尽管有一些警告没有错误。

我不认为它是编译目录.theano上的权限错误,因为如果我chown .theano目录,行为是相同的。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

我终于找到了问题。安装Theano的说明中缺少一个方面,即您必须验证是否设置了LIBRARY_PATH并将cuda库添加到其中(请注意它不是LD_LIBRARY_PATH)。

如果没有设置只是导出它,你会很高兴。所以对于临时修复:

 export LIBRARY_PATH=/usr/local/cuda-8.0/lib64

要保留它可能取决于系统,但通常您可以添加到/etc/environment,添加一行:

LIBRARY_PATH=/usr/local/cuda-8.0/lib64

这修复了root用户的消息,并为普通用户修复了cuda。