1.cuda11.0的配置
查看当前显卡驱动版本:nvidia-smi
可以看出当前cuda驱动最高支持cuda11.0,即不用更新显卡驱动,450.102.04足够了
wget http://developer.download.nvidia.com/compute/cuda/11.0.2/local_installers/cuda_11.0.2_450.51.05_linux.run --no-check-certificate
在当前目录,可以看到cuda_11.0.2_450.51.05_linux.run
sudo chmod 775 cuda_11.0.2_450.51.05_linux.run
sudo ./cuda_11.0.2_450.51.05_linux.run
2.cudnn8.1.1配置
https://developer.nvidia.com/compute/machine-learning/cudnn/secure/8.1.1.33/11.2_20210301/cudnn-11.2-linux-x64-v8.1.1.33.tgz
win10下载好了再拉到linux环境后缀改名为tgz,再解压
解压后文件名为cuda,
sudo cp cuda/include/cudnn.h /usr/local/cuda-11.0/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda-11.0/lib64/
sudo chmod a+r /usr/local/cuda-11.0/include/cudnn.h
sudo chmod a+r /usr/local/cuda-11.0/lib64/libcudnn*
设置环境变量(编辑文件.bashrc)
export PATH="/usr/local/cuda/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda/lib64:$LD_LIBRARY_PATH"
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda
创建cuda.sh脚本,用来快速更换cuda版本,只需更改以下所示的cuda版本安装文件夹名字即可
#! /bin/bash # employ bash shell
if [ -d "/usr/local/cuda" ];then
echo "cuda文件夹存在"
sudo rm -r /usr/local/cuda
else
echo "将重新建立软连接。"
fi
sudo ln -s /usr/local/cuda-11.0 /usr/local/cuda
echo "现将cuda更换为:"
nvcc -V
echo "现将cudnn更换为:"
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
sudo sh cuda.sh
nvcc --version
tensorflow-gpu==2.4.1配置
conda create -n tf2.4 python=3.7
conda activate tf2.4
pip install tensorflow-gpu==2.4.1
print(tf.__version__)
print( tf.test.is_gpu_available())