XiZi's Blog

Ubuntu12.04 安装 CUDA 4.2

翻译自(http://d.hatena.ne.jp/iRiE/20120309/1331303439)

按照下列顺序进行安装

  1. Ubuntu 12.04
  2. NVIDIA 显卡驱动(devdriver_4.2_linux_64_295.41.run)
  3. cudatoolkit_4.2.9_linux_64_ubuntu11.04.run
  4. gpucomputingsdk_4.2.9_linux.run
  5. 代码编译依赖库

Ubuntu 12.04 安装

Ubuntu 的安装,网上教程不少,不会的自己百度一下。

NVIDIA 显卡驱动

sudo apt-get install nvidia-current

CUDA Toolkit

去NVIDIA的网站下载

sudo sh cudatoolkit_4.2.9_linux_64_ubuntu11.04.run

配置库,创建文件(/etc/ld.so.conf.d/cuda.conf)

## /etc/ld.so.conf.d/cuda.conf
/usr/local/cuda/lib64
/usr/local/cuda/lib

重新加载设置

sudo ldconfig

创建系统环境变量文件(/etc/profile.d/cuda.sh

## /etc/profile.d/cuda.sh
export PATH="/usr/local/cuda/bin:$PATH"
export LIBRARY_PATH="/usr/lib/nvidia-current:$LIBRARY_PATH"

修正"/usr/local/cuda/include/host_config.h"(话说这里还没实验,不知到需不需要)

--- host_config.orig.h  2012-01-27 17:20:57.689102815 +0900
+++ host_config.h       2012-01-27 17:29:32.037101532 +0900
@@ -79,7 +79,7 @@
 
 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)
 
-#error -- unsupported GNU version! gcc 4.6 and up are not supported!
+//#error -- unsupported GNU version! gcc 4.6 and up are not supported!
 
 #endif /* __GNUC__> 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5) */

 

gpucomputingsdk

安装GPU_COMPUTING_SDK

sh gpucomputingsdk_4.2.9_linux.run

安装后,进入安装目录执行 make, 一般会出现以下错误。

../../lib/librendercheckgl_x86_64.a(rendercheck_gl.cpp.o): In function `CheckBackBuffer::checkStatus(char const*, int, bool)':
rendercheck_gl.cpp:(.text+0xfbb): undefined reference to `gluErrorString'

这是由于~/NVIDIA_GPU_Computing_SDK/C/common/common.mk 文件中,库文件的链接顺序问题引起的。这里主要受到库$(RENDERCHECKGLLIB)的影响,我们把这个库提前即可。

--- common.orig.mk      2012-01-27 14:34:13.129127766 +0900
+++ common.mk   2012-01-27 14:24:10.433129269 +0900
@@ -267,18 +267,18 @@
 
 # If dynamically linking to CUDA and CUDART, we exclude the libraries from the LIB
 ifeq ($(USECUDADYNLIB),1)
-     LIB += ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) ${LIB} -ldl -rdynamic 
+     LIB += $(RENDERCHECKGLLIB) ${OPENGLLIB} $(PARAMGLLIB) ${LIB} -ldl -rdynamic 
 else
 # static linking, we will statically link against CUDA and CUDART
   ifeq ($(USEDRVAPI),1)
-     LIB += -lcuda   ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) ${LIB} 
+     LIB += -lcuda   $(RENDERCHECKGLLIB) ${OPENGLLIB} $(PARAMGLLIB) ${LIB} 
   else
      ifeq ($(emu),1) 
          LIB += -lcudartemu
      else 
          LIB += -lcudart
      endif
-     LIB += ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) ${LIB}
+     LIB += $(RENDERCHECKGLLIB) ${OPENGLLIB} $(PARAMGLLIB) ${LIB}
   endif
 endif

其他编译所需依赖的安装

必须依赖安装包

sudo apt-get install g++ freeglut3-dev libxi-dev libxmu-dev

如果你还想用mpi,可以安装openmpi的包

sudo apt-get install openmpi-bin openmpi-dev

编译和测试sdk

cd ~/NVIDIA_GPU_Computing_SDK/C
make

测试

cd ~/NVIDIA_GPU_Computing_SDK/C/bin/linux/release
./nbody

 

P。S。

没看动说的啥,先放这里把。

由于64位系统的原因,如果编译的时候出现错误 “/usr/bin/ld: cannot find -lcutil”,你可以尝试创建链接来修正它 。

cd ~/NVIDIA_GPU_Computing_SDK/C/lib
for i in *_x86_64.a; do ln -sv $i ${i%_x86_64.a}.a; done

 

 




Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee