Skip to content

Commit 6c74b9a

Browse files
authored
Merge branch 'kaldi-asr:master' into master
2 parents dc1ce30 + 01aadd7 commit 6c74b9a

File tree

7 files changed

+104
-28
lines changed

7 files changed

+104
-28
lines changed

CMakeLists.txt

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,25 @@ if(CONDA_ROOT)
2020

2121
endif()
2222

23-
include(third_party/get_third_party)
23+
option(BuildForFedora "Build for Fedora. Means that everything is build with Border tools" NO)
24+
25+
if(BuildForFedora)
26+
27+
# You also need to install sudo dnf install lapack-devel openfst-devel
28+
set(CMAKE_CXX_STANDARD 17)
29+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
30+
set(CMAKE_CXX_EXTENSIONS OFF)
31+
32+
#find_package(PkgConfig REQUIRED)
33+
34+
#pkg_check_modules(FST REQUIRED fst)
35+
36+
else()
37+
include(third_party/get_third_party)
38+
39+
include(cmake/third_party/openfst.cmake)
40+
endif()
2441

25-
include(cmake/third_party/openfst.cmake)
2642

2743
find_package(PythonInterp)
2844
if(NOT PYTHON_EXECUTABLE)
@@ -43,8 +59,11 @@ execute_process(COMMAND ${PYTHON_EXECUTABLE}
4359
)
4460
unset(IS_LIB_SHARE)
4561

46-
set(CMAKE_CXX_STANDARD 14)
47-
set(CMAKE_CXX_EXTENSIONS OFF)
62+
if(BuildForFedora)
63+
else()
64+
set(CMAKE_CXX_STANDARD 14)
65+
set(CMAKE_CXX_EXTENSIONS OFF)
66+
endif()
4867
set(CMAKE_INSTALL_MESSAGE LAZY) # hide "-- Up-to-date: ..."
4968
if(BUILD_SHARED_LIBS)
5069
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
@@ -228,8 +247,19 @@ endif()
228247
# PATHS "${CMAKE_CURRENT_SOURCE_DIR}/tools/openfst/include"
229248
# REQUIRED)
230249

250+
if(BuildForFedora)
251+
# Version used used by Fedora 41 is 1.83
252+
# TODO: Detect the right version and put it here.
253+
add_definitions(-DOPENFST_VER=18300)
254+
# link_directories(/usr/lib64)
255+
# include_directories(/usr/include/fst)
256+
endif()
257+
231258
link_libraries(fst)
232259

260+
261+
262+
233263
# add all native libraries
234264
add_subdirectory(src/base) # NOTE, we need to patch the target with version from outside
235265
set_property(TARGET kaldi-base PROPERTY COMPILE_DEFINITIONS "KALDI_VERSION=\"${KALDI_VERSION}\"")

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ Development pattern for contributors
5252
Platform specific notes
5353
-----------------------
5454

55+
### Fedora 41 (and later)
56+
57+
In order to build it on Fedora 41 using the libraries that are provided by the distro, you need to install the development libraries and dependencies with
58+
59+
```
60+
sudo dnf install lapack-devel openfst-devel
61+
```
62+
63+
then build the package as follows:
64+
65+
```
66+
cmake -S ./ -Bbuild/Release -DFETCHCONTENT_FULLY_DISCONNECTED=ON -DBuildForFedora=ON
67+
cmake --build /home/gerhard/workspace/kaldi/build/Release
68+
```
69+
70+
5571
### PowerPC 64bits little-endian (ppc64le)
5672

5773
- Kaldi is expected to work out of the box in RHEL >= 7 and Ubuntu >= 16.04 with
@@ -70,6 +86,6 @@ Platform specific notes
7086
### Web Assembly
7187

7288
- Kaldi supports cross compiling for Web Assembly for in-browser execution
73-
using [emscripten](https://emscripten.org/) and CLAPACK.
74-
- See [this post](https://gitlab.inria.fr/kaldi.web/kaldi-wasm/-/wikis/build_details.md)
89+
using [emscripten](https://emscripten.org) and OpenBLAS
90+
- See [this repo](https://github.com/msqr1/kaldi-wasm2)
7591
for a step-by-step description of the build process.

src/configure

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# ./configure --atlas-root=../tools/ATLAS/build
1818
# ./configure --use-cuda=no # disable CUDA detection (will build cpu-only
1919
# # version of kaldi even on CUDA-enabled machine.
20-
# ./configure --use-cuda --cudatk-dir=/usr/local/cuda/ --cuda-arch=-arch=sm_70
20+
# ./configure --use-cuda=yes --cudatk-dir=/usr/local/cuda/ --cuda-arch=-arch=sm_70
2121
# # Use cuda in /usr/local/cuda and set the arch to sm_70
2222
# ./configure --static --fst-root=/opt/cross/armv8hf \
2323
# --atlas-root=/opt/cross/armv8hf --host=armv8-rpi3-linux-gnueabihf
@@ -69,7 +69,7 @@ Configuration options:
6969
--version Display the version of 'configure' and exit
7070
--static Build and link against static libraries [default=no]
7171
--shared Build and link against shared libraries [default=no]
72-
--use-cuda Build with CUDA [default=yes]
72+
--use-cuda Build with CUDA [default=no]
7373
--with-cudadecoder Build with CUDA decoder [default=yes]
7474
--cudatk-dir=DIR CUDA toolkit directory
7575
--cuda-arch=FLAGS Override the default CUDA_ARCH flags. See:
@@ -894,6 +894,12 @@ if is_set $HOST; then
894894
fi
895895
else
896896
TARGET_ARCH="$HOST"
897+
if ! $static_fst || ! $static_math || $dynamic_kaldi; then
898+
echo "WARNING: Dynamic libraries are not currently supported when compiling to WASM. Overriding --static, --static-math, and --static-fst."
899+
fi
900+
dynamic_kaldi=false
901+
static_math=true
902+
static_fst=true
897903
fi
898904

899905
HOST_CXX="$HOST-c++"
@@ -1360,14 +1366,6 @@ or try another math library, e.g. --mathlib=OPENBLAS (Kaldi may be slower)."
13601366
** You can also use other matrix algebra libraries. For information, see:
13611367
** http://kaldi-asr.org/doc/matrixwrap.html"
13621368
fi
1363-
if [ -f $OPENBLASROOT/lib/libopenblas.so ]; then
1364-
OPENBLASLIBDIR=$OPENBLASROOT/lib
1365-
elif [ -f $OPENBLASROOT/lib64/libopenblas.so ]; then
1366-
# in REDHAT/CentOS package installs, the library is located here
1367-
OPENBLASLIBDIR=$OPENBLASROOT/lib64
1368-
else
1369-
failure "Expected to find the file $OPENBLASROOT/lib/libopenblas.so"
1370-
fi
13711369
if [ -f $OPENBLASROOT/include/cblas.h ] ; then
13721370
OPENBLASINCDIR=$OPENBLASROOT/include
13731371
elif [ -f $OPENBLASROOT/include/openblas/cblas.h ] ; then
@@ -1381,18 +1379,35 @@ or try another math library, e.g. --mathlib=OPENBLAS (Kaldi may be slower)."
13811379
echo "** if it is a package-based install)."
13821380
OPENBLASINCDIR="/usr/include"
13831381
fi
1384-
echo "Your math library seems to be OpenBLAS from $OPENBLASROOT. Configuring appropriately."
1385-
# TODO(kkm): Probably, OpenBLAS required libgfortran.so.3 at some point, but
1386-
# no longer does. *My* linker does not complain about a missing library, but
1387-
# is it safe to keep the reference if no longer required? Try to figure out
1388-
# how long ago the dependency was dropped.
13891382
if $static_math; then
1383+
if [ -f $OPENBLASROOT/lib/libopenblas.a ]; then
1384+
OPENBLASLIBDIR=$OPENBLASROOT/lib
1385+
else
1386+
failure "Expected to find the file $OPENBLASROOT/lib/libopenblas.a"
1387+
fi
13901388
echo "Configuring static OpenBlas since --static-math=yes"
1391-
OPENBLASLIBS="-L$OPENBLASLIBDIR -l:libopenblas.a -lgfortran"
1389+
OPENBLASLIBS="-L$OPENBLASLIBDIR -l:libopenblas.a"
1390+
# No Fortran for OpenBLAS
1391+
if [[ "$HOST" != WASM ]]; then
1392+
OPENBLASLIBS+="-lgfortran"
1393+
fi
13921394
else
1395+
if [ -f $OPENBLASROOT/lib/libopenblas.so ]; then
1396+
OPENBLASLIBDIR=$OPENBLASROOT/lib
1397+
elif [ -f $OPENBLASROOT/lib64/libopenblas.so ]; then
1398+
# in REDHAT/CentOS package installs, the library is located here
1399+
OPENBLASLIBDIR=$OPENBLASROOT/lib64
1400+
else
1401+
failure "Expected to find the file $OPENBLASROOT/lib/libopenblas.so"
1402+
fi
13931403
echo "Configuring dynamically loaded OpenBlas since --static-math=no (the default)"
13941404
OPENBLASLIBS="-L$OPENBLASLIBDIR -lopenblas -lgfortran -Wl,-rpath=$OPENBLASLIBDIR"
13951405
fi
1406+
echo "Your math library seems to be OpenBLAS from $OPENBLASROOT. Configuring appropriately."
1407+
# TODO(kkm): Probably, OpenBLAS required libgfortran.so.3 at some point, but
1408+
# no longer does. *My* linker does not complain about a missing library, but
1409+
# is it safe to keep the reference if no longer required? Try to figure out
1410+
# how long ago the dependency was dropped.
13961411
echo "OPENBLASINC = $OPENBLASINCDIR" >> kaldi.mk
13971412
echo "OPENBLASLIBS = $OPENBLASLIBS" >> kaldi.mk
13981413
echo >> kaldi.mk

src/makefiles/linux_clapack.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ ifeq ($(findstring clang,$(COMPILER)),clang)
4444
CXXFLAGS += -Wno-mismatched-tags
4545
endif
4646

47-
LDFLAGS = $(EXTRA_LDFLAGS) $(OPENFSTLDFLAGS) -rdynamic
47+
LDFLAGS = $(EXTRA_LDFLAGS) $(OPENFSTLDFLAGS)
4848
LDLIBS = $(EXTRA_LDLIBS) $(OPENFSTLIBS) $(CLAPACKLIBS) -lm -ldl
4949

5050
ifneq ($(ARCH), WASM)
51+
LDFLAGS += -rdynamic
5152
CXXFLAGS += -pthread
5253
LDLIBS += -lpthread
5354
endif

src/makefiles/linux_openblas.mk

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ CXXFLAGS = -std=$(CXXLANGVERSION) -I.. -isystem $(OPENFSTINC) -O1 $(EXTRA_CXXFLA
2525
-DOPENFST_VER=$(OPENFSTVER) \
2626
-DKALDI_DOUBLEPRECISION=$(DOUBLE_PRECISION) \
2727
-DHAVE_EXECINFO_H=1 -DHAVE_CXXABI_H -DHAVE_OPENBLAS -I$(OPENBLASINC) \
28-
-msse -msse2 -pthread \
28+
-msse -msse2 \
2929
-g
3030

3131
ifeq ($(KALDI_FLAVOR), dynamic)
@@ -46,5 +46,13 @@ ifeq ($(findstring clang,$(COMPILER)),clang)
4646
CXXFLAGS += -Wno-mismatched-tags
4747
endif
4848

49-
LDFLAGS = $(EXTRA_LDFLAGS) $(OPENFSTLDFLAGS) -rdynamic
50-
LDLIBS = $(EXTRA_LDLIBS) $(OPENFSTLIBS) $(OPENBLASLIBS) -lm -lpthread -ldl
49+
LDFLAGS = $(EXTRA_LDFLAGS) $(OPENFSTLDFLAGS)
50+
LDLIBS = $(EXTRA_LDLIBS) $(OPENFSTLIBS) $(OPENBLASLIBS) -lm -ldl
51+
52+
ifneq ($(ARCH), WASM)
53+
CXXFLAGS += -pthread
54+
LDLIBS += -lpthread
55+
LDFLAGS += -rdynamic
56+
else
57+
CXXFLAGS += -DKALDI_WASM
58+
endif

src/util/kaldi-thread.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@
2222
#include "util/kaldi-thread.h"
2323

2424
namespace kaldi {
25-
int32 g_num_threads = 8; // Initialize this global variable.
2625

26+
int32 g_num_threads =
27+
#ifdef KALDI_WASM
28+
0 // Everything will run on the main thread for WASM
29+
#else
30+
8 // Initialize this global variable.
31+
#endif
32+
;
2733
MultiThreadable::~MultiThreadable() {
2834
// default implementation does nothing
2935
}

tools/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CC ?= gcc # used for sph2pipe
77

88
WGET ?= wget
99

10-
OPENFST_VERSION ?= 1.8.3
10+
OPENFST_VERSION ?= 1.8.4
1111
CUB_VERSION ?= 1.8.0
1212
# No '?=', since there exists only one version of sph2pipe.
1313
SPH2PIPE_VERSION = 2.5

0 commit comments

Comments
 (0)