Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
[src,build] Support web assembly for online2 tcp decoding (kaldi-asr#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mhu-coder authored Apr 10, 2021
1 parent 9419347 commit 5836340
Show file tree
Hide file tree
Showing 6 changed files with 757 additions and 19 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,10 @@ Platform specific notes
OpenBLAS.
- See [this blog post](http://jcsilva.github.io/2017/03/18/compile-kaldi-android/)
for details.

### Web Assembly

- Kaldi supports cross compiling for Web Assembly for in-browser execution
using [emscripten](https://emscripten.org/) and CLAPACK.
- See [this post](https://gitlab.inria.fr/kaldi.web/kaldi-wasm/-/wikis/build_details.md)
for a step-by-step description of the build process.
41 changes: 26 additions & 15 deletions src/configure
Original file line number Diff line number Diff line change
Expand Up @@ -767,28 +767,35 @@ if $android && [[ "$CXX" != *clang++* ]] ; then
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.
# - If it is not equal to WASM
# 1. We prepend it to CXX, AR, AS and RANLIB.
# 2. We parse the target architecture from the HOST triple.
# - Otherwise we take its value as the target architecture
# 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" != aarch64* && "$TARGET_ARCH" != arm* && "$TARGET_ARCH" != ppc64le && \
"$TARGET_ARCH" != x86* && "$TARGET_ARCH" != i686* ]] ; then
# We currently only support building for x86[_64], arm*, aarch64* 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*, aarch64*, ppc64le."

if [[ "$HOST" != WASM ]]; then
CXX="$HOST-$CXX"
AR="$HOST-$AR"
AS="$HOST-$AS"
RANLIB="$HOST-$RANLIB"

# The first field in the PARTS list is the target architecture.
TARGET_ARCH="$PARTS"
if [[ "$TARGET_ARCH" != aarch64* && "$TARGET_ARCH" != arm* && "$TARGET_ARCH" != ppc64le && \
"$TARGET_ARCH" != x86* && "$TARGET_ARCH" != i686* ]] ; then
# We currently only support building for x86[_64], arm*, aarch64* 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*, aarch64*, ppc64le."
fi
else
TARGET_ARCH="$HOST"
fi
else
TARGET_ARCH="`uname -m`"
Expand Down Expand Up @@ -878,6 +885,10 @@ echo >> kaldi.mk
echo "Checking compiler $CXX ..."
check_compiler $CXX

echo "# Target achitecture" >> kaldi.mk
echo "ARCH = $TARGET_ARCH" >> kaldi.mk
echo >> kaldi.mk

echo "# Base configuration" >> kaldi.mk
echo >> kaldi.mk
if $dynamic_kaldi ; then
Expand Down
9 changes: 7 additions & 2 deletions src/makefiles/darwin_clapack.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CXXFLAGS = -std=c++11 -I.. -I$(OPENFSTINC) -O1 $(EXTRA_CXXFLAGS) \
-Wno-deprecated-declarations -Winit-self \
-DKALDI_DOUBLEPRECISION=$(DOUBLE_PRECISION) \
-DHAVE_EXECINFO_H=1 -DHAVE_CXXABI_H -DHAVE_CLAPACK -I../../tools/CLAPACK \
-msse -msse2 -pthread \
-msse -msse2 \
-g

ifeq ($(KALDI_FLAVOR), dynamic)
Expand All @@ -47,4 +47,9 @@ CXXFLAGS += -flax-vector-conversions
endif

LDFLAGS = $(EXTRA_LDFLAGS) $(OPENFSTLDFLAGS) -g
LDLIBS = $(EXTRA_LDLIBS) $(OPENFSTLIBS) $(CLAPACKLIBS) -lm -lpthread -ldl
LDLIBS = $(EXTRA_LDLIBS) $(OPENFSTLIBS) $(CLAPACKLIBS) -lm -ldl

ifneq ($(ARCH), WASM)
CXXFLAGS += -pthread
LDLIBS += -lpthread
endif
9 changes: 7 additions & 2 deletions src/makefiles/linux_clapack.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CXXFLAGS = -std=c++11 -I.. -isystem $(OPENFSTINC) -O1 $(EXTRA_CXXFLAGS) \
-Wno-deprecated-declarations -Winit-self \
-DKALDI_DOUBLEPRECISION=$(DOUBLE_PRECISION) \
-DHAVE_EXECINFO_H=1 -DHAVE_CXXABI_H -DHAVE_CLAPACK -I../../tools/CLAPACK \
-msse -msse2 -pthread \
-msse -msse2 \
-g

ifeq ($(KALDI_FLAVOR), dynamic)
Expand All @@ -44,4 +44,9 @@ CXXFLAGS += -Wno-mismatched-tags
endif

LDFLAGS = $(EXTRA_LDFLAGS) $(OPENFSTLDFLAGS) -rdynamic
LDLIBS = $(EXTRA_LDLIBS) $(OPENFSTLIBS) $(CLAPACKLIBS) -lm -lpthread -ldl
LDLIBS = $(EXTRA_LDLIBS) $(OPENFSTLIBS) $(CLAPACKLIBS) -lm -ldl

ifneq ($(ARCH), WASM)
CXXFLAGS += -pthread
LDLIBS += -lpthread
endif
5 changes: 5 additions & 0 deletions src/online2bin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ BINFILES = online2-wav-gmm-latgen-faster apply-cmvn-online \
online2-tcp-nnet3-decode-faster online2-wav-nnet3-latgen-incremental \
online2-wav-nnet3-wake-word-decoder-faster

# ARCH is defined in kaldi.mk
ifeq ($(ARCH), WASM)
BINFILES += online2-tcp-nnet3-decode-faster-emscripten
endif

OBJFILES =

TESTFILES =
Expand Down
Loading

0 comments on commit 5836340

Please sign in to comment.