Ubuntu18.04的CUDA10.0和CUDA9.0共存方法
注:几个月前写的,忘了发布了。
背景:已经安装了CUDA10.0,需要暂时使用CUDA9.0来调试某个代码库,但安装CUDA9.0失败。
提示:
Error: unsupported compiler: 7.5.0. Use --override to override this check.
===========
= Summary =
===========
Driver: Not Selected
Toolkit: Installation Failed. Using unsupported Compiler.
Samples: Not Selected
原因分析:
$ gcc --version
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
CUDA9.0不支持gcc7.x,查了一下发现支持gcc6.x,于是需要对gcc降级。
sudo apt install gcc-6
$ gcc --version
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
安装后发现还是7.5.0
查看已安装的gcc版本
$ ls /usr/bin/gcc*
/usr/bin/gcc /usr/bin/gcc-ar /usr/bin/gcc-nm /usr/bin/gcc-ranlib
/usr/bin/gcc-6 /usr/bin/gcc-ar-6 /usr/bin/gcc-nm-6 /usr/bin/gcc-ranlib-6
/usr/bin/gcc-7 /usr/bin/gcc-ar-7 /usr/bin/gcc-nm-7 /usr/bin/gcc-ranlib-7
发现确实有gcc-6,但还在运行7,于是给gcc-6设置更高的优先级
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 88
$ gcc --version
gcc (Ubuntu 6.5.0-2ubuntu1~18.04) 6.5.0 20181026
这时候已经可以安装CUDA9.0了。
如果想要切换回gcc-7,就执行
sudo update-alternatives --remove gcc /usr/bin/gcc-6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 88
最后还有点小问题,但似乎不影响使用
Installing the CUDA Toolkit in /usr/local/cuda-9.0 ...
===========
= Summary =
===========
Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-9.0
Samples: Not Selected
Please make sure that
- PATH includes /usr/local/cuda-9.0/bin
- LD_LIBRARY_PATH includes /usr/local/cuda-9.0/lib64, or, add /usr/local/cuda-9.0/lib64 to /etc/ld.so.conf and run ldconfig as root
To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-9.0/bin
Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-9.0/doc/pdf for detailed information on setting up CUDA.
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 384.00 is required for CUDA 9.0 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
sudo <CudaInstaller>.run -silent -driver
Logfile is /tmp/cuda_install_16377.log