深度學習開發環境配置第一彈:Ubuntu16.04下安裝NVIDIA顯示卡驅動+CUDA9.0.176配置
一、解除安裝舊NVIDIA驅動
sudo apt-get remove --purge nvidia*
二、拉黑Ubuntu核心裡面自帶的nouveau驅動
本人親測使用的是:
1、在/etc/modprobe.d/路徑新增並修改配置檔案
[email protected]:~$ sudo touch /etc/modprobe.d/blacklist-nouveau.conf
[email protected]:~$ sudo nano /etc/modprobe.d/blacklist-nouveau.conf
在blacklist-nouveau.conf檔案中新增這幾句話:
blacklist nouveau
options nouveau modeset=0
2、 重新生成 kernel initramfs
[email protected]:~$ sudo update-initramfs -u
update-initramfs: Generating /boot/initrd.img-4.4.0-21-generic
W: Possible missing firmware /lib/firmware/ast_dp501_fw.bin for module ast
3、重啟
[email protected]:~$ sudo reboot
4、最終確認nouveau是否被拉黑
輸入lsmod | grep nouveau檢視,沒有輸出即禁止成功
拉黑前:
[email protected]:~$ lsmod | grep nouveau nouveau 1495040 0 mxm_wmi 16384 1 nouveau video 40960 1 nouveau ttm 98304 2 ast,nouveau drm_kms_helper 139264 2 ast,nouveau i2c_algo_bit 16384 3 ast,igb,nouveau drm 360448 6 ast,ttm,drm_kms_helper,nouveau wmi 20480 2 mxm_wmi,nouveau
拉黑後:
[email protected]:~$ lsmod | grep nouveau
[email protected]:~$ sudo service lightdm stop
三、安裝NVIDIA顯示卡驅動
工作站reboot後analt + ctrl + F1進入textmode模式,輸入使用者和密碼後,禁用lightdm服務:
[email protected]:~$ sudo service lightdm stop
進入NVIDIA顯示卡驅動官網下載驅動(這種下載方式貌似只提供最新的驅動版本下載),切換到驅動.run檔案路徑,使用sudo ./NVIDIA*.run -no-opengl-files安裝NVIDIA驅動(後面的-no-opengl-files不能省掉,否則會造成進不去桌面,卡在登陸介面迴圈):
[email protected]:/media/vslyu/home/sinc-lab$ sudo ./Documents/ubantu伺服器軟體/NVIDIA-Linux-x86_64-390.59.run -no-opengl-files
Verifying archive integrity... OK
Uncompressing NVIDIA Accelerated Graphics Driver for Linux-x86_64 390.59........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
安裝完成後,輸入nvidia-smi命令檢視顯示卡資訊是否存在,存在即說明成功打上驅動:
[email protected]:/media/vslyu/home/sinc-lab/Downloads$ nvidia-smi
Tue Sep 11 17:23:40 2018
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 384.130 Driver Version: 384.130 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 108... Off | 00000000:02:00.0 Off | N/A |
| 23% 41C P0 62W / 250W | 0MiB / 11172MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 1 GeForce GTX 108... Off | 00000000:03:00.0 Off | N/A |
| 24% 44C P0 61W / 250W | 0MiB / 11172MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 2 GeForce GTX 108... Off | 00000000:82:00.0 Off | N/A |
| 23% 41C P0 61W / 250W | 0MiB / 11172MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 3 GeForce GTX 108... Off | 00000000:83:00.0 Off | N/A |
| 23% 39C P0 59W / 250W | 0MiB / 11172MiB | 2% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
(ps:之前安裝的Driver Version為390.87,單這裡輸出的 Driver Version為384.130,這是因為我這裡貼的圖是安裝自帶NVIDIA Driver的本地cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64.deb檔案後的輸出結果)
四、安裝CUDA
參照NVIDIA的NVIDIA CUDA Installation Guide for Linux,按照要求一步一步進行確認,推薦使用.deb檔案進行安裝,使用.run檔案進行安裝時之前在配置TensorRT遇到過一個坑(不好意思,這個坑具體是什麼我忘了),
線上安裝的deb(安裝線上的deb會提醒選擇Driver Version的是否安裝、是否需要更新等資訊):
sudo dpkg -i cuda-repo-ubuntu1604_9.0.176-1_amd64.deb
~$ sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
~$ sudo apt-get update
~$ sudo apt-get install cuda
本地安裝的deb(安裝線上的deb不會提醒選擇Driver Version的是否安裝、是否需要更新等資訊,預設配置本地自帶的Driver,故安裝本地的deb檔案需要先配置Driver,安裝本地的deb檔案會自動安裝配置好):
[email protected]:/media/vslyu/home/sinc-lab/Downloads$ sudo dpkg -i cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64.deb
~$ sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
~$ sudo apt-get update
~$ sudo apt-get install cuda
注意新增.pub公鑰後一定要update一下,建立好apt-cache資訊:
[email protected]:/media/vslyu/home/sinc-lab/Downloads$ sudo apt-get update
Get:1 file:/var/cuda-repo-9-0-local InRelease
Ign:1 file:/var/cuda-repo-9-0-local InRelease
Get:2 file:/var/cuda-repo-9-0-local Release [574 B]
Hit:3 http://mirrors.hust.edu.cn/ubuntu xenial InRelease
Get:2 file:/var/cuda-repo-9-0-local Release [574 B]
Get:4 http://mirrors.hust.edu.cn/ubuntu xenial-security InRelease [107 kB]
Get:5 http://mirrors.hust.edu.cn/ubuntu xenial-updates InRelease [109 kB]
Hit:6 http://mirrors.hust.edu.cn/ubuntu xenial-proposed InRelease
Get:7 http://mirrors.hust.edu.cn/ubuntu xenial-backports InRelease [107 kB]
Get:9 http://mirrors.hust.edu.cn/ubuntu xenial-security/universe Sources [73.6 kB]
Get:10 http://mirrors.hust.edu.cn/ubuntu xenial-security/main amd64 DEP-11 Metadata [67.7 kB]
Get:11 http://mirrors.hust.edu.cn/ubuntu xenial-security/main DEP-11 64x64 Icons [68.0 kB]
Get:12 http://mirrors.hust.edu.cn/ubuntu xenial-security/universe amd64 Packages [370 kB]
Get:13 http://mirrors.hust.edu.cn/ubuntu xenial-security/universe amd64 DEP-11 Metadata [107 kB]
Get:14 http://mirrors.hust.edu.cn/ubuntu xenial-security/universe DEP-11 64x64 Icons [142 kB]
Get:15 http://mirrors.hust.edu.cn/ubuntu xenial-updates/universe Sources [220 kB]
Get:16 http://mirrors.hust.edu.cn/ubuntu xenial-updates/main amd64 DEP-11 Metadata [320 kB]
Get:17 http://mirrors.hust.edu.cn/ubuntu xenial-updates/main DEP-11 64x64 Icons [227 kB]
Get:18 http://mirrors.hust.edu.cn/ubuntu xenial-updates/universe amd64 Packages [683 kB]
Get:19 http://mirrors.hust.edu.cn/ubuntu xenial-updates/universe i386 Packages [624 kB]
Get:20 http://mirrors.hust.edu.cn/ubuntu xenial-updates/universe amd64 DEP-11 Metadata [247 kB]
Get:21 http://mirrors.hust.edu.cn/ubuntu xenial-updates/universe DEP-11 64x64 Icons [335 kB]
Get:22 http://mirrors.hust.edu.cn/ubuntu xenial-updates/multiverse amd64 DEP-11 Metadata [5,960 B]
Get:23 http://mirrors.hust.edu.cn/ubuntu xenial-updates/multiverse DEP-11 64x64 Icons [14.3 kB]
Get:24 http://mirrors.hust.edu.cn/ubuntu xenial-backports/main amd64 DEP-11 Metadata [3,328 B]
Get:25 http://mirrors.hust.edu.cn/ubuntu xenial-backports/universe amd64 DEP-11 Metadata [5,100 B]
Fetched 3,835 kB in 0s (4,534 kB/s)
Reading package lists... Done
[email protected]:/media/vslyu/home/sinc-lab/Downloads$
在環境變數中新增CUDA,sudo許可權開啟~/.bashrc檔案,在檔案末尾新增兩行指令:
export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64\ ${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
再啟用、載入一下配置:
[email protected]:/media/vslyu/home/sinc-lab/Downloads$ source ~/.bashrc
[email protected]:/media/vslyu/home/sinc-lab/Downloads$ sudo ldconfig
[email protected]:/media/vslyu/home/sinc-lab/Downloads$