Ubuntu 16.04 安装 NVIDIA 驱动指引_9.0
原文档来自这里:https://cloud.tencent.com/document/product/560/8048
我按照步骤操作一遍不成功,自己搞定了记录一下。
前言
NVIDIA驱动包含两个部分一个是CUDA(具体是个啥,不清楚,必须安装上就对了),另一个是具体的驱动。
如果以deb包的形式呈现,那么就是如下两个包:
-rw-rw-r-- 1 ubuntu ubuntu 1212738714 Sep 23 2017 cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64.deb
-rw-rw-r-- 1 ubuntu ubuntu 102497768 May 18 09:45 nvidia-diag-driver-local-repo-ubuntu1604-384.145_1.0-1_amd64.deb
为什么要安装9.0
版本呢?tensorflow
指明要安装9.0
以上版本,我就选了9.2
的安装,安装好了训练时报错,找9.0的库文件;这不又折回来安装9.0
版本的了。
安装CUDA Toolkit 9.0
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"
sudo reboot
sudo dpkg -i cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64.deb
sudo apt-key add /var/cuda-repo-9-0-local/7fa2af80.pub
sudo apt-get update
sudo apt-get install cuda
需要注意的是这种安装方法,安装完成后不能使用nvcc --version
。不过问题不大。
修改环境变量
在终端打开并修改.bashrc
文件
vim ~/.bashrc
将如下内容添加到.bashrc文件末尾:
export CUDA_HOME=/usr/local/cuda-9.0
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export PATH=${CUDA_HOME}/bin:${PATH}
export CUPIT_LIB_PATH=${CUDA_HOME}/extras/CUPTI/lib64
export LD_LIBRARY_PATH=${CUPIT_LIB_PATH}:$LD_LIBRARY_PATH
查看安装结果
一定要看到如下结果后再进行
ubuntu@VM-0-13-ubuntu:~$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:03_CDT_2017
Cuda compilation tools, release 9.0, V9.0.176
ubuntu@VM-0-13-ubuntu:~$
安装NVIDIA驱动
在这里选择适合自己的驱动https://www.nvidia.com/Download/Find.aspx,注意CUDA版本要和上面安装的一致(比如这里使用是9.0
版本)
sudo dpkg -i nvidia-diag-driver-local-repo-ubuntu1604-384.145_1.0-1_amd64.deb
已经包含cuda-command-line-tools
不需要再使用正面命令进行安装了
sudo apt-get install cuda-command-line-tools
sudo apt-get update
sudo reboot
重启之后查看安装结果
ubuntu@VM-0-13-ubuntu:~$ nvidia-smi
Tue Sep 11 15:58:11 2018
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 396.37 Driver Version: 396.37 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 Tesla P40 On | 00000000:00:06.0 Off | 0 |
| N/A 22C P8 9W / 250W | 0MiB / 22919MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
ubuntu@VM-0-13-ubuntu:~$ ls
本节来自:https://docs.nvidia.com/cuda/cuda-installation-guide-linux/
安装cuDNN
下载地址:https://developer.nvidia.com/cudnn
cuDNN需要安装三个deb包分别是Runtime Library
和Developer Library
以及Code Samples
。
-rw-rw-r-- 1 ubuntu ubuntu 122730426 Jul 31 20:34 libcudnn7_7.2.1.38-1+cuda9.0_amd64.deb
-rw-rw-r-- 1 ubuntu ubuntu 112867596 Jul 31 20:34 libcudnn7-dev_7.2.1.38-1+cuda9.0_amd64.deb
-rw-rw-r-- 1 ubuntu ubuntu 4909666 Jul 31 20:34 libcudnn7-doc_7.2.1.38-1+cuda9.0_amd64.deb
Navigate to your directory containing cuDNN Debian file.
Install the runtime library, for example:
sudo dpkg -i libcudnn7_7.2.1.38-1+cuda9.0_amd64.deb
Install the developer library, for example:
sudo dpkg -i libcudnn7-dev_7.2.1.38-1+cuda9.0_amd64.deb
Install the code samples and the cuDNN Library User Guide, for example:
sudo dpkg -i libcudnn7-doc_7.2.1.38-1+cuda9.0_amd64.deb
校验是否安装成功
To verify that cuDNN is installed and is running properly, compile the mnistCUDNN sample located in the /usr/src/cudnn_samples_v7 directory in the debian file.
- Copy the cuDNN sample to a writable path.
$cp -r /usr/src/cudnn_samples_v7/ $HOME
- Go to the writable path.
$ cd $HOME/cudnn_samples_v7/mnistCUDNN
- Compile the mnistCUDNN sample.
$ make clean && make
- Run the mnistCUDNN sample.
$ ./mnistCUDNN
If cuDNN is properly installed and running on your Linux system, you will see a message similar to the following:
Test passed!
本节来源:https://docs.nvidia.com/deeplearning/sdk/cudnn-install/