您的位置:首页 > 其它

Ubuntu16.04下同时安装CUDA8.0和CUDA7.0

2017-11-25 16:44 337 查看
首先可以说明一点的是,在ubuntu16.04环境下CUDA8.0和CUDA7.0可以共存。笔者自己先安装的是CUDA8.0,然后再安装的CUDA7.0,安装完CUDA8.0发现安装CUDA7.0一直不成功,后面发现是16.04系统默认版本的GCC、g++版本过高,因此后面又装了gcc-4.8,g++-4.8,即安装了多版本的gcc和g++。

1.安装cuda-8.0

sudo dpkg -i cuda-repo-ubuntu1404-8-0-local-ga2_8.0.61-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda


2.配置环境变量

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64"
export CUDA_HOME=/usr/local/cuda
export PATH="$CUDA_HOME/bin:$PATH"


3.安装cuda-8.0对应的cudnn v5.1

tar xvzf cudnn-8.0-linux-x64-v5.1.tgz
mv cuda cudnn-8.0-v5.1
sudo cp cudnn-8.0-v5.1/include/cudnn.h /usr/local/cuda-8.0/include
sudo cp cudnn-8.0-v5.1/lib64/libcudnn* /usr/local/cuda-8.0/lib64


到此cuda-8.0及其对应的cudnn就安装结束了。

4.安装多版本CUDA

我先安装的是CUDA8.0 后面再安装CUDA7.0

由于当前系统的GCC G++都是5.4.0 对于安装Cuda7.0来说版本太高,因此需要安装低版本的GCC G++ 4.8

原本 /usr/bin目录下

gcc软连接到系统默认的GCC-5.4.0

gcc -> gcc-5

g++链接到系统默认的g++-5.4.0

g++ -> g++-5

首先安装 gcc-4.8 g++-4.8

sudo apt-get install -y gcc-4.8
sudo apt-get install -y g++-4.8
#现在需要把软连接到GCC-4.8 g++-4.8
sudo rm gcc
sudo rm g++
sudo ln -s gcc-4.8 gcc
sudo ln -s g++-4.8 g++


接着安装cuda-7.0和对应的cudnn

./cuda_7.0.28_linux.run
# 给cuda7.0安装对应的cudnn cudnn-7.0-v4.0
tar xvzf cudnn-7.0-linux-x64-v4.0-prod.tgz
mv cuda cudnn-7.0-v4.0
sudo cp cudnn-7.0-v4.0/include/cudnn.h   /usr/local/cuda-7.0/include/
sudo cp cudnn-7.0-v4.0/lib64/libcudnn*  /usr/local/cuda-7.0/lib64/


安装过程中注意事项:

Do you accept the previously read EULA? (accept/decline/quit): accept

You are attempting to install on an unsupported configuration. Do you wish to continue? ((y)es/(n)o) [ default is no ]: y

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 346.46? ((y)es/(n)o/(q)uit): n

Do you want to install the OpenGL libraries? ((y)es/(n)o/(q)uit) [ default is yes ]: n

Install the CUDA 7.0 Toolkit? ((y)es/(n)o/(q)uit): y

Enter Toolkit Location [ default is /usr/local/cuda-7.0 ]:

/usr/local/cuda-7.0 is not writable.

Do you wish to run the installation with ‘sudo’? ((y)es/(n)o): y

Please enter your password:

Do you want to install a symbolic link at /usr/local/cuda? ((y)es/(n)o/(q)uit): n

Install the CUDA 7.0 Samples? ((y)es/(n)o/(q)uit): y

Enter CUDA Samples Location [ default is /home/wty ]:

Installing the CUDA Toolkit in /usr/local/cuda-7.0 …

Installing the CUDA Samples in /home/wty …

Copying samples to /home/wty/NVIDIA_CUDA-7.0_Samples now…

Finished copying samples.

You should pay attention carefully to the prompts offered you during install.

1. Select no when prompted to install the driver from the CUDA 7.5 runfile installer. Keep your CUDA 8 installed driver. It will work with CUDA 7.5

2. Select no when prompted to update the symlink for /usr/local/cuda (unless you want to switch the default config from CUDA 8 to CUDA 7.5)

When you want to actually switch your machine behavior from CUDA 8 to CUDA 7.0, you will need to modify the PATH and LD_LIBRARY_PATH env variables accordingly.

If you previous CUDA 8 install was via runfile installer, this should work fine. I use this method regularly. If you previous CUDA 8 install was via package manager method, I think this should still work but I don’t typically do that.

it’s probably also possible to do side-by-side install using only package manager methods, but I don’t have a set of instructions handy for that.

cudnn链接:

https://developer.nvidia.com/rdp/cudnn-archive
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: