在 Ubuntu 12.04 上使用 nvidia 驱动程序 295.59 安装 CUDA

在 Ubuntu 12.04 上使用 nvidia 驱动程序 295.59 安装 CUDA

我一直在尝试让 cuda 在基于 nvidia gt 650m 的笔记本电脑上运行。我运行的是 Ubuntu 12.04,使用的是 nvidia 295.59 驱动程序。另外,我的笔记本电脑使用 Optimus,所以我通过 bumblebee 安装了驱动程序。Bumblebee 还不能正常工作——不过我相信可以独立安装 CUDA。

要安装 CUDA,我已遵循此处详细的说明: 如何让 nVidia CUDA 或 OpenCL 在装有 nVidia 独立卡/Intel 集成显卡的笔记本电脑上运行?

但是我在构建 sdk 时仍然遇到问题。我在 common.mk 中进行了上述链接中指定的更改,但在构建过程中得到了以下信息(片段):

    make[2]: Entering directory `/home/john/NVIDIA_GPU_Computing_SDK/C/src/fluidsGL'
    /usr/bin/ld: warning: libnvidia-tls.so.302.17, needed by /usr/lib/nvidia-current/libGL.so, not found (try using -rpath or -rpath-link)
    /usr/bin/ld: warning: libnvidia-glcore.so.302.17, needed by /usr/lib/nvidia-current/libGL.so, not found (try using -rpath or -rpath-link)
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv018tls'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv012glcore'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv017glcore'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv012tls'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv015tls'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv019tls'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv000glcore'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv017tls'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv013tls'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv013glcore'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv018glcore'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv022tls'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv007tls'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv009tls'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv020tls'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv014glcore'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv015glcore'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv016tls'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv001glcore'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv006tls'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv021tls'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv011tls'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv020glcore'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv019glcore'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv002glcore'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv021glcore'
    /usr/lib/nvidia-current/libGL.so: undefined reference to `_nv014tls'
    collect2: ld returned 1 exit status
    make[2]: *** [../../bin/linux/release/fluidsGL] Error 1
    make[2]: Leaving directory `/home/john/NVIDIA_GPU_Computing_SDK/C/src/fluidsGL'
    make[1]: *** [src/fluidsGL/Makefile.ph_build] Error 2
    make[1]: Leaving directory `/home/john/NVIDIA_GPU_Computing_SDK/C'
    make: *** [all] Error 2

ld 警告的库就在我的系统上,并且安装在系统上:

    $ locate libnvidia-tls.so.302.17 libnvidia-glcore.so.302.17
    /usr/lib/nvidia-current/libnvidia-glcore.so.302.17
    /usr/lib/nvidia-current/libnvidia-tls.so.302.17
    /usr/lib/nvidia-current/tls/libnvidia-tls.so.302.17
    /usr/lib32/nvidia-current/libnvidia-glcore.so.302.17
    /usr/lib32/nvidia-current/libnvidia-tls.so.302.17
    /usr/lib32/nvidia-current/tls/libnvidia-tls.so.302.17

但是 /usr/lib/nvidia-current 和 /usr/lib32/nvidia-current 未被 ldconfig 拾取。我尝试通过将文件添加到 /etc/ld.so.conf.d/ 来添加它们,这样可以避免此错误,但现在我收到以下错误:

    make[2]: Entering directory `/home/john/NVIDIA_GPU_Computing_SDK/C/src/deviceQueryDrv'
    cc1plus: warning: command line option ‘-Wimplicit’ is valid for C/ObjC but not for C++ [enabled by default]
    obj/x86_64/release/deviceQueryDrv.cpp.o: In function `main':
    deviceQueryDrv.cpp:(.text.startup+0x5f): undefined reference to `cuInit'
    deviceQueryDrv.cpp:(.text.startup+0x99): undefined reference to `cuDeviceGetCount'
    deviceQueryDrv.cpp:(.text.startup+0x10b): undefined reference to `cuDeviceComputeCapability'
    deviceQueryDrv.cpp:(.text.startup+0x127): undefined reference to `cuDeviceGetName'
    deviceQueryDrv.cpp:(.text.startup+0x16a): undefined reference to `cuDriverGetVersion'
    deviceQueryDrv.cpp:(.text.startup+0x1f0): undefined reference to `cuDeviceTotalMem_v2'
    deviceQueryDrv.cpp:(.text.startup+0x262): undefined reference to `cuDeviceGetAttribute'
    deviceQueryDrv.cpp:(.text.startup+0x457): undefined reference to `cuDeviceGetAttribute'
    deviceQueryDrv.cpp:(.text.startup+0x4bc): undefined reference to `cuDeviceGetAttribute'
    deviceQueryDrv.cpp:(.text.startup+0x502): undefined reference to `cuDeviceGetAttribute'
    deviceQueryDrv.cpp:(.text.startup+0x533): undefined reference to `cuDeviceGetAttribute'
    obj/x86_64/release/deviceQueryDrv.cpp.o:deviceQueryDrv.cpp:(.text.startup+0x55e): more undefined references to `cuDeviceGetAttribute' follow
    collect2: ld returned 1 exit status
    make[2]: *** [../../bin/linux/release/deviceQueryDrv] Error 1
    make[2]: Leaving directory `/home/john/NVIDIA_GPU_Computing_SDK/C/src/deviceQueryDrv'
    make[1]: *** [src/deviceQueryDrv/Makefile.ph_build] Error 2
    make[1]: Leaving directory `/home/john/NVIDIA_GPU_Computing_SDK/C'
    make: *** [all] Error 2

如果有人能给我提供帮助,我将不胜感激。如果我能提供更多信息,请告诉我。

谢谢。

答案1

函数引用未定义的问题是由于您没有使用 -lcuda 链接 libcuda 库。指南位于如何让 nVidia CUDA 或 OpenCL 在装有 nVidia 独立卡/Intel 集成显卡的笔记本电脑上运行?提到您应该在 common.mk 中的一个位置删除 -lcuda,但这对我来说不起作用。但是,由于编译器找不到库,因此必须添加库所在的目录,以便 common.mk 中的相应行(对我来说是第 276 行)看起来像

    LIB += -L/usr/lib/nvidia-current -lcuda $(RENDERCHECKGLLIB) ${OPENGLLIB} $(PARAMGLLIB) ${LIB}

必须在 src/deviceQuery 文件夹的 Makefile 中进行类似的修正,最后一行,更改

    LIB += -lcuda

    LIB += -L/usr/lib/nvidia-current -lcuda

希望有帮助!

答案2

我需要做的就是将 nvidia 驱动程序路径放入 LD_LIBRARY_PATH 中:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/nvidia-current。

答案3

我也有同样的问题。

我认为这个问题也相关: 制作 Cuda SDK 时出现“找不到 -lOpenCL”错误

为了能够编译 cuda 和 openCL 示例,我做了以下操作。

我遵循了以下指南:如何让 nVidia CUDA 或 OpenCL 在装有 nVidia 独立卡/Intel 集成显卡的笔记本电脑上运行? 无需安装 bumblebee 并使用 xswat ppa:https://launchpad.net/~ubuntu-x-swat/+archive/x-updates/

gksudo gedit /etc/environment 
change 
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games" 
to 
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/cuda/bin" 

重新加载路径:

source /etc/environment 

设置LD_LIBRARY_PATH:

gksudo gedit /etc/ld.so.conf.d/cuda.conf

Paste into the file: 
/usr/local/cuda/lib64 
/usr/local/cuda/lib 
/usr/lib/nvidia-current
/usr/lib32/nvidia-current

Save and quit the editor. 

重新加载 LD_LIBRARY_PATH:

sudo ldconfig 

编辑~/.bash.rc,添加:

 export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/lib:/usr/lib/nvidia-current:/usr/lib32/nvidia-current

重新加载 ~/bash.rc

 source ~/bash.rc

检查是否找到 openCL:

    ldconfig -v | grep "OpenCL"

    ...
    libOpenCL.so.1 -> libOpenCL.so.1.0.0
libOpenCL.so.1 -> libOpenCL.so.1.0.0
    ...

现在应该可以编译示例了。不过不要抱太大希望。我认为 nvidia 驱动程序有问题,因为我收到以下 cuda 示例错误:

[vectorAddDrv] starting...

Vector Addition (Driver API)
checkCudaErrors() Driver API error = 0100 "CUDA_ERROR_INVALID_VALUE" from file <vectorAddDrv.cpp>, line 207.

对于 openCL 示例:

./oclDeviceQuery 
 [oclDeviceQuery] starting...

 ./oclDeviceQuery Starting...

 OpenCL SW Info:

  Error -1001 in clGetPlatformIDs Call !!!


  !!! Error # -1000 (Unspecified Error) at line 46 , in file oclDeviceQuery.cpp !!!

   Exiting...

相关内容