-
Notifications
You must be signed in to change notification settings - Fork 7
/
NerlnetBuild.sh
executable file
·252 lines (229 loc) · 7.79 KB
/
NerlnetBuild.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
#!/bin/bash
NERLNET_LIB_DIR="/usr/local/lib/nerlnet-lib"
NERLNET_DIR=$NERLNET_LIB_DIR/NErlNet
NERLNET_PREFIX="[NERLNET_SCRIPT]"
NERLNET_BUILD_PREFIX="[Nerlnet Build] "
INPUT_DATA_DIR="inputDataDir"
# arguments parsing
# Thanks to https://github.com/matejak/argbash
Branch="master"
JobsNum=4
NerlWolf=OFF
NerlTorch=OFF
help()
{
echo "-------------------------------------" && echo "Nerlnet Build" && echo "-------------------------------------"
echo "Usage:"
echo "--p or --pull Warning! this uses checkout -f! and branch name checkout to branch $Branch and pull the latest"
echo "--w or --wolf wolfram engine workers infra (nerlwolf)"
echo "--t or --torch torch workers infra (nerltorch)"
echo "--j or --jobs number of jobs to cmake build"
echo "--c or --clean remove build directory"
exit 2
}
print()
{
echo "$NERLNET_BUILD_PREFIX $1"
}
gitOperations()
{
echo "$NERLNET_PREFIX Warning! git checkout -f is about to be executed"
sleep 5
echo "$NERLNET_PREFIX Interrupt is possible in the next 10 seconds"
sleep 10
git checkout -f $Branch
git pull origin $Branch
git submodule update --init --recursive
}
die()
{
local _ret="${2:-1}"
test "${_PRINT_HELP:-no}" = yes && print_help >&2
echo "$1" >&2
exit "${_ret}"
}
begins_with_short_option()
{
local first_option all_short_options='hjp'
first_option="${1:0:1}"
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
}
# THE DEFAULTS INITIALIZATION - OPTIONALS
clean_build_directory()
{
echo "Are you sure that you want to remove build directory?"
sleep 1
echo "Intterupt this process is possible with ctrl+c"
echo "Remove build directory in 10 seconds"
sleep 10
rm -rf build
}
print_help()
{
printf 'Usage: %s [-h|--help] [-c|--clean] [-j|--jobs <arg>] [-p|--pull <arg>]\n' "$0"
printf '\t%s\n' "-j, --jobs: number of jobs (default: '4')"
printf '\t%s\n' "-p, --pull: pull from branch (default: '4')"
printf '\t%s\n' "-w, --wolf: wolfram engine extension build (default: 'off')"
printf '\t%s\n' "-t, --torch: torch engine extension build (default: 'off')"
printf '\t%s\n' "-c, --clean: clean build directory (default: 'off')"
}
get_opennn_version_sha()
{
cd $NERLNET_DIR/src_cpp/opennn
echo "$NERLNET_BUILD_PREFIX OpenNN Commit: $(git rev-parse --verify HEAD)"
cd -
}
parse_commandline()
{
while test $# -gt 0
do
_key="$1"
case "$_key" in
-h|--help)
help
exit 0
;;
-h*)
help
exit 0
;;
-c|--clean)
clean_build_directory
exit 0
;;
-c*)
clean_build_directory
exit 0
;;
-w|--wolf)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
NerlWolf="$2"
shift
;;
--wolf=*)
NerlWolf="${_key##--jobs=}"
;;
-w*)
NerlWolf="${_key##-j}"
;;
-t|--torch)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
NerlTorch="$2"
shift
;;
--torch=*)
NerlTorch="${_key##--jobs=}"
;;
-t*)
NerlTorch="${_key##-j}"
;;
-j|--jobs)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
JobsNum="$2"
shift
;;
--jobs=*)
JobsNum="${_key##--jobs=}"
;;
-j*)
JobsNum="${_key##-j}"
;;
-p|--pull)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
Branch="$2"
gitOperations
shift
;;
--pull=*)
Branch="${_key##--pull=}"
gitOperations
;;
-p*)
Branch="${_key##-p}"
gitOperations
;;
*)
_PRINT_HELP=yes die "FATAL ERROR: Got an unexpected argument '$1'" 1
;;
esac
shift
done
}
parse_commandline "$@"
# end of args parsing
get_opennn_version_sha
OPTION="add_compile_definitions(EIGEN_MAX_ALIGN_BYTES=8)"
is_rasp="$(grep -c raspbian /etc/os-release)"
if [ $is_rasp -gt "0" ]; then
echo "$NERLNET_BUILD_PREFIX Detected raspberrypi => setting alignment to 8"
sed -i "s/^.*#\(${OPTION}\)/\1/" CMakeLists.txt
else
echo "$NERLNET_BUILD_PREFIX Using default alignment"
sed -i "s/^.*\(${OPTION}.*$\)/#\1/" CMakeLists.txt
fi
if [[ ! $NerlTorch =~ OFF ]]; then
print "NerlTorch is enabled"
print "Installation directory points to /usr/local/lib/libtorch"
fi
if command -v python3 >/dev/null 2>&1; then
echo "$NERLNET_BUILD_PREFIX Python 3 is installed"
# Generate auto-generated files
set -e
AUTOGENERATED_WORKER_DEFINITIONS_PATH="`pwd`/src_cpp/common/worker_definitions_ag.h"
AUTOGENERATED_WORKER_DEFINITIONS_PATH_HRL="`pwd`/src_erl/NerlnetApp/src/worker_definitions_ag.hrl"
AUTOGENERATED_DC_DEFINITIONS_PATH_HRL="`pwd`/src_erl/NerlnetApp/src/dc_definitions_ag.hrl"
AUTOGENERATED_SOURCE_DEFINITIONS_PATH_HRL="`pwd`/src_erl/NerlnetApp/src/source_definitions_ag.hrl"
AUTOGENERATED_ROUTER_DEFINITIONS_PATH_HRL="`pwd`/src_erl/NerlnetApp/src/router_definitions_ag.hrl"
AUTOGENERATED_LAYERS_TYPE_INDEX_DEFINITIONS_PATH_HRL="`pwd`/src_erl/NerlnetApp/src/Bridge/layers_types_ag.hrl"
AUTOGENERATED_MODELS_TYPES_INDEX_DEFINITIONS_PATH_HRL="`pwd`/src_erl/NerlnetApp/src/Bridge/models_types_ag.hrl"
echo "$NERLNET_BUILD_PREFIX Generate auto-generated files"
python3 src_py/nerlPlanner/CppHeadersExporter.py --output $AUTOGENERATED_WORKER_DEFINITIONS_PATH #--debug
python3 src_py/nerlPlanner/ErlHeadersExporter.py --gen_worker_fields_hrl --output $AUTOGENERATED_WORKER_DEFINITIONS_PATH_HRL #--debug
python3 src_py/nerlPlanner/ErlHeadersExporter.py --gen_dc_fields_hrl --output $AUTOGENERATED_DC_DEFINITIONS_PATH_HRL #--debug
python3 src_py/nerlPlanner/ErlHeadersExporter.py --gen_source_fields_hrl --output $AUTOGENERATED_SOURCE_DEFINITIONS_PATH_HRL #--debug
python3 src_py/nerlPlanner/ErlHeadersExporter.py --gen_router_fields_hrl --output $AUTOGENERATED_ROUTER_DEFINITIONS_PATH_HRL #--debug
python3 src_py/nerlPlanner/ErlHeadersExporter.py --gen_layers_type_hrl --output $AUTOGENERATED_LAYERS_TYPE_INDEX_DEFINITIONS_PATH_HRL #--debug
python3 src_py/nerlPlanner/ErlHeadersExporter.py --gen_models_types_hrl --output $AUTOGENERATED_MODELS_TYPES_INDEX_DEFINITIONS_PATH_HRL #--debug
set +e
else
echo "$NERLNET_BUILD_PREFIX Python 3 is not installed"
echo "Autogenerated files will not be generated"
echo "These files are based on last generated files brought from the repository"
fi
echo "$NERLNET_BUILD_PREFIX Building Nerlnet Library"
echo "$NERLNET_BUILD_PREFIX Cmake command of Nerlnet NIFPP"
set -e
cmake -S . -B build/release -DNERLWOLF=$NerlWolf -DNERLTORCH=$NerlTorch -DCMAKE_BUILD_TYPE=RELEASE
cd build/release
echo "$NERLNET_BUILD_PREFIX Script CWD: $PWD"
echo "$NERLNET_BUILD_PREFIX Build Nerlnet"
echo "Jobs Number: $JobsNum"
make -j$JobsNum
cd ../../
echo "$NERLNET_BUILD_PREFIX Script CWD: $PWD"
set +e
REBAR3_FILE=src_erl/rebar3/rebar3
REBAR3_SYMLINK=/usr/local/bin/rebar3
if [ -f "$REBAR3_FILE" ]; then
echo "$NERLNET_BUILD_PREFIX rebar3 is installed, location: $REBAR3_FILE"
else
echo "$NERLNET_BUILD_PREFIX rebar3 Builder Start"
cd src_erl/rebar3
./bootstrap
cd ../../
echo "$NERLNET_BUILD_PREFIX rebar3 is Built at $REBAR3_FILE"
fi
if [ -f "$REBAR3_SYMLINK" ]; then
echo "$NERLNET_BUILD_PREFIX rebar3 Synlink exists in /usr/local/bin"
else
echo "$NERLNET_BUILD_PREFIX $(tput setaf 1) Please run the following command from Nerlnet library root folder (or install rebar3 to usr/local/bin): $(tput sgr 0)"
echo "$NERLNET_BUILD_PREFIX $(tput setaf 1) sudo ln -s `pwd`/src_erl/rebar3/rebar3 /usr/local/bin/rebar3 $(tput sgr 0)"
echo "$NERLNET_BUILD_PREFIX "
fi
if [ -d "$INPUT_DATA_DIR" ]; then
echo "$NERLNET_BUILD_PREFIX Input data directory of nerlnet is: $INPUT_DATA_DIR"
else
echo "$NERLNET_BUILD_PREFIX Generating $INPUT_DATA_DIR"
mkdir $INPUT_DATA_DIR
echo "$NERLNET_BUILD_PREFIX Add input data to $INPUT_DATA_DIR"
fi