1. 准备工作
准备安装包
cuda_8.0.61_375.26_linux-run # 最新显卡驱动
http://cn.download.nvidia.com/XFree86/Linux-x86_64/384.66/NVIDIA-Linux-x86_64-384.66.run
NVIDIA-Linux-x86_64-384.66.run # 最新CUDA安装包
https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run
cuda_8.0.61_375.26_linux-run # CUDA补丁包
https://developer.nvidia.com/compute/cuda/8.0/Prod2/patches/2/cuda_8.0.61.2_linux-run
cudnn-8.0-linux-x64-v6.0.tgz # cudnn库v6.0
https://developer.nvidia.com/compute/machine-learning/cudnn/secure/v6/prod/8.0_20170307/cudnn-8.0-linux-x64-v6.0-tgz
2. 安装基础环境
检查显卡
# lspci | grep -i vga 04:00.0 VGA compatible controller: NVIDIA Corporation Device 1b00 (rev a1)
更新系统包
# yum install update -y && reboot
检查系统版本,确保系统支持(需要Linux-64bit系统)
# uname -m && cat /etc/*release x86_64 CentOS Linux release 7.4.1708 (Core)
安装GCC
# yum install gcc gcc-c++
安装Kernel Headers Packages
# yum install kernel-devel-$(uname -r) kernel-headers-$(uname -r)
3. 安装显卡驱动
# bash NVIDIA-Linux-x86_64-384.66.run (提示错误,请执行第四步)
4. 关闭Nouveau
1)把驱动加入黑名单中: /etc/modprobe.d/nvidia-installer-disable-nouveau.conf 在后面加入:
blacklist nouveau
options nouveau modeset=0
2) 使用 dracut重新建立 initramfs image file :* 备份 the initramfs file
# mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak
* 重新建立 the initramfs file
# sudo dracut -v /boot/initramfs-$(uname -r).img $(uname -r)
3) 重启系统至文本模式,init 3 这个可以修改/etc/inittab 文件 init 3是文本模式
4)检查nouveau driver确保没有被加载!
# lsmod | grep nouveau
# bash NVIDIA-Linux-x86_64-384.66.run
Accept
Building kernerl modules 安装
32bit兼容包选择, 这里要注意选择 No,不然后面就会出错
5. 安装CUDA
1)开始安装
# bash cuda_8.0.61_375.26_linux-run
# accept
-------------------------------------------------------------
Do you accept the previously read EULA?
accept/decline/quit: accept
# no
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 375.26?
(y)es/(n)o/(q)uit: n
-------------------------------------------------------------
# 后面的就都选yes或者default
Do you want to install the OpenGL libraries?
(y)es/(n)o/(q)uit [ default is yes ]:
Do you want to run nvidia-xconfig?
This will update the system X configuration file so that the NVIDIA X driver
is used. The pre-existing X configuration file will be backed up.
This option should not be used on systems that require a custom
X configuration, such as systems with multiple GPU vendors.
(y)es/(n)o/(q)uit [ default is no ]: y
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 /root ]:
Installing the NVIDIA display driver...
The driver installation has failed due to an unknown error. Please consult the driver installation log located at /var/log/nvidia-installer.log.
===========
= Summary =
===========
Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-8.0
Samples: Installed in /root, 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_192.log
2)安装CUDA补丁
# bash cuda_8.0.61.2_linux-run
# accept
3)验证安装结果
添加环境变量
在 ~/.bashrc的最后面添加下面两行
export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:/usr/local/cuda-8.0/extras/CUPTI/lib64:$LD_LIBRARY_PATH
使生效
# source ~/.bashrc
查看版本信息
# nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Tue_Jan_10_13:22:03_CST_2017
Cuda compilation tools, release 8.0, V8.0.61
# nvidia-smi
Tue Nov 28 03:05:40 2017
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 384.66 Driver Version: 384.66 |
|-------------------------------+----------------------+----------------------+
| 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 Off | 00000000:85:00.0 Off | 0 |
| N/A 37C P0 50W / 250W | 0MiB / 22912MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
6. 安装 cuDNN 库
# tar -xvzf cudnn-8.0-linux-x64-v6.0.tgz
# cp -P cuda/include/cudnn.h /usr/local/cuda-8.0/include
# cp -P cuda/lib64/libcudnn* /usr/local/cuda-8.0/lib64
# chmod a+r /usr/local/cuda-8.0/include/cudnn.h /usr/local/cuda-8.0/lib64/libcudnn*