Skip to content

Commit 4ae4bb0

Browse files
kkmkkm (aka Kirill Katsnelson)
authored andcommitted
[build] Fix configure breakage from #3194 (MKL default)
Establish MATHLIB as the single ground-truth source for the chosen matrix algebra library.
1 parent 76bdf20 commit 4ae4bb0

File tree

1 file changed

+87
-17
lines changed

1 file changed

+87
-17
lines changed

src/configure

Lines changed: 87 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@
4646
# script, i.e. any change affecting kaldi.mk or the build system as a whole.
4747
CONFIGURE_VERSION=10
4848

49+
# We support bash version 3.2 (Macs still ship with this version as of 2019)
50+
# and above.
51+
[[ $BASH_VERSION < '3.2' ]] && {
52+
echo >&2 "bash version ${BASH_VERSION} is too old, cannot continue." \
53+
"You won't be able to run Kaldi recipes with it anyway." \
54+
"Please upgrade. bash version 3.2 or higher is required."
55+
exit 1;
56+
}
57+
4958
if ! [ -x "$PWD/configure" ]; then
5059
echo 'You must run "configure" from the src/ directory.'
5160
exit 1
@@ -129,6 +138,8 @@ function read_dirname {
129138
echo $retval
130139
}
131140

141+
# TODO(kkm): Kill this. `[[ ${var-} ]]' is the idiomatic equivalent in bash.
142+
# Even better, do not rely on uninitialized variables.
132143
function is_set {
133144
local myvar=${1:-notset}
134145
if [ "$myvar" == "notset" ]; then
@@ -138,6 +149,11 @@ function is_set {
138149
fi
139150
}
140151

152+
# Lowercase/uppercase argument. Only bash 4.2+ has internal faclilties for this,
153+
# and we support versions down to 3.2.
154+
lcase () { awk '{print tolower($0)}' <<<"$1" ; }
155+
ucase () { awk '{print toupper($0)}' <<<"$1" ; }
156+
141157
function failure {
142158
echo "***configure failed: $* ***" >&2
143159
if [ -f kaldi.mk ]; then rm kaldi.mk; fi
@@ -475,14 +491,17 @@ function configure_cuda {
475491
elif [ "`uname -m`" == "ppc64le" ]; then
476492
cat makefiles/cuda_64bit.mk >> kaldi.mk
477493
else
478-
echo "CUDA will not be used! CUDA is not supported with 32-bit builds."
494+
echo "\
495+
WARNING: CUDA will not be used!
496+
CUDA is not supported with 32-bit builds."
479497
exit 1;
480498
fi
481499

482500
else
483-
echo "CUDA will not be used! If you have already installed cuda drivers "
484-
echo "and cuda toolkit, try using --cudatk-dir=... option. Note: this is"
485-
echo "only relevant for neural net experiments"
501+
echo "\
502+
WARNING: CUDA will not be used! If you have already installed cuda drivers
503+
and CUDA toolkit, try using the --cudatk-dir= option. A GPU and CUDA
504+
are required to run neural net experiments in a realistic time."
486505
fi
487506
}
488507

@@ -776,14 +795,17 @@ function linux_configure_dynamic {
776795

777796
# If configuration sets any of these variables, we will switch the external
778797
# math library. Here we unset them so that we can check later.
779-
unset MKLROOT
780-
unset CLAPACKROOT
781-
unset OPENBLASROOT
782-
unset MKLLIBDIR
798+
#TODO(kkm): Maybe allow env vars to provide defaults?
799+
ATLASROOT=
800+
CLAPACKROOT=
801+
MATHLIB=
802+
MKLLIBDIR=
803+
MKLROOT=
804+
OPENBLASROOT=
783805

784806
# This variable identifies the type of system where built programs and
785807
# libraries will run. It is set by the configure script when cross compiling.
786-
unset HOST
808+
HOST=
787809

788810
# These environment variables can be used to override the default toolchain.
789811
CXX=${CXX:-g++}
@@ -809,8 +831,6 @@ threaded_atlas=false
809831
mkl_threading=sequential
810832
android=false
811833

812-
MATHLIB=MKL
813-
MKLROOT=/opt/intel/mkl
814834
FSTROOT=`rel2abs ../tools/openfst`
815835
CUBROOT=`rel2abs ../tools/cub`
816836

@@ -1002,13 +1022,63 @@ else
10021022
TARGET_ARCH="`uname -m`"
10031023
fi
10041024

1005-
# If one of these variables is set, we switch the external math library.
1006-
is_set $MKLLIBDIR && echo "Configuring KALDI to use MKL" && export MATHLIB="MKL"
1007-
is_set $MKLROOT && echo "Configuring KALDI to use MKL"&& export MATHLIB="MKL"
1008-
is_set $CLAPACKROOT && echo "Configuring KALDI to use CLAPACK"&& export MATHLIB="CLAPACK"
1009-
is_set $OPENBLASROOT && echo "Configuring KALDI to use OPENBLAS"&& export MATHLIB="OPENBLAS"
1025+
#------------------------------------------------------------------------------
1026+
# Matrix algebra library selection and validation.
1027+
#--------------
1028+
1029+
declare -a mathlibs # Contains e. g. 'atlas', 'mkl'
1030+
declare -a incompat # Contains mutually-inconsistent switches, if any.
1031+
auto_lib= # Deduced lib name, used when $MATHLIB is not set.
1032+
1033+
# Validate the (optionally) provided MATHLIB value.
1034+
case $MATHLIB in
1035+
''|ATLAS|CLAPACK|MKL|OPENBLAS) : ;;
1036+
*) failure "Unknown --mathlib='${MATHLIB}'. Supported libs: ATLAS CLAPACK MKL OPENBLAS" ;;
1037+
esac
1038+
1039+
# See which library-root switches are set, what mathlib they imply, and whether
1040+
# there are any conflicts betweeh the switches.
1041+
[[ $MKLLIBDIR || $MKLROOT ]] && { mathlibs+=(mkl); auto_lib=MKL; }
1042+
[[ $CLAPACKROOT ]] && { mathlibs+=(clapack); auto_lib=CLAPACK; }
1043+
[[ $OPENBLASROOT ]] && { mathlibs+=(openblas); auto_lib=OPENBLAS; }
1044+
[[ $ATLASROOT ]] && { mathlibs+=(atlas); auto_lib=ATLAS; }
1045+
1046+
# When --mathlib= is explicitly provided, and some mathlib(s) deduced, but
1047+
# MATHLIB is not among them, record a conflict for the --mathlib= value.
1048+
shopt -s nocasematch
1049+
[[ $MATHLIB && $mathlibs && ! " ${mathlibs[@]} " =~ " $MATHLIB " ]] &&
1050+
incompat+=(--mathlib=$MATHLIB)
1051+
shopt -u nocasematch
1052+
1053+
# If more than one library specified, or a conflict has been recorded above
1054+
# already, then add all deduced libraries as conflicting options (not all may
1055+
# be conflicting sensu stricto, but let the user deal with it).
1056+
if [[ ${#mathlibs[@]} -gt 1 || $incompat ]]; then
1057+
for libpfx in "${mathlibs[@]}"; do
1058+
# Handle --mkl-libdir out of common pattern.
1059+
[[ $libpfx == mkl && $MKLLIBDIR ]] && incompat+=(--mkl-libdir=)
1060+
# All other switches follow the pattern --$libpfx-root.
1061+
incompat+=(--$(lcase $libpfx)-root=)
1062+
done
1063+
failure "Incompatible configuration switches: ${incompat[@]}"
1064+
fi
1065+
1066+
# When no library roots were provided, so that auto_lib is not deduced, and
1067+
# MATHLIB is also not explicitly provided by the user, then default to MKL.
1068+
[[ ! $auto_lib && ! $MATHLIB ]] && auto_lib=MKL
1069+
: ${MATHLIB:=$auto_lib}
1070+
export MATHLIB #TODO(kkm): Likely not needed. Briefly tested without,
1071+
# but left in the hotfix. Remove when doing the #3192.
1072+
1073+
# Define default library roots where known (others may be found by probing).
1074+
case $MATHLIB in
1075+
MKL) [[ ! $MKLLIBDIR && ! $MKLROOT ]] && MKLROOT=/opt/intel/mkl ;;
1076+
ATLAS) : ${ATLASROOT:=$(rel2abs ../tools/ATLAS_headers/)} ;;
1077+
esac
1078+
1079+
unset auto_lib incompat libpfx mathlibs
10101080

1011-
echo "Configuring ..."
1081+
echo "Configuring KALDI to use ${MATHLIB}."
10121082

10131083
# Back up the old kaldi.mk in case we modified it
10141084
if [ -f kaldi.mk ]; then

0 commit comments

Comments
 (0)