1. 软件查找与版本选择
1.1 tensorflow GPU 各软件版本对应表
https://www.tensorflow.org/install/source#gpu
1.2版本选择
查询ubuntu20.04目前支持的各软件的版本,然后选择响应的版本
1.2.1 信息收集
(1)cuda版本选择,搜索可用的cuda版本
apt-cache madison nvidia-cuda-toolkit
#这里我的结果为10.1版本,第二步找合适cuDNN7.6版本
#nvidia-cuda-toolkit | 10.1.243-3 | http://cn.archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages
(2)cuDNN版本选择,通过查询以下网站,查找cuda10.1(基于我的cuda版本)对应的cuDNN版本
http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/
http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu2004/x86_64/
#我使用cuDNN如下
#[libcudnn7-dev_7.6.5.32-1+cuda10.1_amd64.deb](https://developer.download.nvidia.cn/compute/machine-learning/repos/ubuntu1804/x86_64/libcudnn7-dev_7.6.5.32-1+cuda10.1_amd64.deb)
#[libcudnn7_7.6.5.32-1+cuda10.1_amd64.deb](https://developer.download.nvidia.cn/compute/machine-learning/repos/ubuntu1804/x86_64/libcudnn7_7.6.5.32-1+cuda10.1_amd64.deb)
我各软件版本选择如下,尽量最新
cuda 10.1; cuDNN 7.6; python 3.8; tensofrflow 2.3;
nvidia-driver-460-server
(3)python3.8 使用conda安装
(4)tensorflow2.3 使用conda安装
(5)nvidia-driver-460 使用ubuntu自带的驱动管理工具安装
2. 软件安装
2.1 安装NVIDIA显卡驱动
(1)图形化界面安装,选择>=450的版本
software-properties-gtk
(2)安装后,检测nvidia显卡驱动是否安装成功
nvidia-smi
**2.2 安装 cuda10.1(cudatoolki)
(1)安装cudatoolkit
sudo apt install nvidia-cuda-toolkit
#检查toolkit是否安装成功
function lib_installed() { /sbin/ldconfig -N -v $(sed 's/:/ /' <<< $LD_LIBRARY_PATH) 2>/dev/null | grep $1; }
function check() { lib_installed $1 && echo "$1 is installed" || echo "ERROR: $1 is NOT installed"; }
check libcuda
check libcudart
2.3 安装 cuDNN 7.6
- 下载安装
(1)下载cuda与安装
wget https://developer.download.nvidia.cn/compute/machine-learning/repos/ubuntu1804/x86_64/libcudnn7-dev_7.6.5.32-1+cuda10.1_amd64.deb
wget https://developer.download.nvidia.cn/compute/machine-learning/repos/ubuntu1804/x86_64/libcudnn7_7.6.5.32-1+cuda10.1_amd64.deb
sudo dpkg -i libcudnn7-dev_7.6.5.32-1+cuda10.1_amd64.deb libcudnn7_7.6.5.32-1+cuda10.1_amd64.deb
(2)检测是否安装成功
function lib_installed() { /sbin/ldconfig -N -v $(sed 's/:/ /' <<< $LD_LIBRARY_PATH) 2>/dev/null | grep $1; }
function check() { lib_installed $1 && echo "$1 is installed" || echo "ERROR: $1 is NOT installed"; }
check libcudnn
- 额外的安装
链接: https://pan.baidu.com/s/1Mb5EqVP585vDJuh6Ub3Uqg 提取码: p2kw 复制这段内容后打开百度网盘手机App,操作更方便哦
tar -xvzf cudnn-10.1-linux-x64-v7.6.5.32.tgz
sudo cp cuda/include/cudnn.h /usr/lib/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/lib/cuda/lib64/
sudo chmod a+r /usr/lib/cuda/include/cudnn.h /usr/lib/cuda/lib64/libcudnn*
sudo mkdir /usr/local/cuda
sudo mkdir /usr/local/cuda/include
sudo mkdir /usr/local/cuda/lib64
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
2.4 安装python3 tensorflow(pip3)
sudo apt install python3-pip
pip3 install tensorflow==2.3 -i https://pypi.tuna.tsinghua.edu.cn/simple
#测试tensorflow是否可以使用gpu,如果最后print的字符为true,则成功
python3
import tensorflow as tf
print(tf.test.is_gpu_available())
2.5 conda python3.8 tensorflow2.3 (cuda)
conda create -n py38 python=3.8
conda activate py38
conda install cudatoolkit=10.1 l cudnn=7.6 tensorflow=2.3
#测试tensorflow是否可以使用gpu,如果最后print的字符为true,则成功
python3
import tensorflow as tf
print(tf.test.is_gpu_available())
网友评论