Centos7 安装配置tensorflow-gpu环境

1. 安装显卡驱动

我的显卡是GTX1080,访问官网:http://www.geforce.cn/drivers 根据你自己的显卡型号,选择相应的显卡,进行下载勒,下载下来的是一个.run 的文件。

Centos7 安装配置tensorflow-gpu环境_第1张图片

wget https://us.download.nvidia.com/XFree86/Linux-x86_64/418.56/NVIDIA-Linux-x86_64-418.56.run
  1. 安装编译环境:
yum -y install gcc* kernel-devel epel-release dkms
  1. 编辑grub文件,
vim /etc/default/grub

在“GRUB_CMDLINE_LINUX”中添加

rd.driver.blacklist=nouveau nouveau.modeset=0
  1. 生成配置
grub2-mkconfig -o /boot/grub2/grub.cfg
  1. 创建创建blacklist:
vim /etc/modprobe.d/blacklist.conf

添加

blacklist nouveau
  1. 更新配置:
mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r)-nouveau.img
dracut /boot/initramfs-$(uname -r).img $(uname -r)
  1. 重启
reboot
  1. 确认是否禁用了nouveau
lsmod | grep nouveau
  1. 安装显卡驱动:
# 注意:修改kernel 版本为你安装的版本
sh NVIDIA-Linux-x86_64-418.56.run --kernel-source-path=/usr/src/kernels/3.10.0-957.10.1.el7.x86_64
  1. 验证:
[root@t8t software]# nvidia-smi
Wed Apr 24 16:07:20 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 418.56       Driver Version: 418.56       CUDA Version: 10.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 1080    Off  | 00000000:01:00.0 Off |                  N/A |
| 23%   46C    P5    25W / 198W |      0MiB /  8119MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+


2. 安装tensorflow-gpu

pip install tensorflow-gpu

我这里安装的是1.13.1 版本

根据安装的tensorflow 版本选择对应的Bazel, CUDA,cuDNN

Centos7 安装配置tensorflow-gpu环境_第2张图片

3. 安装Bazel

参考官网:https://docs.bazel.build/versions/master/install-redhat.html#installing-menu

cd /etc/yum.repos.d/
wget https://copr.fedorainfracloud.org/coprs/vbatts/bazel/repo/epel-7/vbatts-bazel-epel-7.repo
yum install bazel

4. 安装CUDA

首先选择对应的版本:https://developer.nvidia.com/cuda-toolkit-archive

Centos7 安装配置tensorflow-gpu环境_第3张图片

选择相关配置,获取下载链接(可在开发者工具中查看,或者直接在DownLoad 标签复制链接)

Centos7 安装配置tensorflow-gpu环境_第4张图片

wget https://developer.nvidia.com/compute/cuda/10.0/Prod/local_installers/cuda-repo-rhel7-10-0-local-10.0.130-410.48-1.0-1.x86_64
sudo rpm -i cuda-repo-rhel7-10-0-local-10.0.130-410.48-1.0-1.x86_64.rpm
sudo yum clean all
sudo yum install cuda

5. 安装cuDNN

cuDNN下载需要登录,可以自行注册,查看官网(https://developer.nvidia.com/rdp/cudnn-archive),
获取对应文件,下载到本地,通过传输工具再传到Centos系统中。

Centos7 安装配置tensorflow-gpu环境_第5张图片

然后解压,并放到指定路径:

tar -xzvf cudnn-10.0-linux-x64-v7.4.2.24.tgz
cp cuda/include/cudnn.h /usr/local/cuda/include/
cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

6. 添加环境变量

vim /etc/profile

# 添加环境变量
export PATH=$PATH:/usr/local/anaconda3/bin:/usr/local/cuda/bin
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
export CUDA_HOME=/usr/local/cuda

7. 验证

(gpu) [root@t8t ~]# python
Python 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:22:34) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.test.is_built_with_cuda()
True

显示True则代表tensorflow已经成功使用了GPU。

你可能感兴趣的:(Centos7 安装配置tensorflow-gpu环境)