-
Notifications
You must be signed in to change notification settings - Fork 3
/
install_cuda.sh
200 lines (173 loc) · 7.24 KB
/
install_cuda.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
cuda() {
read -n1 -r -p "Install CUDA. press ENTER to continue!" ENTER
if [[ -f installers/${CUDA} ]]; then
echo "[AUTO-CUDA] Installing ${CUDA}.."
sudo sh installers/${CUDA} --override --silent --toolkit
echo "[AUTO-CUDA] CUDA Installation done."
echo " "
read -p "Do you have CUDA update patch? [y/N]: " UPDATE
UPDATE="${UPDATE:=N}"
if [[ $UPDATE = "N" ]] || [[ $UPDATE = "n" ]]; then
cudnn
elif [[ $UPDATE = "Y" ]] || [[ $UPDATE = "y" ]]; then
read -p "How many CUDA update patch do you have? " NO_PATCH
COUNTER=1
while [ $COUNTER -le $NO_PATCH ]; do
echo 'Here the content of "installers" directory:'
ls installers/
read -p "Please specify CUDA update patch no. $COUNTER: " CUPDATE
sudo sh installers/${CUPDATE}
let COUNTER=COUNTER+1
done
cudnn
else
echo "[AUTO-CUDA] Input invalid."
echo "[AUTO-CUDA] Installation aborted."
exit
fi
else
echo "[AUTO-CUDA] CUDA installers not found."
echo "[AUTO-CUDA] Installation aborted"
exit
fi
}
cudnn() {
read -n1 -r -p "Install CUDNN. press ENTER to continue!" ENTER
if [[ -f installers/${CUDNN} ]]; then
echo "[AUTO-CUDA] Installing ${CUDNN}.."
mkdir installers/cudnn
tar -xzvf installers/${CUDNN} -C installers/cudnn --strip-components=1
sudo cp installers/cudnn/include/cudnn.h /usr/local/cuda-10.1/include
sudo cp installers/cudnn/lib64/libcudnn* /usr/local/cuda-10.1/lib64
sudo chmod a+r /usr/local/cuda-10.1/include/cudnn.h /usr/local/cuda-10.1/lib64/libcudnn*
echo "[AUTO-CUDA] Cofiguring cuda in linux enviroment.."
read -p "Have you set the cuda in ~./bashrc? [y/N]: " UPDATE_ENV
UPDATE_ENV="${UPDATE_ENV:=N}"
if [[ $UPDATE_ENV = "N" ]] || [[ $UPDATE_ENV = "n" ]]; then
echo "[AUTO-CUDA] Backup linux enviroment before add cuda enviroment.."
cp ~/.bashrc ~/.bashrc.orig.cuda
echo " " >> ~/.bashrc
echo '# CUDA Enviroment' >> ~/.bashrc
echo 'export PATH=/usr/local/cuda-10.1/bin${PATH:+:${PATH}}$' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}' >> ~/.bashrc
echo 'export CUDA_HOME="/usr/local/cuda"' >> ~/.bashrc
nccl
elif [[ $UPDATE_ENV = "Y" ]] || [[ $UPDATE_ENV = "y" ]]; then
nccl
else
echo "[AUTO-CUDA] Input invalid."
echo "[AUTO-CUDA] Installation aborted."
exit
fi
else
echo "[AUTO-CUDA] CUDNN installers not found."
echo "[AUTO-CUDA] CUDNN installation failed"
exit
fi
}
nccl() {
read -n1 -r -p "Install NCCL. press ENTER to continue!" ENTER
if [[ -f installers/${NCCL} ]]; then
echo "[AUTO-CUDA] Installing ${NCCL}.."
mkdir installers/nccl
tar Jxvf installers/${NCCL} -C installers/nccl/ --strip-components=1
sudo cp installers/nccl/lib/libnccl* /usr/local/cuda-10.1/lib64/
sudo cp installers/nccl/include/nccl.h /usr/local/cuda-10.1/include/
clear_pkg
else
echo "[AUTO-CUDA] NCCL installers not found."
echo "[AUTO-CUDA] NCCL installation failed"
exit
fi
}
clear_pkg(){
read -n1 -r -p "Clear installation packages. press ENTER to continue!" ENTER
if [[ -d installers/nccl ]] && [[ -d installers/cudnn ]]; then
echo "[AUTO-CUDA] Deleting installation packages.."
sudo rm -r installers/cudnn
sudo rm -r installers/nccl
else
echo "[AUTO-CUDA] NCCL installers not found."
echo "[AUTO-CUDA] NCCL installation failed"
exit
fi
}
echo "==============================================================================================="
echo "Welcome to Cuda Installers"
echo "==============================================================================================="
echo "WARNING! Please run this script as user not root."
echo " "
echo "This process will be install the latest cuda and tensorflow."
echo 'It require "installers file" and put it in "installers directory". Here is the installers list: '
echo " + Latest CUDA installers [ex: cuda_10.1.105_418.39_linux.run]."
echo " + Latest CUDNN library [ex: cudnn-10.1-linux-x64-v7.6.5.32.tgz]."
echo " + Latest NCCL installer [ex: nccl_2.8.3-1+cuda10.1_x86_64.txz]."
echo " "
echo 'If you have the "cuda toolkit update patch" put in "installers" directory too!'
echo " "
echo 'Have you put it all in "installers" and "installers/update-toolkit-patch" directory?'
read -n1 -r -p "Press ENTER to continue or CTRL + C to cancel!" ENTER
echo " "
echo 'Here the content of "installers" directory:'
ls installers/
echo " "
read -n1 -r -p "Check nvidia driver is installed correctly. press ENTER to continue!" ENTER
ubuntu-drivers devices
lsmod | grep nvidia
echo "[AUTO-CUDA] Checking CUDA in your computer.."
if [[ -L /usr/local/cuda ]]; then
echo "[AUTO-CUDA] CUDA has installed in your system."
read -p "Still want to continue the process or add more cuda version? [y/N]: " FORCE
FORCE="${FORCE:=N}"
if [[ $FORCE = "N" ]] || [[ $FORCE = "n" ]]; then
echo "[AUTO-CUDA] Clean previous CUDA Installation if you want to re-install!"
echo "[AUTO-CUDA] CUDA installation canceled."
echo " "
echo "==============================================================================================="
echo "CUDA Post Installation Notes"
echo "==============================================================================================="
echo "Run this command to delete exisisting CUDA version."
echo "$ sudo rm -r /usr/local/cuda*"
echo " "
echo "==============================================================================================="
echo " "
exit
elif [[ $FORCE = "Y" ]] || [[ $FORCE = "y" ]]; then
read -p "Please specify CUDA installers file. [Defaut: cuda_10.1.105_418.39_linux.run]:" CUDA
CUDA="${CUDA:=cuda_10.1.105_418.39_linux.run}"
read -p "Please specify CDNN installers file. [Defaut: cudnn-10.1-linux-x64-v7.6.5.32.tgz]:" CUDNN
CUDNN="${CUDNN:=cudnn-10.1-linux-x64-v7.6.5.32.tgz}"
read -p "Please specify NCCL installers file. [Defaut: nccl_2.8.3-1+cuda10.1_x86_64.txz]:" NCCL
NCCL="${NCCL:=nccl_2.8.3-1+cuda10.1_x86_64.txz}"
echo " "
cuda
else
echo "[AUTO-CUDA] Input invalid."
echo "[AUTO-CUDA] Installation aborted."
exit
fi
else
read -p "Please specify CUDA installers file. [Defaut: cuda_10.1.105_418.39_linux.run]:" CUDA
CUDA="${CUDA:=cuda_10.1.105_418.39_linux.run}"
read -p "Please specify CDNN installers file. [Defaut: cudnn-10.1-linux-x64-v7.6.5.32.tgz]:" CUDNN
CUDNN="${CUDNN:=cudnn-10.1-linux-x64-v7.6.5.32.tgz}"
read -p "Please specify NCCL installers file. [Defaut: nccl_2.8.3-1+cuda10.1_x86_64.txz]:" NCCL
NCCL="${NCCL:=nccl_2.8.3-1+cuda10.1_x86_64.txz}"
echo " "
cuda
fi
sudo ldconfig
echo "[AUTO-CUDA] CUDA Installation done."
echo " "
echo "==============================================================================================="
echo "CUDA Post Installation Notes"
echo "==============================================================================================="
echo "Load bash profile or bashrc configuration: "
echo " $ source ~/.bashrc"
echo " $ sudo ldconfig"
echo " "
echo "Verify CUDA in linux enviroment: "
echo ' $ echo $CUDA_HOME'
echo "==============================================================================================="
echo " "