nvcc正在挑选错误的libcudart库

时间:2017-02-09 02:54:50

标签: cuda linker linker-errors loader nvcc

当我尝试使用gpu模式导入theano时出现此问题。在导入theano时,它会尝试编译一些代码,创建它的共享库并尝试加载它。 这是制作so文件的命令。

nvcc -shared -O3 -m64 -Xcompiler -DCUDA_NDARRAY_CUH=mc72d035fdf91890f3b36710688069b2e,\
  -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION,-fPIC,-fvisibility=hidden -Xlinker \
  -rpath,/home/jay/.theano/compiledir_Linux-4.8--ARCH-x86_64-with-arch-Arch-Linux--3.6.0-64/cuda_ndarray \
  -I/usr/lib/python3.6/site-packages/Theano-0.9.0b1-py3.6.egg/theano/sandbox/cuda \
  -I/usr/lib/python3.6/site-packages/numpy-1.13.0.dev0+72839c4-py3.6-linux-x86_64.egg/numpy/core/include \
  -I/usr/include/python3.6m -I/usr/lib/python3.6/site-packages/Theano-0.9.0b1-py3.6.egg/theano/gof \
  -L/usr/lib -o /home/jay/.theano/compiledir_Linux-4.8--ARCH-x86_64-with-arch-Arch-Linux--3.6.0-64/cuda_ndarray/cuda_ndarray.so \
   mod.cu -lcublas -lpython3.6m 

它成功编译但无法为cudart找到正确的库。 ldconfig似乎知道这个库的位置,这是正确的。

$ ldconfig -p | grep libcuda
    libcudart.so.8.0 (libc6,x86-64) => /opt/cuda/lib64/libcudart.so.8.0
    libcudart.so (libc6,x86-64) => /opt/cuda/lib64/libcudart.so
    libcuda.so.1 (libc6,x86-64) => /usr/lib/libcuda.so.1
    libcuda.so (libc6,x86-64) => /usr/lib/libcuda.so

但是当我检查库时,它会用libcudart来说明问题。

$ ldd cuda_ndarray.so  | grep cuda
    libcublas.so.8.0 => /opt/cuda/lib64/libcublas.so.8.0 (0x00007f006dd1b000)
    libcudart.so.7.5 => not found

阅读精灵标题

$ readelf -a cuda_ndarray.so | grep NEEDED
 0x0000000000000001 (NEEDED)             Shared library: [libcublas.so.8.0]
 0x0000000000000001 (NEEDED)             Shared library: [libpython3.6m.so.1.0]
 0x0000000000000001 (NEEDED)             Shared library: [libcudart.so.7.5]
 0x0000000000000001 (NEEDED)             Shared library: [librt.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]

出了什么问题,导致选择错误的库cudart7.5而不是cudart8.0

这是我的nvcc -V

的输出
$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Sun_Sep__4_22:14:01_CDT_2016
Cuda compilation tools, release 8.0, V8.0.44

我的libcudart.so指向正确的库版本

$ ls -la | grep libcudart
lrwxrwxrwx  1 root root        16 Jan 10 06:10 libcudart.so -> libcudart.so.8.0
lrwxrwxrwx  1 root root        19 Jan 10 06:10 libcudart.so.8.0 -> libcudart.so.8.0.44
-rwxr-xr-x  1 root root    415432 Jan 10 06:10 libcudart.so.8.0.44
-rw-r--r--  1 root root    775162 Jan 10 06:10 libcudart_static.a

还有一个更普遍的问题,链接器如何解析输入的实际文件位置,如-lm-lcudart或编译时使用的任何简写符号?

我尝试了cuda附带的两个示例程序,其中包括libcudart

$ grep -rnw . -e 'lcudart'
./3_Imaging/cudaDecodeGL/Makefile:329:LIBRARIES += -lcudart -lnvcuvid
./0_Simple/simpleMPI/Makefile:284:LIBRARIES += -L$(CUDA_PATH)/lib$(LIBSIZE) -lcudart
这两个simpleMPI中的

没有错误地运行。

$ ./simpleMPI 
Running on 1 nodes
Average of square roots is: 0.667242
PASSED

另一个因早期错误而失败

$ ./cudaDecodeGL 
./cudaDecodeGL: error while loading shared libraries: libcudart.so.7.5: cannot open shared object file: No such file or directory

1 个答案:

答案 0 :(得分:2)

我在CUDA8的旧安装上方安装了CUDA7.5,因此它将旧的cuda库移至cuda/lib64/stubs。删除该目录后,一切都按预期工作。