1. Installation preparation
1. Check the nvidia graphics card, mine is a T4 graphics card
lspci | grep -i nvidia
2. View the linux system version
uname -m && cat /etc/redhat-release
3. Installation dependencies
yum install gcc kernel-devel kernel-headers
2. Install the nvidia driver
1. Disable nouveau
lsmod | grep nouveau
If there is output, then nouveau is enabled and needs to be turned off, follow the steps below. Disable method in centos7:
#打开如下文件
sudo vim /usr/lib/modprobe.d/dist-blacklist.conf
#写入以下内容
blacklist nouveau
options nouveau modeset=0
#保存并退出
:wq
#重启
sudo reboot
#最后输入上面的命令验证
lsmod | grep nouveau
No output, nouveau disabled
2. Install the driver
Step 1: Open the NVIDIA driver download link http://www.nvidia.com/Download/Find.aspx
Step 2: Choose the driver that suits you, including product series, operating system, language, etc.
I will install it here is version 11.2
rpm -i nvidia-driver-local-repo-rhel7-460.106.00-1.0-1.x86_64.rpm
yum clean all
yum install cuda-drivers
reboot
3. Check whether the driver is installed successfully
nvidia-smi
3. Install cuda
1. Enter the address in the browser: https://developer.nvidia.com/cuda-toolkit-archive,
click Download Latest CUDA Toolkit, jump to this page, and select according to the system version
wget https://developer.download.nvidia.com/compute/cuda/11.2.0/local_installers/cuda_11.2.0_460.27.04_linux.run
chmod +x cuda_11.2.0_460.27.04_linux.run
./cuda_11.2.0_460.27.04_linux.run
Press Enter to cancel Diver
2. Configure environment variables
vim ~/.bashrc
写入:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.2/lib64
export PATH=$PATH:/usr/local/cuda-11.2/bin
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda-11.2
source vim ~/.bashrc
3. Verify that cuda takes effect:
nvcc -V
Fourth, install cudnn
1. Download address: https://developer.nvidia.com/rdp/cudnn-download
2. Unzip cudnn
tar -xvf cudnn-linux-x86_64-8.7.0.84_cuda11-archive.tar.xz
cd cudnn-linux-x86_64-8.7.0.84_cuda11-archive
sudo cp include/cudnn*.h /usr/local/cuda-11.2/include/
sudo cp lib/libcudnn* /usr/local/cuda-11.2/lib64/
sudo chmod a+r /usr/local/cuda-11.2/include/cudnn.h
sudo chmod a+r /usr/local/cuda-11.2/lib64/libcudnn*
2. Check the installation of cudnn
cat /usr/local/cuda-11.2/include/cudnn_version.h | grep CUDNN_MAJOR -a
Five, install anaconda
1. Download the anaconda installation package at https://repo.anaconda.com/archive/.
Select python3.88 version
2, install anaconda
sh Anaconda3-2021.05-Linux-x86_64.sh
3. Configure environment variables
vim ~/.bashrc
# 配置anaconda
export PATH=/root/anaconda3/bin:$PATH
source ~/.bashrc
4. Check conda
conda -V
6. Configure pip source
1. Create a .pip folder in the root directory
mkdir ~/.pip
2. Use vim to open the pip.conf configuration file
vim ~/.pip/pip.conf
3. pip source configuration file
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
7. Install tensorflow
1. Install tensorflow
pip install tensorflow==2.5.0
2. Enter python to enter the development
Method 1:
import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
Method Two:
import tensorflow as tf
a = tf.test.is_built_with_cuda() # 判断CUDA是否可以用
b = tf.test.is_gpu_available(
cuda_only=False,
min_cuda_compute_capability=None
) # 判断GPU是否可以用
print(a)
print(b)