KaldiDecoder (Source Compilation)

These instructions are for KaldiDecoder version 2.5.0 or later.

Compilation Environment

  • OS
    • Ubuntu 16.04 Xenial (64bit)
    • Ubuntu 18.04 Bionic (64bit)
    • Ubuntu 20.04 Focal (64bit)

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

For Ubuntu 20.04 or later users, you will need to additionally install the python2.7 package.

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.2.0-openblas
    • COMMIT_ID = c0a555e4ce (Kaldi 5.5.214)

 

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

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

 

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/
  • DISTRO : Ubuntu distribution
      e.g.) xenial, bionic, focal, 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.
 

Back to Top