This repository has been archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
install.sh
executable file
·356 lines (303 loc) · 11.2 KB
/
install.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
#!/usr/bin/env bash
export CC=
export CXX=
#compiling option
intel=$1 # compiler icc/gcc
avx512=$2 # AVX512F on/off
#omp=$3 # intel intel/gnu
use_mklml=$3 # intel intel/gnu
skip=$4 # skip openblas, value = noskip/skip, default is noskip
if [[ $skip == 'skip' ]]; then
echo "skip openblas check"
else
#identify user level, and check openblas.For root user, check /opt/OpenBLAS, for none root user, check ~/OpenBLAS
if [ "$(ls -A /opt/OpenBLAS)" ]; then
echo "OpenBLAS is installed in /opt"
else
if [[ $EUID -ne 0 ]]; then
#none root user
RTN=$(echo $LD_LIBRARY_PATH |grep -i openblas)
if [ -z "$RTN" ]; then
echo "OpenBLAS is not installed, or environment is not set"
bash install-openblas.sh
else
echo "OpenBLAS installed."
fi
else
#root user
echo "ERROR: please instal OpenBLAS: bash install-deps , or apt-get install -y libopenblas-dev "
fi
fi
fi
FORCE_AVX512_v=OFF
if [[ $avx512 == 'avx512' ]]; then
FORCE_AVX512_v=ON
else
FORCE_AVX512_v=OFF
fi
USE_MKLML_v=OFF
if [[ $use_mklml == 'mklml' ]]; then
USE_MKLML_v=ON
else
USE_MKLML_v=OFF
fi
WITH_IOMP_v=ON
:<<hallo
if [[ $omp == 'iomp' ]]; then
WITH_IOMP_v=ON
elif [[ $omp == 'gomp' ]]; then
WITH_IOMP_v=OFF
fi
hallo
SKIP_R=0
BATCH_INSTALL=0
THIS_DIR=$(cd $(dirname $0); pwd)
if [[ "$THIS_DIR" == *" "* ]]; then
echo "$THIS_DIR: Torch cannot install to a path containing whitespace.
Please try a different path, one without any spaces."
exit 1
fi
PREFIX=${PREFIX:-"${THIS_DIR}/install"}
TORCH_LUA_VERSION=${TORCH_LUA_VERSION:-"LUAJIT21"} # by default install LUAJIT21
while getopts 'bsh' x; do
case "$x" in
h)
echo "usage: $0
This script will install Torch and related, useful packages into $PREFIX.
-b Run without requesting any user input (will automatically add PATH to shell profile)
-s Skip adding the PATH to shell profile
"
exit 2
;;
b)
BATCH_INSTALL=1
;;
s)
SKIP_RC=1
;;
esac
done
# Scrub an anaconda/conda install, if exists, from the PATH.
# It has a malformed MKL library (as of 1/17/2015)
OLDPATH=$PATH
if [[ $(echo $PATH | grep conda) ]]; then
export PATH=$(echo $PATH | tr ':' '\n' | grep -v "conda[2-9]\?" | uniq | tr '\n' ':')
fi
echo "Prefix set to $PREFIX"
if [[ `uname` == 'Linux' ]]; then
ICC_ON=0
if [[ $intel == 'icc' ]]; then
if [[ `which icc` == '' ]]; then
CC=gcc
else
CC=icc
fi
if [[ `which icpc` == '' ]]; then
CXX=g++
else
CXX=icpc
fi
if [[ `echo $CC | grep icc` != '' ]]; then
ICC_ON=1
fi
else
ICC_ON=0
fi
if [[ $ICC_ON == 1 ]]; then
echo 'using Intel compiler to compile torch'
else
echo 'using GNU compilter to compile torch'
fi
#`./prepare_mklml.sh $ICC_ON`
RETURN_STRING=`./prepare_mklml.sh $ICC_ON $USE_MKLML_v`
export MKLML_ROOT=`echo $RETURN_STRING | awk '{print $1}'`
if [ $USE_MKLML_v == ON ]; then
echo "Path of MKLML_ROOT is:"
else
echo "Path of MKL_ROOT is:"
fi
echo $MKLML_ROOT
MKLML_LIBRARY_PATH=$MKLROOT/lib
MKLML_INCLUDE_PATH=$MKLROOT/include
export CMAKE_LIBRARY_PATH=/opt/OpenBLAS/include:/opt/OpenBLAS/lib:$MKLML_LIBRARY_PATH:$CMAKE_LIBRARY_PATH
export CMAKE_INCLUDE_PATH=/opt/OpenBLAS/include:$MKLML_INCLUDE_PATH:$CMAKE_INCLUDE_PATH
export CMAKE_LIBRARY_PATH=$PREFIX/include:/opt/OpenBLAS/include:$PREFIX/lib:/opt/OpenBLAS/lib:$CMAKE_LIBRARY_PATH
export CMAKE_LIBRARY_PATH=~/OpenBLAS/include:~/OpenBLAS/lib:$CMAKE_LIBRARY_PATH
export LD_LIBRARY_PATH=~/OpenBLAS/include:~/OpenBLAS/lib:$LD_LIBRARY_PATH
fi
export CMAKE_PREFIX_PATH=$PREFIX
if [[ $intel == 'gcc' ]]; then
export CC=`which gcc`
export CXX=`which g++`
fi
git submodule update --init --recursive
# If we're on OS X, use clang
if [[ `uname` == "Darwin" ]]; then
# make sure that we build with Clang. CUDA's compiler nvcc
# does not play nice with any recent GCC version.
export CC=clang
export CXX=clang++
fi
# If we're on Arch linux, use gcc v5
if [[ `uname -a` == *"ARCH"* ]]; then
path_to_gcc5=$(which gcc-5)
if [ -x "$path_to_gcc5" ]; then
export CC="$path_to_gcc5"
else
echo "Warning: GCC v5 not found. CUDA v8 is incompatible with GCC v6, if installation fails, consider running \$ pacman -S gcc5"
fi
fi
echo "Installing Lua version: ${TORCH_LUA_VERSION}"
mkdir -p install
mkdir -p build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX="${PREFIX}" -DCMAKE_BUILD_TYPE=Release -DWITH_${TORCH_LUA_VERSION}=ON 2>&1 >>$PREFIX/install.log || exit 1
(make 2>&1 >>$PREFIX/install.log || exit 1) && (make install 2>&1 >>$PREFIX/install.log || exit 1)
cd ..
# Check for a CUDA install (using nvcc instead of nvidia-smi for cross-platform compatibility)
path_to_nvcc=$(which nvcc)
if [ $? == 1 ]; then { # look for it in /usr/local
if [[ -f /usr/local/cuda/bin/nvcc ]]; then {
path_to_nvcc=/usr/local/cuda/bin/nvcc
}
elif [[ -f /opt/cuda/bin/nvcc ]]; then { # default path for arch
path_to_nvcc=/opt/cuda/bin/nvcc
} fi
} fi
# check if we are on mac and fix RPATH for local install
path_to_install_name_tool=$(which install_name_tool 2>/dev/null)
if [ -x "$path_to_install_name_tool" ]
then
if [ ${TORCH_LUA_VERSION} == "LUAJIT21" ] || [ ${TORCH_LUA_VERSION} == "LUAJIT20" ] ; then
install_name_tool -id ${PREFIX}/lib/libluajit.dylib ${PREFIX}/lib/libluajit.dylib
else
install_name_tool -id ${PREFIX}/lib/liblua.dylib ${PREFIX}/lib/liblua.dylib
fi
fi
if [ -x "$path_to_nvcc" ] || [ -x "$path_to_nvidiasmi" ]
then
echo "Found CUDA on your machine. Installing CMake 3.6 modules to get up-to-date FindCUDA"
cd ${THIS_DIR}/cmake/3.6 && \
(cmake -E make_directory build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX="${PREFIX}" \
&& make install) && echo "FindCuda bits of CMake 3.6 installed" || exit 1
fi
setup_lua_env_cmd=$($PREFIX/bin/luarocks path)
eval "$setup_lua_env_cmd"
echo "$CC"
echo "Installing common Lua packages"
cd ${THIS_DIR}/extra/luafilesystem && $PREFIX/bin/luarocks make rockspecs/luafilesystem-1.6.3-1.rockspec || exit 1
cd ${THIS_DIR}/extra/penlight && $PREFIX/bin/luarocks make penlight-scm-1.rockspec || exit 1
cd ${THIS_DIR}/extra/lua-cjson && $PREFIX/bin/luarocks make lua-cjson-2.1devel-1.rockspec || exit 1
echo "Installing core Torch packages"
cd ${THIS_DIR}/extra/luaffifb && $PREFIX/bin/luarocks make luaffi-scm-1.rockspec || exit 1
cd ${THIS_DIR}/pkg/sundown && $PREFIX/bin/luarocks make rocks/sundown-scm-1.rockspec || exit 1
cd ${THIS_DIR}/pkg/cwrap && $PREFIX/bin/luarocks make rocks/cwrap-scm-1.rockspec || exit 1
cd ${THIS_DIR}/pkg/paths && $PREFIX/bin/luarocks make rocks/paths-scm-1.rockspec || exit 1
cd ${THIS_DIR}/pkg/torch && $PREFIX/bin/luarocks make WITH_IOMP=$WITH_IOMP_v FORCE_AVX512=$FORCE_AVX512_v USE_MKLML=$USE_MKLML_v rocks/torch-scm-1.rockspec || exit 1
cd ${THIS_DIR}/pkg/dok && $PREFIX/bin/luarocks make rocks/dok-scm-1.rockspec || exit 1
cd ${THIS_DIR}/exe/trepl && $PREFIX/bin/luarocks make trepl-scm-1.rockspec || exit 1
cd ${THIS_DIR}/pkg/sys && $PREFIX/bin/luarocks make sys-1.1-0.rockspec || exit 1
cd ${THIS_DIR}/pkg/xlua && $PREFIX/bin/luarocks make xlua-1.0-0.rockspec || exit 1
cd ${THIS_DIR}/extra/nn && $PREFIX/bin/luarocks make FORCE_AVX512=$FORCE_AVX512_v rocks/nn-scm-1.rockspec || exit 1
cd ${THIS_DIR}/extra/mkltorch && $PREFIX/bin/luarocks make FORCE_AVX512=$FORCE_AVX512_v mkltorch-scm-1.rockspec || exit 1
cd ${THIS_DIR}/extra/mklnn && $PREFIX/bin/luarocks make FORCE_AVX512=$FORCE_AVX512_v mklnn-scm-1.rockspec || exit 1
cd ${THIS_DIR}/extra/graph && $PREFIX/bin/luarocks make rocks/graph-scm-1.rockspec || exit 1
cd ${THIS_DIR}/extra/nngraph && $PREFIX/bin/luarocks make nngraph-scm-1.rockspec || exit 1
cd ${THIS_DIR}/pkg/image && $PREFIX/bin/luarocks make image-1.1.alpha-0.rockspec || exit 1
cd ${THIS_DIR}/pkg/optim && $PREFIX/bin/luarocks make optim-1.0.5-0.rockspec || exit 1
if [ -x "$path_to_nvcc" ]
then
echo "Found CUDA on your machine. Installing CUDA packages"
cd ${THIS_DIR}/extra/cutorch && $PREFIX/bin/luarocks make rocks/cutorch-scm-1.rockspec || exit 1
cd ${THIS_DIR}/extra/cunn && $PREFIX/bin/luarocks make rocks/cunn-scm-1.rockspec || exit 1
fi
# Optional packages
echo "Installing optional Torch packages"
cd ${THIS_DIR}/pkg/gnuplot && $PREFIX/bin/luarocks make rocks/gnuplot-scm-1.rockspec
cd ${THIS_DIR}/exe/env && $PREFIX/bin/luarocks make env-scm-1.rockspec
cd ${THIS_DIR}/extra/nnx && $PREFIX/bin/luarocks make nnx-0.1-1.rockspec
cd ${THIS_DIR}/exe/qtlua && $PREFIX/bin/luarocks make rocks/qtlua-scm-1.rockspec
cd ${THIS_DIR}/pkg/qttorch && $PREFIX/bin/luarocks make rocks/qttorch-scm-1.rockspec
cd ${THIS_DIR}/extra/threads && $PREFIX/bin/luarocks make rocks/threads-scm-1.rockspec
cd ${THIS_DIR}/extra/argcheck && $PREFIX/bin/luarocks make rocks/argcheck-scm-1.rockspec
# Optional CUDA packages
if [ -x "$path_to_nvcc" ]
then
echo "Found CUDA on your machine. Installing optional CUDA packages"
cd ${THIS_DIR}/extra/cudnn && $PREFIX/bin/luarocks make cudnn-scm-1.rockspec
fi
export PATH=$OLDPATH # Restore anaconda distribution if we took it out.
# Add C libs to LUA_CPATH
if [[ `uname` == "Darwin" ]]; then
CLIB_LUA_CPATH=$PREFIX/lib/?.dylib
else
CLIB_LUA_CPATH=$PREFIX/lib/?.so
fi
cat <<EOF >$PREFIX/bin/torch-activate
$setup_lua_env_cmd
export PATH=$PREFIX/bin:\$PATH
export LD_LIBRARY_PATH=$PREFIX/lib:\$LD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=$PREFIX/lib:\$DYLD_LIBRARY_PATH
export LUA_CPATH='$CLIB_LUA_CPATH;'\$LUA_CPATH
EOF
chmod +x $PREFIX/bin/torch-activate
if [[ $SKIP_RC == 1 ]]; then
exit 0
fi
RC_FILE=0
DEFAULT=yes
if [[ $(echo $SHELL | grep bash) ]]; then
RC_FILE=$HOME/.bashrc
elif [[ $(echo $SHELL | grep zsh) ]]; then
RC_FILE=$HOME/.zshrc
else
echo "
Non-standard shell $SHELL detected. You might want to
add the following lines to your shell profile:
. $PREFIX/bin/torch-activate
"
fi
if [[ $skip == 'skip' ]]; then
BATCH_INSTALL=1
RC_FILE=
fi
WRITE_PATH_TO_PROFILE=0
if [[ $BATCH_INSTALL == 0 ]]; then
if [ -f "$RC_FILE" ]; then
echo "
Do you want to automatically prepend the Torch install location
to PATH and LD_LIBRARY_PATH in your $RC_FILE? (yes/no)
[$DEFAULT] >>> "
read input
if [[ $input == "" ]]; then
input=$DEFAULT
fi
is_yes() {
yesses={y,Y,yes,Yes,YES}
if [[ $yesses =~ $1 ]]; then
echo 1
fi
}
if [[ $(is_yes $input) ]]; then
WRITE_PATH_TO_PROFILE=1
fi
fi
else
if [[ "$RC_FILE" ]]; then
WRITE_PATH_TO_PROFILE=1
fi
fi
WRITE_PATH_TO_PROFILE=0
if [[ $WRITE_PATH_TO_PROFILE == 1 ]]; then
echo "
. $PREFIX/bin/torch-activate" >> "$RC_FILE"
echo "
. $PREFIX/bin/torch-activate" >> "$HOME"/.profile
else
echo "
Not updating your shell profile.
You might want to
add the following lines to your shell profile:
. $PREFIX/bin/torch-activate
"
fi