Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install tcmalloc #4564

Merged
merged 4 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/configure
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ Configuration options:
--android-incdir=DIR Android include directory
--enable-kenlm enable kenlm runtime library installed in "../tools/kenlm"
via extras/install_kenlm_query_only.sh, [default=no]
--enable-tcmalloc enable tcmalloc library installed in "../tools/gperftools"
via extras/install_tcmalloc.sh, [default=no]

Following environment variables can be used to override the default toolchain.
CXX C++ compiler [default=g++]
Expand Down Expand Up @@ -611,6 +613,7 @@ static_fst=false
static_math=false
android=false
enable_kenlm=false
enable_tcmalloc=false

FSTROOT=`rel2abs ../tools/openfst`
CUBROOT=`rel2abs ../tools/cub`
Expand Down Expand Up @@ -746,6 +749,9 @@ do
--enable-kenlm)
enable_kenlm=true
shift ;;
--enable-tcmalloc)
enable_tcmalloc=true
shift ;;
*) echo "Unknown argument: $1, exiting"; usage; exit 1 ;;
esac
done
Expand Down Expand Up @@ -1287,6 +1293,22 @@ else
appropriate configuration for this platform. Please contact the developers."
fi

if $enable_tcmalloc ; then
if [ -f ../tools/gperftools/lib/libtcmalloc_minimal.so ]; then
TCMALLOC_ROOT=$(rel2abs ../tools/gperftools)
echo "Configuring tcmalloc since --enable-tcmalloc"
if [ "$(uname)" == "Linux" ]; then
echo "LDLIBS += -Wl,-rpath=$TCMALLOC_ROOT/lib -ltcmalloc_minimal" >> kaldi.mk
else
failure "Now, --enable-tcmalloc option is only supported for Linux"
fi
echo "Successfully configured tcmalloc for Linux from $TCMALLOC_ROOT"
else
failure "Can't find tcmalloc in tools/gperftools. Run" \
"'extras/install_tcmalloc.sh' in 'tools/' to install."
fi
fi

# Append the flags set by environment variables last so they can be used
# to override the automatically generated configuration.
echo >> kaldi.mk
Expand Down
1 change: 1 addition & 0 deletions tools/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.tar.gz
*.tgz
*.zip
*.bak

env.sh

Expand Down
52 changes: 52 additions & 0 deletions tools/extras/install_tcmalloc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
#
# Copyright 2021 Hang Lyu
# 2021 kkm
#
# This script attempts to install tcmalloc.
# The tcmalloc provides the more efficient way to malloc so that it can speed
# up the code, especially for the decoding code which contains massive memory
# allocation operations.
#
# At the same time, the tcmalloc also provides some profilers which can help
# the user to analysis the performance of the code.
# However, there may have some deadlock problems when you use the profilers with
# default build-in glibc. So the libunwind is recommanded to be installed. When
# the deadlock problems happen, the user can try to link with the library
# libunwind. But there may still be some crash on x64 platform. (Link with
# "-lunwind" after your installation if you want to include it.)
# As very rare end users will need it and we believe the users who need it must
# be qualified to reconfigure and build as much of toolset as they want, we skip
# the installation around libunwind.
#
# Depending on different platforms which are used by different users, the users
# also can try differnet malloc libraries such as tbbmalloc, ptmalloc and so on.
# From our test, the tcmalloc is most efficient on our platform.

set -e

# Make sure we are in the tools/ directory.
if [ $(basename $PWD) == extras ]; then
cd ..
fi

! [ $(basename $PWD) == tools ] && \
echo "You must call this script from the tools/ directory" && exit 1;

# prepare tcmalloc
if [ -d gperftools ]; then
echo "$0: existing 'gperftools' subdirectory is renamed 'gperftools.bak'"
mv -f gpreftools gpreftools.bak

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! #4629

fi

wget https://github.com/gperftools/gperftools/releases/download/gperftools-2.9.1/gperftools-2.9.1.tar.gz &&
tar xzf gperftools-2.9.1.tar.gz &&
mv gperftools-2.9.1 gperftools

# install tcmalloc
(
cd gperftools &&
./configure --prefix=$PWD --enable-minimal --disable-debugalloc --disable-static &&
make &&
make install
)