Ubuntu18.04安装完应该做的一些事 显卡驱动安装和cuda8.0

  博主装Ubuntu18.04主要是为了用于跑深度学习,所以我们先来搞搞gcc环境

第一步:安装多版本gcc、g++可切换

sudo apt-get install gcc-4.8 gcc-4.8-multilib
sudo apt-get install g++-4.8 g++-4.8-multilib
sudo apt-get install gcc-5 gcc-5-multilib
sudo apt-get install g++-5 g++-5-multilib
sudo apt-get install gcc-6 gcc-6-multilib
sudo apt-get install g++-6 g++-6-multilib
sudo apt-get install gcc-7 gcc-7-multilib
sudo apt-get install g++-7 g++-7-multilib
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 48
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 50
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 48
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 50
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 60
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 70

  切换版本命令

sudo update-alternatives --config gcc 
sudo update-alternatives --config g++

  根据自己想要的环境选择

第二步:准备安装显卡驱动和cuda8.0等相关文件

  最新cuda8.0 及其补丁
  cuda_8.0.61.2_linux.run 
  cuda_8.0.61_375.26_linux.run
  最新支持cuda8.0的CUDNN
  libcudnn7_7.1.4.18-1+cuda8.0_amd64.deb
  libcudnn7-dev_7.1.4.18-1+cuda8.0_amd64.deb
  libcudnn7-doc_7.1.4.18-1+cuda8.0_amd64.deb
  cuda8.0 安装包解压文件
  /001/InstallUtils.pm(从cuda_8.0.61.2_linux.run中解压出来的文件,后面会讲到)
第三步:安装显卡驱动
  • 1、开机 nomodeset 进入系统
    • 开机进引导界面 第一项 按e 进入配置启动
    • 在quiet splash - - -后加上 nomodeset
    • 按F10 保存 进入系统
quiet splash - - -
quiet splash nomodeset
  • 2、禁用系统自带NVIDIA驱动
sudo vim /etc/modprobe.d/blacklist.conf
# 在文件尾加入
blacklist nouveau
options nouveau modeset=0
# 保存并退出 执行下面命令 更新引导
sudo update-initramfs –u
  • 3、安装 NVIDIA 驱动
# 切换gcc 版本 到gcc-5 以上 (使用高版本感觉会好一点)
# 查看支持的驱动版本
ubuntu-drivers devices
# 安装驱动
sudo ubuntu-drivers autoinstall
# 根据查询的版本安装比较保险 例如
sudo apt-get install nvidia-driver-390
# 装驱动 需要关闭 安全启动
  • 5、重启系统
sudo reboot
# 查看NVIDIA驱动 使用情况
nvidia-smi
  • 6、安装cuda8.0
    • 安装依赖
  • sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev
    • 切换gcc版本到 4.8
  • sudo update-alternatives --config gcc
    • 解压cuda8.0
  • sh cuda_8.0.61_375.26_linux.run --noexec --target 001 
    # 将runfile文件解压并且放到001文件夹中
    # 将InstalUtil.pm 拷贝到 /etc/perl/
    sudo cp InstalUtil.pm /etc/perl/
    • 安装cuda8.0及补丁
  • # 可选 加运行权限 
    chmod u+x cuda_8.0.61_375.26_linux.run
    chmod u+x cuda_8.0.61.2_linux.run
    # 运行
    sudo ./chmod u+x cuda_8.0.61_375.26_linux.run
    
    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 375.26?
    (y)es/(n)o/(q)uit: n
    
    Install the CUDA 8.0 Toolkit?
    (y)es/(n)o/(q)uit: y
    
    Enter Toolkit Location
    [ default is /usr/local/cuda-8.0 ]:
    
    Do you want to install a symbolic link at /usr/local/cuda?
    (y)es/(n)o/(q)uit: y
    
    Install the CUDA 8.0 Samples?
    (y)es/(n)o/(q)uit: y
    
    Enter CUDA Samples Location
    [ default is /home/deep ]:
    
    # 安装补丁
    sudo ./cuda_8.0.61.2_linux.run
    • 添加环境变量
  • cd 
    vim .bashrc
    # 添加到文件尾部
    export PATH=/usr/local/cuda-8.0/bin:$PATH 
    export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64$LD_LIBRARY_PATH
    # 保存 退出
    sudo su
    source .bashrc
    • 重启系统
  • sudo reboot
    • 安装cudnn
  • sudo dpkg -i libcudnn7_7.1.4.18-1+cuda8.0_amd64.deb
    sudo dpkg -i libcudnn7-dev_7.1.4.18-1+cuda8.0_amd64.deb
    sudo dpkg -i libcudnn7-doc_7.1.4.18-1+cuda8.0_amd64.deb
    • 查看cuda版本和cudnn版本
  • # cuda 版本
    cat /usr/local/cuda/version.txt
    # cudnn 版本
    cat /usr/include/x86_64-linux-gnu/cudnn_v7.h | grep CUDNN_MAJOR -A 2
    • 编译
  • # 不用编译全部 只编译deviceQuery
    cd /home/deep/NVIDIA_CUDA-8.0_Samples/1_Utilities/deviceQuery
    make
    • 测试
  • ./deviceQuery
    
    # 出现显卡信息
    ./deviceQuery Starting...
    
    CUDA Device Query (Runtime API) version (CUDART static linking)
    
    Detected 1 CUDA Capable device(s)
    
    Device 0: "GeForce GTX 1080"
      CUDA Driver Version / Runtime Version          9.1 / 8.0
      CUDA Capability Major/Minor version number:    6.1
      Total amount of global memory:                 8116 MBytes (8510701568 bytes)
      (20) Multiprocessors, (128) CUDA Cores/MP:     2560 CUDA Cores
      GPU Max Clock rate:                            1734 MHz (1.73 GHz)
      Memory Clock rate:                             5005 Mhz
      Memory Bus Width:                              256-bit
      L2 Cache Size:                                 2097152 bytes
      Maximum Texture Dimension Size (x,y,z)         1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
      Maximum Layered 1D Texture Size, (num) layers  1D=(32768), 2048 layers
      Maximum Layered 2D Texture Size, (num) layers  2D=(32768, 32768), 2048 layers
      Total amount of constant memory:               65536 bytes
      Total amount of shared memory per block:       49152 bytes
      Total number of registers available per block: 65536
      Warp size:                                     32
      Maximum number of threads per multiprocessor:  2048
      Maximum number of threads per block:           1024
      Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
      Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
      Maximum memory pitch:                          2147483647 bytes
      Texture alignment:                             512 bytes
      Concurrent copy and kernel execution:          Yes with 2 copy engine(s)
      Run time limit on kernels:                     Yes
      Integrated GPU sharing Host Memory:            No
      Support host page-locked memory mapping:       Yes
      Alignment requirement for Surfaces:            Yes
      Device has ECC support:                        Disabled
      Device supports Unified Addressing (UVA):      Yes
      Device PCI Domain ID / Bus ID / location ID:   0 / 1 / 0
      Compute Mode:
         < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
    
    deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 9.1, CUDA Runtime Version = 8.0, NumDevs = 1, Device0 = GeForce GTX 1080
    Result = PASS

     

如果出现相应的显卡信息表示安装成功了。

 

 

 

转载于:https://www.cnblogs.com/sleepylulu/p/10574230.html

你可能感兴趣的:(Ubuntu18.04安装完应该做的一些事 显卡驱动安装和cuda8.0)