aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYimin Zhang2017-10-24 15:08:26 -0500
committerYimin Zhang2017-10-24 15:08:26 -0500
commita472be2e2f8598a3e360bc7ca87ff4f73afa2d9e (patch)
treeb9d1f841eb5f1dfc61ad75033453feb942a0d9dc
parent98757696efce1ead21eca603e9f9d90d460d42f6 (diff)
downloadkaldi_1-0-0.tar.gz
kaldi_1-0-0.tar.xz
kaldi_1-0-0.zip
add scripts to make kaldi on am57x.kaldi_1-0-0
-rw-r--r--export_kaldi.sh155
-rw-r--r--[-rwxr-xr-x]src/configure110
-rw-r--r--src/makefiles/ti_am57.mk32
3 files changed, 271 insertions, 26 deletions
diff --git a/export_kaldi.sh b/export_kaldi.sh
new file mode 100644
index 000000000..255613fa1
--- /dev/null
+++ b/export_kaldi.sh
@@ -0,0 +1,155 @@
1# Texas Instruments 2017
2#
3# This script can be used to extract the components of Kaldi ASR that are only
4# necessary for decoding. Specify the type of decoding you you will be doing
5# along with the corpus directories you wish to export along with kaldi.
6# Note that the copied binaries will be those necessary to run the standard
7# decoding scripts for that type of decoding, i.e. for nnet3-online the
8# binaries required for steps/online/nnet3/decode.sh. It is also important
9# that the corpus directories specified each have their own copies of utils
10# and steps, such that they are not symbolically linked.
11
12function usage {
13 cat <<EOF
14Usage: export_kaldi.sh [decoding_opts] [corpus_directory_names] <kaldi_root> <export_dir>
15Ex: ./export_kaldi.sh --nnet3-online --rm --apiai_decode /home/user/kaldi/kaldi-trunk /home/user/export_kaldi
16
17Currently supported decoding options:
18nnet2
19nnet3
20nnet2-online
21nnet3-online
22
23For corpus directory names, just specify --[name in egs folder]
24
25EOF
26}
27
28nnet2=false
29nnet3=false
30nnet2_online=false
31nnet3_online=false
32corpuses=()
33
34
35# Parse options
36
37while [ $# -gt 2 ];
38do
39 case "$1" in
40 --nnet2)
41 nnet2=true;
42 shift ;;
43 --nnet3)
44 nnet3=true;
45 shift ;;
46 --nnet2-online)
47 nnet2_online=true;
48 shift ;;
49 --nnet3-online)
50 nnet3_online=true;
51 shift ;;
52 --*)
53 hold=`expr "$1" : '--\(.[A-Za-z0-9_]*\)'`;
54 corpuses=("${corpuses[@]}" "$hold");
55 shift ;;
56 *) echo "Error: Unrecognized argument $1";
57 echo "Exiting ...";
58 usage; exit 1 ;;
59 esac
60done
61
62kaldi_root=$1
63export_dir=$2
64
65# Check that Kaldi root exists
66if [ ! -d $kaldi_root ] ; then
67 echo "Error: Could not find Kaldi root: $kaldi_root" && exit 1;
68fi
69
70# Remove and recreate any pre-existing export directory
71echo "Removing any previous export directory and making a new one"
72rm -rf $export_dir || exit 1 ;
73mkdir -p $export_dir || exit 1;
74mkdir -p $export_dir/src || exit 1;
75mkdir -p $export_dir/egs || exit 1;
76mkdir -p $export_dir/tools/config || exit 1;
77echo "Successfully removed and created new export directory"
78
79# Copy common path script
80echo "Copying common path script..."
81cp $kaldi_root/tools/config/common_path.sh $export_dir/tools/config || exit 1;
82
83# Check that specified corpus directories actuall exist
84# If they do, copy them
85echo "Copying corpus directories..."
86for dir in "${corpuses[@]}"; do
87 if [ ! -d $kaldi_root/egs/$dir ]; then
88 echo "Error: Could not find corpus directory $kaldi_root/egs/$dir";
89 echo "Exiting..." && exit 1;
90 else
91 cp -r $kaldi_root/egs/$dir $export_dir/egs;
92 fi
93done
94
95# Copy any required binaries to the src folder
96echo "Copying binaries..."
97if $nnet2; then
98 mkdir -p $export_dir/src/nnet2bin
99 mkdir -p $export_dir/src/featbin
100 mkdir -p $export_dir/src/bin
101 required_bins=("nnet2bin/nnet-latgen-faster" "featbin/apply-cmvn" "featbin/extract-segments" "featbin/compute-mfcc-feats" "featbin/copy-feats" "featbin/compute-cmvn-stats-two-channel" "featbin/compute-cmvn-stats" "bin/copy-matrix" "featbin/splice-feats" "featbin/transform-feats" "featbin/paste-feats" "featbin/subsample-feats")
102 for bin in "${required_bins[@]}"; do
103 if [ ! -e $kaldi_root/src/$bin ]; then
104 echo "Error: Could not find binary $kaldi_root/src/$bin" && exit 1;
105 else
106 cp -r $kaldi_root/src/$bin $export_dir/src/$bin;
107 fi
108 done
109fi
110
111if $nnet3; then
112 mkdir -p $export_dir/src/nnet3bin
113 mkdir -p $export_dir/src/featbin
114 mkdir -p $export_dir/src/latbin
115 mkdir -p $export_dir/src/bin
116 required_bins=("nnet3bin/nnet3-latgen-faster" "latbin/lattice-scale" "featbin/apply-cmvn" "featbin/extract-segments" "featbin/compute-mfcc-feats" "featbin/copy-feats" "featbin/compute-cmvn-stats-two-channel" "featbin/compute-cmvn-stats" "bin/copy-matrix" "featbin/splice-feats" "featbin/transform-feats")
117 for bin in "${required_bins[@]}"; do
118 if [ ! -e $kaldi_root/src/$bin ]; then
119 echo "Error: Could not find binary $kaldi_root/src/$bin" && exit 1;
120 else
121 cp -r $kaldi_root/src/$bin $export_dir/src/$bin;
122 fi
123 done
124fi
125
126if $nnet2_online; then
127 mkdir -p $export_dir/src/online2bin
128 mkdir -p $export_dir/src/featbin
129 required_bins=("online2bin/online2-wav-nnet2-latgen-faster" "featbin/wav-copy")
130 for bin in "${required_bins[@]}"; do
131 if [ ! -e $kaldi_root/src/$bin ]; then
132 echo "Error: Could not find binary $kaldi_root/src/$bin" && exit 1;
133 else
134 cp -r $kaldi_root/src/$bin $export_dir/src/$bin;
135 fi
136 done
137fi
138
139if $nnet3_online; then
140 mkdir -p $export_dir/src/online2bin
141 mkdir -p $export_dir/src/featbin
142 mkdir -p $export_dir/src/latbin
143 required_bins=("online2bin/online2-wav-nnet3-latgen-faster" "featbin/wav-copy" "latbin/lattice-scale")
144 for bin in "${required_bins[@]}"; do
145 if [ ! -e $kaldi_root/src/$bin ]; then
146 echo "Error: Could not find binary $kaldi_root/src/$bin" && exit 1;
147 else
148 cp -r $kaldi_root/src/$bin $export_dir/src/$bin;
149 fi
150 done
151fi
152
153echo "Success: Copied all corpuses and binaries to $export_dir" && exit 0;
154
155exit 0;
diff --git a/src/configure b/src/configure
index 66aacc475..cacbbde6a 100755..100644
--- a/src/configure
+++ b/src/configure
@@ -63,8 +63,7 @@ Configuration options:
63 --shared Build and link against shared libraries [default=no] 63 --shared Build and link against shared libraries [default=no]
64 --use-cuda Build with CUDA [default=yes] 64 --use-cuda Build with CUDA [default=yes]
65 --cudatk-dir=DIR CUDA toolkit directory 65 --cudatk-dir=DIR CUDA toolkit directory
66 --double-precision Build with BaseFloat set to double if yes [default=no], 66 --double-precision Build with double precision floats [default=no]
67 mostly useful for testing purposes.
68 --static-fst Build with static OpenFst libraries [default=no] 67 --static-fst Build with static OpenFst libraries [default=no]
69 --fst-root=DIR OpenFst root directory [default=../tools/openfst/] 68 --fst-root=DIR OpenFst root directory [default=../tools/openfst/]
70 --fst-version=STR OpenFst version string 69 --fst-version=STR OpenFst version string
@@ -88,6 +87,10 @@ Configuration options:
88 If provided, it is prepended to all toolchain programs. 87 If provided, it is prepended to all toolchain programs.
89 --android-incdir=DIR Andraid include directory 88 --android-incdir=DIR Andraid include directory
90 89
90 --ti-cross-compile Cross compile for Texas Instruments device [default=no]
91 --ti-device=DEVICE TI device to compile for; currently supported
92 AM57
93
91Following environment variables can be used to override the default toolchain. 94Following environment variables can be used to override the default toolchain.
92 CXX C++ compiler [default=g++] 95 CXX C++ compiler [default=g++]
93 AR Archive maintenance utility [default=ar] 96 AR Archive maintenance utility [default=ar]
@@ -409,13 +412,6 @@ function configure_cuda {
409 MIN_UNSUPPORTED_GCC_VER="6.0" 412 MIN_UNSUPPORTED_GCC_VER="6.0"
410 MIN_UNSUPPORTED_GCC_VER_NUM=60000; 413 MIN_UNSUPPORTED_GCC_VER_NUM=60000;
411 ;; 414 ;;
412 9_*)
413 MIN_UNSUPPORTED_GCC_VER="7.0"
414 MIN_UNSUPPORTED_GCC_VER_NUM=70000;
415 ;;
416 *)
417 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;
418 ;;
419 esac 415 esac
420 if [ $GCC_VER_NUM -ge $MIN_UNSUPPORTED_GCC_VER_NUM ]; then 416 if [ $GCC_VER_NUM -ge $MIN_UNSUPPORTED_GCC_VER_NUM ]; then
421 failure "CUDA $CUDA_VERSION does not support $CXX (g++-$GCC_VER). 417 failure "CUDA $CUDA_VERSION does not support $CXX (g++-$GCC_VER).
@@ -428,7 +424,6 @@ function configure_cuda {
428 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" ;; 424 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" ;;
429 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" ;; 425 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" ;;
430 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" ;; 426 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" ;;
431 9_*) CUDA_ARCH="-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 -gencode arch=compute_70,code=sm_70" ;;
432 *) 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 ;; 427 *) 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 ;;
433 esac 428 esac
434 429
@@ -850,7 +845,7 @@ android=false
850 845
851MATHLIB='ATLAS' 846MATHLIB='ATLAS'
852ATLASROOT=`rel2abs ../tools/ATLAS/` 847ATLASROOT=`rel2abs ../tools/ATLAS/`
853FSTROOT=`rel2abs ../tools/openfst` 848FSTROOT=`rel2abs ../tools/openfst-1.6.2`
854 849
855# Save the command line to include in kaldi.mk 850# Save the command line to include in kaldi.mk
856cmd_line="$0 $@" 851cmd_line="$0 $@"
@@ -982,6 +977,18 @@ do
982 # will infer the target architecture from the specified host triple. 977 # will infer the target architecture from the specified host triple.
983 HOST=`expr "X$1" : '[^=]*=\(.*\)'`; 978 HOST=`expr "X$1" : '[^=]*=\(.*\)'`;
984 shift ;; 979 shift ;;
980 --ti-cross-compile)
981 ti_cross_compile=true
982 shift ;;
983 --ti-cross-compile=yes)
984 ti_cross_compile=true
985 shift ;;
986 --ti-cross-compile=no)
987 ti_cross_compile=no
988 shift ;;
989 --ti-device=*)
990 TIDEVICE=`expr "X$1" : '[^=]*=\(.*\)'`
991 shift ;;
985 --android-incdir=*) 992 --android-incdir=*)
986 android=true; 993 android=true;
987 threaded_math=false; 994 threaded_math=false;
@@ -1282,21 +1289,72 @@ elif [ "`uname`" == "Linux" ]; then
1282 if [ -z "$CLAPACKROOT" ]; then 1289 if [ -z "$CLAPACKROOT" ]; then
1283 failure "Must specify the location of CLAPACK with --clapack-root option (and it must exist)" 1290 failure "Must specify the location of CLAPACK with --clapack-root option (and it must exist)"
1284 fi 1291 fi
1285 if [ ! -f ../tools/CLAPACK/clapack.h ]; then 1292
1286 failure "could not find file ../tools/CLAPACK/clapack.h" 1293 #-----THIS SECTION ADDED BY TI FOR CROSS COMPILING-----
1287 fi 1294 if $ti_cross_compile; then
1288 if [ ! -d "$CLAPACKROOT" ]; then 1295 # Checking for specific device
1289 failure "The directory $CLAPACKROOT does not exist" 1296 echo "Checking for which TI device to use"
1290 fi 1297 if [ -z "$TIDEVICE" ]; then
1291 # Also check for cblas.h and f2c.h 1298 failure "Must specify a specific TI platform"
1292 echo "Using CLAPACK libs from $CLAPACKROOT as the linear algebra library." 1299 fi
1293 if [ ! -f makefiles/linux_clapack.mk ]; then 1300
1294 failure "makefiles/linux_clapack.mk not found." 1301 # AM57xx or AM57xx evm devices
1295 fi 1302 if [ "$TIDEVICE" == "am57" ] || [ "$TIDEVICE" == "AM57" ]; then
1296 if [[ "$TARGET_ARCH" == arm* ]]; then 1303
1297 cat makefiles/linux_clapack_arm.mk >> kaldi.mk 1304 # Checking for header files
1305 echo "Checking for TI linalg header files"
1306 declare -a ti_linalg_headers=("cblas.h" "ticblas/ticblas.h" "f2c.h" "blaswrap.h" "clapack.h")
1307
1308 for i in "${ti_linalg_headers[@]}"
1309 do
1310 if [ ! -f "$CLAPACKROOT/$i" ]; then
1311 failure "could not find file $CLAPACKROOT/$i"
1312 fi
1313 done
1314
1315 # Checking for required libraries
1316 echo "Checking for TI linalg libraries"
1317 declare -a ti_linalg_libs=("liblapack.a" "libcblaswr.a" "libf2c.a" "libcblas_armplusdsp.a")
1318 CLAPACKLIBS=''
1319
1320 for i in "${ti_linalg_libs[@]}"
1321 do
1322 if [ ! -f "$CLAPACKROOT/lib/$i" ]; then
1323 failure "could not find file $CLAPACKROOT/lib/$i"
1324 fi
1325 CLAPACKLIBS+="$CLAPACKROOT/lib/$i "
1326 done
1327
1328 # Add corresponding device makefile to kaldi.mk
1329 echo "Adding the corresponding device file"
1330 if [ ! -f makefiles/ti_am57.mk ]; then
1331 failure "Could not find file makesfiles/ti_am57.mk"
1332 fi
1333 echo CLAPACKROOT = $CLAPACKROOT >> kaldi.mk
1334 echo CLAPACKLIBS = $CLAPACKLIBS >> kaldi.mk
1335
1336 cat makefiles/ti_am57.mk >> kaldi.mk
1337 else
1338 failure "Could not identify device $TIDEVICE. Currently supported devices: AM57"
1339 fi
1298 else 1340 else
1299 cat makefiles/linux_clapack.mk >> kaldi.mk 1341
1342 if [ ! -f ../tools/CLAPACK/clapack.h ]; then
1343 failure "could not find file ../tools/CLAPACK/clapack.h"
1344 fi
1345 if [ ! -d "$CLAPACKROOT" ]; then
1346 failure "The directory $CLAPACKROOT does not exist"
1347 fi
1348 # Also check for cblas.h and f2c.h
1349 echo "Using CLAPACK libs from $CLAPACKROOT as the linear algebra library."
1350 if [ ! -f makefiles/linux_clapack.mk ]; then
1351 failure "makefiles/linux_clapack.mk not found."
1352 fi
1353 if [[ "$TARGET_ARCH" == arm* ]]; then
1354 cat makefiles/linux_clapack_arm.mk >> kaldi.mk
1355 else
1356 cat makefiles/linux_clapack.mk >> kaldi.mk
1357 fi
1300 fi 1358 fi
1301 echo "Warning (CLAPACK): this part of the configure process is not properly tested and may not work." 1359 echo "Warning (CLAPACK): this part of the configure process is not properly tested and may not work."
1302 echo "Successfully configured for Linux with CLAPACK libs from $CLAPACKROOT" 1360 echo "Successfully configured for Linux with CLAPACK libs from $CLAPACKROOT"
@@ -1352,7 +1410,7 @@ if [ -n "$ENV_LDLIBS" ]; then echo "LDLIBS += $ENV_LDLIBS" >> kaldi.mk; fi
1352 1410
1353# We check for slow exp implementation just before we exit. This check uses 1411# We check for slow exp implementation just before we exit. This check uses
1354# and possibly modifies the kaldi.mk file that we just generated. 1412# and possibly modifies the kaldi.mk file that we just generated.
1355check_for_slow_expf; 1413#check_for_slow_expf;
1356echo "SUCCESS" 1414echo "SUCCESS"
1357echo "To compile: make clean -j; make depend -j; make -j" 1415echo "To compile: make clean -j; make depend -j; make -j"
1358echo " ... or e.g. -j 10, instead of -j, to use a specified number of CPUs" 1416echo " ... or e.g. -j 10, instead of -j, to use a specified number of CPUs"
diff --git a/src/makefiles/ti_am57.mk b/src/makefiles/ti_am57.mk
new file mode 100644
index 000000000..e14ee7b21
--- /dev/null
+++ b/src/makefiles/ti_am57.mk
@@ -0,0 +1,32 @@
1# Configuration for Texas Instruments AM57* devices
2
3ifndef DOUBLE_PRECISION
4$(error DOUBLE_PRECISION not defined.)
5endif
6ifndef OPENFSTINC
7$(error OPENFSTINC not defined.)
8endif
9ifndef OPENFSTLIBS
10$(error OPENFSTLIBS not defined.)
11endif
12ifndef CLAPACKROOT
13$(error CLAPACKROOT not defined.)
14endif
15ifndef CLAPACKLIBS
16$(error CLAPACKLIBS not defined.)
17endif
18
19CXXFLAGS = -std=c++11 -I.. -I$(OPENFSTINC) $(EXTRA_CXXFLAGS) \
20 -Wall -Wno-sign-compare -Wno-unused-local-typedefs \
21 -Wno-deprecated-declarations -Winit-self \
22 -DKALDI_DOUBLEPRECISION=$(DOUBLE_PRECISION) \
23 -DHAVE_EXECINFO_H=1 -DHAVE_CXXABI_H -DHAVE_CLAPACK -I$(CLAPACKROOT) \
24 -I$(CLAPACKROOT)/ticblas -ftree-vectorize -pthread \
25 -g # -O0 -DKALDI_PARANOID
26
27ifeq ($(KALDI_FLAVOR), dynamic)
28CXXFLAGS += -fPIC
29endif
30
31LDFLAGS = $(EXTRA_LDFLAGS) $(OPENFSTLDFLAGS) -rdynamic
32LDLIBS = $(EXTRA_LDLIBS) $(OPENFSTLIBS) $(CLAPACKLIBS) -lOpenCL -locl_util -lstdc++ -lrt -lgomp -lm -lpthread -ldl