nvidia显卡驱动和cuda安装

时间:2021-07-13 17:21:55

1、添加驱动源

sudo add-apt-repository ppa:graphics-drivers/ppa

sudo apt-get update

2、安装Nvidia驱动

sudo apt-get install nvidia-367

sudo apt-get install mesa-common-dev

sudo apt-get install freeglut3-dev

执行上述3命令后应当验证是否安装ok

参考:http://blog.csdn.net/u010837794/article/details/63251725

执行完上述后,重启:

sudo reboot

必须要重启哦。重启后执行

nvidia-smi

如果出现了你的GPU列表,则说明驱动安装成功了。

另外也可以通过:nvidia-settings查看自己机器上详细的GPU信息。这个会弹出图形界面的东西,不建议使用。

3、    使用aria2下载CUDA8.0

下载引导页地址:https://developer.nvidia.com/cuda-80-ga2-download-archive

实际下载地址:http://developer2.download.nvidia.com/compute/cuda/8.0/secure/Prod2/local_installers/cuda_8.0.61_375.26_linux.run?BE5UwVtdx1qOSXGlLZrDPBI-8R_QEVT5NXWlmdEXeXWtUkPZngemVgMPEXTnIH81sSHBZQMvJxq-Sga204QpbbfGVqpFKIIQXPTR4TPiwlH9uD4x4NmWpUJOEl_foKhj7WgtzKmp0uV75Qy_Luc5C1osdM9ZcW3AhIoDaaV9uSiDKTDWo4mINAov

大小:1.4G

名称:cuda_8.0.61_375.26_linux.run

我使用Aria2下载(如果没有则安装aria2:sudo apt-get install aria2):

aria2c -s 3 http://developer2.download.nvidia.com/compute/cuda/8.0/secure/Prod2/local_installers/cuda_8.0.61_375.26_linux.run?VOvimfVryGI24xcQZtHNpKQy9VxlQZt8ZR0kVqkWkI6bAr-hxaAXDiuzoS76lgXTrleU-am1NMOP0mP_pXgdEAwWPxFmUgN1OiIBZj9xfxE7y-LQqTNbqvXlLCVVv-w4EyzwOsZo3eCtSjvBqV-Bq4GpUyLL6wS38qNDep79V5WyYnkTomOX6_iq

下载完成后执行命令

cd ~

mkdir download

cuda_8.0.61_375.26_linux.run download/

sudo sh cuda_8.0.61_375.26_linux.run

Summary提示安装失败:

It appears that an X server is running. Please exit X before installation

处理方式:

再次执行下最后一条命令sudo sh xxx.run

进行选择时留意以下选项:

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 361.62?

答案必须是n

参考:http://www.52nlp.cn/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E4%B8%BB%E6%9C%BA%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE-ubuntu-16-04-nvidia-gtx-1080-cuda-8

执行后安装后显示

Driver:   Not Selected

Toolkit:  Installed in /usr/local/cuda-8.0

Samples:  Installed in /home/john, but missing recommended libraries

Driver:   Not Selected,虽然看起来不大对,但参考文章中也是如此,暂且认为正常。

4、    更改配置文件

vim ~/.bashrc

(末尾)添加

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

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

在执行:

nvidia-smi看看是否正常。

在测试下刚才安装是否正常:

cd /usr/local/cuda/samples

cd 1_Utilities/deviceQuery

sudo make

执行正常后,在执行

./deviceQuery

应该会输出显卡信息,这里则说明cuda安装ok。

(若想进步一测试

cd ../../5_Simulations/nbody/

sudo make

./nbody -benchmark -numbodies=256000 -device=0

5、下载安装CUDNN

aria2c -s 3 http://developer.download.nvidia.com/compute/redist/cudnn/v6.0/cudnn-8.0-linux-x64-v6.0-rc.tgz

下载后执行:

tar -xzvf cudnn-8.0-linux-x64-v6.0.tgz

sudo cp cuda/include/cudnn.h /usr/local/cuda/include

sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/ -d

sudo chmod a+r /usr/local/cuda/include/cudnn.h

sudo chmod a+r /usr/local/cuda/lib64/libcudnn*

TODO补充:如何验证cudnn安装成功