Kaldi¶
To compile Kaldi, submit the following script as a job at the GPU partition:
#!/bin/bash -l
#
#SBATCH --job-name="kaldi-comp"
#SBATCH --time=24:00:00
#SBATCH --partition=gpu
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=8
#SBATCH --mem-per-cpu=1G
echo "###########################################################"
echo "### ###"
echo "### Local installation of Kaldi on DelftBlue ###"
echo "### ###"
echo "### Compiling on a GPU node ###"
echo "### ###"
echo "### Compiling in /scratch/$USER/tools/kaldi-install-gpu ###"
echo "### ###"
echo "###########################################################"
# 0. Preparation: checking or creating folders
echo "##########################################"
echo "Step 0: Checking or creating folders..."
echo "##########################################"
if [ -d "/scratch/$USER/tools" ]
then
echo "Directory /scratch/$USER/tools exists."
else
cd /scratch/$USER
mkdir tools
echo "Directory /scratch/$USER/tools created."
fi
if [ -d "/scratch/$USER/tools/kaldi-install-gpu" ]
then
echo "Directory /scratch/$USER/tools/kaldi-install-gpu exists and will be removed."
cd /scratch/$USER/tools
rm -rf kaldi-install-gpu
mkdir kaldi-install-gpu
echo "Existing /scratch/$USER/tools/kaldi-install-gpu was deleted"
echo "and replaced with a new empty directory."
else
cd /scratch/$USER/tools
mkdir kaldi-install-gpu
echo "Directory /scratch/$USER/tools/kaldi-install-gpu created."
fi
echo "##########################################"
echo "Step 0 completed: compilation will take place in /scratch/$USER/tools/kaldi-install-gpu"
echo "##########################################"
# 1. Load necessary modules:
echo "##########################################"
echo "Step 1: Loading modules..."
echo "##########################################"
module load 2023r1
module load intel/oneapi-all
export MKL_ROOT=/mnt/shared/apps/generic/intel/oneapi/mkl/latest
module load python
module load lz4
module load expat
module load sqlite
module load cuda
module load cudnn
echo "##########################################"
echo "Step 1 completed. Modules loaded."
echo "##########################################"
# 2. Install sox:
echo "##########################################"
echo "Step 2: Installing sox..."
echo "##########################################"
cd /scratch/$USER/tools/kaldi-install-gpu
mkdir sox-install
export INSTALL_DIR=/scratch/$USER/tools/kaldi-install-gpu/sox-install
wget https://nchc.dl.sourceforge.net/project/sox/sox/14.4.2/sox-14.4.2.tar.gz
tar xvfz sox-14.4.2.tar.gz
cd sox-14.4.2
echo "Configuring sox..."
./configure --prefix=$INSTALL_DIR
echo "Done configuring sox."
echo "Running make -s and make install for sox..."
make -s && make install
export PATH=/scratch/$USER/tools/kaldi-install-gpu/sox-install/bin:$PATH
export LD_LIBRARY_PATH=/scratch/$USER/tools/kaldi-install-gpu/sox-install/lib:$LD_LIBRARY_PATH
echo "##########################################"
echo "Step 2 completed: Done with sox."
echo "##########################################"
# 3. Install APR for subversion:
echo "##########################################"
echo "Step 3: Installing APR and APR-util..."
echo "##########################################"
echo "Installing APR..."
cd /scratch/$USER/tools/kaldi-install-gpu
mkdir apr-install
export INSTALL_DIR=/scratch/$USER/tools/kaldi-install-gpu/apr-install
wget https://dlcdn.apache.org//apr/apr-1.7.0.tar.gz
tar xvfz apr-1.7.0.tar.gz
cd apr-1.7.0
echo "Configuring apr..."
./configure --prefix=$INSTALL_DIR
echo "Done configuring apr."
echo "Running make and make install for apr..."
make
make install
echo "Done with apr."
echo "Installing APR-util..."
cd /scratch/$USER/tools/kaldi-install-gpu
mkdir apr-util-install
export INSTALL_DIR=/scratch/$USER/tools/kaldi-install-gpu/apr-util-install
wget https://dlcdn.apache.org//apr/apr-util-1.6.1.tar.gz
tar xvfz apr-util-1.6.1.tar.gz
cd apr-util-1.6.1
echo "Configuring apr-util..."
./configure --prefix=$INSTALL_DIR --with-apr=/scratch/$USER/tools/kaldi-install-gpu/apr-install --with-expat=/apps/arch/2023r1/software/linux-rhel8-x86_64_v3/gcc-8.5.0/expat-2.4.8-jf2dt5en337wd5j5rd56st4amhcbhbff/
echo "Done configuring apr-util."
echo "Running make and make install for apr-util..."
make
make install
echo "Done with apr-util."
echo "##########################################"
echo "Step 3 completed: Done with apr and apr-util."
echo "##########################################"
# 4. Install subversion:
echo "##########################################"
echo "Step 4: Installing SVN..."
echo "##########################################"
cd /scratch/$USER/tools/kaldi-install-gpu
mkdir svn-install
export INSTALL_DIR=/scratch/$USER/tools/kaldi-install-gpu/svn-install
wget https://dlcdn.apache.org/subversion/subversion-1.14.2.tar.gz
tar xvfz subversion-1.14.2.tar.gz
cd subversion-1.14.2
echo "Configuring svn..."
./configure --prefix=$INSTALL_DIR --with-utf8proc=internal --with-apr=/scratch/$USER/tools/kaldi-install-gpu/apr-install --with-apr-util=/scratch/$USER/tools/kaldi-install-gpu/apr-util-install --with-sqlite=/apps/arch/2023r1/software/linux-rhel8-x86_64_v3/gcc-8.5.0/sqlite-3.39.4-fzqw2rphdxajs3xo7ckdrzshyczyxjkz
echo "Done configuring svn..."
echo "Running make and make install for svn..."
make
make install
export PATH=/scratch/$USER/tools/kaldi-install-gpu/svn-install/bin:$PATH
export LD_LIBRARY_PATH=/scratch/$USER/tools/kaldi-install-gpu/svn-install/lib:$LD_LIBRARY_PATH
echo "##########################################"
echo "Step 4 completed: Done with svn."
echo "##########################################"
# 5. Check Kaldi dependencies:
echo "##########################################"
echo "Step 5: Checking Kaldi dependencies..."
echo "##########################################"
cd /scratch/$USER/tools/kaldi-install-gpu
git clone https://github.com/kaldi-asr/kaldi.git kaldi --origin upstream
cd kaldi
cd tools
./extras/check_dependencies.sh
echo "##########################################"
echo "Step 5 completed: Done checking Kaldi dependencies."
echo "##########################################"
# 6. Compile Kaldi tools inside of the "/scratch/$USER/tools/kaldi-install-gpu/kaldi/tools" folder:
echo "##########################################"
echo "Step 6: Compiling Kaldi tools..."
echo "##########################################"
CXX=g++ make -j 4
echo "##########################################"
echo "Step 6 completed: Done compiling Kaldi tools."
echo "##########################################"
# 7. Compile Kaldi itself inside of the "/scratch/$USER/tools/kaldi-install-gpu/kaldi/src" folder:
echo "##########################################"
echo "Step 7: Installing Kaldi..."
echo "##########################################"
cd /scratch/$USER/tools/kaldi-install-gpu/kaldi/src
echo "Configuring Kaldi..."
./configure --shared --mkl-root=/mnt/shared/apps/generic/intel/oneapi/mkl/latest --cudatk-dir=/beegfs/apps/generic/cuda-11.6
echo "Done configuring Kaldi."
echo "Running make for Kaldi..."
make clean depend -j 8
make -j 8
echo "##########################################"
echo "Step 7 completed: Done with Kaldi."
echo "##########################################"