Ubuntu18之driver,cuda,cudnn

prepare env

nouveau模式

#Disable the Nouveau Drivers
sudo vim /etc/modprobe.d/blacklist-nouveau.conf
#Add the following two lines to the file
blacklist nouveau
options nouveau modeset=0
#Regenerate the kernel initramfs
sudo update-initramfs -u
reboot

編譯組件

#sudo apt-get install gcc
sudo apt-get install build-essential

driver

驅動下載,選擇自己對應顯卡的驅動

chmod +x NVIDIA-Linux-x86_64-410.78.run
sudo init 3    #重點,否則會出現安裝後任然找不到顯卡驅動
sudo ./NVIDIA-Linux-x86_64-410.78.run
reboot
nvidia-smi   #查看GPU設備
nvidia-settings #圖形化顯卡配置
watch -n 0.1 nvidia-smi #查看GPU實時資源使用情況
#If there are some troubles, remove the driver, and run the installer:
sudo apt-get remove --purge nvidia*
sudo ./NVIDIA-Linux-x86_64-410.78.run --no-opengl-files

推薦參考
其它安裝方式:2 ways

#open up a terminal window and check which driver is being used for Nvidia card with the following command.
sudo lshw -c display

#You can also use video instead of display as the class name.
sudo lshw -c video

#run the following command to list available driver for your Nvidia card from the default Ubuntu repository.
sudo ubuntu-drivers devices

#To install the recommended driver, run the following command.
# method 1
sudo ubuntu-drivers autoinstall
# method 3
sudo apt install nvidia-driver-version-number
#for example
#sudo apt install nvidia-driver-430
sudo reboot

#Now the proprietary Nvidia driver is being used.
sudo lshw -c display

#You can check which card is being used now with following command:
prime-select query

#If you want to use Intel graphics card, run the following command:
sudo prime-select intel

#To switch back to Nvidia card, run
sudo prime-select nvidia

#If for some reason you don’t want the proprietary driver any more, you can remove it by running the following command.
sudo apt purge nvidia-*
sudo apt autoremove

Notice that you may need reboot for the change to take effect if you had swithced the Intel graphics/Nvidia card.

雙顯卡自動切換,集顯用於顯示,nvidia獨顯用於計算:
https://www.jianshu.com/p/5bbf234da1d7
http://www.61k.com/1162359.html

如果是uefi模式安裝的ubuntu18系統,安裝顯卡是需要安全密碼,根據提示設置一個密碼,顯卡驅動安裝完成後,系統重啓會進入perform mok mangement
選擇配置步驟如下
enroll mok -> continue -> yes -> 輸入設定的密碼 -> reboot

在這裏插入圖片描述
or
在這裏插入圖片描述
00:02.0 對應 如下配置文件 參數 BusID “PCI:0:2:0”

sudo vi /etc/X11/xorg.conf
Section "ServerLayout"
    Identifier "Layout0"
    Screen   0 "Screen0"
EndSection

Section "Screen"
    Identifier "Screen0"
    Device     "Device0"
EndSection

Section "Device"
    Identifier "Device0"
    Driver     "intel"
    VendorName "Intel Corporation"
    BusID      "PCI:0:2:0"
EndSection
sudo reboot
sudo prime-select nvidia
nvidia-smi    #可以看到n卡內存佔用爲0

lspci -i | grep VGA
lspci -k | grep -A 2 -i "VGA"

cuda

cuda下載

#選擇自己需要的cuda10.1版本,其它cuda版本方法類似
sudo sh cuda_10.1.243_418.87.00_linux.run
#注意選項driver爲no,因爲已經先裝了driver

gvim ~/.bashrc
#添加如下兩行代碼
export PATH=/usr/local/cuda-10.1/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

source ~/.bashrc
nvcc -V    #查看cuda版本信息

若不幸安裝失敗,執行下面的命令卸載cuda,然後重新安裝

cd /usr/local/cuda/bin
sudo ./cuda-uninstaller

cudnn

#cuDNN link: https://developer.nvidia.com/rdp/cudnn-download
#下載 cuDNN Runtime Library for Ubuntu18.04 (Deb) 版本
sudo dpkg -i libcudnn7*

dpkg安裝與卸載

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