forked from torch/distro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-nv.sh
executable file
·287 lines (229 loc) · 9.5 KB
/
install-nv.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
#!/usr/bin/env bash
SKIP_RC=0
BATCH_INSTALL=0
THIS_DIR=$(cd $(dirname $0); pwd)
PREFIX=${PREFIX:-"${THIS_DIR}/install"}
TH_INSTALL_PREFIX=${PREFIX}
BUILD_DIR=${THIS_DIR}/build
TORCH_LUA_VERSION=${TORCH_LUA_VERION:-"LUAJIT21"} # by default install LUAJIT21
while getopts 'absvnh:' x; do
case "$x" in
a)
export CUDA_ARCH_NAME=All
;;
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
-v Verbose execution
"
exit 2
;;
b)
BATCH_INSTALL=1
;;
v)
export IVERBOSE="--verbose"
;;
n)
TORCH_LUA_VERSION="NATIVE"
;;
s)
SKIP_RC=1
;;
esac
done
# Scrub an anaconda install, if exists, from the PATH.
# It has a malformed MKL library (as of 1/17/2015)
OLDPATH=$PATH
if [[ $(echo $PATH | grep anaconda) ]]; then
export PATH=$(echo $PATH | tr ':' '\n' | grep -v "anaconda/bin" | grep -v "anaconda/lib" | grep -v "anaconda/include" | uniq | tr '\n' ':')
fi
echo "Prefix set to $PREFIX"
if [[ `uname` == 'Linux' ]]; then
export CMAKE_LIBRARY_PATH=/opt/OpenBLAS/include:/opt/OpenBLAS/lib:$CMAKE_LIBRARY_PATH
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
echo "Installing Lua version: ${TORCH_LUA_VERSION}"
mkdir -p ${PREFIX}
mkdir -p ${BUILD_DIR}
cd ${BUILD_DIR}
echo "Configuring Lua version: ${TORCH_LUA_VERSION}"
(cmake ${THIS_DIR} -DCMAKE_INSTALL_PREFIX="${PREFIX}" -DCMAKE_BUILD_TYPE=Release -DWITH_${TORCH_LUA_VERSION}=ON || exit 1)
if [[ "$TORCH_LUA_VERSION" == "NATIVE" ]]; then
# echo "Using NATIVE Lua version:"
export LUAROCKS="luarocks --tree="$PREFIX/" $IVERBOSE"
export LUA=luajit
else
echo "Installing Lua version: ${TORCH_LUA_VERSION}"
# (cmake ${THIS_DIR} -DCMAKE_INSTALL_PREFIX="${PREFIX}" -DCMAKE_BUILD_TYPE=Release -DWITH_${TORCH_LUA_VERSION}=ON || exit 1)
(make 2>&1 || exit 1) && (make install 2>&1 || exit 1)
cd ..
export LUAROCKS="${PREFIX}/bin/luarocks --tree="${PREFIX}" $IVERBOSE"
fi
# Done installing LuaRocks
echo "Using luarocks: ${LUAROCKS}"
# echo "LUA_PATH: ${LUA_PATH}"
export CMAKE_PREFIX_PATH=${PREFIX}
export CMAKE_INSTALL_PREFIX=${PREFIX}
export CMAKE_INSTALL_SUBDIR="share/cmake/torch"
# Check for a CUDA install (using nvcc instead of nvidia-smi for cross-platform compatibility)
path_to_nvcc=$(which nvcc)
path_to_nvidiasmi=$(which nvidia-smi)
if [ -x "$path_to_nvcc" ] || [ -x "$path_to_nvidiasmi" ]
then
echo "Found CUDA on your machine. Installing FindCUDA module to work around .cu bug in CMake 2.8/3.5"
cd ${THIS_DIR}/extra/FindCUDA && \
(cmake -E make_directory build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}" -DCMAKE_INSTALL_SUBDIR="${CMAKE_INSTALL_SUBDIR}" && make install) \
&& echo "FindCuda installed" || exit 1
fi
#
# lua/luajit do not accept --tree option, set environment
#
fix_path() {
$LUAROCKS path -bin | sed "s@$1@$2@ig"
}
setup_lua_env_cmd=`fix_path "${HOME}/.luarocks" "$PREFIX"`
eval "$setup_lua_env_cmd"
# end environment setup
echo "Installing common Lua packages into ${TH_INSTALL_PREFIX}"
cd ${THIS_DIR}/extra/luafilesystem && $LUAROCKS make rockspecs/luafilesystem-1.6.3-1.rockspec || exit 1
cd ${THIS_DIR}/extra/penlight && $LUAROCKS make || exit 1
cd ${THIS_DIR}/extra/lua-cjson && $LUAROCKS make || exit 1
# 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
echo "Installing core Torch packages"
cd ${THIS_DIR}/pkg/sundown && $LUAROCKS make rocks/sundown-scm-1.rockspec || exit 1
cd ${THIS_DIR}/pkg/cwrap && $LUAROCKS make rocks/cwrap-scm-1.rockspec || exit 1
cd ${THIS_DIR}/pkg/paths && $LUAROCKS make rocks/paths-scm-1.rockspec || exit 1
cd ${THIS_DIR}/pkg/torch && $LUAROCKS make rocks/torch-scm-1.rockspec || exit 1
cd ${THIS_DIR}/pkg/dok && $LUAROCKS make rocks/dok-scm-1.rockspec || exit 1
cd ${THIS_DIR}/exe/trepl && $LUAROCKS make || exit 1
cd ${THIS_DIR}/pkg/sys && $LUAROCKS make sys-1.1-0.rockspec || exit 1
cd ${THIS_DIR}/pkg/xlua && $LUAROCKS make xlua-1.0-0.rockspec || exit 1
cd ${THIS_DIR}/extra/luaffifb && $LUAROCKS make luaffi-scm-1.rockspec || exit 1
cd ${THIS_DIR}/extra/nn && $LUAROCKS make rocks/nn-scm-1.rockspec || exit 1
cd ${THIS_DIR}/extra/graph && $LUAROCKS make rocks/graph-scm-1.rockspec || exit 1
cd ${THIS_DIR}/extra/nngraph && $LUAROCKS make || exit 1
cd ${THIS_DIR}/pkg/image && $LUAROCKS make image-1.1.alpha-0.rockspec || exit 1
cd ${THIS_DIR}/pkg/optim && $LUAROCKS make optim-1.0.5-0.rockspec || exit 1
if [ -x "$path_to_nvcc" ] || [ -x "$path_to_nvidiasmi" ]
then
echo "Found CUDA on your machine. Installing CUDA packages"
cd ${THIS_DIR}/extra/cutorch && $LUAROCKS make rocks/cutorch-scm-1.rockspec || exit 1
cd ${THIS_DIR}/extra/cunn && $LUAROCKS make rocks/cunn-scm-1.rockspec || exit 1
fi
# Optional packages
echo "Installing optional Torch packages"
cd ${THIS_DIR}/pkg/gnuplot && $LUAROCKS make rocks/gnuplot-scm-1.rockspec || exit 1
cd ${THIS_DIR}/exe/env && $LUAROCKS make || exit 1
cd ${THIS_DIR}/extra/nnx && $LUAROCKS make nnx-0.1-1.rockspec || exit 1
# cd ${THIS_DIR}/exe/qtlua && $LUAROCKS make rocks/qtlua-scm-1.rockspec || exit 1
# cd ${THIS_DIR}/pkg/qttorch && $LUAROCKS make rocks/qttorch-scm-1.rockspec || exit 1
cd ${THIS_DIR}/extra/threads && $LUAROCKS make rocks/threads-scm-1.rockspec || exit 1
cd ${THIS_DIR}/extra/graphicsmagick && $LUAROCKS make graphicsmagick-1.scm-0.rockspec || exit 1
cd ${THIS_DIR}/extra/argcheck && $LUAROCKS make rocks/argcheck-scm-1.rockspec || exit 1
cd ${THIS_DIR}/extra/audio && $LUAROCKS make audio-0.1-0.rockspec || exit 1
cd ${THIS_DIR}/extra/fftw3 && $LUAROCKS make rocks/fftw3-scm-1.rockspec || exit 1
cd ${THIS_DIR}/extra/signal && $LUAROCKS make rocks/signal-scm-1.rockspec || exit 1
#Support for Protobuf
cd ${THIS_DIR}/extra/lua-pb && $LUAROCKS make lua-pb-scm-0.rockspec || exit 1
# Lua Wrapper for LMDB, latest from github (lightningmdb)
cd ${THIS_DIR}/extra/lmdb && $LUAROCKS make LMDB_INCDIR=/usr/include LMDB_LIBDIR=/usr/lib/x86_64-linux-gnu lightningmdb-scm-1.rockspec || exit 1
cd ${THIS_DIR}/extra/totem && $LUAROCKS make rocks/totem-0-0.rockspec || exit 1
#HDF5 filesystem support
cd ${THIS_DIR}/extra/hdf5 && $LUAROCKS make hdf5-0-0.rockspec || exit 1
#NCCL (experimental) support
cd ${THIS_DIR}/extra/nccl && $LUAROCKS make nccl-scm-1.rockspec || exit 1
# Optional CUDA packages
if [ -x "$path_to_nvcc" ]
then
echo "Found CUDA on your machine. Installing optional CUDA packages"
cd ${THIS_DIR}/extra/cudnn && $LUAROCKS make cudnn-scm-1.rockspec || exit 1
# cd ${THIS_DIR}/extra/cunnx && $LUAROCKS make rocks/cunnx-scm-1.rockspec || exit 1
fi
export PATH=$OLDPATH # Restore anaconda distribution if we took it out.
if [[ `uname` == "Darwin" ]]; then
cd ${THIS_DIR}/extra/iTorch && $LUAROCKS make OPENSSL_DIR=/usr/local/opt/openssl/
else
cd ${THIS_DIR}/extra/iTorch && $LUAROCKS make
fi
if [[ $SKIP_RC == 1 ]]; then
exit 0
fi
cat <<EOF >$PREFIX/bin/torch-activate
$setup_lua_env_cmd
export PATH=$PREFIX/bin:\$PATH
export LD_LIBRARY_PATH=$PREFIX/lib:$PREFIX/local/lib:\$LD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=$PREFIX/lib:$PREFIX/local/lib:\$DYLD_LIBRARY_PATH
export LUA_CPATH="$PREFIX/lib/?.so;$PREFIX/local/lib/?.so;${LUA_CPATH}"
EOF
chmod +x $PREFIX/bin/torch-activate
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
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
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