-
Notifications
You must be signed in to change notification settings - Fork 16
/
configure
executable file
·216 lines (196 loc) · 6.48 KB
/
configure
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
#!/bin/bash
OS=$(uname -s | tr [:upper:] [:lower:])
OS_LIST="linux darwin"
echo $OS_LIST | grep -w -i -q $OS
if [ $? -ne 0 ]; then
echo "Error: unsupported OS $OS"
exit 1
fi
set_variable () {
echo "Setting $1 to $2"
grep "^$1" config/os-${OS}.make > /dev/null
if [ $? -ne 0 ]; then
echo "Error: dependency path variable $1 not found"
exit 1
fi
sed -i "s:\\(^$1[ ]*=\\).*:\1 $2:g" config/os-${OS}.make
}
set_openfst () {
echo "Setting up OpenFST at $1"
version=$(cat $1/configure.ac | head -n 1 | grep -oE "[0-9][0-9.]*[0-9]")
if [ $? -ne 0 ]; then
echo "Error: version information not found, please validate directory"
exit 1
fi
echo "found OpenFST version $version"
set_variable "OPENFSTDIR" $1
set_variable "OPENFST_VERSION" $version
}
set_python () {
PYTHON_PATH=$1
PYTHON_BIN_PATH=$1/bin
VERSION_STRING=$(${PYTHON_BIN_PATH}/python3 --version | grep -o "[0-9.]*")
if [ $? -ne 0 ];then exit 1;fi
VERSION_ARRAY=( ${VERSION_STRING//./ } )
MAJOR=${VERSION_ARRAY[0]}
MINOR=${VERSION_ARRAY[1]}
if [ $MAJOR -ne 3 ]; then
echo "Error: Expected Python version 3, found $MAJOR"
exit 1
fi
if [ $MINOR -ge 8 ]; then
# python version beginning from 3.8 do not include -lpython3.X when calling
# python3-config without --embed, so add it if such minor version is found
grep "python3-config --ldflags --embed" config/os-${OS}.make > /dev/null
if [ $? -ne 0 ]; then
echo "Python minor version is > 8, adding --embed"
sed -i "s/\\(python3-config --ldflags\\)/\1 --embed/g" config/os-${OS}.make
fi
fi
# make sure there is a trailing slash
[[ "${PYTHON_PATH}" != */ ]] && PYTHON_PATH="${PYTHON_PATH}/"
set_variable "PYTHON_PATH" "$PYTHON_PATH"
}
set_tensorflow () {
set_variable "TF_COMPILE_BASE" $1
if [ -d $1/bazel-tensorflow/external/mkl_linux ]; then
echo "Found MKL, will compile with MKL library from TF"
sed -i "s/^#[ ]*USE_TENSORFLOW_MKL/USE_TENSORFLOW_MKL/g" config/os-${OS}.make
else
echo "MKL not found, please manually set the correct BLAS lib if needed"
fi
}
set_march () {
sed -i "s/-march=.*/-march=$1/g" config/proc-x86_64.make
}
enable_module () {
echo "Enable module $1"
grep "^MODULES[ ]*+= MODULE_$1" Modules.make > /dev/null
if [ $? -eq 0 ]; then
echo "Module already activated"
return
fi
grep "^#[ ]*MODULES[ ]*+= MODULE_$1" Modules.make > /dev/null
if [ $? -ne 0 ]; then
echo "Error: Module not found"
exit 1
else
sed -i "s/^#[ ]*MODULES[ ]*+= MODULE_$1/MODULES += MODULE_$1/g" Modules.make
fi
}
disable_module () {
echo "Disable module $1"
grep "^#[ ]*MODULES[ ]*+= MODULE_$1" Modules.make > /dev/null
if [ $? -eq 0 ]; then
echo "Module already deactivated"
return
fi
grep "^MODULES[ ]*+= MODULE_$1" Modules.make > /dev/null
if [ $? -ne 0 ]; then
echo "Error: Module not found"
exit 1
else
sed -i "s/^MODULES[ ]*+= MODULE_$1/# MODULES += MODULE_$1/g" Modules.make
fi
}
configure_i6 () {
set_python "/work/tools/asr/python/3.8.0"
set_tensorflow "/work/tools/asr/tensorflow/2.3.4-generic+cuda10.1+mkl/tensorflow"
set_openfst "/work/speech/tools/openfst-1.6.3"
set_march "barcelona"
enable_module "CORE_CACHE_MANAGER"
}
apply_apptainer_setup() {
BASE_DIR=$(dirname "$0")
FULL_PATH=$BASE_DIR/apptainer/$1/setup_makefiles.sh
if [ -f $FULL_PATH ] ; then
echo "Set up makefiles via $FULL_PATH"
$FULL_PATH
else
echo "Error: Setup-script $FULL_PATH does not exist!"
exit 1
fi
}
show_help(){
cat <<EOF
Usage: configure [options]
Options: [defaults in brackets after descriptions]
This tool can be used to configure the most used options for compiling RASR.
For more fine-grained control please manually edit Config.make,
Options.make and Modules.make, as well as the files under config/
Help options:
--help print this message
General options:
--i6 configures RASR for a default i6 build,
including default modules and tensorflow path.
Please use this always as first argument.
--apptainer-setup=<VERSION_NAME> apply the setup-script in
apptainer/<VERSION_NAME>/setup_makefiles.sh
to enable compilation with the image
given by apptainer/<VERSION_NAME>/image.def
GCC Options:
--set-march set the target architecture to compile for
(see: https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html)
Module options:
--enable-module=<MOD_NAME> enables module "MODULE_<MOD_NAME>"
--disable-module=<MOD_NAME> disables module "MODULE_<MOD_NAME>"
Dependency options:
--set-openfst=OPENFST_DIR set the path to an OpenFST directory
--set-python=PYTHON_DIR set the folder of a python installation
which contains /bin, /lib etc..
--set-tensorflow=TF_COMPILE_BASE set the Tensorflow root directory path
EOF
exit 0
}
for i in "$@"; do
case $i in
-h|--help)
show_help
;;
--i6)
configure_i6
shift
;;
--apptainer-setup=*)
VERSION_NAME="${i#*=}"
apply_apptainer_setup $VERSION_NAME
shift
;;
--set-tensorflow=*)
TF_DIR="${i#*=}"
set_tensorflow $TF_DIR
shift
;;
--set-openfst=*)
OPENFST_DIR="${i#*=}"
set_openfst $OPENFST_DIR
shift
;;
--set-python=*)
PYTHON_DIR="${i#*=}"
set_python $PYTHON_DIR
shift
;;
--set-march=*)
MARCH="${i#*=}"
set_march $MARCH
shift
;;
--enable-module=*)
MODULE="${i#*=}"
enable_module $MODULE
shift
;;
--disable-module=*)
MODULE="${i#*=}"
disable_module $MODULE
shift
;;
-*|--*)
echo "Error: Unknown option $i"
exit 1
;;
*)
;;
esac
done