cuda的安装
一、查询显示服务器cuda可驱动的GPU
yum install pciutils
lspci | grep -i nvidia
输出
[root@bhs ~]# lspci | grep -i nvidia
00:07.0 VGA compatible controller: NVIDIA Corporation Device 1bb3 (rev a1)
到如下链接地址确认产品型号
http://pci-ids.ucw.cz/mods/PC/10de?action=help?help=pci
选择适合自己服务器的驱动
二、确定LINUX系统版本是不是支持cuda
uname -m && cat /etc/*release
x86_64
CentOS Linux release 7.2.1511 (Core)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
CentOS Linux release 7.2.1511 (Core)
CentOS Linux release 7.2.1511 (Core)
[root@bhs ~]# more /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
Table 1. CUDA Toolkit and Compatible Driver Versions
三、 确定系统安装了GCC
gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
yum install gcc gcc-c++
四、确定系统有正确的内核头文件Kernel Headers和development packages
内核头文件经常在需要安装驱动,重新编译内核时用到,如果你的内核版本是3.10.0-514,那么3.10.0-514的kernel headers and development packages必须安装。
内核版本查看使用
uname -r
CentOS系统使用如下命令安装
sudo yum install kernel-devel-$(uname -r) kernel-headers-$(uname -r)
五、 Disable the Nouveau drivers
Nouveau是由第三方为NVIDIA显卡开发的一个开源3D驱动,也没能得到NVIDIA的认可与支持。
sudo vim /etc/modprobe.d/blacklist-nouveau.conf
# 1、添加下列两⾏
blacklist nouveau
options nouveau modeset=0
# 2、输⼊下⾯命令并进⾏重启
sudo dracut --force
sudo reboot #重启
lsmod | grep nouveau #若无结果显示则表明成功禁用
六、安装依赖
yum install libX*
七、NVIDIA驱动安装
./NVIDIA-Linux-x86_64-410.129-diagnostic.run
八、安装
根据操作系统选择下载相应的CUDA Toolkit版本(https://developer.nvidia.com/cuda-downloads),下载的是一个.run文件,下载完成后以root用户直接运行该文件安装
sudo sh cuda_10.0.130_410.48_linux.run
安装最后会提示确认相关信息
-----------------
Do you accept the previously read EULA?
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?
(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: y
Enter CUDA Samples Location
[ default is /root ]:
Installing the CUDA Toolkit in /usr/local/cuda-10.0 ...
Please make sure that
- PATH includes /usr/local/cuda-10.0/bin
- LD_LIBRARY_PATH includes /usr/local/cuda-10.0/lib64, or, add /usr/local/cuda-10.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-10.0/bin
Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-10.0/doc/pdf for detailed information o
n setting up CUDA.
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of ver
sion at least 384.00 is required for CUDA 10.0 functionality to work.To install the driver using this installer, run the following command, replacing <CudaInstaller> with t
he name of this run file: sudo <CudaInstaller>.run -silent -driver
Logfile is /tmp/cuda_install_2292.log
To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-10.0/bin
To uninstall the NVIDIA Driver, run nvidia-uninstall
九、配置环境
vi /etc/profile
可在⽂件末尾加入一下下配置:
export PATH=/usr/local/cuda-10.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64:$LD_LIBRARY_PATH
配置文件生效
source /etc/profile
验证是否安装完成,在终端输入:nvcc -V
[root@bhs ~]# nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:01_CDT_2018
Cuda compilation tools, release 10.0, V10.0.130
显示上面的结果即成功
十、cudnn安装
[root@bhs ~]# tar -xvf cudnn-10.0-linux-x64-v7.6.5.32.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.6.5
cuda/lib64/libcudnn_static.a
$ 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*
十一、TensorFlow-gpu版本安装
pip install tensorflow-gpu==2.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
进行测试
import tensorflow as tf
con = tf.constant('hello world')
print(con)