forked from deeplearning4j/deeplearning4j
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-dl4j-stack.sh
executable file
·268 lines (249 loc) · 6.59 KB
/
build-dl4j-stack.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
#!/bin/bash -e
# helper function that ensures cmd returns 0 exit code
function checkexit {
"$@"
local status=$?
if [ $status -ne 0 ]; then
echo "error with $1" >&2
exit 1
fi
return $status
}
function maybeUpdateRepo {
if [ $UPDATE_REPOS == "true" ]; then
# are there uncommited changes in the repo?
if ! (git diff-index --quiet HEAD --) then
echo "Some uncommited changes found in this repo! Stashing..."
git stash
fi
git pull
fi
}
# check incoming parameters
while [[ $# -gt 1 ]]
do
key="$1"
#Build type (release/debug), packaging type, chip: cpu,gpu,lib type (static/dynamic)
case $key in
-b|--build-type)
BUILD="$2"
shift # past argument
;;
-p|--packaging)
PACKAGING="$2"
shift # past argument
;;
-c|--chip)
CHIP="$2"
shift # past argument
;;
-cc|--compute)
COMPUTE="$2"
shift # past argument
;;
-a|--march)
NATIVE="$2"
shift # past argument
;;
-l|--libtype)
LIBTYPE="$2"
shift # past argument
;;
--scalav)
SCALAV="$2"
shift # past argument
;;
-s|--shallow)
SHALLOW="YES"
;;
-r|--repostrategy)
REPO_STRATEGY="$2"
shift # past argument
;;
--testnd4j)
TEST_ND4J="YES"
;;
--testdatavec)
TEST_DATAVEC="YES"
;;
--testdl4j)
TEST_DL4J="YES"
;;
--mvnopts)
MVN_OPTS="$2"
shift
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
# default for chip
if [ -z "$CHIP" ]; then
# test for cuda libraries
if (ldconfig -p | grep -q libcuda\.so) then
CHIP="cuda"
else
CHIP="cpu"
fi
fi
# adjust scala versions
if [ "$SCALAV" == "2.10" ]; then
SCALA="2.10.6"
fi
# adjust scala versions
if [ "$SCALAV" == "2.11" ]; then
SCALA="2.11.7"
fi
# set git cloning to a shallow depth if the option says so
if [ -z $SHALLOW ]; then
GIT_CLONE="git clone"
else
GIT_CLONE="git clone --depth 1"
fi
# Report argument values
echo BUILD = "${BUILD}"
echo PACKAGING = "${PACKAGING}"
echo CHIP = "${CHIP}"
echo COMPUTE = "${COMPUTE}"
echo NATIVE = "${NATIVE}"
echo LIBTYPE = "${LIBTYPE}"
echo SCALAV = "${SCALAV}"
echo SHALLOW = "${SHALLOW}"
echo REPO_STRATEGY = "${REPO_STRATEGY}"
echo TEST_ND4J = "${TEST_ND4J}"
echo TEST_DATAVEC = "${TEST_DATAVEC}"
echo TEST_DL4J = "${TEST_DL4J}"
echo MVN_OPTS = "${MVN_OPTS}"
###########################
# Script execution starts #
###########################
pushd ..
# removes lingering snapshot artifacts from existing maven cache to ensure a
# clean build
JAVA_PROJECTS="nd4j datavec deeplearning4j"
for dirName in $JAVA_PROJECTS; do
if [ -d "$dirName" ]; then
pushd "$dirName"
mvn dependency:purge-local-repository -DreResolve=false
popd
fi
done
# What to do with existing repos
case $REPO_STRATEGY in
"delete")
DELETE_REPOS="true"
UPDATE_REPOS=""
;;
"update")
UPDATE_REPOS="true"
DELETE_REPOS=""
;;
*) # unknown : do nothing
UPDATE_REPOS=""
DELETE_REPOS=""
;;
esac
# removes any existing repositories to ensure a clean build
if ! [ -z "$DELETE_REPOS" ]; then
PROJECTS="libnd4j nd4j datavec deeplearning4j"
for dirName in $PROJECTS; do
find . -maxdepth 1 -iname "$dirName" -exec rm -rf "{}" \;
done
fi
# compile libnd4j
if ! [ -z $DELETE_REPOS ] || ! [ -d libnd4j ]; then
checkexit $GIT_CLONE https://github.com/deeplearning4j/libnd4j.git
fi
pushd libnd4j
maybeUpdateRepo
if [ -z "$NATIVE" ]; then
checkexit bash buildnativeoperations.sh "$@" -a native
else
checkexit bash buildnativeoperations.sh "$@"
fi
if [ "$CHIP" == "cuda" ]; then
if [ -z "$COMPUTE" ]; then
checkexit bash buildnativeoperations.sh -c cuda
else
checkexit bash buildnativeoperations.sh -c cuda -cc "$COMPUTE"
fi
fi
LIBND4J_HOME=$(pwd)
export LIBND4J_HOME
popd
# build and install nd4j to maven locally
if ! [ -z $DELETE_REPOS ] || ! [ -d nd4j ]; then
checkexit $GIT_CLONE https://github.com/deeplearning4j/nd4j.git
fi
if [ -z "$TEST_ND4J" ]; then
ND4J_OPTIONS="-DskipTests"
else
ND4J_OPTIONS=""
fi
pushd nd4j
maybeUpdateRepo
if [ "$CHIP" == "cpu" ]; then
checkexit bash buildmultiplescalaversions.sh clean install -Dmaven.javadoc.skip=true -pl '!:nd4j-cuda-8.0,!:nd4j-cuda-8.0-platform,!:nd4j-tests' $ND4J_OPTIONS $MVN_OPTS
else
checkexit bash buildmultiplescalaversions.sh clean install -Dmaven.javadoc.skip=true $ND4J_OPTIONS $MVN_OPTS
fi
popd
# build and install datavec
if ! [ -z $DELETE_REPOS ] || ! [ -d datavec ]; then
checkexit $GIT_CLONE https://github.com/deeplearning4j/datavec.git
fi
if [ -z "$TEST_DATAVEC" ]; then
DATAVEC_OPTIONS="-DskipTests"
else
if [ "$CHIP" == "cuda" ]; then
DATAVEC_OPTIONS="-Ptest-nd4j-cuda-8.0"
else
DATAVEC_OPTIONS="-Ptest-nd4j-native"
fi
fi
pushd datavec
maybeUpdateRepo
if [ "$SCALAV" == "" ]; then
checkexit bash buildmultiplescalaversions.sh clean install -Dmaven.javadoc.skip=true $DATAVEC_OPTIONS $MVN_OPTS
else
checkexit mvn clean install -Dmaven.javadoc.skip=true -Dscala.binary.version="$SCALAV" -Dscala.version="$SCALA" $DATAVEC_OPTIONS $MVN_OPTS
fi
popd
# build and install deeplearning4j
if ! [ -z $DELETE_REPOS ] || ! [ -d deeplearning4j ]; then
checkexit $GIT_CLONE https://github.com/deeplearning4j/deeplearning4j.git
fi
if [ -z "$TEST_DL4J" ]; then
DL4J_OPTIONS="-DskipTests"
else
if [ "$CHIP" == "cuda" ]; then
DL4J_OPTIONS="-Ptest-nd4j-cuda-8.0"
else
DL4J_OPTIONS="-Ptest-nd4j-native"
fi
fi
pushd deeplearning4j
maybeUpdateRepo
if [ $DELETE_REPOS == "true" ]; then
# reset the working diectory to the latest version of the tracking branch
git remote update
TRACKING_BRANCH=$(git rev-parse --abbrev-ref --symbolic-full-name @{u})
git reset --hard $TRACKING_BRANCH
fi
if [ "$SCALAV" == "" ]; then
if [ "$CHIP" == "cpu" ]; then
checkexit bash buildmultiplescalaversions.sh clean install -Dmaven.javadoc.skip=true -pl '!:deeplearning4j-cuda-8.0' $DL4J_OPTIONS $MVN_OPTS
else
checkexit bash buildmultiplescalaversions.sh clean install -Dmaven.javadoc.skip=true $DL4J_OPTIONS $MVN_OPTS
fi
else
if [ "$CHIP" == "cpu" ]; then
checkexit mvn clean install -Dmaven.javadoc.skip=true -Dscala.binary.version="$SCALAV" -Dscala.version="$SCALA" -pl '!:deeplearning4j-cuda-8.0' $DL4J_OPTIONS $MVN_OPTS
else
checkexit mvn clean install -Dmaven.javadoc.skip=true -Dscala.binary.version="$SCALAV" -Dscala.version="$SCALA" $DL4J_OPTIONS $MVN_OPTS
fi
fi
popd
popd