-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfigure
executable file
·1368 lines (1244 loc) · 50.4 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
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# This configure script is hand-generated, not auto-generated.
# It creates the file kaldi.mk, which is %included by the Makefiles
# in the subdirectories.
# The file kaldi.mk is editable by hand -- for example, you may want to
# remove the options -g -O0 -DKALDI_PARANOID, or edit the
# DOUBLE_PRECISION variable (to be 1 not 0).
# Example command lines:
# ./configure --shared ## shared libraries.
# ./configure
# ./configure --mkl-root=/opt/intel/mkl
# ./configure --mkl-root=/opt/intel/mkl --threaded-math=yes
# ./configure --mkl-root=/opt/intel/mkl --threaded-math=yes --mkl-threading=tbb
# # This is for MKL 11.3, which does not seem to provide Intel OMP libs
# ./configure --openblas-root=../tools/OpenBLAS/install
# # Before doing this, cd to ../tools and type "make openblas".
# # Note: this is not working correctly on all platforms, do "make test"
# # and look out for segmentation faults.
# ./configure --atlas-root=../tools/ATLAS/build
# ./configure --use-cuda=no # disable CUDA detection (will build cpu-only
# # version of kaldi even on CUDA-enabled machine
# ./configure --static --fst-root=/opt/cross/armv8hf \
# --atlas-root=/opt/cross/armv8hf --host=armv8-rpi3-linux-gnueabihf
# # Cross compile for armv8hf, this assumes that you have openfst built
# # with the armv8-rpi3-linux-gnueabihf toolchain and installed to
# # /opt/cross/armv8hf. It also assumes that you have an ATLAS library
# # built for the target install to /opt/cross/armv8hf and that the
# # armv8-rpi3-linux-gnueabihf toolchain is available in your path
# ./configure --static --openblas-root=/opt/cross/arm-linux-androideabi \
# --fst-root=/opt/cross/arm-linux-androideabi --fst-version=1.4.1 \
# --android-incdir=/opt/cross/arm-linux-androideabi/sysroot/usr/include \
# --host=arm-linux-androideabi
# # Cross compile for Android on arm. The only difference here is the
# # addition of the the --android-includes flag because the toolchains
# # produced by the Android NDK don't always include the C++ stdlib
# # headers in the normal cross compile include path.
# This should be incremented after any significant change to the configure
# script, i.e. any change affecting kaldi.mk or the build system as a whole.
CONFIGURE_VERSION=6
if ! [ -x "$PWD/configure" ]; then
echo 'You must run "configure" from the src/ directory.'
exit 1
fi
function usage {
cat <<EOF
'configure' configures Kaldi installation.
Usage: [VAR=VALUE]... $0 [OPTION]...
The default configuration is to build and link against static Kaldi libraries.
OpenFst and Math libraries are linked dynamically.
Configuration options:
--help Display this help message and exit
--version Display the version of 'configure' and exit
--static Build and link against static libraries [default=no]
--shared Build and link against shared libraries [default=no]
--use-cuda Build with CUDA [default=yes]
--cudatk-dir=DIR CUDA toolkit directory
--double-precision Build with double precision floats [default=no]
--static-fst Build with static OpenFst libraries [default=no]
--fst-root=DIR OpenFst root directory [default=../tools/openfst/]
--fst-version=STR OpenFst version string
--mathlib=LIB Math library [default=ATLAS]
Supported libraries: ATLAS, MKL, CLAPACK, OPENBLAS.
--static-math Build with static math libraries [default=no]
--threaded-math Build with multi-threaded math libraries [default=no]
--threaded-atlas Build with multi-threaded ATLAS libraries [default=no]
--atlas-root=DIR ATLAS root directory [default=../tools/ATLAS/]
--openblas-root=DIR OpenBLAS root directory
--clapack-root=DIR CLAPACK root directory
--gsl-root=DIR GSL root directory
--mkl-root=DIR MKL root directory
--mkl-libdir=DIR MKL library directory
--mkl-threading=LIB MKL threading layer [default=sequential]
Supported layers: sequential, iomp, tbb, gomp.
--omp-libdir=DIR OpenMP directory
--speex-root=DIR SPEEX root directory
--speex-libdir=DIR SPEEX library directory
--speex-incdir=DIR SPEEX include directory
--host=HOST Host triple in the format 'cpu-vendor-os'
If provided, it is prepended to all toolchain programs.
--android-incdir=DIR Andraid include directory
Following environment variables can be used to override the default toolchain.
CXX C++ compiler [default=g++]
AR Archive maintenance utility [default=ar]
AS Assembler [default=as]
RANLIB Archive indexing utility [default=ranlib]
If a host triple is provided, it is prepended to CXX, AR, AS and RANLIB.
Following environment variables can be used to provide additional flags to the
compiler/linker.
CXXFLAGS Additional C++ compiler flags, e.g. -I<include-dir>
LDFLAGS Additional linker flags, e.g. -L<lib-dir>
LDLIBS Additional libraries to pass to the linker, e.g. -l<lib>
EOF
}
function rel2abs {
if [ ! -z "$1" ]; then
local retval=`cd $1 2>/dev/null && pwd || exit 1`
echo $retval
fi
}
function read_dirname {
local dir_name=`expr "X$1" : '[^=]*=\(.*\)'`;
local retval=`rel2abs $dir_name`
[ -z $retval ] && echo "Bad option '$1': no such directory" && exit 1;
echo $retval
}
function is_set {
local myvar=${1:-notset}
if [ "$myvar" == "notset" ]; then
return 1
else
return 0
fi
}
function failure {
echo "***configure failed: $* ***" >&2
if [ -f kaldi.mk ]; then rm kaldi.mk; fi
exit 1;
}
function check_exists {
if [ ! -f $1 ]; then failure "$1 not found."; fi
}
function check_library {
local libpath=$1
local libname=$2
local libext=$3
local full_libname="$libpath/$libname.$libext"
##echo "Testing $full_libname" >&2
test -f "$full_libname" && return ;
return 1
}
function check_compiler {
COMPILER=$1
if ! which $COMPILER >&/dev/null; then
failure "$COMPILER is not installed.
You need g++ >= 4.7, Apple clang >= 5.0 or LLVM clang >= 3.3."
else
COMPILER_VER_INFO=$($COMPILER --version 2>/dev/null)
if [[ $COMPILER_VER_INFO == *"g++"* ]]; then
GCC_VER=$($COMPILER -dumpversion)
GCC_VER_NUM=$(echo $GCC_VER | sed 's/\./ /g' | xargs printf "%d%02d%02d")
if [ $GCC_VER_NUM -lt 40700 ]; then
failure "$COMPILER (g++-$GCC_VER) is not supported.
You need g++ >= 4.7, Apple clang >= 5.0 or LLVM clang >= 3.3."
elif [ $GCC_VER_NUM == 40801 ] || [ $GCC_VER_NUM == 40802 ]; then
failure "$COMPILER (g++-$GCC_VER) is not supported.
GCC 4.8.1 and 4.8.2 have a bug in the implementation of
the nth_element algorithm provided by the standard library.
This will cause Kaldi to crash (make test would fail).
Please use another C++ compiler with C++11 support.
You need g++ >= 4.7, Apple clang >= 5.0 or LLVM clang >= 3.3."
fi
elif [[ $COMPILER_VER_INFO == *"Apple"* ]]; then
CLANG_VER=$(echo $COMPILER_VER_INFO | grep version | sed "s/.*version \([0-9\.]*\).*/\1/")
CLANG_VER_NUM=$(echo $COMPILER_VER_INFO | grep version | sed "s/.*clang-\([0-9]*\).*/\1/")
if [ $CLANG_VER_NUM -lt 500 ]; then
failure "$COMPILER (Apple clang-$CLANG_VER) is not supported.
You need g++ >= 4.7, Apple clang >= 5.0 or LLVM clang >= 3.3."
fi
elif [[ $COMPILER_VER_INFO == *"LLVM"* ]]; then
CLANG_VER=$(echo $COMPILER_VER_INFO | grep version | sed "s/.*version \([0-9\.]*\).*/\1/")
CLANG_VER_NUM=$(echo $CLANG_VER | sed 's/\./ /g' | xargs printf "%d%02d")
if [ $CLANG_VER_NUM -lt 303 ]; then
failure "$COMPILER (LLVM clang-$CLANG_VER) is not supported.
You need g++ >= 4.7, Apple clang >= 5.0 or LLVM clang >= 3.3."
fi
fi
fi
}
function check_for_slow_expf {
# We cannot run this test if we are cross compiling.
if [[ "$TARGET_ARCH" == "`uname -m`" ]] ; then
cd probe
rm -f exp-test
make -f Makefile.slow_expf 1>/dev/null
./exp-test
if [ $? -eq 1 ]; then
echo "*** WARNING: expf() seems to be slower than exp() on your machine. This is a known bug in old versions of glibc. Please consider updating glibc. ***"
echo "*** Kaldi will be configured to use exp() instead of expf() in base/kaldi-math.h Exp() routine for single-precision floats. ***"
echo "CXXFLAGS += -DKALDI_NO_EXPF" >> ../kaldi.mk
fi
cd ..
fi
}
# MKL functions
function linux_configure_mkllibdir {
local mklroot=$1
if [ -d $mklroot/lib/em64t ]; then
echo $mklroot/lib/em64t
elif [ -d $mklroot/lib/intel64 ]; then
echo $mklroot/lib/intel64
else
return 1;
fi
}
function linux_configure_mkl_includes {
test -d $1/include && echo "$1/include" && return;
test -d $2/../../include && echo "$2/../../include" && return;
failure "Could not find the MKL include directory"
}
function linux_configure_mkl_libraries {
local mkllibdir=$1
local static=$2
local threaded=$3
local mplib=$4
declare -A mkl_libs
mkl_libs=(
[sequential]="mkl_intel_lp64 mkl_core mkl_sequential"
[gomp]="mkl_intel_lp64 mkl_core mkl_gnu_thread"
[iomp]="mkl_intel_lp64 mkl_core mkl_intel_thread "
[tbb]="mkl_intel_lp64 mkl_core mkl_tbb_thread "
)
if [ -z "${mkl_libs[$threaded]}" ]; then
echo >&2 "Unknown threading mode: $threaded"
return 1;
fi
local linkline=""
if ! $static ; then
linkline="-L$mkllibdir -Wl,-rpath=$mkllibdir"
for file in ${mkl_libs[$threaded]}; do
local libfile=$mkllibdir/lib$file.so
check_exists $libfile
linkline+=" -l$file "
done
else
if [ $threaded == "sequential" ] ; then
test -f "$mkllibdir/libmkl_solver_lp64.a" && \
linkline="$linkline $mkllibdir/libmkl_solver_lp64.a"
else
test -f "$mkllibdir/libmkl_solver_lp64_sequential.a" && \
linkline="$linkline $mkllibdir/libmkl_solver_lp64_sequential.a"
fi
linkline="$linkline -Wl,--start-group"
for file in ${mkl_libs[$threaded]}; do
local libfile=$mkllibdir/lib${file}.a
check_exists $libfile
linkline="$linkline $libfile"
done
linkline="$linkline -Wl,--end-group "
fi
echo "$linkline"
}
function linux_configure_mkl_extra {
local static=$1
local threaded=$2
declare -A extra_libs
extra_libs=(
[sequential]="-ldl -lpthread -lm"
[gomp]="-lgomp -ldl -lpthread -lm"
[iomp]="-ldl -lpthread -lm"
[tbb]=" -ldl -lpthread -lm "
)
echo "$linkline ${extra_libs[$threaded]}"
}
function linux_configure_threadinglibdir {
local library=$1
local mklroot=$2
local mkllibdir=$3
local libexts=$4
##First we try to use the library in the same directory
##where the mkl libraries reside
##Afterwards, just try some possibilities for different MKL layouts
for libext in $libexts; do
check_library $mkllibdir "lib$library" $libext \
&& echo `readlink -f $mkllibdir` && return 0
local testdir=`(cd $mklroot; cd ..; cd lib/intel64;pwd)`
test -d $testdir && check_library $testdir "lib$library" $libext && echo `readlink -f $testdir` && return 0;
local testdir=`(cd $mklroot; cd ..; cd lib/em64t;pwd)`
test -d $testdir && check_library $testdir "lib$library" $libext && echo `readlink -f $testdir` && return 0;
local testdir=`(cd $mkllibdir; cd ../../..; cd lib/intel64;pwd)`
test -d $testdir && check_library $testdir "lib$library" $libext && echo `readlink -f $testdir` && return 0;
local testdir=`(cd $mklroot; cd ../../..; cd lib/em64t;pwd)`
test -d $testdir && check_library $testdir "lib$library" $libext && echo `readlink -f $testdir` && return 0;
done
#failure "Could not find the library iomp5, use the configure switch --omp-libdir"
return 1
}
function linux_configure_mkl_threading {
local mklroot=$1
local mkllibdir=$2
local static=$3
local threading=$4
declare -A libs
libs=(
[sequential]=""
[gomp]=""
[iomp]="iomp5"
[tbb]="tbb"
)
echo >&2 "Configuring MKL threading as $threading"
library=${libs[$threading]}
if [ -z "$library" ]; then
return 0
fi
if ! is_set $OMPLIBDIR ; then
if $static ; then
OMPLIBDIR=`linux_configure_threadinglibdir $library "$MKLROOT" "$MKLLIBDIR" "a"`
else
OMPLIBDIR=`linux_configure_threadinglibdir $library "$MKLROOT" "$MKLLIBDIR" "so"`
fi
fi
check_library $OMPLIBDIR "lib$library" "a" || \
check_library $OMPLIBDIR "lib$library" "so" || \
failure "Could not find the $library library, have your tried the --omp-libdir switch?"
OMP_LINK_LINE=''
# TODO(arnab): in the following conditional, the $static_math test is
# needed since the OpenMP library is assumed to be dynamic.
if [ "$OMPLIBDIR" != "$MKLLIBDIR" ] ; then
OMP_LINK_LINE="-L${OMPLIBDIR}"
fi
#if the libiomp5 library is dynamic, we add the rpath attribute
if ! $static_math ; then
OMP_LINK_LINE="$OMP_LINK_LINE -Wl,-rpath=$OMPLIBDIR -l$library"
else
OMP_LINK_LINE="$OMP_LINK_LINE -Wl,-Bstatic -l$library -Wl,-Bdynamic"
fi
echo "$OMP_LINK_LINE"
}
# CUDA is used only in selected directories including src/cudamatrix, src/nnet*
# and src/chain*. It is used to accelerate the neural network training.
# The rest of Kaldi runs on CPUs.
function configure_cuda {
# Check for CUDA toolkit in the system
if [ ! -d "$CUDATKDIR" ]; then
for base in /Developer/NVIDIA/CUDA-6.0 /usr/local/share/cuda /usr/local/cuda /pkgs_local/cuda-3.2/ /opt/nvidia_cuda/cuda-6.0/ /usr/; do
if [ -f $base/bin/nvcc ]; then
CUDATKDIR=$base
fi
done
fi
if [ -d "$CUDATKDIR" ]; then
if [ ! -f $CUDATKDIR/bin/nvcc ]; then
failure "Cannnot find nvcc in CUDATKDIR=$CUDATKDIR"
fi
if [[ "$TARGET_ARCH" != "`uname -m`" ]] ; then
failure "Cannot cross compile with CUDA support"
fi
echo "Using CUDA toolkit $CUDATKDIR (nvcc compiler and runtime libraries)"
echo >> kaldi.mk
echo "# CUDA configuration" >> kaldi.mk
echo >> kaldi.mk
echo CUDA = true >> kaldi.mk
echo CUDATKDIR = $CUDATKDIR >> kaldi.mk
# Determine 'CUDA_ARCH',
CUDA_VERSION=$($CUDATKDIR/bin/nvcc -V | tr '.,' '_ ' | awk '/release/{sub(/.*release/,""); print $1;}') # MAJOR_MINOR,
if [ -z "$CUDA_VERSION" ] ; then
echo "Cannot figure out CUDA_VERSION from the nvcc output. Either your CUDA is too new or too old."
exit 1
fi
case $CUDA_VERSION in
5_5) CUDA_ARCH="-gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35" ;;
6_*) CUDA_ARCH="-gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50" ;;
7_*) CUDA_ARCH="-gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_53,code=sm_53" ;;
8_*) CUDA_ARCH="-gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_53,code=sm_53 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_62,code=sm_62" ;;
*) echo "Unsupported CUDA_VERSION (CUDA_VERSION=$CUDA_VERSION), please report it to Kaldi mailing list, together with 'nvcc -h' or 'ptxas -h' which lists allowed -gencode values..."; exit 1 ;;
esac
echo "CUDA_ARCH = $CUDA_ARCH" >> kaldi.mk
echo >> kaldi.mk
# 64bit/32bit? We do not support cross compilation with CUDA so, use direct calls to uname -m here
if [ "`uname -m`" == "x86_64" ]; then
if [ "`uname`" == "Darwin" ]; then
sed 's/lib64/lib/g' < makefiles/cuda_64bit.mk >> kaldi.mk
else
cat makefiles/cuda_64bit.mk >> kaldi.mk
fi
elif [ "`uname -m`" == "ppc64le" ]; then
cat makefiles/cuda_64bit.mk >> kaldi.mk
else
cat makefiles/cuda_32bit.mk >> kaldi.mk
fi
else
echo "CUDA will not be used! If you have already installed cuda drivers "
echo "and cuda toolkit, try using --cudatk-dir=... option. Note: this is"
echo "only relevant for neural net experiments"
fi
}
function linux_configure_speex {
# Check whether the user has called tools/extras/install_speex.sh or not
[ ! -z "$SPEEXROOT" ] || SPEEXROOT=`pwd`/../tools/speex
[ ! -z "$SPEEXLIBDIR" ] || SPEEXLIBDIR="$SPEEXROOT"/lib
[ ! -z "$SPEEXINCDIR" ] || SPEEXINCDIR="$SPEEXROOT"/include
static_speex=$1
if [ "foo"$static_speex == "foo" ]; then
static_speex=false
fi
if $static_speex; then
spx_type=a
else
spx_type=so
fi
if [ ! -f "$SPEEXLIBDIR/libspeex.${spx_type}" ];then
echo "Info: configuring Kaldi not to link with Speex (don't worry, it's only needed if you"
echo "intend to use 'compress-uncompress-speex', which is very unlikely)"
return
fi
if [ -f $SPEEXINCDIR/speex/speex.h ]; then
echo >> kaldi.mk
echo CXXFLAGS += -DHAVE_SPEEX -I${SPEEXINCDIR} >> kaldi.mk
if $static_speex; then
echo LDLIBS += $SPEEXLIBDIR/libspeex.a
else
echo LDLIBS += -L${SPEEXLIBDIR} -lspeex >> kaldi.mk
echo LDFLAGS += -Wl,-rpath=${SPEEXLIBDIR} >> kaldi.mk
fi
echo "Successfully configured with Speex at $SPEEXROOT, (static=[$static_speex])"
else
echo "Speex will not be used. If you want to use it, run tools/extras/install_speex.sh first."
fi
}
function linux_atlas_failure {
echo ATLASINC = $ATLASROOT/include >> kaldi.mk
echo ATLASLIBS = [somewhere]/liblapack.a [somewhere]/libcblas.a [somewhere]/libatlas.a [somewhere]/libf77blas.a $ATLASLIBDIR >> kaldi.mk
echo >> kaldi.mk
if [[ "$TARGET_ARCH" == arm* ]]; then
cat makefiles/linux_atlas_arm.mk >> kaldi.mk
elif [[ "$TARGET_ARCH" == ppc64le ]]; then
cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
else
cat makefiles/linux_atlas.mk >> kaldi.mk
fi
echo "** $* ***"
echo "** ERROR **"
echo "** Configure cannot proceed automatically."
echo "** If you know that you have ATLAS installed somewhere on your machine, you"
echo "** may be able to proceed by replacing [somewhere] in kaldi.mk with a directory."
echo "** If you have sudo (root) access you could install the ATLAS package on your"
echo "** machine, e.g. 'sudo apt-get install libatlas-dev libatlas-base-dev' or"
echo "** 'sudo yum install atlas.x86_64' or 'sudo zypper install libatlas3-devel',"
echo "** or on cygwin, install atlas from the installer GUI; and then run ./configure"
echo "** again."
echo "**"
echo "** Otherwise (or if you prefer OpenBLAS for speed), you could go the OpenBLAS"
echo "** route: cd to ../tools, type 'extras/install_openblas.sh', cd back to here,"
echo "** and type './configure --openblas-root=../tools/OpenBLAS/install'"
exit 1;
}
function linux_check_static {
# will exit with success if $dir seems to contain ATLAS libraries with
# right architecture (compatible with default "nm")
echo "int main(void) { return 0; }" > test_linking.cc;
if [ -f $dir/libatlas.a ]; then # candidate...
# Note: on the next line, the variable assignment
# LANG=en_US should apply just to the program called on that line.
if LANG=en_US $CXX -o test_linking test_linking.cc -u ATL_flushcache $dir/libatlas.a 2>&1 | grep -i "incompatible" >/dev/null; then
echo "Directory $dir may contain ATLAS libraries but seems to be wrong architecture";
rm test_linking test_linking.cc 2>/dev/null
return 1;
fi
rm test_linking test_linking.cc 2>/dev/null
return 0;
else
rm test_linking.cc
return 1;
fi
}
function linux_configure_debian_ubuntu {
m=$1
ATLASLIBS="/usr/lib$m/atlas-base/libatlas.so.3gf /usr/lib$m/atlas-base/libf77blas.so.3gf /usr/lib$m/atlas-base/libcblas.so.3gf /usr/lib$m/atlas-base/liblapack_atlas.so.3gf"
for f in $ATLASLIBS; do
[ ! -f $f ] && return 1;
done
lapacklib=$(echo $ATLASLIBS | awk '{print $NF}')
if ! nm --dynamic $lapacklib | grep ATL_cgetrf >/dev/null; then
exit 1;
fi
echo ATLASINC = $ATLASROOT/include >> kaldi.mk
echo ATLASLIBS = $ATLASLIBS >> kaldi.mk
echo >> kaldi.mk
if [[ "$TARGET_ARCH" == arm* ]]; then
cat makefiles/linux_atlas_arm.mk >> kaldi.mk
elif [[ "$TARGET_ARCH" == ppc64le ]]; then
cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
else
cat makefiles/linux_atlas.mk >> kaldi.mk
fi
echo "Successfully configured for Debian/Ubuntu Linux [dynamic libraries] with ATLASLIBS =$ATLASLIBS"
$use_cuda && configure_cuda
linux_configure_speex
}
function linux_configure_debian_ubuntu3 {
ATLASLIBS="/usr/lib/libatlas.so.3 /usr/lib/libf77blas.so.3 /usr/lib/libcblas.so.3 /usr/lib/liblapack_atlas.so.3"
for f in $ATLASLIBS; do
[ ! -f $f ] && return 1;
done
lapacklib=$(echo $ATLASLIBS | awk '{print $NF}')
if ! nm --dynamic $lapacklib | grep ATL_cgetrf >/dev/null; then
exit 1;
fi
echo ATLASINC = $ATLASROOT/include >> kaldi.mk
echo ATLASLIBS = $ATLASLIBS >> kaldi.mk
echo >> kaldi.mk
if [[ "$TARGET_ARCH" == arm* ]]; then
cat makefiles/linux_atlas_arm.mk >> kaldi.mk
elif [[ "$TARGET_ARCH" == ppc64le ]]; then
cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
else
cat makefiles/linux_atlas.mk >> kaldi.mk
fi
echo "Successfully configured for Debian/Ubuntu Linux [dynamic libraries] with ATLASLIBS =$ATLASLIBS"
$use_cuda && configure_cuda
linux_configure_speex
}
function linux_configure_debian7 {
ATLASLIBS="/usr/lib/atlas-base/libatlas.so.3.0 /usr/lib/atlas-base/libf77blas.so.3.0 /usr/lib/atlas-base/libcblas.so.3 /usr/lib/atlas-base/liblapack_atlas.so.3"
for f in $ATLASLIBS; do
[ ! -f $f ] && return 1;
done
lapacklib=$(echo $ATLASLIBS | awk '{print $NF}')
if ! nm --dynamic $lapacklib | grep ATL_cgetrf >/dev/null; then
exit 1;
fi
libdir=$(dirname $(echo $ATLASLIBS | awk '{print $1}'))
[ -z "$libdir" ] && echo "Error getting libdir in linux_configure_debian7" && exit 1;
echo ATLASINC = $ATLASROOT/include >> kaldi.mk
echo ATLASLIBS = $ATLASLIBS -Wl,-rpath=$libdir >> kaldi.mk
echo >> kaldi.mk
if [[ "$TARGET_ARCH" == arm* ]]; then
cat makefiles/linux_atlas_arm.mk >> kaldi.mk
elif [[ "$TARGET_ARCH" == ppc64le ]]; then
cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
else
cat makefiles/linux_atlas.mk >> kaldi.mk
fi
echo "Successfully configured for Debian 7 [dynamic libraries] with ATLASLIBS =$ATLASLIBS"
$use_cuda && configure_cuda
linux_configure_speex
}
function linux_configure_redhat {
m=$1 # 64 or empty.
ATLASLIBS="/usr/lib$m/atlas/libatlas.so.3 /usr/lib$m/atlas/libf77blas.so.3 /usr/lib$m/atlas/libcblas.so.3 /usr/lib$m/atlas/libclapack.so.3"
for f in $ATLASLIBS; do
[ ! -f $f ] && return 1;
done
libdir=$(dirname $(echo $ATLASLIBS | awk '{print $1}'))
[ -z "$libdir" ] && echo "Error getting libdir in linux_configure_redhat" && exit 1;
echo ATLASINC = $ATLASROOT/include >> kaldi.mk
echo ATLASLIBS = $ATLASLIBS -Wl,-rpath=$libdir >> kaldi.mk
echo >> kaldi.mk
if [[ "$TARGET_ARCH" == arm* ]]; then
cat makefiles/linux_atlas_arm.mk >> kaldi.mk
elif [[ "$TARGET_ARCH" == ppc64le ]]; then
cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
else
cat makefiles/linux_atlas.mk >> kaldi.mk
fi
echo "Successfully configured for red hat [dynamic libraries] with ATLASLIBS =$ATLASLIBS"
$use_cuda && configure_cuda
}
function linux_configure_redhat_fat {
# This is for when only two so-called 'fat' ATLAS libs are provided:
# libsatlas.so.3 and libtatlas.so.3.
# See http://stackoverflow.com/questions/13439296/build-shared-libraries-in-atlas.
m=$1 # 64 or empty.
ATLASLIBS="/usr/lib$m/atlas/libsatlas.so.3 /usr/lib$m/atlas/libtatlas.so.3"
for f in $ATLASLIBS; do
[ ! -f $f ] && return 1;
done
libdir=$(dirname $(echo $ATLASLIBS | awk '{print $1}'))
[ -z "$libdir" ] && echo "Error getting libdir in linux_configure_redhat_fat" && exit 1;
echo ATLASINC = $ATLASROOT/include >> kaldi.mk
echo ATLASLIBS = $ATLASLIBS -Wl,-rpath=$libdir >> kaldi.mk
echo >> kaldi.mk
if [[ "$TARGET_ARCH" == arm* ]]; then
cat makefiles/linux_atlas_arm.mk >> kaldi.mk
elif [[ "$TARGET_ARCH" == ppc64le ]]; then
cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
else
cat makefiles/linux_atlas.mk >> kaldi.mk
fi
echo "Successfully configured for red hat [dynamic libraries, fat] with ATLASLIBS =$ATLASLIBS"
$use_cuda && configure_cuda
}
function linux_configure_static {
if $threaded_atlas; then pt=pt; else pt=""; fi
if [ -z $ATLASLIBDIR ]; then # Note: it'll pick up the last one below.
for dir in /usr{,/local}/lib{64,}{,/atlas,/atlas-sse2,/atlas-sse3} \
/usr/local/atlas/lib{,64} `pwd`/../tools/ATLAS/build/install/lib/ $ATLASROOT/lib; do
linux_check_static && ATLASLIBDIR=$dir
done
if [ -z $ATLASLIBDIR ]; then # Note: it'll pick up the last one below.
echo "Could not find libatlas.a in any of the generic-Linux places, but we'll try other stuff..."
return 1;
fi
elif [ ! -f $ATLASLIBDIR/libatlas.a ]; then
echo "Could not find libatlas.a in '$ATLASLIBDIR'"
return 1;
fi
echo "Validating presence of ATLAS libs in $ATLASLIBDIR"
ATLASLIBS=
# The Lapack part of ATLAS seems to appear under various different names.. but it
# should always have symbols like ATL_cgetrf defined, so we test for this,
# for all the names we have encountered.
for libname in liblapack liblapack_atlas libclapack; do
if [ -f $ATLASLIBDIR/${libname}.a -a "$ATLASLIBS" == "" ]; then
if nm $ATLASLIBDIR/${libname}.a | grep ATL_cgetrf >/dev/null; then
ATLASLIBS=$ATLASLIBDIR/${libname}.a
echo "Using library $ATLASLIBS as ATLAS's CLAPACK library."
fi
fi
done
if [ "$ATLASLIBS" == "" ]; then
echo Could not find any libraries $ATLASLIBDIR/{liblapack,liblapack_atlas,libclapack} that seem to be an ATLAS CLAPACK library.
return 1;
fi
for x in lib${pt}cblas.a libatlas.a lib${pt}f77blas.a; do
if [ ! -f $ATLASLIBDIR/$x ]; then
echo "Configuring static ATLAS libraries failed: Could not find library $x in directory $ATLASLIBDIR"
return 1;
fi
ATLASLIBS="$ATLASLIBS $ATLASLIBDIR/$x"
done
if $threaded_atlas; then ATLASLIBS="$ATLASLIBS"; fi
echo ATLASINC = $ATLASROOT/include >> kaldi.mk
echo ATLASLIBS = $ATLASLIBS >> kaldi.mk
echo >> kaldi.mk
if [[ "$TARGET_ARCH" == arm* ]]; then
cat makefiles/linux_atlas_arm.mk >> kaldi.mk
elif [[ "$TARGET_ARCH" == ppc64le ]]; then
cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
else
cat makefiles/linux_atlas.mk >> kaldi.mk
fi
$use_cuda && configure_cuda
linux_configure_speex
echo "Successfully configured for Linux [static libraries] with ATLASLIBS =$ATLASLIBS"
}
function linux_check_dynamic {
# will exit with success if $dir seems to contain ATLAS libraries with
# right architecture (compatible with default "nm")
if $threaded_atlas; then pt=t; else pt=s; fi
for atlas_libname in libatlas.so lib${pt}atlas.so; do
if [ -f $dir/$atlas_libname ]; then # candidate...
if nm --dynamic $dir/$atlas_libname 2>&1 | grep "File format not recognized" >/dev/null; then
echo "Directory $dir may contain dynamic ATLAS libraries but seems to be wrong architecture";
return 1;
fi
echo "Atlas found in $dir";
return 0;
fi
done
# echo "... no {libatlas,lib${pt}atlas}.so in $dir";
return 1;
}
function linux_configure_dynamic {
if $threaded_atlas; then pt=t; else pt=s; fi # relevant to "fat" libraries, will change later for separate ones
if [ -z $ATLASLIBDIR ]; then # Note: it'll pick up the last one below.
for dir in /usr{,/local}/lib{,64}{,/atlas,/atlas-sse2,/atlas-sse3} \
`pwd`/../tools/ATLAS/build/install/lib/ $ATLASROOT/lib; do
linux_check_dynamic && ATLASLIBDIR=$dir && ATLASLIBNAME=$atlas_libname
done
if [ -z $ATLASLIBDIR -o -z $ATLASLIBNAME ]; then
echo "Could not find {libatlas,lib${pt}atlas}.so in any of the obvious places, will most likely try static:"
return 1;
fi
fi
# If using "fat" libraries we only need one file to link against
if [ $ATLASLIBNAME != libatlas.so ]; then
if [ -f $ATLASLIBDIR/$ATLASLIBNAME ]; then
ATLASLIBS="$ATLASLIBDIR/$ATLASLIBNAME"
else
echo "Configuring dynamic ATLAS library failed: library $ATLASLIBNAME not found in $ATLASLIBDIR"
return 1;
fi
else # with "thin" libraries, we have several object to link against, and different single/multi-thread names
if $threaded_atlas; then pt=pt; else pt=""; fi
echo "Validating presence of ATLAS libs in $ATLASLIBDIR"
ATLASLIBS=
# The Lapack part of ATLAS seems to appear under various different names.. but it
# should always have symbols like ATL_cgetrf defined, so we test for this,
# for all the names we have encountered.
for libname in lapack lapack_atlas clapack; do
if [ -f $ATLASLIBDIR/lib${libname}.so -a "$ATLASLIBS" == "" ]; then
if nm --dynamic $ATLASLIBDIR/lib${libname}.so | grep ATL_cgetrf >/dev/null; then
ATLASLIBS="$ATLASLIBDIR/lib${libname}.so"
echo "Using library $ATLASLIBS as ATLAS's CLAPACK library."
fi
fi
done
if [ "$ATLASLIBS" == "" ]; then
echo Could not find any libraries $ATLASLIBDIR/{liblapack,liblapack_atlas,libclapack} that seem to be an ATLAS CLAPACK library.
return 1;
fi
for x in ${pt}cblas atlas ${pt}f77blas; do
if [ ! -f $ATLASLIBDIR/lib$x.so ]; then
echo "Configuring dynamic ATLAS libraries failed: Could not find library $x in directory $ATLASLIBDIR"
return 1;
fi
ATLASLIBS="$ATLASLIBS $ATLASLIBDIR/lib${x}.so"
done
if $threaded_atlas; then ATLASLIBS="$ATLASLIBS"; fi
fi
echo ATLASINC = $ATLASROOT/include >> kaldi.mk
echo ATLASLIBS = $ATLASLIBS >> kaldi.mk
echo >> kaldi.mk
if [[ "$TARGET_ARCH" == arm* ]]; then
cat makefiles/linux_atlas_arm.mk >> kaldi.mk
elif [[ "$TARGET_ARCH" == ppc64le ]]; then
cat makefiles/linux_atlas_ppc64le.mk >> kaldi.mk
else
cat makefiles/linux_atlas.mk >> kaldi.mk
fi
$use_cuda && configure_cuda
linux_configure_speex
echo "Successfully configured for Linux [dynamic libraries] with ATLASLIBS =$ATLASLIBS"
}
############################# CONFIGURATION #############################
# If configuration sets any of these variables, we will switch the external
# math library. Here we unset them so that we can check later.
unset MKLROOT
unset CLAPACKROOT
unset OPENBLASROOT
unset MKLLIBDIR
# This variable identifies the type of system where built programs and
# libraries will run. It is set by the configure script when cross compiling.
unset HOST
# These environment variables can be used to override the default toolchain.
CXX=${CXX:-g++}
AR=${AR:-ar}
AS=${AS:-as}
RANLIB=${RANLIB:-ranlib}
# These environment variables can be used to provide additional flags to the
# compiler/linker. We want these flags to override the flags determined by the
# configure script, so we append them to the appropriate variables (CXXFLAGS,
# LDFLAGS and LDLIBS) after those variables are set by the configure script.
ENV_CXXFLAGS=$CXXFLAGS
ENV_LDFLAGS=$LDFLAGS
ENV_LDLIBS=$LDLIBS
# Default configuration
double_precision=false
dynamic_kaldi=false
use_cuda=true
static_fst=false
static_math=false
threaded_atlas=false
mkl_threading=sequential
android=false
MATHLIB='ATLAS'
ATLASROOT=`rel2abs ../tools/ATLAS/`
FSTROOT=`rel2abs ../tools/openfst`
# Save the command line to include in kaldi.mk
cmd_line="$0 $@"
while [ $# -gt 0 ];
do
case "$1" in
--help)
usage; exit 0 ;;
--version)
echo $CONFIGURE_VERSION; exit 0 ;;
--static)
dynamic_kaldi=false;
static_math=true;
static_fst=true;
shift ;;
--shared)
dynamic_kaldi=true;
static_math=false;
static_fst=false;
shift ;;
--double-precision)
double_precision=true;
shift ;;
--double-precision=yes)
double_precision=true;
shift ;;
--double-precision=no)
double_precision=false;
shift ;;
--atlas-root=*)
ATLASROOT=`read_dirname $1`;
shift ;;
--threaded-atlas)
threaded_atlas=true;
shift ;;
--threaded-atlas=yes)
threaded_atlas=true;
shift ;;
--threaded-atlas=no)
threaded_atlas=false;
shift ;;
--threaded-math)
threaded_atlas=true;
mkl_threading=iomp
shift ;;
--threaded-math=yes)
threaded_atlas=true;
mkl_threading=iomp
shift ;;
--threaded-math=no)
threaded_atlas=false;
mkl_threading=sequential
shift ;;
--use-cuda)
use_cuda=true;
shift ;;
--use-cuda=yes)
use_cuda=true;
shift ;;
--use-cuda=no)
use_cuda=false;
shift ;;
--static-math)
static_math=true;
shift ;;
--static-math=yes)
static_math=true;
shift ;;
--static-math=no)
static_math=false;
shift ;;
--static-fst)
static_fst=true;
shift ;;
--static-fst=yes)
static_fst=true;
shift ;;
--static-fst=no)
static_fst=false;
shift ;;
--mkl-threading=sequential)
threaded_atlas=false;
mkl_threading=sequential;
shift ;;
--mkl-threading=*)
mkl_threading=`expr "X$1" : '[^=]*=\(.*\)'`;
threaded_atlas=true;
shift ;;
--fst-root=*)
FSTROOT=`read_dirname $1`;
shift ;;
--clapack-root=*)
CLAPACKROOT=`read_dirname $1`;
shift ;;
--gsl-root=*)
GSLROOT=`read_dirname $1`;
shift ;;
--openblas-root=*)
OPENBLASROOT=`read_dirname $1`;
shift ;;
--mkl-root=*)
MKLROOT=`read_dirname $1`;
shift ;;
--mkl-libdir=*)
MKLLIBDIR=`read_dirname $1`;
shift ;;
--speex-root=*)
SPEEXROOT=`read_dirname $1`;
shift ;;
--speex-libdir=*)
SPEEXLIBDIR=`read_dirname $1`;
shift ;;
--speex-incdir=*)
SPEEXINCDIR=`read_dirname $1`;
shift ;;
--omp-libdir=*)
OMPLIBDIR=`read_dirname $1`;
shift ;;
--mathlib=*)
MATHLIB=`expr "X$1" : '[^=]*=\(.*\)'`;
shift ;;
--cudatk-dir=*)
CUDATKDIR=`read_dirname $1`;
shift ;; #CUDA is used in src/cudamatrix and src/nnet{,bin} only
--fst-version=*)
OPENFST_VER=`expr "X$1" : '[^=]*=\(.*\)'`;
shift;;
--host=*)
# The type of system where built programs and libraries will run.
# It should be in the format cpu-vendor-os. If specified, this script
# will infer the target architecture from the specified host triple.
HOST=`expr "X$1" : '[^=]*=\(.*\)'`;
shift ;;
--android-incdir=*)
android=true;
threaded_math=false;
static_math=true;
static_fst=true;
dynamic_kaldi=false;
MATHLIB='OPENBLAS';
ANDROIDINC=`read_dirname $1`;
shift;;
*) echo "Unknown argument: $1, exiting"; usage; exit 1 ;;
esac
done
# The idea here is that if you change the configuration options from using
# CUDA to not using it, or vice versa, we want to recompile all parts of the
# code that may use a GPU. Touching this file is a way to force this.
touch cudamatrix/cu-common.h 2>/dev/null
if $android && [[ "$CXX" != *clang++* ]] ; then
failure "Android build requires clang++. Make sure you have clang++ installed
on your system and then override the default compiler by setting CXX, e.g.
CXX=clang++ ./configure"
fi
# If HOST is set
# 1. We prepend it to CXX, AR, AS and RANLIB.
# 2. We parse the target architecture from the HOST triple.
# Otherwise we set the target architecture to the output of `uname -m`.
if is_set $HOST; then
CXX="$HOST-$CXX"
AR="$HOST-$AR"
AS="$HOST-$AS"
RANLIB="$HOST-$RANLIB"
# The host triple will be something like "armv8-rpi3-linux-gnueabihf". We
# need the first field which is the target architecture for this build. The
# following command will take the host triple "armv8-rpi3-linux-gnueabihf"
# and return ["armv8", "rpi3", "linux", "gnueabihf"] in PARTS.
IFS='-' read -ra PARTS <<< "$HOST"
# The first field in the PARTS list is the target architecture.
TARGET_ARCH="$PARTS"
if [[ "$TARGET_ARCH" != arm* && "$TARGET_ARCH" != ppc64le && "$TARGET_ARCH" != x86* ]] ; then
# We currently only support building for x86[_64], arm*, and ppc64le.
# If TARGET_ARCH was read from the HOST variable, it must be one of these.
failure "$TARGET_ARCH is not a supported architecture.
Supported architectures: x86[_64], arm*, ppc64le."
fi
else
TARGET_ARCH="`uname -m`"