为了学习CenterNet,配置环境弄了半天。。由于我是主用tensorflow的,pytorch搞不来,只能按他的步骤来。他的环境比较老,是cuda 9.0 cudnn 7.1的,然而我早就在用cuda 10.1 cudnn 7.5了,所以我还得安装这个版本的cuda

下面我就说下安装多个版本的cuda的注意点。

安装cuda 9.0

下载好了之后执行(因为我是18.04 所以要加override避免gcc版本不匹配的无法安装问题):

sudo sh cuda_9.0.176_384.81_linux.run --override

记得安装过程中下面两点要选no

  1. Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 375.26?

  2. Do you want to install a symbolic link at /usr/local/cuda?

安装cudnn

下载好了之后:

tar -xvf cudnn-9.0-linux-x64-v7.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda-9.0/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda-9.0/lib64/
sudo chmod a+r /usr/local/cuda-9.0/include/cudnn.h
sudo chmod a+r /usr/local/cuda-9.0/lib64/libcudnn*

修改环境变量

改为如下:

export CUDA_HOME=/usr/local/cuda
export PATH=$PATH:$CUDA_HOME/bin
export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

设置版本切换器:

sudo update-alternatives --install /usr/local/cuda cuda /usr/local/cuda-9.0 40
sudo update-alternatives --install /usr/local/cuda cuda /usr/local/cuda-10.0 50

然后输入sudo update-alternatives --config cuda即可选择版本:

There are 2 choices for the alternative cuda (providing /usr/local/cuda).

Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/local/cuda-10.0 50 auto mode
1 /usr/local/cuda-10.0 50 manual mode
2 /usr/local/cuda-9.0 40 manual mode

Press <enter> to keep the current choice[*], or type selection number: