From 09a4a2844deecbf20ea4be167dfa127188d42bca Mon Sep 17 00:00:00 2001 From: msqr1 Date: Sun, 4 Feb 2024 16:44:17 -0800 Subject: [PATCH] use flto on clapack-wasm --- .gitignore | 1 + src/Makefile | 7 ++-- src/clapack-wasm.patch | 75 +++++++++++++++++++++++++++++++++--------- 3 files changed, 65 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 0646fe6..d7a4050 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ minitest libarchive .vscode clapack-wasm +openfst emsdk \ No newline at end of file diff --git a/src/Makefile b/src/Makefile index 47b557e..677b569 100644 --- a/src/Makefile +++ b/src/Makefile @@ -14,7 +14,7 @@ COMPILE_JOBS?:=$(nproc) SRC:=$(realpath src) KALDI:=$(realpath kaldi) VOSK:=$(realpath vosk-api) -OPENFST:=$(KALDI)/tools/openfst +OPENFST:=$(realpath openfst) LIBARCHIVE:=$(realpath libarchive) ZSTD:=$(realpath zstd) CLAPACK_WASM:=$(realpath clapack-wasm) @@ -29,7 +29,7 @@ browser-recognizer: vosk libarchive prepare: sudo apt install shtool libtool autogen autotools-dev pkg-config make && \ - [ $(EMSDK) != ../emsdk -a ! -d $(EMSDK) ] && \ + [ $(EMSDK) != ../emsdk ! -d $(EMSDK) ] && \ echo "Invalid emsdk path"; \ exit 1; \ [ $(MAX_THREAD) -lt 2 ] && \ @@ -69,6 +69,7 @@ libarchive: zstd clapack-wasm: prepare git clone --depth=1 https://gitlab.inria.fr/multispeech/kaldi.web/clapack-wasm.git $(CLAPACK_WASM) && \ cd $(CLAPACK_WASM) && \ + git apply $(SRC)/clapack-wasm.patch && bash ./install_repo.sh emcc openfst: prepare @@ -85,7 +86,7 @@ kaldi: openfst clapack-wasm git clone -b vosk --depth=1 https://github.com/alphacep/kaldi $(KALDI) && \ cd $(KALDI)/src && \ git apply $(SRC)/kaldi.patch && \ - CXXFLAGS="-O3 -msimd128 -UHAVE_EXECINFO_H -pthread -flto" LDFLAGS="-O3 -sERROR_ON_UNDEFINED_SYMBOLS=0 -lembind -pthread -flto" emconfigure ./configure --use-cuda=no --with-cudadecoder=no --static --static-math=yes --static-fst=yes --debug-level=0 --double-precision=yes --clapack-root=$(CLAPACK_WASM) --host=WASM && \ + CXXFLAGS="-O3 -msimd128 -UHAVE_EXECINFO_H -pthread -flto" LDFLAGS="-O3 -sERROR_ON_UNDEFINED_SYMBOLS=0 -lembind -pthread -flto" emconfigure ./configure --use-cuda=no --with-cudadecoder=no --static --static-math=yes --static-fst=yes --debug-level=0 --double-precision=yes --fst-root=$(OPENFST) --clapack-root=$(CLAPACK_WASM) --host=WASM && \ emmake make -j$(COMPILE_JOBS) online2 lm rnnlm vosk: kaldi diff --git a/src/clapack-wasm.patch b/src/clapack-wasm.patch index 2d9f321..01d6f04 100644 --- a/src/clapack-wasm.patch +++ b/src/clapack-wasm.patch @@ -1,16 +1,61 @@ -diff --git a/libf2c/main.c b/libf2c/main.c -index d95fdc9..ac82f68 100644 ---- a/libf2c/main.c -+++ b/libf2c/main.c -@@ -105,9 +105,9 @@ char **xargv; +diff --git a/CBLAS/Makefile.in.WASM b/CBLAS/Makefile.in.WASM +index bf7eda6..5fedaf6 100644 +--- a/CBLAS/Makefile.in.WASM ++++ b/CBLAS/Makefile.in.WASM +@@ -36,7 +36,7 @@ LOADER = $(CC) + # Flags for Compilers + #----------------------------------------------------------------------------- - int - #ifdef KR_headers --main(argc, argv) int argc; char **argv; -+m(argc, argv) int argc; char **argv; - #else --main(int argc, char **argv) -+m(int argc, char **argv) - #endif - { - xargc = argc; +-CFLAGS = -DADD_ -O3 ++CFLAGS = -DADD_ -O3 -flto + + #----------------------------------------------------------------------------- + # Archive programs and flags +diff --git a/CLAPACK-3.2.1/make.inc.WASM b/CLAPACK-3.2.1/make.inc.WASM +index 80037d0..a964b2d 100644 +--- a/CLAPACK-3.2.1/make.inc.WASM ++++ b/CLAPACK-3.2.1/make.inc.WASM +@@ -23,7 +23,7 @@ PLAT = + # This is used to compile C libary + # if no wrapping of the blas library is needed, uncomment next line + CC = emcc # -DNO_BLAS_WRAP +-CFLAGS = -I$(TOPDIR)/INCLUDE -I$(TOPDIR)/../libf2c -O3 ++CFLAGS = -I$(TOPDIR)/INCLUDE -I$(TOPDIR)/../libf2c -O3 -flto + LOADER = $(CC) + LOADOPTS = + NOOPT = -O0 -I$(TOPDIR)/INCLUDE -I$(TOPDIR)/../libf2c +diff --git a/f2c_BLAS-3.8.0/make.inc.WASM b/f2c_BLAS-3.8.0/make.inc.WASM +index e071614..4647c2b 100644 +--- a/f2c_BLAS-3.8.0/make.inc.WASM ++++ b/f2c_BLAS-3.8.0/make.inc.WASM +@@ -16,7 +16,7 @@ PLAT = + # desired load options for your machine. + # + CC = emcc +-CFLAGS = -I../libf2c -O3 ++CFLAGS = -I../libf2c -O3 -flto + DRVOPTS = $(OPTS) + NOOPT = + LOADER = emcc +diff --git a/libf2c/makefile.WASM b/libf2c/makefile.WASM +index 6221401..d93b87f 100644 +--- a/libf2c/makefile.WASM ++++ b/libf2c/makefile.WASM +@@ -15,7 +15,7 @@ + .SUFFIXES: .c .o + CC = emcc + SHELL = /bin/sh +-CFLAGS = -DNON_UNIX_STDIO -O3 ++CFLAGS = -DNON_UNIX_STDIO -O3 -flto + + LD = wasm-ld + RANLIB = emranlib +@@ -24,7 +24,7 @@ AR = emar + # compile, then strip unnecessary symbols + .c.o: + $(CC) -c -DSkip_f2c_Undefs $(CFLAGS) $*.c +- $(LD) --relocatable -o $*.xxx $*.o ++ $(LD) --no-entry -r -o $*.xxx $*.o + mv $*.xxx $*.o + ## Under Solaris (and other systems that do not understand ld -x), + ## omit -x in the ld line above.