From 2b27bad25cd1d381c8175f1ec24eed4508749fcb Mon Sep 17 00:00:00 2001 From: "Thejaswi. N. S" Date: Thu, 7 Jul 2022 11:00:46 +0200 Subject: [PATCH] Ability to use ccache to speedup local builds (#729) 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: https://github.com/rapidsai/raft/pull/729 --- build.sh | 36 ++++++++++++++++++------ conda/environments/raft_dev_cuda11.0.yml | 1 + conda/environments/raft_dev_cuda11.2.yml | 1 + conda/environments/raft_dev_cuda11.4.yml | 1 + conda/environments/raft_dev_cuda11.5.yml | 1 + 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/build.sh b/build.sh index d0eebbd010..8b00fa69dd 100755 --- a/build.sh +++ b/build.sh @@ -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 [ ...] [ ...] [--cmake-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 [ ...] [ ...] [--cmake-args=\"\"] [--cache-tool=] where is: clean - remove all existing build artifacts and configuration (start over) libraft - build the raft C++ code only. Also builds the C-wrapper library @@ -33,7 +33,6 @@ HELP="$0 [ ...] [ ...] [--cmake-args=\"\"] and 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 @@ -45,6 +44,8 @@ HELP="$0 [ ...] [ ...] [--cmake-args=\"\"] --no-nvtx - disable nvtx (profiling markers), but allow enabling it in downstream projects --show_depr_warn - show cmake deprecation warnings --cmake-args=\\\"\\\" - pass arbitrary list of CMake configuration options (escape all quotes in argument) + --cache-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 @@ -69,7 +70,7 @@ ENABLE_NN_DEPENDENCIES=OFF ENABLE_thrust_DEPENDENCY=ON -SCCACHE_ARGS="" +CACHE_ARGS="" NVTX=ON CLEAN=0 UNINSTALL=0 @@ -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 @@ -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}" @@ -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 @@ -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 diff --git a/conda/environments/raft_dev_cuda11.0.yml b/conda/environments/raft_dev_cuda11.0.yml index a7df4e5383..e790af992a 100644 --- a/conda/environments/raft_dev_cuda11.0.yml +++ b/conda/environments/raft_dev_cuda11.0.yml @@ -22,6 +22,7 @@ dependencies: - doxygen>=1.8.20 - libfaiss>=1.7.0 - faiss-proc=*=cuda +- ccache - pip - pip: - sphinx_markdown_tables diff --git a/conda/environments/raft_dev_cuda11.2.yml b/conda/environments/raft_dev_cuda11.2.yml index 8312ab3c5a..fe1ea14d5f 100644 --- a/conda/environments/raft_dev_cuda11.2.yml +++ b/conda/environments/raft_dev_cuda11.2.yml @@ -22,6 +22,7 @@ dependencies: - doxygen>=1.8.20 - libfaiss>=1.7.0 - faiss-proc=*=cuda +- ccache - pip - pip: - sphinx_markdown_tables diff --git a/conda/environments/raft_dev_cuda11.4.yml b/conda/environments/raft_dev_cuda11.4.yml index 1ef1a40c9f..283a200d23 100644 --- a/conda/environments/raft_dev_cuda11.4.yml +++ b/conda/environments/raft_dev_cuda11.4.yml @@ -22,6 +22,7 @@ dependencies: - doxygen>=1.8.20 - libfaiss>=1.7.0 - faiss-proc=*=cuda +- ccache - pip - pip: - sphinx_markdown_tables diff --git a/conda/environments/raft_dev_cuda11.5.yml b/conda/environments/raft_dev_cuda11.5.yml index d146791978..15ffd90c9c 100644 --- a/conda/environments/raft_dev_cuda11.5.yml +++ b/conda/environments/raft_dev_cuda11.5.yml @@ -23,6 +23,7 @@ dependencies: - doxygen>=1.8.20 - libfaiss>=1.7.0 - faiss-proc=*=cuda +- ccache - pip - pip: - sphinx_markdown_tables