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- gcc--multilib
sudo apt-get install g++- g++--multilib
sudo apt-get install gcc- gcc--multilib
sudo apt-get install g++- g++--multilib
sudo apt-get install gcc- gcc--multilib
sudo apt-get install g++- g++--multilib
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-

  切换版本命令

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=
# 保存并退出 执行下面命令 更新引导
sudo update-initramfs –u
  • 3、安装 NVIDIA 驱动
# 切换gcc 版本 到gcc- 以上 (使用高版本感觉会好一点)
# 查看支持的驱动版本
ubuntu-drivers devices
# 安装驱动
sudo ubuntu-drivers autoinstall
# 根据查询的版本安装比较保险 例如
sudo apt-get install nvidia-driver-
# 装驱动 需要关闭 安全启动
  • 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..61_375.26_linux.run --noexec --target
    # 将runfile文件解压并且放到001文件夹中
    # 将InstalUtil.pm 拷贝到 /etc/perl/
    sudo cp InstalUtil.pm /etc/perl/
    • 安装cuda8.0及补丁
  • # 可选 加运行权限
    chmod u+x cuda_8..61_375.26_linux.run
    chmod u+x cuda_8.0.61.2_linux.run
    # 运行
    sudo ./chmod u+x cuda_8..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.-+cuda8.0_amd64.deb
    sudo dpkg -i libcudnn7-dev_7.1.4.-+cuda8.0_amd64.deb
    sudo dpkg -i libcudnn7-doc_7.1.4.-+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
    • 编译
  • # 不用编译全部 只编译deviceQuery
    cd /home/deep/NVIDIA_CUDA-.0_Samples/1_Utilities/deviceQuery
    make
    • 测试
  • ./deviceQuery
    
    # 出现显卡信息
    ./deviceQuery Starting... CUDA Device Query (Runtime API) version (CUDART static linking) Detected CUDA Capable device(s) Device : "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: MBytes ( bytes)
    () Multiprocessors, () CUDA Cores/MP: CUDA Cores
    GPU Max Clock rate: MHz (1.73 GHz)
    Memory Clock rate: Mhz
    Memory Bus Width: -bit
    L2 Cache Size: bytes
    Maximum Texture Dimension Size (x,y,z) 1D=(), 2D=(, ), 3D=(, , )
    Maximum Layered 1D Texture Size, (num) layers 1D=(), layers
    Maximum Layered 2D Texture Size, (num) layers 2D=(, ), layers
    Total amount of constant memory: bytes
    Total amount of shared memory per block: bytes
    Total number of registers available per block:
    Warp size:
    Maximum number of threads per multiprocessor:
    Maximum number of threads per block:
    Max dimension size of a thread block (x,y,z): (, , )
    Max dimension size of a grid size (x,y,z): (, , )
    Maximum memory pitch: bytes
    Texture alignment: bytes
    Concurrent copy and kernel execution: Yes with 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: / /
    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 = , Device0 = GeForce GTX
    Result = PASS

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

 

上一篇:Ubuntu 14.04 Nvidia显卡驱动安装及设置


下一篇:ubuntu环境下,ubuntu16.04装机到nvdia显卡驱动安装、cuda8安装、cudnn安装