Nvidia CUDA + Theano:找不到符号“cuDevicePrimaryCtxGetState”

Nvidia CUDA + Theano:找不到符号“cuDevicePrimaryCtxGetState”

我正在使用 Ubuntu 16.04,我有一块稍旧的 Nvidia 9600 GT 显卡。它启用了 CUDA(1.1 计算能力),虽然是旧版。我试图在使用 Keras 时利用它,为此我遵循了本指南安装 CUDA 和这个安装 cuDNN。我的显卡驱动程序是 304.104 版本,支持我的显卡的最后一个 CUDA 版本是 6.5。安装后,我在控制台中输入以下内容进行验证:

$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2014 NVIDIA Corporation
Built on Thu_Jul_17_21:41:27_CDT_2014
Cuda compilation tools, release 6.5, V6.5.12

$ nvidia-smi
Fri Dec 22 23:02:08 2017       
+------------------------------------------------------+                       
| NVIDIA-SMI 340.104    Driver Version: 340.104        |                       
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce 9600 GT     Off  | 0000:01:00.0     N/A |                  N/A |
| 40%   46C    P0    N/A /  N/A |     77MiB /  1023MiB |     N/A      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Compute processes:                                               GPU Memory |
|  GPU       PID  Process name                                     Usage      |
|=============================================================================|
|    0            Not Supported                                               |
+-----------------------------------------------------------------------------+

样本编译也deviceQuery成功了:

CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GeForce 9600 GT"
  CUDA Driver Version / Runtime Version          6.5 / 6.5
  CUDA Capability Major/Minor version number:    1.1
  Total amount of global memory:                 1024 MBytes (1073414144 bytes)
  ( 8) Multiprocessors, (  8) CUDA Cores/MP:     64 CUDA Cores
  GPU Clock rate:                                1625 MHz (1.62 GHz)
  Memory Clock rate:                             400 Mhz
  Memory Bus Width:                              256-bit
  Maximum Texture Dimension Size (x,y,z)         1D=(8192), 2D=(65536, 32768), 3D=(2048, 2048, 2048)
  Maximum Layered 1D Texture Size, (num) layers  1D=(8192), 512 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(8192, 8192), 512 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       16384 bytes
  Total number of registers available per block: 8192
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  768
  Maximum number of threads per block:           512
  Max dimension size of a thread block (x,y,z): (512, 512, 64)
  Max dimension size of a grid size    (x,y,z): (65535, 65535, 1)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             256 bytes
  Concurrent copy and kernel execution:          Yes with 1 copy engine(s)
  Run time limit on kernels:                     Yes
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      No                                                                                                    
  Device PCI Bus ID / PCI location ID:           1 / 0                                                                                                 
  Compute Mode:                                                                                                                                        
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >                                                          

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 6.5, CUDA Runtime Version = 6.5, NumDevs = 1, Device0 = GeForce 9600 GT                       
Result = PASS

然后我跟着此推荐的安装方法本文档安装 Theano,因为与 TensorFlow 相比,它能够在我的显卡上运行。我创建了.theanorc文件

[global]
device = cuda0
floatX = float32

[cuda]
root=/usr/local/cuda-6.5/bin/

[dnn]
include_path = /usr/local/cuda-6.5/include/
library_path = /usr/local/cuda-6.5/lib64/

我还将适当的变量导出到.profile

export PATH=/usr/local/cuda-6.5/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-6.5/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

但是当我尝试运行这个简单的测试脚本时:

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')

我收到以下错误:

ERROR (theano.gpuarray): Could not initialize pygpu, support disabled
Traceback (most recent call last):
  File "/home/kuba/anaconda3/lib/python3.6/site-packages/theano/gpuarray/__init__.py", line 227, in <module>
    use(config.device)
  File "/home/kuba/anaconda3/lib/python3.6/site-packages/theano/gpuarray/__init__.py", line 214, in use
    init_dev(device, preallocate=preallocate)
  File "/home/kuba/anaconda3/lib/python3.6/site-packages/theano/gpuarray/__init__.py", line 99, in init_dev
    **args)
  File "pygpu/gpuarray.pyx", line 651, in pygpu.gpuarray.init
  File "pygpu/gpuarray.pyx", line 587, in pygpu.gpuarray.pygpu_init
pygpu.gpuarray.GpuArrayException: b'Could not find symbol "cuDevicePrimaryCtxGetState": /usr/lib/libcuda.so.1: undefined symbol: cuDevicePrimaryCtxGetState'

我不明白这个错误,因为在 Nvidia 的文档中这个函数确实存在。有人知道吗?问题可能是因为我使用的是 Python 3.6,而在上述文档中<3.6 之前有一个符号?路径是否有错误?

答案1

一般来说,所有这些组件至少需要 CUDA 7 和 cuDNN 3 或更新版本,而这又需要 GPU 的 CUDA 计算能力至少为 2.0。

相关内容