Skip to content

Commit

Permalink
Ability to use ccache to speedup local builds (#729)
Browse files Browse the repository at this point in the history
I noticed that we have support for `sccache` in `build.sh` for building RAFT, but no `ccache` (especially if one wants to do local builds). This PR adds support for the latter. Also includes changes to install `ccache` in raft dev conda env.

Let me know in case you have any concerns with adding this.

Authors:
  - Thejaswi. N. S (https://github.com/teju85)

Approvers:
  - Robert Maynard (https://github.com/robertmaynard)
  - Ray Douglass (https://github.com/raydouglass)
  - AJ Schmidt (https://github.com/ajschmidt8)

URL: #729
  • Loading branch information
teju85 authored Jul 7, 2022
1 parent 8aae19f commit 2b27bad
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
36 changes: 27 additions & 9 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ ARGS=$*
# script, and that this script resides in the repo dir!
REPODIR=$(cd $(dirname $0); pwd)

VALIDARGS="clean libraft pyraft pylibraft docs tests bench clean -v -g --install --compile-libs --compile-nn --compile-dist --allgpuarch --sccache --no-nvtx --show_depr_warn -h --buildfaiss --minimal-deps"
HELP="$0 [<target> ...] [<flag> ...] [--cmake-args=\"<args>\"]
VALIDARGS="clean libraft pyraft pylibraft docs tests bench clean -v -g --install --compile-libs --compile-nn --compile-dist --allgpuarch --no-nvtx --show_depr_warn -h --buildfaiss --minimal-deps"
HELP="$0 [<target> ...] [<flag> ...] [--cmake-args=\"<args>\"] [--cache-tool=<tool>]
where <target> is:
clean - remove all existing build artifacts and configuration (start over)
libraft - build the raft C++ code only. Also builds the C-wrapper library
Expand All @@ -33,7 +33,6 @@ HELP="$0 [<target> ...] [<flag> ...] [--cmake-args=\"<args>\"]
and <flag> is:
-v - verbose build mode
-g - build for debug
--sccache - enable sccache
--compile-libs - compile shared libraries for all components
--compile-nn - compile shared library for nn component
--compile-dist - compile shared library for distance component
Expand All @@ -45,6 +44,8 @@ HELP="$0 [<target> ...] [<flag> ...] [--cmake-args=\"<args>\"]
--no-nvtx - disable nvtx (profiling markers), but allow enabling it in downstream projects
--show_depr_warn - show cmake deprecation warnings
--cmake-args=\\\"<args>\\\" - pass arbitrary list of CMake configuration options (escape all quotes in argument)
--cache-tool=<tool> - pass the build cache tool (eg: ccache, sccache, distcc) that will be used
to speedup the build process.
-h - print this text
default action (no args) is to build both libraft and pyraft targets
Expand All @@ -69,7 +70,7 @@ ENABLE_NN_DEPENDENCIES=OFF

ENABLE_thrust_DEPENDENCY=ON

SCCACHE_ARGS=""
CACHE_ARGS=""
NVTX=ON
CLEAN=0
UNINSTALL=0
Expand Down Expand Up @@ -113,6 +114,26 @@ function cmakeArgs {
fi
}

function cacheTool {
# Check for multiple cache options
if [[ $(echo $ARGS | { grep -Eo "\-\-cache\-tool" || true; } | wc -l ) -gt 1 ]]; then
echo "Multiple --cache-tool options were provided, please provide only one: ${ARGS}"
exit 1
fi
# Check for cache tool option
if [[ -n $(echo $ARGS | { grep -E "\-\-cache\-tool" || true; } ) ]]; then
# There are possible weird edge cases that may cause this regex filter to output nothing and fail silently
# the true pipe will catch any weird edge cases that may happen and will cause the program to fall back
# on the invalid option error
CACHE_TOOL=$(echo $ARGS | sed -e 's/.*--cache-tool=//' -e 's/ .*//')
if [[ -n ${CACHE_TOOL} ]]; then
# Remove the full CACHE_TOOL argument from list of args so that it passes validArgs function
ARGS=${ARGS//--cache-tool=$CACHE_TOOL/}
CACHE_ARGS="-DCMAKE_CUDA_COMPILER_LAUNCHER=${CACHE_TOOL} -DCMAKE_C_COMPILER_LAUNCHER=${CACHE_TOOL} -DCMAKE_CXX_COMPILER_LAUNCHER=${CACHE_TOOL}"
fi
fi
}

if hasArg -h || hasArg --help; then
echo "${HELP}"
exit 0
Expand All @@ -121,6 +142,7 @@ fi
# Check for valid usage
if (( ${NUMARGS} != 0 )); then
cmakeArgs
cacheTool
for a in ${ARGS}; do
if ! (echo " ${VALIDARGS} " | grep -q " ${a} "); then
echo "Invalid option: ${a}"
Expand All @@ -134,10 +156,6 @@ if hasArg --install; then
INSTALL_TARGET="install"
fi

if hasArg --sccache; then
SCCACHE_ARGS="-DCMAKE_CUDA_COMPILER_LAUNCHER=sccache -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache"
fi

if hasArg --minimal-deps; then
ENABLE_thrust_DEPENDENCY=OFF
fi
Expand Down Expand Up @@ -257,7 +275,7 @@ if (( ${NUMARGS} == 0 )) || hasArg libraft || hasArg docs || hasArg tests || has
-DRAFT_COMPILE_DIST_LIBRARY=${COMPILE_DIST_LIBRARY} \
-DRAFT_USE_FAISS_STATIC=${BUILD_STATIC_FAISS} \
-DRAFT_ENABLE_thrust_DEPENDENCY=${ENABLE_thrust_DEPENDENCY} \
${SCCACHE_ARGS} \
${CACHE_ARGS} \
${EXTRA_CMAKE_ARGS}

if [[ ${CMAKE_TARGET} != "" ]]; then
Expand Down
1 change: 1 addition & 0 deletions conda/environments/raft_dev_cuda11.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies:
- doxygen>=1.8.20
- libfaiss>=1.7.0
- faiss-proc=*=cuda
- ccache
- pip
- pip:
- sphinx_markdown_tables
Expand Down
1 change: 1 addition & 0 deletions conda/environments/raft_dev_cuda11.2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies:
- doxygen>=1.8.20
- libfaiss>=1.7.0
- faiss-proc=*=cuda
- ccache
- pip
- pip:
- sphinx_markdown_tables
Expand Down
1 change: 1 addition & 0 deletions conda/environments/raft_dev_cuda11.4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies:
- doxygen>=1.8.20
- libfaiss>=1.7.0
- faiss-proc=*=cuda
- ccache
- pip
- pip:
- sphinx_markdown_tables
Expand Down
1 change: 1 addition & 0 deletions conda/environments/raft_dev_cuda11.5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies:
- doxygen>=1.8.20
- libfaiss>=1.7.0
- faiss-proc=*=cuda
- ccache
- pip
- pip:
- sphinx_markdown_tables
Expand Down

0 comments on commit 2b27bad

Please sign in to comment.