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