46
46
# script, i.e. any change affecting kaldi.mk or the build system as a whole.
47
47
CONFIGURE_VERSION=10
48
48
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
+
49
58
if ! [ -x " $PWD /configure" ]; then
50
59
echo ' You must run "configure" from the src/ directory.'
51
60
exit 1
@@ -129,6 +138,8 @@ function read_dirname {
129
138
echo $retval
130
139
}
131
140
141
+ # TODO(kkm): Kill this. `[[ ${var-} ]]' is the idiomatic equivalent in bash.
142
+ # Even better, do not rely on uninitialized variables.
132
143
function is_set {
133
144
local myvar=${1:- notset}
134
145
if [ " $myvar " == " notset" ]; then
@@ -138,6 +149,11 @@ function is_set {
138
149
fi
139
150
}
140
151
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
+
141
157
function failure {
142
158
echo " ***configure failed: $* ***" >&2
143
159
if [ -f kaldi.mk ]; then rm kaldi.mk; fi
@@ -475,14 +491,17 @@ function configure_cuda {
475
491
elif [ " ` uname -m` " == " ppc64le" ]; then
476
492
cat makefiles/cuda_64bit.mk >> kaldi.mk
477
493
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."
479
497
exit 1;
480
498
fi
481
499
482
500
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."
486
505
fi
487
506
}
488
507
@@ -776,14 +795,17 @@ function linux_configure_dynamic {
776
795
777
796
# If configuration sets any of these variables, we will switch the external
778
797
# 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=
783
805
784
806
# This variable identifies the type of system where built programs and
785
807
# libraries will run. It is set by the configure script when cross compiling.
786
- unset HOST
808
+ HOST=
787
809
788
810
# These environment variables can be used to override the default toolchain.
789
811
CXX=${CXX:- g++}
@@ -809,8 +831,6 @@ threaded_atlas=false
809
831
mkl_threading=sequential
810
832
android=false
811
833
812
- MATHLIB=MKL
813
- MKLROOT=/opt/intel/mkl
814
834
FSTROOT=` rel2abs ../tools/openfst`
815
835
CUBROOT=` rel2abs ../tools/cub`
816
836
@@ -1002,13 +1022,63 @@ else
1002
1022
TARGET_ARCH=" ` uname -m` "
1003
1023
fi
1004
1024
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
1010
1080
1011
- echo " Configuring .. ."
1081
+ echo " Configuring KALDI to use ${MATHLIB} ."
1012
1082
1013
1083
# Back up the old kaldi.mk in case we modified it
1014
1084
if [ -f kaldi.mk ]; then
0 commit comments