網頁

2018年12月22日 星期六

ubuntu 18.04 install cuda

安裝前,如果廠商是先灌Windows的話,記得要先到BIOS的secure boot把OS改為other os (主機板是ASUS ROG STRIX Z390-H GAMING)。

強烈建議使用runfile (local)安裝,會比deb (local)方便非常多。



1. 安裝make
$ sudo apt install make

2. 如果沒有依照下面步驟,安裝過程會出現"The driver installation is unable to locate the kernel source. Please make sure that the kernel source packages are installed and set up correctly. If you know that the kernel source packages are installed and set up correctly, you may pass the location of the kernel source with the '--kernel-source-path' flag."


1. 砍掉X server session
$ sudo service lightdm stop

X是管理一個或多個圖形顯示的應用程序。 因為它的主要組件負責調整窗口,裝飾元素,標題欄,最小化,關閉按鈕等的大小和移動。安裝顯卡驅動需要禁用該服務,否則會安裝終止,並出現相應需要禁用該服務的錯誤

2. 安裝build-essential package
$ sudo apt-get install build-essential
$ https://www.cnblogs.com/pprp/p/9430836.html

如果某些庫需要C / C ++編譯器,則需要安裝build-essential。

3. 黑名單"nouveau" driver
$ echo -e "blacklist nouveau\nblacklist lbm-nouveau\noptions nouveau modeset=0\nalias nouveau off\nalias lbm-nouveau off\n" | sudo tee /etc/modprobe.d/blacklist-nouveau.conf
$ echo options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf
$ sudo update-initramfs -u

$ sudo gedit /etc/modprobe.d/blacklist-nouveau.conf
確認以下內容
blacklist nouveau
blacklist lbm-nouveau
options nouveau modeset=0
alias nouveau off
alias lbm-nouveau off

$ lsmod | grep nouveau 如果沒有輸出表示成功

Nouveau是一款免費的開源驅動程序,由reverse engineering Nvidia專有的Linux驅動程序開發而成。 有很多原因不考慮使用它:與Nvidia專有的圖形設備驅動程序相比性能較差,沒有CUDA支持,我們需要相應地配置xserver以避免黑屏/登錄循環問題(關掉有衝突的module)。

4. 重開機

5. 安裝linux kernel modules
$ sudo apt-get install linux-image-extra-virtual

Nvidia的驅動程序依賴於drm module,但是它不包含在雲端的默認'虛擬'ubuntu中(因為它通常沒有圖形)。它可以在linux-image-extra-virtual軟件包中找到(或者推測和linux-image -generic有關),但只是直接安裝它們將為最新的可用內核安裝drm module,而不是我們當前正在運行的內核。因此,我們需要手動指定版本。這個命令可能需要重新運行 每次升級內核並重新啟動時。

6. 安裝linux source and headers
$ sudo apt-get install linux-source 
$ sudo apt-get source linux-image-$(uname -r) 
$ sudo apt-get install linux-headers-$(uname -r)

主要針對"unable to locate the kernel source"。CUDA驅動程序需要在安裝驅動程序時安裝內核運行版本的內核頭文件和開發包,以及重建驅動程序時。例如,如果您的系統運行的是內核版本3.17.4 -301,還必須安裝3.17.4-301內核頭文件和開發包。

7. 設置PATH
$ sudo vim /etc/profile
把下面兩行進去
export PATH=/usr/local/cuda-10.0/bin:$PATH 
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64:$LD_LIBRARY_PATH

$ source /etc/profile




$ lspci | grep -i nvidia
$ lspci | grep -i nvidia
$ sudo apt-get install linux-headers-$(uname -r)
$ md5sum cuda-repo-ubuntu1804-10-0-local-10.0.130-410.48_1.0-1_amd64.deb
$ sudo dpkg -i cuda-repo-ubuntu1804-10-0-local-10.0.130-410.48_1.0-1_amd64.deb
$ sudo apt-key add /var/cuda-repo-10-0-local-10.0.130-410.48/7fa2af80.pub
$ sudo apt-get update
$ sudo apt-get install cuda
$ sudo vi /etc/modprobe.d/blacklist-nouveau.conf
blacklist nouveau 
options nouveau modeset=0
$ sudo update-initramfs -u


Security Boot disable
進入BIOS -> Security Boot -> Key Management -> Clear Secure Boot keys
$ sudo add-apt-repository ppa:graphics-drivers/ppa
$ sudo apt update
$ sudo apt remove --purge nvidia*
$ sudo ubuntu-drivers autoinstall
$ nvidia-smi
$ reboot
$ sudo bash cuda_10.0.130_410.48_linux.run

Logging to /opt/temp//cuda_install_6583.log
Using more to view the EULA.
End User License Agreement
--------------------------
Preface
-------
The following contains specific license terms and conditions
for four separate NVIDIA products. By accepting this
agreement, you agree to comply with all the terms and
conditions applicable to the specific product(s) included
herein.
Do you accept the previously read EULA?
accept/decline/quit: accept
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 361.62?
(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/textminer ]:
Installing the CUDA Toolkit in /usr/local/cuda-8.0 ...
Installing the CUDA Samples in /home/textminer ...
Copying samples to /home/textminer/NVIDIA_CUDA-8.0_Samples now...
Finished copying samples.
===========
= Summary =
===========
Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-8.0
Samples: Installed in /home/textminer
Please make sure that
- PATH includes /usr/local/cuda-8.0/bin
- LD_LIBRARY_PATH includes /usr/local/cuda-8.0/lib64, or, add /usr/local/cuda-8.0/lib64 to /etc/ld.so.conf and run ldconfig as root
To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-8.0/bin
Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-8.0/doc/pdf for detailed information on setting up CUDA.
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 361.00 is required for CUDA 8.0 functionality to work.
To install the driver using this installer, run the following command, replacing with the name of this run file:
sudo .run -silent -driver
Logfile is /opt/temp//cuda_install_6583.log

$ cd ../../5_Simulations/nbody/
$ make
$ ./nbody

如果出現/usr/bin/ld: cannot find -lglut
$ sudo apt-get install freeglut3 freeglut3-dev



參考
https://linuxconfig.org/how-to-install-the-nvidia-drivers-on-ubuntu-18-04-bionic-beaver-linux
http://www.52nlp.cn/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E4%B8%BB%E6%9C%BA%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE-ubuntu-16-04-nvidia-gtx-1080-cuda-8

$ sudo add-apt-repository universe
$ sudo apt update
$ sudo apt-get purge "nvidia*"
$ vi ~/.zshrc
setopt no_nomatch
$ lsmod |grep nouv*
$ sudo add-apt-repository ppa:graphics-drivers
$ sudo apt-get update
$ ubuntu-drivers devices
$ sudo apt-get install nvidia-driver-440 nvidia-settings



參考
https://tw.openrobot.org/article/index?sn=11691&fbclid=IwAR0ez9EHbaIrrMpcu8Sah8lYQhX8xmp0tN5jmnXA2jw_692-6asujmlb9To

2 則留言:

  1. Finally I solved it using command below
    "sh ./NVIDIA-Linux-x86_64-430.50.run"

    Below are previous trials that fail
    command: cuda_10.0.130_410.48_linux.run
    error message: The driver installation is unable to locate the kernel source.

    trials (fail)
    sudo apt-get purge linux-image-4.18.0-15-generic
    sudo apt-get purge linux-header4.18.0-15-generic

    sh ./cuda_10.0.130_410.48_linux.run --kernel-source-path=/lib/modules/5.0.0-32-generic/build/include/

    回覆刪除