在安装之前,建议先浏览一下官方的安装文档,以下的安装步骤也是这样来的。(https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html)
一、CUDA 9.0安装
安装前检查:
1. Verify You Have a CUDA-Capable GPU
$ lspci | grep -i nvidia
2.Verify You Have a Supported Version of Linux
$ uname -m && cat /etc/*release
You should see output similar to the following, modified for your particular system:
x86_64
Red Hat Enterprise Linux Workstation release 6.0 (Santiago)
The x86_64 line indicates you are running on a 64-bit system.
3. Verify the System Has gcc Installed
$ gcc --version
If an error message displays, you need to install the development tools from your Linux distribution or obtain a version of gcc and its accompanying toolchain from the Web.
参考另一篇博客,可以使用如下命令进行安装:
sudo apt-get install build-essential
4. Verify the System has the Correct Kernel Headers and Development Packages Installed
(1)查看系统版本:
$ uname -r
(2)在终端输入:
$ sudo apt-get install linux-headers-$(uname -r)
可以安装对应kernel版本的kernel header和package development
结果显示:
......
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 4 个软件包未被升级。
表示系统里已经有了,不用重复安装。
若以上各项验证检查均满足要求,便可进行下面的正式安装过程。如果没有满足要求的话,可以参考cuda的官方文档,里面有详细的针对每个问题的解决方案。
开始安装:
这里选择runfile安装,首先从官网下载对应版本的runfile文件,这里下载的是cuda 9.0版本。
下载完后,用MD5 检验,如果序号不和,需要重新下载。
$ md5sum cuda_9.0.176_linux.run
1.禁用nouveau驱动
(1)在如下目录创建文件
/etc/modprobe.d/blacklist-nouveau.conf
文件中的内容为:
blacklist nouveau
options nouveau modeset=0
(2)执行如下命令:
$ sudo update-initramfs -u
2.重启电脑,进入登录界面的时候,不要登录进入桌面(否则可能会失败,若不小心进入,请重启电脑),直接按Ctrl+Alt+F1进入文本模式(命令行界面),登录账户。
3.输入 $ sudo service lightdm stop 关闭图形化界面
4.切换到cuda安装文件的路径,并执行如下命令:
$ sudo sh cuda_9.0.176_linux.run
5.然后就进入安装过程,开始都是End User License Agreement,你可以CTRL +C 跳过,然后accept,下面就是安装的交互界面,开始的Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 367.48?选择n,因为你已经安装驱动了。
Using more to view the EULA.
End User License Agreement
--------------------------
Preface
-------
The following contains specific license terms and conditions
for four separate NVIDIA products. By accepting this
agreement, you agree to comply with all the terms and
conditions applicable to the specific product(s) included
herein.
NVIDIA CUDA Toolkit
Description
The NVIDIA CUDA Toolkit provides command-line and graphical
tools for building, debugging and optimizing the performance
of applications accelerated by NVIDIA GPUs, runtime and math
libraries, and documentation including programming guides,
user manuals, and API references. The NVIDIA CUDA Toolkit
License Agreement is available in Chapter 1.
Default Install Location of CUDA Toolkit
Windows platform:
Do you accept the previously read EULA?
accept/decline/quit: accept
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 367.48?
(y)es/(n)o/(q)uit: n
Install the CUDA 8.0 Toolkit?
(y)es/(n)o/(q)uit: y
Enter Toolkit Location
[ default is /usr/local/cuda-8.0 ]:
Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y
Install the CUDA 8.0 Samples?
(y)es/(n)o/(q)uit: y
Enter CUDA Samples Location
[ default is /home/kinny ]:
Installing the CUDA Toolkit in /usr/local/cuda-8.0 ...
Missing recommended library: libXmu.so
Installing the CUDA Samples in /home/kinny ...
Copying samples to /home/kinny/NVIDIA_CUDA-8.0_Samples now...
Finished copying samples.
===========
= Summary =
===========
Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-8.0
Samples: Installed in /home/kinny, but missing recommended libraries
Please make sure that
- PATH includes /usr/local/cuda-8.0/bin
- LD_LIBRARY_PATH includes /usr/local/cuda-8.0/lib64, or, add /usr/local/cuda-8.0/lib64 to /etc/ld.so.conf and run ldconfig as root
To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-8.0/bin
Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-8.0/doc/pdf for detailed information on setting up CUDA.
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 361.00 is required for CUDA 8.0 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
sudo <CudaInstaller>.run -silent -driver
Logfile is /tmp/cuda_install_17494.log
6.配置cuda环境变量
export PATH="$PATH:/usr/local/cuda-8.0/bin"
export LD_LIBRARY_PATH="/usr/local/cuda-8.0/lib64"
nvidia-smi
结果出现以下输出,说明配置成功
二、安装 cuDNN v7.0.5 (Dec 5, 2017), for CUDA 9.0
1、进入cudnn下载页面,找到cuda 9.0对应的cudnn版本,有不同的版本可以选择,这里用的是 cuDNN v7.0.5。(https://developer.nvidia.com/rdp/cudnn-archive)
2、选择安装方式,有两种方式可以选择,一个是Tar文件安装,一个是Debian文件安装。
这里建议选择Tar文件方式进行安装。我最开始用Debian方式安装,结果安装失败,后面改用Tar文件安装,安装成功。
首先,下载Tar文件文件,选择如下选项下载:
然后,将下载下来的tar文件进行解压:
$ tar -xzvf cudnn-9.0-linux-x64-v7.tgz
接下来,在命令终端执行如下操作:
$ sudo cp cuda/include/cudnn.h /usr/local/cuda/include
$ sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
$ sudo chmod a+r /usr/local/cuda/include/cudnn.h
/usr/local/cuda/lib64/libcudnn*
安装结束。
参考:
1、https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html
2、https://developer.download.nvidia.com/compute/machine-learning/cudnn/secure/v7.0.5/prod/Doc/cuDNN-Installation-Guide.pdf?F3g1KdjFNYdiLJij-scgwW_WEl1bB36K3_6RXs4hVMIBuA4fONuQXiUhm8KYaiHCJ4ZOuqAVZ5tB6D8VKSnR2qLmwtp7LmB9_I5flrHeLNwmN8OV6pqrkuroZXrVIk6DTPHSbNzJd1NZpcmGUExpit-iIy4qPy4o3QhNf-_DuGX7RGPJHN2P53yFYb53WN6mCw
3、https://blog.csdn.net/qlulibin/article/details/78714596
4、https://www.cnblogs.com/xia-Autumn/p/6228911.html