ubuntu16.04安装cuda10.1、cudnn7.6、tensorflow2.2

(1)参考tensorflow官网给出的示例:https://www.tensorflow.org/install/gpu

# Add NVIDIA package repositories
# Add HTTPS support for apt-key
sudo apt-get install gnupg-curl
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_10.1.243-1_amd64.deb
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
sudo dpkg -i cuda-repo-ubuntu1604_10.1.243-1_amd64.deb
sudo apt-get update
wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64/nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb
sudo apt install ./nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb
sudo apt-get update

# Install NVIDIA driver
# Issue with driver install requires creating /usr/lib/nvidia
sudo mkdir /usr/lib/nvidia
sudo apt-get install --no-install-recommends nvidia-418
# Reboot. Check that GPUs are visible using the command: nvidia-smi

# Install development and runtime libraries (~4GB)
sudo apt-get install --no-install-recommends \
    cuda-10-1 \
    libcudnn7=7.6.4.38-1+cuda10.1  \
    libcudnn7-dev=7.6.4.38-1+cuda10.1


# Install TensorRT. Requires that libcudnn7 is installed above.
sudo apt-get install -y --no-install-recommends \
    libnvinfer6=6.0.1-1+cuda10.1 \
    libnvinfer-dev=6.0.1-1+cuda10.1 \
    libnvinfer-plugin6=6.0.1-1+cuda10.1

(2)配置环境变量

# 打开配置文件
vi ~/.bashrc
# 也可以使用
gedit ~/.bashrc

#导入下面语句
export PATH=/usr/local/cuda/bin:${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/extras/CUPTI/lib64

(3)请注意这一句

sudo apt-get install --no-install-recommends nvidia-418

(4)安装tensorflow2.2,集成了cpu和gpu版本,无需单独安装cpu或者gpu版本

pip install tensorflow

(5)运行python程序,测试tensorflow是否使用gpu,如果没有使用gpu,那么请注意我们之前安装的语句

sudo apt-get install --no-install-recommends nvidia-418

(6)查看运行python程序时,会报错 nvidia driver 418和450(我的是这个错误)不匹配

(7)这时我们只需要安装对应的那个高的版本就可以了

sudo apt-get install --no-install-recommends nvidia-450

(8)错误不尽相同,这里仅供参考

你可能感兴趣的:(Tensorflow)