2 - Ubuntu 16.04 + nvidia + cuda9.1

很久沒用實(shí)驗(yàn)室的電腦,覺得很浪費(fèi),所以想好好重整一下環(huán)境。本來電腦上是只有一個(gè)ubuntu系統(tǒng),現(xiàn)在裝雙系統(tǒng),win10和ubuntu,全部從頭安裝,都裝在固態(tài)硬盤上。安裝系統(tǒng)的過程就不說了,ubuntu的安裝見系列1。

這是一個(gè)系列:
1、Ubuntu 系統(tǒng)安裝
2、Ubuntu 16.04 + nvidia + cuda9.1
3、Ubuntu 基本工作環(huán)境 + 深度學(xué)習(xí)環(huán)境配置
4、Ubuntu 16.04 + SSR

一、安裝nvidia驅(qū)動(dòng)

1、首先去官網(wǎng)上適合你的GPU驅(qū)動(dòng)

my_type_1
my_type_2

2、執(zhí)行如下語句,安裝:

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt-get install nvidia-390   # 這邊數(shù)字對(duì)應(yīng)上面搜索出的版本
sudo apt-get install mesa-common-dev
sudo apt-get install freeglut3-dev

3、執(zhí)行完上述后,重啟: sudo reboot
4、輸入nvidia-smi,如果出現(xiàn)了你的GPU列表,則說明驅(qū)動(dòng)安裝成功了。另外也可以通過nvidia-settings查看自己機(jī)器上詳細(xì)的GPU信息。

如果驅(qū)動(dòng)安裝有問題,見我這篇:ubuntu 16.04 nvidia顯卡驅(qū)動(dòng)相關(guān)問題

二、安裝cuda

cuda是nvidia的編程語言平臺(tái),想使用GPU就必須要使用cuda。
1、從這里cuda9.1找適合自己的安裝文件。

download_cuda

下載下面第一個(gè)cuda9.1的runfile(local)文件:cuda_9.1.85_387.26_linux.run
這里是nvidia給出的官方安裝指南,遇到問題時(shí)可以查閱 。

2、進(jìn)入下載好的runfile文件所在目錄下,執(zhí)行如下語句,運(yùn)行runfile文件:

sudo sh cuda_9.1.85_387.26_linux.run 

注意:因?yàn)轵?qū)動(dòng)之前已經(jīng)安裝,這里就不要選擇安裝驅(qū)動(dòng)(第一條跳出問 cuda accelerated graphic driver之類的問你要不要安裝,選no就行)。其余的都直接continue或者選yes即可。如果報(bào)錯(cuò):

Do you accept the previously read EULA?
accept/decline/quit: accept

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 387.26?
(y)es/(n)o/(q)uit: no

Install the CUDA 9.1 Toolkit?
(y)es/(n)o/(q)uit: y

Enter Toolkit Location
 [ default is /usr/local/cuda-9.1 ]:                         

Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y

Install the CUDA 9.1 Samples?
(y)es/(n)o/(q)uit: y

Enter CUDA Samples Location
 [ default is /home/mdt ]: 

Installing the CUDA Toolkit in /usr/local/cuda-9.1 ...
Missing recommended library: libXi.so
Missing recommended library: libXmu.so

Installing the CUDA Samples in /home/mdt ...
Copying samples to /home/mdt/NVIDIA_CUDA-9.1_Samples now...
Finished copying samples.

===========
= Summary =
===========

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-9.1
Samples:  Installed in /home/mdt, but missing recommended libraries

Please make sure that
 -   PATH includes /usr/local/cuda-9.1/bin
 -   LD_LIBRARY_PATH includes /usr/local/cuda-9.1/lib64, or, add /usr/local/cuda-9.1/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-9.1/bin

Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-9.1/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 384.00 is required for CUDA 9.1 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
    sudo <CudaInstaller>.run -silent -driver

Logfile is /tmp/cuda_install_2139.log

Solution:

sudo apt-get install libglu1-mesa libxi-dev libxmu-dev libglu1-mesa-dev

3、打開“profile”文件: sudo gedit /etc/profile
在末尾處添加(注意不要有空格,不然會(huì)報(bào)錯(cuò)):

# 可以先去check一下自己的/usr/local/下有沒有或者是不是cuda-9.1
export PATH=/usr/local/cuda-9.1/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-9.1/lib64$LD_LIBRARY_PATH

4、重啟電腦: sudo reboot
5、測(cè)試cuda的samples:

cd /usr/local/cuda-9.1/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery

如果顯示的是一些關(guān)于GPU的信息,則說明安裝成功了。

參考目錄:
https://blog.csdn.net/u010837794/article/details/63251725

========================================================

查看cuda安裝版本:

nvcc -V
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容