【NVIDIA】Ubuntu18.04安装CUDA-9.0 (已安装CUDA-10.0, CUDNN-7.3.0)

廉价感情. 提交于 2019-11-29 08:19:24

GCC, G++版本降级:

    由于CUDA 9.0仅支持GCC 6.0及以下版本,而Ubuntu 18.04预装GCC版本为7.3,故手动安装gcc-5与g++-5:

sudo apt-get install gcc-5
sudo apt-get install g++-5

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 50
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 50


gcc -v
--------------------------------------------------
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.5.0-12ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.5.0 20171010 (Ubuntu 5.5.0-12ubuntu1)

一. CUDA-9.0下载

    下载链接:CUDA Toolkit Archive

      CUDA Toolkit 9.0 Downloads

    下载cuda_9.0.176_384.81_linux.run及四个Patch.

二. CUDA-9.0安装

cd CUDA-9.0
sudo sh cuda_9.0.176_384.81_linux.run    # 开始安装



Logging to /tmp/cuda_install_20700.log
Using more to view the EULA.
End User License Agreement
--------------------------


Preface
-------

1. NVIDIA Software License Agreement
------------------------------------


Release Date: October 20, 2016
------------------------------


IMPORTANT NOTICE -- READ BEFORE DOWNLOADING, INSTALLING,
COPYING OR USING THE LICENSED SOFTWARE:
--------------------------------------------------------

# 按 "q"键退出协议说明 #

----------------------------------------------------------------------------------
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 384.81?
(y)es/(n)o/(q)uit: n    # 由于已经安装显卡驱动,选择n

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

Enter Toolkit Location
 [ default is /usr/local/cuda-9.0 ]:    # 工具包安装地址,默认回车即可

Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: n    # 添加链接**注意这个连接,因为安装过另一个版本的cuda10.0,除非你确定想要用这个新版本的cuda,否则这里就建议选no,因为指定该链接后会将cuda指向这个新的版本**

Install the CUDA 9.0 Samples?
(y)es/(n)o/(q)uit: y    # 安装样例

Enter CUDA Samples Location
 [ default is /home/zzw ]: /data0/zzw/CUDA-9.0    # 样例安装地址

Installing the CUDA Toolkit in /usr/local/cuda-9.0 ...
Installing the CUDA Samples in /data0/zzw/CUDA-9.0 ...
Copying samples to /data0/zzw/CUDA-9.0/NVIDIA_CUDA-9.0_Samples now...
Finished copying samples.

===========
= Summary =
===========

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-9.0
Samples:  Installed in /data0/zzw/CUDA-9.0

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_20700.log

# ***安装完成***

1. 配置CUDA-9.0的环境变量:

sudo vim ~/.bashrc

export PATH=/usr/local/cuda-9.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH

source ~/.bashrc

2. 使用命令nvcc -V测试是否安装成功:

nvcc -V

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:01_CDT_2018
Cuda compilation tools, release 10.0, V10.0.130


# -----------------------------------------------
Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: n    # 因为选择了n

3. 编译 CUDA Samples

cd CUDA-9.0/NVIDIA_CUDA-9.0_Samples

make

------------------------------------------------------------
cp conjugateGradientUM ../../bin/x86_64/linux/release
make[1]: Leaving directory '/data0/zzw/CUDA-9.0/NVIDIA_CUDA-9.0_Samples/7_CUDALibraries/conjugateGradientUM'
Finished building CUDA samples

    如果没有报错,则安装完成.

4. 安装下载的四个Patch

cd CUDA-9.0

sudo sh cuda_9.0.176.1_linux.run
sudo sh cuda_9.0.176.2_linux.run
sudo sh cuda_9.0.176.3_linux.run
sudo sh cuda_9.0.176.4_linux.run


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

Enter CUDA Toolkit installation directory
 [ default is /usr/local/cuda-9.0 ]: 

Installation complete!
Installation directory: /usr/local/cuda-9.0

二. CUDNN7.4.2安装

    下载链接:cuDNN Archive

tar -zxf cudnn-9.0-linux-x64-v7.4.2.24.tgz

sudo cp lib64/libcudnn.*    /usr/local/cuda-9.0/lib64/    
sudo cp include/cudnn.h     /usr/local/cuda-9.0/include/

# 添加权限
sudo chmod a+r /usr/local/cuda-9.0/include/cudnn.h /usr/local/cuda-9.0/lib64/libcudnn*

三. 使用新的CUDA-9.0

cd usr/local

sudo rm -rf cuda
sudo ls -n cuda-9.0 cuda

参考链接:使用TensorFlow-GUP并在Ubuntu上安装CUDA cuDNN

     Ubuntu18.04深度学习环境配置

     Ubuntu18.04+Cuda9.0+Cudnn7.1环境配置Tensorflow-gpu

     Cuda + cudnn 在Ubuntu18.04上的手动安装

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!