经过本人三天的奋战,终于在自己机器上完成了CUDA3.0的安装,本人的安装的版本应该是普适的,可以根据自己情况对比安装。
cuda 3.0不支持gcc 4.4或以上的版本,建议gcc 4.3或以下。
http://archive.ubuntu.com/ubuntu/pool/universe/g/gcc-4.3/提供了安装包。一般要安装五个文件:
gcc-3.4-base_3.4.6-6ubuntu3_i386.deb、
gcc-3.4_3.4.6-6ubuntu3_i386.deb、
cpp-3.4_3.4.6-6ubuntu3_i386.deb、
g++-3.4_3.4.6-6ubuntu3_i386.deb、
libstdc++6-dev_3.4.6-6ubuntu3_i386.deb
(上面是gcc 3.4安装文件,可以根据自己需要去下载其他版本,其他版本也类似这五个文件)
顺序安装这五个文件,最后两个文件会出现相互依赖的错误,利用sudo dpkg --force-depends -i xxx.deb强制安装
一、安装显卡驱动
下面我们来安装驱动
1) 载掉原来的驱动(如果有):sudo nvidia-installer --uninstall
(2) 关闭gdm:sudo /etc/init.d/gdm stop
(3) 屏幕黑了之后,使用alt+F1进入终端
(4) 进入下载目录,运行安装: sudo sh devdriver_3.1_linux_32_256.40.run
(6) 点击 “Accept”接受 LICENSE,等待进度条完成后,运行startx回到可视化桌面
中间可能会出现以下问题
"ERROR: Unable to load the kernel module 'nvidia.ko'. This happens most frequently when this kernel module was built against the wrong or improperly configured kernel sources, with a version of gcc that differs from the one used to build the target kernel, or if a driver such as rivafb/nvidiafb is present and prevents the NVIDIA kernel module from obtaining ownership of the NVIDIA graphics device(s), or NVIDIA GPU installed in this system is not supported by this NVIDIA Linux graphics driver release."
解救方法如下:
I'm running the 195.36.24 driver and it's running smoothly.
Getting it to work was the difficult part 'cause the installation procedure differs from the previous versions.
Here's what I did to install the binary drivers from nvidia's site.
1) Make sure you downloaded the correct driver from nvidia's site.
2) remove current nvidia packages:
(if you have enabled nvidia in system->administration->hardware drivers, then disable them first and possibly reboot)
sudo apt-get purge nvidia-*
3) Create the file "/etc/modprobe.d/nvidia-graphics-drivers.conf" with the following contents
blacklist vga16fb
blacklist nouveau
blacklist lbm-nouveau
blacklist nvidia-173
blacklist nvidia-96
blacklist nvidia-current
blacklist nvidiafb
4) create or adjust the /etx/X11/xorg.conf file to:
Section "Device"
Identifier "Device0"
Driver "nvidia"
VendorName "NVIDIA Corporation"
EndSection
5) reboot
6) it will tell you that it can't start X ( low graphics mode ) , then choose a text based console login
(if it does start in X, just press ctrl-F1, log yourself in and call "sudo service gdm stop"
7) run the nvidia installer and when it asks to run nvidia-x-config, answer yes
8) start X: sudo service gdm start
择自:http://forums.nvidia.com/index.php?showtopic=167422
二、安装toolkit
(1) 进入下载目录,运行安装: sudo sh cudatoolkit_3.1_linux_32_ubuntu9.10.run
(2) 回车,安装至默认位置 /usr/local/cuda
三、安装sdk
(1) 进入下载目录,运行安装: sh gpucomputingsdk_3.1_linux.run
(建议还不要用管理员安装)
(2) 回车,安装至默认位置 ~/NVIDIA_GPU_Computing_SDK
四、设置环境变量
运行sudo gedit ~/.bashrc
, 在打开的文件最后加入下面脚本:
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib:$LD_LIBRARY_PATH
五、配置GCC
因为CUDA是使用GCC4.3编译的,所以必须下载GCC4.3。
sudo apt-get install g++-4.3 gcc-4.3
下面是为了方便在多个GCC版本间切换
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 44 --slave /usr/bin/g++ g++ /usr/bin/g++-4.4 --slave /usr/bin/gcov gcov /usr/bin/gcov-4.4
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 43 --slave /usr/bin/g++ g++ /usr/bin/g++-4.3 --slave /usr/bin/gcov gcov /usr/bin/gcov-4.3
显示gcc版本sudo update-alternatives --display gcc
修改gcc版本sudo update-alternatives --config gcc
运行这行后选择4.3版的gcc
六、编译sdk example
进入sdk安装目录:
cd ~/NVIDIA_GPU_Computing_SDK/C
运行make编译。
你可能会遇到缺少以下包:
1.缺少glu.hsudo apt-get install freeglut3-dev
2.gcc: error trying to exec ‘cc1plus’
## 如果安装gcc4.3却没有安装g++4.3可能会出现这个错误,安装g++4.3即可.sudo apt-get install g++-4.3
3./usr/bin/ld: cannot find -lparamgl
## /usr/bin/ld: cannot find -lrendergl
## these are built as part of the CUDA SDK
## cd to your NVIDIA_GPU_Computing_SDK/Csudo make
4.inline function ‘void* memset(void*, int, size_t)’ cannot be declared weak
如果是这个错误,可能是使用了gcc/g++ 4.4,重新安装gcc 4.3 and g++4.3即可,方法上面有.
5.CUDA version is insufficient for CUDART version.
重新安装新的显卡驱动程序.
你可以使用”find /usr/lib | grep cuda.so
“来查看cuda的版本.
6.cudaSafeCall() Runtime API error : no CUDA-capable device is available.
要不是你的电脑上根本没有支持cuda的显卡,要么是你没有正确安装驱动程序.
sudo rm /usr/lib/libGL.so
cd /usr/lib
sudo ln -s libGL.so.256.40 libGL.so
;其中256.40是我安装的驱动版本,可能每台电脑会有不同
cuda 2.3使用 g++ 4.3编译;
@ubuntu:~$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 44 --slave /usr/bin/g++ g++ /usr/bin/g++-4.4 --slave /usr/bin/gcov gcov /usr/bin/gcov-4.4
@ubuntu:~$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 43 --slave /usr/bin/g++ g++ /usr/bin/g++-4.3 --slave /usr/bin/gcov gcov /usr/bin/gcov-4.3
@ubuntu:~$ sudo update-alternatives --display gcc
@ubuntu:~$ sudo update-alternatives --config gcc
[b]环境变量的设置:
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib:$LD_LIBRARY_PATH
把以上两条命令写到~/.bashrc中。
注:ubuntu中环境变量写在.bashrc或.profile文件中。
[c] Modifying ld.so.conf: (this file located in the /etc derectory)
把 <CUDA_INSTALL_PATH>/cuda/lib (32bit)
或者 <CUDA_INSTALL_PATH>/cuda/lib64 (64bit)
写入ld.so.conf文件中 .
[4]bulid the SDK
@ubuntu:~$ cd [to your NVIDIA_GPU_Computing_SDK/C]
@ubuntu:~$ make
-release : input "make"
-debug : input "make dbg=1"
-emurelease: input "make emu=1"
-emudebug: input "make emu=1 dbg=1"
or
@ubuntu:~$ cd [to your NVIDIA_GPU_Computing_SDK/C]/src/[project name]
@ubuntu:~$ make
[5]execute example project
@ubuntu:~$ cd [to your NVIDIA_GPU_Computing_SDK/C]/src/deviceQuery
@ubuntu:~$ make
@ubuntu:~$ cd [to your NVIDIA_GPU_Computing_SDK/C]/bin/linux/release
@ubuntu:~$ ./deviceQuery
---------------result-----------------
./deviceQuery Starting...
CUDA Device Query (Runtime API) version (CUDART static linking)
There is 1 device supporting CUDA
Device 0: "GeForce GTS 250"
CUDA Driver Version: 3.10
CUDA Runtime Version: 3.10
CUDA Capability Major revision number: 1
CUDA Capability Minor revision number: 1
Total amount of global memory: 536674304 bytes
Number of multiprocessors: 16
Number of cores: 128
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 block: 512
Maximum sizes of each dimension of a block: 512 x 512 x 64
Maximum sizes of each dimension of a grid: 65535 x 65535 x 1
Maximum memory pitch: 2147483647 bytes
Texture alignment: 256 bytes
Clock rate: 1.62 GHz
Concurrent copy and execution: Yes
Run time limit on kernels: No
Integrated: No
Support host page-locked memory mapping: No
Compute mode: Default (multiple host threads can use this device simultaneously)
Concurrent kernel execution: No
Device has ECC support enabled: No
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 3.10, CUDA Runtime Version = 3.10, NumDevs = 1, Device = GeForce GTS 250
PASSED
Press <Enter> to Quit...
-----------------------------deviceQuery end----------------------------------
@ubuntu:~$ cd [to your NVIDIA_GPU_Computing_SDK/C]/src/bandwidthTest
@ubuntu:~$ make
@ubuntu:~$ cd [to your NVIDIA_GPU_Computing_SDK/C]/bin/linux/release
@ubuntu:~$ ./bandwidthTest
----------------reslut--------------------------------
[bandwidthTest]
./bandwidthTest Starting...
Running on...
Device 0: GeForce GTS 250
Quick Mode
Host to Device Bandwidth, 1 Device(s), Paged memory
Transfer Size (Bytes) Bandwidth(MB/s)
33554432 1470.6
Device to Host Bandwidth, 1 Device(s), Paged memory
Transfer Size (Bytes) Bandwidth(MB/s)
33554432 1308.4
Device to Device Bandwidth, 1 Device(s)
Transfer Size (Bytes) Bandwidth(MB/s)
33554432 51895.2
[bandwidthTest] - Test results:
PASSED
Press <Enter> to Quit...
-----------------------------------------------------------
OVER! good luck !
[参考信息]
[01]http://www.docin.com/p-44550472.html (CUDA在linux系统上安装指南)
[02]http://www.devbaldwin.com/blog/2010/03/15/setting-up-cuda-on-ubuntu-9-10/
[03]http://www.linuxidc.com/Linux/2010-02/24329p3.htm (Ubuntu下CUDA安装)
[04]http://forums.nvidia.com/index.php?showtopic=167422
增加gcc3.4和gcc 4.4可选项
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 40
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-3.4 30
切换版本到gcc-3.4
$ sudo update-alternatives --config gcc
现有 2 个可选项,它们都提供了“gcc”
< 选择 可选项-----------------------------------------------
1 /usr/bin/gcc-3.4*+
2 /usr/bin/gcc-4.2
要维持缺省值[*],按回车键,或者键入选择的编号:1
使用“/usr/bin/gcc-3.4”来提供“gcc”。
至此gcc3.4安装成功
可以利用gcc --version来查看版本
整完后,会发现,系统找不到g++了,所以还得自己安装一下g++:
sudo apt-get install g++