注:幾個月前寫的,忘了發布了。
背景:已經安裝了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