KaldiDecoder (Source Compilation)

These instructions are for KaldiDecoder version 2.5.0 or later.

Compilation Environment

Notes: KaldiDecoder uses the Kaldi libraries, so it can only be built in an environment supported by the Kaldi officially site (http://kaldi-asr.org/).

 

Installation instruction

Step.1 Get build tools and dependent libraries.

sudo apt update
sudo apt install git automake autoconf libtool cmake cmake-extras build-essential libopenblas-base libopenblas-dev gfortran liblapack-dev liblapacke-dev zlib1g-dev sox subversion

Users running Ubuntu 20.04 or later who want to use packages older than 3.4.0-openblas will need to additionally install the python2.7 package. If you use 3.4.0-openblas or later, use Kaldi’s COMMIT_ID: 1a233a11db or a later commit and it will work if you have python3.

sudo apt install python2.7

 

Step.2 Get the official Kaldi source code.

cd ~/
mkdir YOUR_DIR
cd YOUR_DIR
git clone https://github.com/kaldi-asr/kaldi.git
cd kaldi
git checkout COMMIT_ID

The binary package provided by us was built based on the commit ID below. If you change the base Kaldi version, the build may fail.

  • kaldidecoder-hark: 2.5.0-openblas, 3.0.0-openblas, 3.0.5-openblas
    • COMMIT_ID = 4571f47f84 (Kaldi 5.4.173)
  • kaldidecoder-hark: 3.1.0-openblas, 3.1.2.1-openblas, (and internal release 3.1.3-openblas, 3.1.4-openblas, 3.1.5-openblas, 3.1.6-openblas, 3.1.7-openblas, 3.2.0-openblas)
    • COMMIT_ID = c0a555e4ce (Kaldi 5.5.214)
  • kaldidecoder-hark: 3.4.0-openblas, (and internal release 3.4.1-openblas and 3.4.2-openblas)
    • COMMIT_ID = 7a50987e7 (Kaldi 5.5.636 : Although it is possible to build it, it was not adopted in the packaged version.)
    • COMMIT_ID = 1a233a11db (The newer commit we saw was committed on May 26, 2022, at 01:03:14 JST)
  • kaldidecoder-hark: 3.5.0 or later
    • COMMIT_ID = 1a233a11db
    • COMMIT_ID = 21ae411fd4 (Latest commit as of December 12, 2023, at 16:57 JST. We have confirmed that it can be built, but we have not confirmed that it works.)

 

Step.3 Build Kaldi’s external tool (and dependent library).

If you use Kaldi 5.5.636 or earlier, it will look like this:

cd tools
extras/check_dependencies.sh
#### The following message is displayed but there is no problem. Because we use openblas.
# You should probably do:
#  sudo apt-get install libatlas3-base
make

If you checked out the commit ID of a relatively new commit (e.g. 1a233a11db) from your Kaldi repository, it will look like this:

cd tools
extras/check_dependencies.sh
#### The following message is displayed but there is no problem. Because we use openblas.
# extras/check_dependencies.sh: Intel MKL does not seem to be installed.
# ... Run extras/install_mkl.sh to install it. Some distros (e.g., Ubuntu 20.04) provide
# ... a version of MKL via the package manager, but verify that it is up-to-date.
# ... You can also use other matrix algebra libraries. For information, see:
# ...   http://kaldi-asr.org/doc/matrixwrap.html
make

 

Step.4 Build Kaldi with the set up to use openblas library.

For Ubuntu 16.04 users.

cd ../src
./configure --mathlib=OPENBLAS --openblas-root=/usr
make clean -j CORES
make depend -j CORES
make -j CORES
  • CORES : How many cores do you have
      e.g.) 4
      Note: About 2GB of memory is required for each core when compiling. Please set the number of cores considering free memory capacity.

 

For Ubuntu 18.04 or later users, the following workaround is required because the openblas library path was changed.

cd ../src
mkdir fakeroot
ln -s /usr/include/x86_64-linux-gnu/ fakeroot/include
ln -s /usr/lib/x86_64-linux-gnu/ fakeroot/lib
./configure --mathlib=OPENBLAS --openblas-root=fakeroot
make clean -j CORES
make depend -j CORES
make -j CORES
  • CORES : How many cores do you have
      e.g.) 4
      Note: About 2GB of memory is required for each core when compiling. Please set the number of cores considering free memory capacity.

 

Step5. Build KaldiDecoder.

cd ../
wget http://archive.hark.jp/harkrepos/dists/DISTRO/non-free/source/kaldidecoder-hark_HARK_VER.tar.xz
tar -Jxvf kaldidecoder-hark_HARK_VER.tar.xz
cd kaldidecoder3
mkdir build
cd build
cmake .. -DOPENBLAS_ROOT_DIR:STRING=/usr -DCMAKE_VERBOSE_MAKEFILE:BOOL=TRUE
make
sudo make install

If you want to know which HARK_VER that can be downloaded, please access directly from your browser at the following location.

  • For Ubuntu 16.04 (xenial) users.
      http://archive.hark.jp/harkrepos/dists/xenial/non-free/source/
  • For Ubuntu 18.04 (bionic) users.
      http://archive.hark.jp/harkrepos/dists/bionic/non-free/source/
  • For Ubuntu 20.04 (focal) users.
      http://archive.hark.jp/harkrepos/dists/focal/non-free/source/
  • For Ubuntu 22.04 (jammy) users.
      http://archive.hark.jp/harkrepos/dists/jammy/non-free/source/
  • DISTRO : Ubuntu distribution
      e.g.) xenial, bionic, focal, jammy, noble, etc…

 

Q&A

Q.1 Is there a way to enable CUDA?
A.1 If you are using 3.1.0-openblas or later, the answer is Yes, but do so at your own risk.

Steps 1 to 3 are the same. For installation of CUDA toolkit please refer to nVidia official installation instructions.

  • nVidia CUDA Toolkit
      https://developer.nvidia.com/cuda-downloads

 

Step.4 Build Kaldi with the set up to use openblas library. (with CUDA)

For Ubuntu 16.04 users.

cd ../src
./configure --mathlib=OPENBLAS --openblas-root=/usr --use-cuda --cudatk-dir=/usr/local/cuda
make clean -j CORES
make depend -j CORES
make -j CORES

Only the arguments of '--use-cuda' and '--cudatk-dir=PATH' have been added by the './configure' command.
 

For Ubuntu 18.04 or later users, the following workaround is required because the openblas library path was changed.

cd ../src
mkdir fakeroot
ln -s /usr/include/x86_64-linux-gnu/ fakeroot/include
ln -s /usr/lib/x86_64-linux-gnu/ fakeroot/lib
./configure --mathlib=OPENBLAS --openblas-root=fakeroot --use-cuda --cudatk-dir=/usr/local/cuda
make clean -j CORES
make depend -j CORES
make -j CORES

Only the arguments of '--use-cuda' and '--cudatk-dir=PATH' have been added by the './configure' command.
 

Step5. Build KaldiDecoder. (with CUDA)

cd ../
wget http://archive.hark.jp/harkrepos/dists/DISTRO/non-free/source/kaldidecoder-hark_HARK_VER.tar.xz
tar -Jxvf kaldidecoder-hark_HARK_VER.tar.xz
cd kaldidecoder3
mkdir build
cd build
cmake .. -DOPENBLAS_ROOT_DIR:STRING=/usr -DCMAKE_VERBOSE_MAKEFILE:BOOL=TRUE -DUSE_CUDA=ON
make
sudo make install

Only the arguments of '-DUSE_CUDA=ON' have been added by the 'cmake' command.
If you have multiple versions of CUDA installed and you want to set your PATH:

cmake .. -DOPENBLAS_ROOT_DIR:STRING=/usr -DCMAKE_VERBOSE_MAKEFILE:BOOL=TRUE -DUSE_CUDA=ON -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-9.0

Make sure that the PATH specified here is the same as the PATH specified in Step 4.
 

Q.2 Build fails on CUDA11. Is there a workaround?
A.2 Use a combination of Kaldi 5.5.636 or later and KaldiDecoder 3.4.0 or later. We recommend always using the latest version of KaldiDecoder source code to support new CUDA version.

Back to Top