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

在Ubuntu16.04中,CUDA8.0和CUDA7.0可以共存。安装CUDA7.0时因系统默认GCC、g++版本过高需降级至4.8。详细步骤包括安装CUDA8.0及cudnn v5.1,然后安装GCC-4.8和g++-4.8,接着安装CUDA7.0,注意安装过程中拒绝驱动和OpenGL库安装,并适当调整环境变量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先可以说明一点的是,在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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值