1. 程式人生 > >Ubuntu下安裝CUDA8.0及nvidia驅動(詳細教程)

Ubuntu下安裝CUDA8.0及nvidia驅動(詳細教程)

1. 選擇對的系統安裝nvidia驅動

為什麼說對的系統呢,這是因為在多次嘗試後發現,如果使用ubuntu14安裝顯示卡驅動會出現無法進入系統,一直在迴圈在登入介面,而ubuntu16則不會出現這個問題,所以說最好升級一下吧,畢竟14有點太老了。

重要的一點是不要在安裝或安裝後升級核心,否則cuda無法識別核心而導致安裝失敗!(如果已經升級並且cuda報錯,那麼百度或谷歌一下如何降核心吧)

先安裝一些依賴吧,接下來可能用的到

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install git cmake build-essential

使用如下指令安裝你的nvidia驅動(ubntun14會無法進入系統)

sudo apt-get update
sudo apt-get install nvidia-367

安裝好後重啟,按super(windows)鍵,在你的程式中搜索nvidia就可以看到

表示你已經成功安裝顯示卡驅動

2. 下載cuda8.0

從這裡下載 https://developer.nvidia.com/cuda-downloads

下載出來的1G多的那個就好,下載好後將檔案剪下到你的home下,右擊檔案,點選屬性,開啟後如圖,選擇許可權,勾選執行

3. 安裝CUDA8.0

配置一下環境變數

sudo gedit ~/.bashrc

加入這兩行:

export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH

export LD_LIBRARY_PATH=/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH

然後,就可以開始安裝了

cd ~
sudo sh cuda_8.0.61_375.26_linux.run

然後會看到(按照我下面的輸入即可)

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 /root ]:
回車

接下來會出現

Installing the CUDA Toolkit in /usr/local/cuda-8.0 …
Installing the CUDA Samples in /root …
Copying samples to /home/derek/NVIDIA_CUDA-8.0_Samples now…
Finished copying samples.

= Summary =

Driver: Installed
Toolkit: Installed in /usr/local/cuda-8.0
Samples: Installed in /home/derek

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 filesudo.run -silent -driver

這樣就已經安裝好了,就是這麼簡單不要懷疑,只要不出error就可以,如果出現kernel相關錯誤,那一般是由於核心太高了,cuda不能識別,包括cuda9等等後來的也不能,所以還是想辦法降一下核心吧

4. 編輯配置檔案

sudo gedit ~/.bash_profile
開啟配置檔案,加入以下幾行
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda-8.0/lib64:/usr/local/cuda-8.0/extras/CUPTI/lib64"
export CUDA_HOME=/usr/local/cuda-8.0

也可以在.bashrc中配置

sudo gedit ~/.bashrc

加入這兩行

export PATH=/usr/local/cuda-8.0/bin:$PATH

export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH

source ~/.bashrc

現在就可以驗證一下cuda是否安裝成功咯

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