我的显卡是GTX1080,访问官网:http://www.geforce.cn/drivers 根据你自己的显卡型号,选择相应的显卡,进行下载勒,下载下来的是一个.run 的文件。
wget https://us.download.nvidia.com/XFree86/Linux-x86_64/418.56/NVIDIA-Linux-x86_64-418.56.run
yum -y install gcc* kernel-devel epel-release dkms
vim /etc/default/grub
在“GRUB_CMDLINE_LINUX”中添加
rd.driver.blacklist=nouveau nouveau.modeset=0
grub2-mkconfig -o /boot/grub2/grub.cfg
vim /etc/modprobe.d/blacklist.conf
添加
blacklist nouveau
mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r)-nouveau.img
dracut /boot/initramfs-$(uname -r).img $(uname -r)
reboot
lsmod | grep nouveau
# 注意:修改kernel 版本为你安装的版本
sh NVIDIA-Linux-x86_64-418.56.run --kernel-source-path=/usr/src/kernels/3.10.0-957.10.1.el7.x86_64
[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 |
+-----------------------------------------------------------------------------+
pip install tensorflow-gpu
我这里安装的是1.13.1 版本
根据安装的tensorflow 版本选择对应的Bazel, CUDA,cuDNN
参考官网: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
首先选择对应的版本:https://developer.nvidia.com/cuda-toolkit-archive
选择相关配置,获取下载链接(可在开发者工具中查看,或者直接在DownLoad 标签复制链接)
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
cuDNN下载需要登录,可以自行注册,查看官网(https://developer.nvidia.com/rdp/cudnn-archive),
获取对应文件,下载到本地,通过传输工具再传到Centos系统中。
然后解压,并放到指定路径:
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*
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
(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。