Ubuntu12.04配置CUDA编程环境

配置目标:

CUDA包括opencl

OMPSs

DLB

这篇文章仅先介绍手动安装CUDA的安装,在CUDA官网上也有通过apt-get安装的方法,但是没有尝试

http://docs.nvidia.com/cuda/cuda-getting-started-guide-for-linux/index.html#package-manager-installation  

不同于以前的CUDA版本,现在CUDA Toolkit 和SDK 整合了起来,所以只用安装一个就好了


环境:

全新Ubuntu12.04

NVIDAGT630M+Intel集成显卡


1.配置CUDA环境

2.配置OmpSs

3.配置DLB


.安装CUDA环境

首先要安装NVIDIA的显卡,由于是双显卡,所以上网搜的一般方法是不行的,要用bumblebee才可以,这个软件可以管理optiums双显卡

所以现在首先安装bumblebee这个软件

先看看bumblebee的重要性

However, when you need to show graphical examples using OpenGL,

 you do need something like Bumblebee for Optimus systems, 

otherwise you either don't see anything on your display or get the error:

这是Ubuntu论坛上的讨论

具体参见这里:https://wiki.ubuntu.com/Bumblebee


sudo add-apt-repository ppa:bumblebee/stable


sudo apt-get update


sudo apt-get install bumblebee bumblebee-nvidia virtualgl linux-headers-generic

  • 如果是 13.10 :
sudo apt-get install bumblebee bumblebee-nvidia primus linux-headers-generic


reboot


重启就好了

由于安装bumblebee的时候默认安装的是304版本的显卡

由于CUDA要求显卡驱动版本至少是319,所以我们现在升级显卡驱动的版本

sudoapt-get install nvidia-331*

把最新版本所有的东西都安装下来就好了


由于bumblebee每次升级显卡驱动以后都要手动配置才可以


所以现在手动配置/etc/bumblebee/bumblebee.conf


1.

找到一行

Driver=

这里设置默认显卡驱动

把这一行改成

Driver=nvidia


2.


[driver-nvidia]

#Module name to load, defaults to Driver if empty or unset

KernelDriver=nvidia-331-updates

PMMethod=auto

#colon-separated path to the nvidia libraries

LibraryPath=/usr/lib/nvidia-331-updates:/usr/lib32/nvidia-nvidia-331-updates

#comma-separated path of the directory containing nvidia_drv.so andthe

#default Xorg modules path

XorgModulePath=/usr/lib/nvidia-331-updates/xorg,/usr/lib/xorg/modules

XorgConfFile=/etc/bumblebee/xorg.conf.nvidia


找到对应上面的位置,改成这样,注意黑体字是修改了的地方

current改成黑体字就好了


3.重新启动bumblebee

sudo service bumblebeed restart


optirun -b none nvidia-settings -c :8


4.到这里就OK了,显卡驱动安装了,也升级了


现在测试一下是不是有用,并和Intel显卡性能比较一下


先用intel显卡执行一下


root@xianb:/home/xianb#glxspheres64

Polygonsin scene: 62464

VisualID of window: 0x95

Contextis Direct

OpenGLRenderer: Mesa DRI Intel(R) Ivybridge Mobile

59.292266frames/sec - 66.170169 Mpixels/sec


root@xianb:/home/xianb#optirun glxspheres64

Polygonsin scene: 62464

VisualID of window: 0x21

Contextis Direct

OpenGLRenderer: GeForce GT 630M/PCIe/SSE2


可以看到用GT630M显卡的时候,中间的小球动的明显快多了


xianb@xianb:~$optirun -b none nvidia-settings -c :8

[5662.837009] [ERROR]You've no permission to communicate with theBumblebee daemon. Try adding yourself to the 'bumblebee' group

[5662.837054] [ERROR]Could not connect to bumblebee daemon - is itrunning?


的解决办法,root用户是默认在这个组里面的

下面这一段话是从官方CUDA的安装文档里看到的

看一看有好处,不看也无妨


Ifyou are using an Optimus system and are installing the driver, youmust pass the --optimus option to the CUDA Toolkit installer.If you are instead installing a stand alone driver on an optimussystem, you must pass --no-opengl-files to the installer and declinethe xorg.conf update at the end of the installation. If the DisplayDriver component fails to install, you may have the Nouveau driversworked into your root filesystem (initramfs). To remove this, youwill have to rebuild your initramfs image:

sudo mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r)-nouveau.img
sudo dracut /boot/initramfs-$(uname -r).img $(uname -r)

If you are usingGrub2 as a bootloader, you may also need to edit its config toprevent Nouveau from loading. Add "rdblacklist=nouveaunouveau.modeset=0" to the end of the GRUB_CMDLINE_LINUX entry in/etc/default/grub. Then, remake your Grub configuration by running:

grub2-mkconfig -o /boot/grub2/grub.cfg

. Once this isdone, reboot your machine and attempt the install again. You canselect which packages you wish to install at the start of theinstallation. The CUDA Toolkit installation defaults to/usr/local/cuda-5.5. In addition, a symbolic link iscreated from/usr/local/cuda to/usr/local/cuda-5.5in order for existing projects to make use of the new CUDA Toolkit. Apristine copy of the samples is installed within the toolkitdirectory. The CUDA Samples are installed to a user folder whichdefaults to$(HOME)/NVIDIA_CUDA-5.5_Samples.


现在开始安装CUDA

参考这个网站

http://docs.nvidia.com/cuda/cuda-getting-started-guide-for-linux/index.html


从官网上下载CUDA的安装包

解压到当前目录比如

sh cuda-5.5××××××.run -extract=/home/xianb/Tmp


注意双显卡系统一定要传送--optimus这个flags才行

然后安装

sh cuda-linux64-rel-5.5.22-16488124.run –optimus

sh cuda-linux64-rel-5.5.22-16488124.run –optimus


安装成功后

修改一些变量


export PATH=/usr/local/cuda-5.5/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-5.5/lib64:$LD_LIBRARY_PATH

要先安装一些东西才行

apt-get install binutils build-essential g++-4.6 linux-headers-`uname -r` mpich2 libglui-dev libxmu-dev libxi-dev


然后进入/usr/local/samples/目录
make
安装一下例子
安装成功就说明CUDA环境安装成功了
但是出现了问题

/usr/bin/ld: cannot find -lcuda
collect2: ld 返回 1
make[1]: *** [simpleTextureDrv] 错误 1
make[1]:正在离开目录 `/usr/local/cuda-5.5/samples/0_Simple/simpleTextureDrv'
make: *** [0_Simple/simpleTextureDrv/Makefile.ph_build] 错误 2
-L/usr/lib/nvidia-current -lcuda 
它要到nvidia-current目录下找-lcuda,但是没有这个目录了,我们创建一个符号链接

ln -s /usr/lib/nvidia-331-updates /usr/lib/nvidia-current
接可以了
不知道用不用在32位库里也来一个
试试也无妨
ln -s /usr/lib32/nvidia-331-updates /usr/lib32/nvidia-current

这是因为默认的链接库是链接到nvidia-current这个目录下,

但是由于安装双显卡把current卸载掉了,所以这个目录是不存在的


但是还是遇到了一些问题!


/usr/bin/ld:warning: libnvidia-tls.so.304.51, needed by/usr/lib/nvidia-current/libGL.so, not found (try using -rpath or-rpath-link)

/usr/bin/ld:warning: libnvidia-glcore.so.304.51, 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'


原因是没有加上一些路径所以提示没找到对应的动态库


所以我们加上一些路径


注意:

在此期间我还改了一个地方

不太清楚到底是那个起了作用

不过我觉得应该还是这个问题

PS:最后验证是第一个方法是对的,第二个应该是没有用的


加上一些路径

~/.bashrc中加上这些东西

然后执行source ~./bashrc

root和自己的用户都要加上才行



export PATH=/usr/local/cuda-5.5/bin:$PATH

export LD_LIBRARY_PATH=/usr/local/cuda-5.5/lib64:$LD_LIBRARY_PATH

export LD_LIBRARY_PATH=/usr/local/cuda-5.5/lib:$LD_LIBRARY_PATH

export LD_LIBRARY_PATH=/usr/lib/nvidia-current:/usr/lib32/nvidia-current:$LD_LIBRARY_PATH

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


直接复制上去吧,可能有一些是重复的,但是没影响


http://askubuntu.com/questions/158822/installing-cuda-on-ubuntu-12-04-with-nvidia-driver-295-59


http://huoyanzhuiren.blog.163.com/blog/static/72373411201293111515116/


http://askubuntu.com/questions/131506/how-can-i-get-nvidia-cuda-or-opencl-working-on-a-laptop-with-nvidia-discrete-car


这里参考了这些地方



还有一个地方我也改了,但是应该不是这里的问题,但是改了也没有影响


我把samples/common/findgllib.mk

里面ubuntu那个选项里加上了一个



LDPATH


P=/usr/lib32/nvidia-current


然后在下面LDPATH的地方加上了

find$(P)


最后像这样子

    ifeq ("$(DISTRO)","ubuntu")
        GLPATH    ?= /usr/lib/nvidia-current
        P         ?= /usr/lib32/nvidia-current
        GLLINK    ?= -L/usr/lib/nvidia-current -L/usr/lib32/nvidia-current
        DFLT_PATH ?= /usr/lib
    endif


  # find libGL, libGLU, libXi,
  GLLIB  := $(shell find $(P) $(GLPATH) $(DFLT_PATH) -name libGL.so  -print 2>/dev/null)
  GLULIB := $(shell find $(P) $(GLPATH) $(DFLT_PATH) -name libGLU.so -print 2>/dev/null)
  X11LIB := $(shell find $(P) $(GLPATH) $(DFLT_PATH) -name libX11.so -print 2>/dev/null)
  XILIB  := $(shell find $(P) $(GLPATH) $(DFLT_PATH) -name libXi.so  -print 2>/dev/null)
  XMULIB := $(shell find $(P) $(GLPATH) $(DFLT_PATH) -name libXmu.so -print 2>/dev/null)


虽然可能没用,但是改了也无妨

这个mk文件只对这些samples的编译有用,所以改了也无妨,只要这一次编译通过了就可以了


重要的是在~/.bashrc中的修改


记得修改后执行

source/.bashrc



编译完成后,

cd/usr/local/cuda-5.5/samples/bin/x86_64/linux/release

执行

optirun./deviceQuery

正确输出一些信息,而不是报错


optirun./nbody

有图形出来

就成功了!

注意,一定要用optirun来执行,

因为bumblebee是默认关闭NVIDIA显卡的


终于成功安装上了CUDA!!!




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值