缺少 nvcc 编译器 - theano

Missing nvcc compiler - theano

我使用 ubuntu 14.04 和 cuda 7.5。我使用 $ nvcc --version 获取 cuda 版本信息:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2015 NVIDIA Corporation
Built on Tue_Aug_11_14:27:32_CDT_2015
Cuda compilation tools, release 7.5, V7.5.17

$PATH 和 $LD_LIBRARY_PATH 如下:

$ echo $PATH
/usr/local/cuda-7.5/bin:/usr/local/cuda-7.5/bin/:/opt/ros/indigo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

$ echo $LD_LIBRARY_PATH
/usr/local/cuda-7.5/lib64

我安装了theano。我将它与 cpu 一起使用,但不与 gpu 一起使用。 This guide 表示

Testing Theano with GPU¶ To see if your GPU is being used, cut and paste the following program into a file and run it.

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
> 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, T.Elemwise) for x in
> f.maker.fgraph.toposort()]):
>     print('Used the cpu') else:
>     print('Used the gpu') The program just computes the exp() of a bunch of random numbers. Note that we use the shared function to make
> sure that the input x is stored on the graphics device.

If I run this program (in check1.py) with device=cpu, my computer takes a little over 3 seconds, whereas on the GPU it takes just over 0.64 seconds. The GPU will not always produce the exact same floating-point numbers as the CPU. As a benchmark, a loop that calls numpy.exp(x.get_value()) takes about 46 seconds.

$ THEANO_FLAGS=mode=FAST_RUN,device=cpu,floatX=float32 python check1.py [Elemwise{exp,no_inplace}()] Looping 1000 times took 3.06635117531 seconds Result is [ 1.23178029 1.61879337 1.52278066 ..., 2.20771813 2.29967761 1.62323284] Used the cpu

$ THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python check1.py Using gpu device 0: GeForce GTX 580 [GpuElemwise{exp,no_inplace}(), HostFromGpu(GpuElemwise{exp,no_inplace}.0)] Looping 1000 times took 0.638810873032 seconds Result is [ 1.23178029 1.61879349 1.52278066 ..., 2.20771813 2.29967761 1.62323296] Used the gpu Note that GPU operations in Theano require for now floatX to be float32 (see also below).

我 运行 gpu 版本命令没有 sudo,它抛出权限被拒绝的错误:

/theano/gof/cmodule.py", line 741, in refresh
    files = os.listdir(root)
OSError: [Errno 13] Permission denied: '/home/user/.theano/compiledir_Linux-3.16--generic-x86_64-with-Ubuntu-14.04-trusty-x86_64-2.7.6-64/tmp077r7U'

如果我将它与 sudo 一起使用,编译器找不到 nvcc 路径。

ERROR (theano.sandbox.cuda): nvcc compiler not found on $PATH. Check your nvcc installation and try again.

我该如何解决这个错误?

尝试运行

chown -R user /home/user/.theano
chmod -R 775 /home/user/.theano

这将更改您的 python 脚本无法访问的文件夹的权限。第一个将使文件夹属于您的用户,第二个将更改权限为用户可读、可写和可执行。

仅针对此错误:

您可以检查您的 NVCC 安装位置,默认路径是“/usr/local/cuda/bin”,如果您在那里看到它,请执行以下操作:

$  export PATH="/usr/local/cuda/bin:$PATH"
$  source .bashrc

这对我有用,现在我可以使用 NVCC,它不再丢失。