Ubuntu 17.10 安裝 CUDA Toolkit 9.0
近年來很火紅的新IT趨勢——深度學習。專為深度學習設計的開發套件也是百花齊放,
其中最有名的莫過於Google開發的Tensorflow,然而Tensorflow除了CPU版之外,同時也開發了一個以NVIDIA CUDA作為底層框架的GPU版。
既然如此,若欲使用運算速度比CPU快上百倍的GPU替你的深度學習專案進行運算,就要必須安裝NVIDIA CUDA Toolkit在執行Tensorflow-GPU的電腦上!
安裝必要軟體
安裝相關必要套件
1 |
[andy@Ubuntu ~]$ sudo apt-get install g++ freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev |
下載CUDA Toolkit
下載Nvidia CUDA Toolkit,在此挑選你需要的版本。請選擇下載『runfile』!
1 |
[andy@Ubuntu ~]$ wget https://developer.nvidia.com/compute/cuda/9.0/Prod/local_installers/cuda_9.0.176_384.81_linux-run |
開始安裝CUDA Toolkit
將CUDA安裝檔設為可執行,開始安裝!
1 2 |
[andy@Ubuntu ~]$ sudo chmod u+x cuda_9.0.176_384.81_linux-run [andy@Ubuntu ~]$ ./cuda_9.0.176_384.81_linux-run |
若遇到這個錯誤:
『Toolkit: Installation Failed. Using unsupported Compiler.』
可以到這邊看解決方法:Ubuntu 17.10安裝 CUDA Toolkit 9.0 遇到錯誤“Toolkit: Installation Failed. Using unsupported Compiler.”
安裝過程會跳出以下詢問對話:
- End User License Agreement:看完或想結束,請按下Q跳出
接下來,安裝程式會問你是否同意:
Do you accept the previously read EULA?
accept/decline/quit: accept -
You are attempting to install on an unsupported configuration. Do you wish to continue?
(y)es/(n)o [ default is no ]: y -
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81?
(y)es/(n)o/(q)uit: n -
Install the CUDA 9.0 Toolkit?
(y)es/(n)o/(q)uit: y -
Enter Toolkit Location
[ default is /usr/local/cuda-9.0 ]: <<按下Enter>> -
/usr/local/cuda-9.0 is not writable.
Do you wish to run the installation with ‘sudo’?
(y)es/(n)o: y
Please enter your password: <<輸入密碼>> -
Please enter your password:
Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y -
這一步會問你是否要安裝CUDA的範例檔,這就看自己需求了!
Install the CUDA 9.0 Samples?
(y)es/(n)o/(q)uit: y
選則安裝CUDA範例檔的話,就要選擇範例檔的安裝路徑~預設值是家目錄
Enter CUDA Samples Location
[ default is /home/andy ]: <<按下Enter>>
如果最後遇到錯誤『Can’t locate InstallUtils.pm in @INC』的錯誤,可以參考這篇文章:
Ubuntu 18.04安裝 CUDA Toolkit 遇到錯誤“Can’t locate InstallUtils.pm in @INC”
修改系統變數
增加系統變數,增加PATH, LD_LIBRARY_PATH
路徑沒有使用“/usr/local/cuda-9.0/bin”的原因是剛才的安裝程式已經建立一個捷徑cuda指向cuda-9.0。(上個步驟的第7個問題)
1 |
[andy@Ubuntu ~]$ sudo vim ~/.bashrc |
1 2 |
export PATH=${PATH}:/usr/local/cuda/bin export LD_LIBRARY_PATH=/usr/local/cuda/lib64 |
更改完.bashrc之後記得要更新系統變數才會生效!
1 |
[andy@Ubuntu ~]$ source ~/.bashrc |
測試CUDA是否正確安裝!
1 2 3 |
[andy@Ubuntu ~]$ cd ~/NVIDIA_CUDA-9.0_Samples/5_Simulations/smokeParticles/ [andy@Ubuntu smokeParticles]$ make [andy@Ubuntu smokeParticles]$ ./smokeParticles |
畫面應該會跑出一個飛來飛去的煙~
How can I install CUDA 9 on Ubuntu 17.10
Ubuntu 16.04 安裝 TensorFlow GPU GTX 1060