天天看點

Ubuntu 16 安裝 torch7 、顯示卡驅動、CUDA、CUDNN

此步驟安裝的是 pytorch 的前身 torch7

硬體環境

Ubuntu 16.04

2080ti * 1

apt 安裝 git

(建議執行)

apt

換國内源,極大提升

apt install

速度:

ubuntu、conda、pip 換北外源(北京外國語大學開源軟體鏡像站)

sudo apt install git

(建議執行)

git

挂代理或鏡像站:

git clone一個github上的倉庫,太慢,經常連接配接失敗,但是github官網流暢通路,為什麼?

安裝 torch

注:此步驟最好在未安裝驅動、

CUDA

CUDNN

時進行,否則 bug、沖突多多多多多多多。

重要:首先将

export TORCH_CUDA_ARCH_LIST="6.0"

寫入

~/.bashrc

末尾,此環境變量在于限制硬體算力至

CUDA

版本對應上限(

CUDA8.0

對應

6.0

torch

安裝指令參考官方文檔即可(不用

sudo

):

git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch; bash install-deps;
./install.sh
source ~/.bashrc
           

注:解除安裝

torch

隻要

rm -rf ~/torch

即可,但同時也建議把

.bashrc

末尾的

torch

環境變量删除。

如果已安裝驅動、

CUDA

CUDNN

,建議解除安裝後再安裝

torch

,否則有硬體算力、各種版本沖突。

安裝(解除安裝)顯示卡驅動

推薦在 安裝(解除安裝) CUDA

同樣推薦 下載下傳 後安裝;

此例中使用的是

cuda_8.0.44_linux.run

安裝指令:

sudo sh cuda_8.0.44_linux.run

安裝後在

~/.bashrc

裡添加以下兩行(配置環境變量):

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

儲存退出後執行

source ~/.bashrc

激活環境變量。

解除安裝指令:

cd /usr/local/cuda-8.0/bin/
sudo ./uninstall_cuda_8.0.pl
           

安裝(解除安裝)CUDNN

同樣推薦 下載下傳(需簡單注冊登入)後安裝;

此例中使用的是

libcudnn7_7.1.3.16-1+cuda8.0_amd64.deb

安裝指令:

sudo dpkg -i libcudnn7_7.1.3.16-1+cuda8.0_amd64.deb
sudo cp /usr/local/cuda-8.0/lib64/libcudart.so.8.0 /usr/local/lib/libcudart.so.8.0 && sudo ldconfig
           

解除安裝指令:

sudo rm -rf /usr/local/cuda/include/cudnn.h
sudo rm -rf /usr/local/cuda/lib64/libcudnn*
           

安裝 torch 庫

# 不用 sudo 
luarocks install cudnn
luarocks install cutorch
luarocks install tds
luarocks install gnuplot
luarocks install xlua
...