Ubuntu下Nvidia显卡驱动安装

1. 下载显卡驱动

Nvidia官网 查询自己的显卡驱动,下载。

2. 禁用 nouveau

  • 新建文件 blacklist-nouveau.conf

    sudo gedit /etc/modprobe.d/blacklist-nouveau.conf
    
  • 往文件中写入以下内容并保存文件。

    blacklist nouveau
    blacklist lbm-nouveau
    options nouveau modeset=0
    alias nouveau off
    alias lbm-nouveau off
    
  • 使配置生效:

    sudo update-initramfs -u
    
  • 重启电脑。

  • 执行以下命令,如果没有任何输出则证明禁用nouveau成功。

    lsmod | grep nouveau
    

3. 关闭图形界面

sudo service lightdm stop

以上命令会关闭图形界面,等屏幕变黑后,按 Ctrl-Alt+F1 进入命令行界面,输入用户名和密码登录。

4. 安装驱动

  • 进入驱动所在的目录。

  • 给文件加上权限:

    sudo chmod a+x NVIDIA-Linux-x86_64-430.50.run
    
  • 开始安装:

    sudo ./NVIDIA-Linux-x86_64-430.50.run –no-opengl-files  # 参数不可省略
    
  • 如果有旧版本的驱动,会提示你要不要继续,继续会卸载旧版本。然后后面的选项基本都是选“No”,直到安装完成。

  • 重启电脑。

5. 测试

  • 开启图形界面:

    sudo service lightdm start
    
  • 在终端输入:

    $ nvidia-smi
    

    比如我的会显示如下:

    Fri Sep 20 10:26:16 2019       
    +-----------------------------------------------------------------------------+
    | NVIDIA-SMI 430.50       Driver Version: 430.50       CUDA Version: 10.1     |
    |-------------------------------+----------------------+----------------------+
    | GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
    | Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
    |===============================+======================+======================|
    |   0  TITAN Xp            Off  | 00000000:01:00.0  On |                  N/A |
    | 23%   34C    P8    13W / 250W |    204MiB / 12194MiB |     14%      Default |
    +-------------------------------+----------------------+----------------------+
                                                                                   
    +-----------------------------------------------------------------------------+
    | Processes:                                                       GPU Memory |
    |  GPU       PID   Type   Process name                             Usage      |
    |=============================================================================|
    |    0       971      G   /usr/lib/xorg/Xorg                           202MiB |
    +-----------------------------------------------------------------------------+
    

    证明安装成功。

6. 安装CUDA

参见博客:Ubuntu 多版本 CUDA 共存

7. 测试CUDA

  • 进入Sample目录:

    cd /usr/local/cuda-10.0/samples/1_Utilities/deviceQuery
    
  • 编译:

    sudo make
    
  • 运行:

    ./deviceQuery
    
  • 我的输出:

    ./deviceQuery Starting...
    
     CUDA Device Query (Runtime API) version (CUDART static linking)
    
    Detected 1 CUDA Capable device(s)
    
    Device 0: "TITAN Xp"
      CUDA Driver Version / Runtime Version          10.1 / 10.0
      CUDA Capability Major/Minor version number:    6.1
      Total amount of global memory:                 12195 MBytes (12787122176 bytes)
      (30) Multiprocessors, (128) CUDA Cores/MP:     3840 CUDA Cores
      GPU Max Clock rate:                            1582 MHz (1.58 GHz)
      Memory Clock rate:                             5705 Mhz
      Memory Bus Width:                              384-bit
      L2 Cache Size:                                 3145728 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 supports Compute Preemption:            Yes
      Supports Cooperative Kernel Launch:            Yes
      Supports MultiDevice Co-op Kernel Launch:      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 = 10.1, CUDA Runtime Version = 10.0, NumDevs = 1
    Result = PASS
    

    重点在最后一行的 Result = PASS

  • 然后同样的:

    cd ../bandwidthTest
    sudo make
    ./bandwidthTest
    

    输出:

    [CUDA Bandwidth Test] - Starting...
    Running on...
    
     Device 0: TITAN Xp
     Quick Mode
    
     Host to Device Bandwidth, 1 Device(s)
     PINNED Memory Transfers
       Transfer Size (Bytes)	Bandwidth(MB/s)
       33554432			12395.1
    
     Device to Host Bandwidth, 1 Device(s)
     PINNED Memory Transfers
       Transfer Size (Bytes)	Bandwidth(MB/s)
       33554432			12824.5
    
     Device to Device Bandwidth, 1 Device(s)
     PINNED Memory Transfers
       Transfer Size (Bytes)	Bandwidth(MB/s)
       33554432			416472.7
    
    Result = PASS
    

参考博客:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章