ubuntu - 如何在 Ubuntu 16.04 上使用 Theano 和 GPU?

标签 ubuntu theano theano-cuda

我使用以下脚本来测试 GPU 是否正常工作:

#!/usr/bin/env python
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' % iters, t1 - t0, 'seconds'
print 'Result is', 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')

当我运行它时,我得到:

http://pastebin.com/wM9jaGMF

有趣的部分在最后:

ERROR (theano.sandbox.cuda): Failed to compile cuda_ndarray.cu: ('nvcc return status', 1, 'for cmd', 'nvcc -shared -O3 -m64 -Xcompiler -DCUDA_NDARRAY_CUH=c72d035fdf91890f3b36710688069b2e,-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION,-fPIC,-fvisibility=hidden -Xlinker -rpath,/home/moose/.theano/compiledir_Linux-4.4--generic-x86_64-with-Ubuntu-16.04-xenial-x86_64-2.7.11+-64/cuda_ndarray -I/home/moose/.local/lib/python2.7/site-packages/theano/sandbox/cuda -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -I/home/moose/.local/lib/python2.7/site-packages/theano/gof -o /home/moose/.theano/compiledir_Linux-4.4--generic-x86_64-with-Ubuntu-16.04-xenial-x86_64-2.7.11+-64/cuda_ndarray/cuda_ndarray.so mod.cu -L/usr/lib -lcublas -lpython2.7 -lcudart')
WARNING (theano.sandbox.cuda): CUDA is installed, but device gpu is not available  (error: cuda unavailable)

我的系统

  • 我使用 Ubuntu 16.04。
  • 我已经通过标准存储库 (V7.5.17) 安装了 CUDA。 nvcc --version 有效。
  • 我已经通过 pip 安装了 Theano
  • 我有 CuDNN 4(可与 TensorFlow 配合使用)
  • 我设置了 CUDA_ROOT=/usr/bin/LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/(我不确定这是否正确)

我的~/.theanorc

[global]
exception_verbosity=high
device=gpu
floatX=float32

[cuda]
root=/usr/bin/

路径

我认为从标准存储库安装可能与手动安装有所不同。以下是一些可能会发现一些问题的路径:

/usr/bin/nvcc
/usr/lib/x86_64-linux-gnu/libcuda.so
/usr/lib/x86_64-linux-gnu/libcudart.so
/usr/lib/nvidia-cuda-toolkit
/usr/include/cudnn.h

问题

我怎样才能让它发挥作用?

最佳答案

我不确定是什么解决了这个问题,但以下一项或两项 ( source )

sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ libopenblas-dev libblas-dev git
echo -e "\n[nvcc]\nflags=-D_FORCE_INLINES\n" >> ~/.theanorc

关于ubuntu - 如何在 Ubuntu 16.04 上使用 Theano 和 GPU?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37472340/

相关文章:

gpu - theano - 仅使用外部 GPU 进行机器学习,使用集成 GPU 进行显示

python - 如何使用 Theano 形成复合函数?

python - Theano 中的逐元素矩阵乘法

windows - 无法在上下文 None 上使用 cuDNN, fatal error : cudnn. h:没有这样的文件或目录

python - 带有 GPU 的 Theano。在上下文中使用 cuDNN 版本 5110 无

python - 在 Keras 中实现自定义损失函数

ubuntu - docker 中的 LD_PRELOAD

ubuntu - 软件包 GCL 和 CLISP 之间有什么区别?

linux - 命令源码

ruby-on-rails - Ubuntu 在代理问题后面安装 Nginx