英伟达驱动安装

整体系统信息如下:
操作系统:Centos7.X
显卡:两块GeForce RTX 2080Ti
一、安装准备
1、机器上必须有支持CUDA的Nvidia GPU,查看支持CUDA的GPU列表 查看自己的机器的GPU

lspci | grep -i nvidia

我这边服务器使用的是两块GeForce RTX 2080Ti
2、验证系统是否是受支持的Linux版本

uname -m && cat /etc/redhat-release

服务器的输出为:

Centos 7 安装development tools centos 7 安装显卡驱动_CUDA


到这里可以查看受支持的Linux版本:https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#system-requirements 3、验证系统是否有GCC编译环境

gcc -v

如果没有任何输出,需要安装gcc,安装很简单

yum install gcc

服务器输出:

Centos 7 安装development tools centos 7 安装显卡驱动_服务器_02


gcc版本必须为4.8.5才行

4、验证系统是否安装了正确的内核头文件和开发包

sudo yum install kernel-devel-Centos 7 安装development tools centos 7 安装显卡驱动_CUDA_03(uname -r)

二、开始安装

1、禁用nouveau
nouveau是一个第三方开元的Nvidia驱动,一般Linux系统安装的时候都会默认安装这个驱动。这个驱动会与nvidia官方的驱动冲突,在安装nvidia驱动和cuda之前应该先禁用nouveau
查看系统是否正在使用nouveau

lsmod | grep nouveau

如果有任何输出,那么就是nouveau在启用,需要关闭,按照以下步骤:centos7中禁用方法:

#打开如下文件
sudo vim /usr/lib/modprobe.d/dist-blacklist.conf
#写入以下内容
blacklist nouveau
options nouveau modeset=0
#保存并退出
:wq
#备份当前的镜像
sudo mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak
#建立新的镜像
sudo dracut /boot/initramfs-$(uname -r).img $(uname -r)
#重启
sudo reboot
#最后输入上面的命令验证
lsmod | grep nouveau

直到没有任何输出,说明nouveau禁用了

2、安装驱动

GPU服务器需要正常工作需要安装正确的基础设施软件,对NVIDIA系列GPU而言,有两个层次的软件包需要安装:

(1)驱动GPU工作的硬件驱动程序。

(2)上层应用程序所需要的库

若把NVIDIA GPU用作通用计算,需要安装GeForce Driver + CUDA(这里英伟达对每一个系列的GPU均有不同的驱动(Driver),GeForce和TITAN及Tesla均不同,需要去官网下载)

以下分为两步完成

第一步:打开NVIDIA驱动下载链接http://www.nvidia.com/Download/Find.aspx 第二步:选择适合自己的驱动,包括产品系列、操作系统、语言等

Centos 7 安装development tools centos 7 安装显卡驱动_深度学习_04


点击SEARCH

Centos 7 安装development tools centos 7 安装显卡驱动_tensorflow_05


点击下载,下载完成为.run后缀的文件,上传到服务器上,修改权限就可以跑了:

chmod +x NVIDIA-Linux-x86_64-440.64.run
./NVIDIA-Linux-x86_64-440.64.run

安装过程有一些选项,基本上有默认的选默认的,有些查一下看看意思选,里面有四个选择需要去做
(1)he distribution-provided pre-install script failed!Are you sure you want to continue?
不用管,继续
(2)Would you like to register the kernel module sources with DKMS?This will allow DKMS to auomatically build a new module,if you install a different kernel later
选择“no”
(3)Install Nvidia’s 32-bit compatibility libraries? 选择 No 继续
(4)Would you like to run the nvidia-xconfig utility to automatically update your X configuration file so that the NVIDIA X driver will be user whten you rest…”什么的,选择 No。
注意:到这里安装成就成功了,否则就是失败了,如果安装过程中出现任何错误,需要去看安装日志:
这里极其容易出错,安装不好后面就比较麻烦

cat /var/log/nvidia-install.log

有任何问题去Google,然后重新运行安装程序即可。
我这里安装的时候暂时没有什么问题,不做记录。

如果没有问题,输入nvidia-smi

nvidia-smi

输出以下内容:

Centos 7 安装development tools centos 7 安装显卡驱动_CUDA_06


说明NVIDIA驱动安装成功

3、记录问题:

如果遇到以下问题,说明没有装,或者装的有问题

NVIDIA-SMI has failed because it couldn’t communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running

需要重新安装即可。

CUDA和CuDNN安装

一、部署环境及相应软件及版本号

cat /etc/*release

看到如下界面:

Centos 7 安装development tools centos 7 安装显卡驱动_tensorflow_07

uname -r uname -a

可以输出系统的内核版本号

Centos 7 安装development tools centos 7 安装显卡驱动_神经网络_08


2、检查电脑是否配置NVIDIA先看

/usr/sbin/lspci | grep -i nvidia

3、检查是否安装正确了GCC版本
gcc --version

这里有对应表,对应CUDA和Linux驱动之间的关系,对应上了才可以安装

Centos 7 安装development tools centos 7 安装显卡驱动_tensorflow_09


二、安装CUDA和cuDNN

(1)从Google的tensorflow官方网站查看版本

Centos 7 安装development tools centos 7 安装显卡驱动_服务器_10


注意:版本一定要对应上,否则后患无穷,这里一定对应好

我的选择:tensorflow-gpu1.12.0,python3.6.8,cuDNN(cudnn-9.0-linux-x64-v7.tgz)、CUDA(cuda-repo-rhel7-9-0-local-9.0.176-1.x86_64.rpm)这几个即可。

CUDA下载页面:https://developer.nvidia.com/cuda-toolkit-archive cuDNN下载页面:https://developer.nvidia.com/rdp/cudnn-archive,cuDNN下载需要注册账号,否则不能下载

选择合适的版本进行下载即可。

CUDA文件较大,选择本地安装RPM包,可以避免很多的问题出现。

Centos 7 安装development tools centos 7 安装显卡驱动_CUDA_11


注意:下面的安装,是由于系统是rhel7.0,错误的认为是centos7导致未安装需要单独下载,一般对应版本是不需要在额外下载RPM包

cuda-repo-rhel7-9-0-local-9.0.176-1.x86_64.rpm #centos7,由于centos是基于rhel7的开源发型版本,所以名字是rhel7

将以上软件发送到服务器上。

(2)cuda和cudnn安装

按照官网的方法安装即可

Centos 7 安装development tools centos 7 安装显卡驱动_深度学习_12


安装过程不需要进行任何选择,默认安装完毕即可

(3)安装过程错误处理

会报错两个:dkms和libvdpau没有

http://rpmfind.net/linux/rpm2html/search.php?query=dkms

在此页面搜索dkms-2.6.1-1.el7.noarch.rpm,下载即可

http://www.rpmfind.net/linux/rpm2html/search.php?query=libvdpau(x86-64)

在此页面下载libvdpau-1.1.1-3.el7.x86_64.rpm

Centos 7 安装development tools centos 7 安装显卡驱动_服务器_13


–> Finished Dependency Resolution

Error: Package: 1:nvidia-kmod-384.81-2.el7.x86_64 (cuda-9-0-local)

Requires: dkms

You could try using --skip-broken to work around the problem

You could try running: rpm -Va --nofiles --nodigest

[root@lab-250 ~]# rpm -ivh dkms-2.6.1-1.el7.noarch.rpm

warning: dkms-2.6.1-1.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY

error: Failed dependencies:

elfutils-libelf-devel is needed by dkms-2.6.1-1.el7.noarch

[root@lab-250 ~]#

[root@lab-250 ~]# yum install -y elfutils-libelf-devel

Resolving Dependencies

–> Running transaction check

—> Package elfutils-libelf-devel.x86_64 0:0.158-3.el7 will be installed

–> Finished Dependency Resolution

Dependencies Resolved

然后安装即可
(4)设置环境变量

#默认安装位置
/usr/local/cuda-9.0
vim /etc/profile
#在文件末尾添加如下内容:
export PATH=/usr/local/cuda-9.0/bin:Centos 7 安装development tools centos 7 安装显卡驱动_tensorflow_14LD_LIBRARY_PATH

然后重启

source /etc/profile

即可
(5)cuDNN安装
只需要将压缩包解压,并把文件覆盖到CUDA对应的目录中去即可

$ tar -zxvf cudnn-9.0-linux-x64-v7.tgz
$ cd cuda
$ cp include/* /usr/local/cuda-9.0/inlcude/
$ cp lib64/lib* /usr/local/cuda-9.0/lib64/

至此NVIDIA GPU驱动以及CUDA和cuDNN安装完毕

安装miniconda3以及配置python虚拟环境

一、环境及版本

conda官网,下载自己所需的miniconda3版本,考虑到一些兼容性等问题,这里选择:Miniconda3-4.5.12-Linux-x86_64.sh

Centos 7 安装development tools centos 7 安装显卡驱动_CUDA_15


上传到服务器上

二、安装

直接运行

sh Miniconda3-4.5.12-Linux-x86_64.sh

注意:这里有选择安装目录,这里安装在/usr/local/miniconda3下面

Centos 7 安装development tools centos 7 安装显卡驱动_神经网络_16


miniconda3安装完毕

然后需要把conda命令加入环境变量里:

vim /etc/profile

在默认加上

export PATH=/usr/local/miniconda3/bin:$PATH

重启

source /etc/profile

其他人可以用了
三、安装python3.6.8虚拟环境及安装tensorflow-gpu1.12.0

conda create -n py36 python=3.6.8
conda activate py36
conda install tensorflow-gpu1.12.0

四、测试tensorflow-gpu是否可以正常调用NVIDIA GPU

conda activate py36
python

#进入python虚拟环境里面
#输入以下内容

import tensorflow as tf
hello = tf.constant("Hello, TensorFlow")
sess = tf.Session()
sess.run(hello)
#或者输入以下内容也可以:
#from tensorflow.python.client import device_lib
#print(device_lib.list_local_devices())

输出以下内容,表明GPU调用成功

Centos 7 安装development tools centos 7 安装显卡驱动_CUDA_17


可以看到在sess = tf.Session()下面会输出服务器带有的两个NVIDIA GPU(GeForce RTX 2080Ti)。