博主裝Ubuntu18.04主要是為了用於跑深度學習,所以我們先來搞搞gcc環境 第一步:安裝多版本gcc、g++可切換 切換版本命令 根據自己想要的環境選擇 第二步:準備安裝顯卡驅動和cuda8.0等相關文件 最新cuda8.0 及其補丁 cuda_8.0.61.2_linux.run cuda_ ...
博主裝Ubuntu18.04主要是為了用於跑深度學習,所以我們先來搞搞gcc環境
第一步:安裝多版本gcc、g++可切換
sudo apt-get install gcc-4.8 gcc-4.8-multilib sudo apt-get install g++-4.8 g++-4.8-multilib sudo apt-get install gcc-5 gcc-5-multilib sudo apt-get install g++-5 g++-5-multilib sudo apt-get install gcc-6 gcc-6-multilib sudo apt-get install g++-6 g++-6-multilib sudo apt-get install gcc-7 gcc-7-multilib sudo apt-get install g++-7 g++-7-multilib sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 48 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 50 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 48 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 50 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 60 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 70
切換版本命令
sudo update-alternatives --config gcc sudo update-alternatives --config g++
根據自己想要的環境選擇
第二步:準備安裝顯卡驅動和cuda8.0等相關文件
最新cuda8.0 及其補丁 cuda_8.0.61.2_linux.run cuda_8.0.61_375.26_linux.run 最新支持cuda8.0的CUDNN libcudnn7_7.1.4.18-1+cuda8.0_amd64.deb libcudnn7-dev_7.1.4.18-1+cuda8.0_amd64.deb libcudnn7-doc_7.1.4.18-1+cuda8.0_amd64.deb cuda8.0 安裝包解壓文件 /001/InstallUtils.pm(從cuda_8.0.61.2_linux.run中解壓出來的文件,後面會講到)第三步:安裝顯卡驅動
- 1、開機 nomodeset 進入系統
- 開機進引導界面 第一項 按e 進入配置啟動
- 在quiet splash - - -後加上 nomodeset
- 按F10 保存 進入系統
quiet splash - - -
quiet splash nomodeset
- 2、禁用系統自帶NVIDIA驅動
sudo vim /etc/modprobe.d/blacklist.conf # 在文件尾加入 blacklist nouveau options nouveau modeset=0 # 保存並退出 執行下麵命令 更新引導 sudo update-initramfs –u
- 3、安裝 NVIDIA 驅動
# 切換gcc 版本 到gcc-5 以上 (使用高版本感覺會好一點) # 查看支持的驅動版本 ubuntu-drivers devices # 安裝驅動 sudo ubuntu-drivers autoinstall # 根據查詢的版本安裝比較保險 例如 sudo apt-get install nvidia-driver-390 # 裝驅動 需要關閉 安全啟動
- 5、重啟系統
sudo reboot # 查看NVIDIA驅動 使用情況 nvidia-smi
- 6、安裝cuda8.0
- 安裝依賴
-
sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev
- 切換gcc版本到 4.8
-
sudo update-alternatives --config gcc
- 解壓cuda8.0
-
sh cuda_8.0.61_375.26_linux.run --noexec --target 001 # 將runfile文件解壓並且放到001文件夾中 # 將InstalUtil.pm 拷貝到 /etc/perl/ sudo cp InstalUtil.pm /etc/perl/
- 安裝cuda8.0及補丁
-
# 可選 加運行許可權 chmod u+x cuda_8.0.61_375.26_linux.run chmod u+x cuda_8.0.61.2_linux.run # 運行 sudo ./chmod u+x cuda_8.0.61_375.26_linux.run 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 375.26? (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/deep ]: # 安裝補丁 sudo ./cuda_8.0.61.2_linux.run
- 添加環境變數
-
cd vim .bashrc # 添加到文件尾部 export PATH=/usr/local/cuda-8.0/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64$LD_LIBRARY_PATH # 保存 退出 sudo su source .bashrc
- 重啟系統
-
sudo reboot
- 安裝cudnn
-
sudo dpkg -i libcudnn7_7.1.4.18-1+cuda8.0_amd64.deb sudo dpkg -i libcudnn7-dev_7.1.4.18-1+cuda8.0_amd64.deb sudo dpkg -i libcudnn7-doc_7.1.4.18-1+cuda8.0_amd64.deb
- 查看cuda版本和cudnn版本
-
# cuda 版本 cat /usr/local/cuda/version.txt # cudnn 版本 cat /usr/include/x86_64-linux-gnu/cudnn_v7.h | grep CUDNN_MAJOR -A 2
- 編譯
-
# 不用編譯全部 只編譯deviceQuery cd /home/deep/NVIDIA_CUDA-8.0_Samples/1_Utilities/deviceQuery make
- 測試
-
./deviceQuery # 出現顯卡信息 ./deviceQuery Starting... CUDA Device Query (Runtime API) version (CUDART static linking) Detected 1 CUDA Capable device(s) Device 0: "GeForce GTX 1080" CUDA Driver Version / Runtime Version 9.1 / 8.0 CUDA Capability Major/Minor version number: 6.1 Total amount of global memory: 8116 MBytes (8510701568 bytes) (20) Multiprocessors, (128) CUDA Cores/MP: 2560 CUDA Cores GPU Max Clock rate: 1734 MHz (1.73 GHz) Memory Clock rate: 5005 Mhz Memory Bus Width: 256-bit L2 Cache Size: 2097152 bytes Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384) Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers Total amount of constant memory: 65536 bytes Total amount of shared memory per block: 49152 bytes Total number of registers available per block: 65536 Warp size: 32 Maximum number of threads per multiprocessor: 2048 Maximum number of threads per block: 1024 Max dimension size of a thread block (x,y,z): (1024, 1024, 64) Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535) Maximum memory pitch: 2147483647 bytes Texture alignment: 512 bytes Concurrent copy and kernel execution: Yes with 2 copy engine(s) Run time limit on kernels: Yes Integrated GPU sharing Host Memory: No Support host page-locked memory mapping: Yes Alignment requirement for Surfaces: Yes Device has ECC support: Disabled Device supports Unified Addressing (UVA): Yes Device PCI Domain ID / Bus ID / location ID: 0 / 1 / 0 Compute Mode: < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) > deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 9.1, CUDA Runtime Version = 8.0, NumDevs = 1, Device0 = GeForce GTX 1080 Result = PASS
如果出現相應的顯卡信息表示安裝成功了。