ubuntu16.04安装1080ti显卡驱动+cuda9.1+cudnn7

大城市里の小女人 提交于 2019-11-27 16:21:38

一、查看显卡信息:

终端输入命令:lspci |grep -i vga

二、安装显卡驱动

1. 禁用nouveau驱动

参考博客:https://blog.csdn.net/qq_33200967/article/details/80689543

终端输入:

sudo gedit /etc/modprobe.d/blacklist.conf​

在文本最后添加:

blacklist nouveau
options nouveau modeset=0

然后执行:

sudo update-initramfs -u

重启后,执行以下命令,如果没有屏幕输出,说明禁用nouveau成功:

lsmod | grep nouveau

2. 下载安装驱动

方法一:

参考博客https://blog.csdn.net/weixin_40294256/article/details/79157838

源头为:AINLP公众号的“从零开始搭建深度学习服务器: 基础环境配置(Ubuntu + GTX 1080 TI + CUDA + cuDNN)”

参考博客:https://blog.csdn.net/sinat_25640747/article/details/79231482

安装1080TI显卡驱动, 终端输入:

sudo apt-get purge nvidia*
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt-get install nvidia-384 nvidia-settings

安装完毕后重启电脑,终端输入:nvidia-smi , 查看显卡驱动,结果类似于下图

(来自公众号AINLP)

方法二:

参考博客:https://blog.csdn.net/qq_33200967/article/details/80689543

(1)驱动下载网址为:

https://www.geforce.cn/drivers

下载完成之后会得到一个安装包,不同版本文件名不同:

NVIDIA-Linux-x86_64-418.43.run

(2)卸载旧驱动

以下操作都需要在命令界面操作,执行快捷键  “Ctrl-Alt+F1”  进入命令界面,并登录(输入用户名即安装ubuntu时自己给电脑取的名和密码)

执行以下命令禁用X-Window服务,否则无法安装显卡驱动:

sudo service lightdm stop

出现菱形块时输入密码

执行以下三条命令卸载原有显卡驱动:

sudo apt-get remove --purge nvidia*

(如果之前的显卡驱动是run文件安装,则再输入以下两句)
sudo chmod +x NVIDIA-Linux-x86_64-410.93.run
sudo ./NVIDIA-Linux-x86_64-410.93.run --uninstall

(3)安装新驱动

直接执行驱动文件即可安装新驱动,一直默认即可:

sudo su

sh NVIDIA-Linux-x86_64-418.43.run

提示是否继续安装/退出安装时,选择继续安装

提示“Would you like to run the nvidia-xconfid utility to automatically update your X configuration file...”时,选择NO

执行以下命令启动X-Window服务

sudo service lightdm start

若没有返回桌面,则按Ctrl+Alt+F7返回

最后执行重启命令,重启系统即可:

reboot

注意: 若安装错误版本的显卡驱动,系统重启之后可能出现重复登录的情况。

三、安装CUDA

下载网址:https://developer.nvidia.com/cuda-toolkit

deb文件安装如下:

选择类似下图(来自公众号AINLP)

事先网盘里有cuda-repo-ubuntu1604-9-1-local_9.1.85-1_amd64.deb

则在终端输入命令:

sudo dpkg -i cuda-repo-ubuntu1604-9-1-local_9.1.85-1_amd64.deb

sudo apt-key add /var/cuda-repo-9-1-local/7fa2af80.pub

sudo apt-get update

sudo apt-get install cuda

卸载:版本号视情况而定

sudo apt-get autoremove --purge cuda

sudo rm -rf /usr/local/cuda-9.1/

run文件安装如下:

下载网址:https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1604&target_type=runfilelocal

sudo sh cuda_9.1.85_387.26_linux.run

按”空格“键加载更多,选择”accept“,有一步是安装显卡驱动的,选择n,剩下都选择y,或者按回车

参考博客:https://blog.csdn.net/qq_33200967/article/details/80689543#CUDA_71

开始安装之后,需要阅读说明,可以使用Ctrl + C直接阅读完成,或者使用空格键慢慢阅读。然后进行配置:

(是否同意条款,必须同意才能继续安装)
accept/decline/quit: accept

(这里不要安装驱动,因为已经安装最新的驱动了,否则可能会安装旧版本的显卡驱动,导致重复登录的情况)
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 410.48?
(y)es/(n)o/(q)uit: n

Install the CUDA 10.0 Toolkit?(是否安装CUDA 10 ,这里必须要安装)
(y)es/(n)o/(q)uit: y

Enter Toolkit Location(安装路径,使用默认,直接回车就行)
 [ default is /usr/local/cuda-10.0 ]:  

Do you want to install a symbolic link at /usr/local/cuda?(同意创建软链接)
(y)es/(n)o/(q)uit: y

Install the CUDA 10.0 Samples?(不用安装测试,本身就有了)
(y)es/(n)o/(q)uit: n

Installing the CUDA Toolkit in /usr/local/cuda-10.0 ...(开始安装)

卸载:

sudo /usr/local/cuda-9.1/bin/uninstall_cuda_9.1.pl

sudo rm -rf /usr/local/cuda-9.1/

添加环境变量:

sudo gedit ~/.bashrc

在文件最后加入以下两行并保存关闭

export PATH=/usr/local/cuda-9.1/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-9.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

运行 source ~/.bashrc 使其生效

通过命令  “nvcc -V”   查看安装的版本信息

测试:

cd /usr/local/cuda-9.1/samples/1_Utilities/deviceQuery

sudo make

sudo ./deviceQuery

结果输出如下证明安装成功:

./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GeForce GTX 1080 Ti"
  CUDA Driver Version / Runtime Version          10.1 / 9.1
  CUDA Capability Major/Minor version number:    6.1
  Total amount of global memory:                 11177 MBytes (11720130560 bytes)
  (28) Multiprocessors, (128) CUDA Cores/MP:     3584 CUDA Cores
  GPU Max Clock rate:                            1683 MHz (1.68 GHz)
  Memory Clock rate:                             5505 Mhz
  Memory Bus Width:                              352-bit
  L2 Cache Size:                                 2883584 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
  Maximum Layered 1D Texture Size, (num) layers  1D=(32768), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(32768, 32768), 2048 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  2048
  Maximum number of threads per block:           1024
  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 2 copy engine(s)
  Run time limit on kernels:                     Yes
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      Yes
  Supports Cooperative Kernel Launch:            Yes
  Supports MultiDevice Co-op Kernel Launch:      Yes
  Device PCI Domain ID / Bus ID / location ID:   0 / 3 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 10.1, CUDA Runtime Version = 9.1, NumDevs = 1
Result = PASS

四、下载安装Cudnn

下载地址:https://developer.nvidia.com/rdp/cudnn-download

需要先登录再下载,下载得到压缩包如:cudnn-9.1-linux-x64-v7.1.tgz

先解压:

tar -zxvf cudnn-9.1-linux-x64-v7.1.tgz

解压后得到:

cuda/include/cudnn.h
cuda/NVIDIA_SLA_cuDNN_Support.txt
cuda/lib64/libcudnn.so
cuda/lib64/libcudnn.so.7
cuda/lib64/libcudnn.so.7.1.2
cuda/lib64/libcudnn_static.a

再执行:

sudo cp cuda/include/cudnn.h /usr/local/cuda-9.1/include/ 
sudo cp cuda/lib64/libcudnn* /usr/local/cuda-9.1/lib64/ -d
注意最后一行拷贝时 "-d"不能少, 否则会提示.so不是symbol link(参考博客:https://blog.csdn.net/weixin_40294256/article/details/79157838)

拷贝完成之后,可以使用以下命令查看CUDNN的版本信息:

cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2

 

 

 

 

 

 

 

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!