From 340b421ab81c50468ade9ce337d23d05595875ff Mon Sep 17 00:00:00 2001 From: Thejaswi Rao Date: Thu, 30 Jun 2022 07:53:16 -0700 Subject: [PATCH 1/4] added ability to use ccache to speedup local builds --- build.sh | 16 ++++++++++++++-- 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, 18 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index d0eebbd010..e27e583b4a 100755 --- a/build.sh +++ b/build.sh @@ -18,7 +18,7 @@ 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" +VALIDARGS="clean libraft pyraft pylibraft docs tests bench clean -v -g --install --compile-libs --compile-nn --compile-dist --allgpuarch --sccache --ccache --no-nvtx --show_depr_warn -h --buildfaiss --minimal-deps" HELP="$0 [ ...] [ ...] [--cmake-args=\"\"] where is: clean - remove all existing build artifacts and configuration (start over) @@ -33,7 +33,8 @@ HELP="$0 [ ...] [ ...] [--cmake-args=\"\"] and is: -v - verbose build mode -g - build for debug - --sccache - enable sccache + --sccache - enable sccache + --ccache - enable ccache --compile-libs - compile shared libraries for all components --compile-nn - compile shared library for nn component --compile-dist - compile shared library for distance component @@ -70,6 +71,7 @@ ENABLE_NN_DEPENDENCIES=OFF ENABLE_thrust_DEPENDENCY=ON SCCACHE_ARGS="" +CCACHE_ARGS="" NVTX=ON CLEAN=0 UNINSTALL=0 @@ -134,10 +136,19 @@ if hasArg --install; then INSTALL_TARGET="install" fi +if hasArg --sccache && hasArg --ccache; then + echo "Cannot enable both sccache and ccache at the same time!" + exit 1 +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 --ccache; then + CCACHE_ARGS="-DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache" +fi + if hasArg --minimal-deps; then ENABLE_thrust_DEPENDENCY=OFF fi @@ -258,6 +269,7 @@ if (( ${NUMARGS} == 0 )) || hasArg libraft || hasArg docs || hasArg tests || has -DRAFT_USE_FAISS_STATIC=${BUILD_STATIC_FAISS} \ -DRAFT_ENABLE_thrust_DEPENDENCY=${ENABLE_thrust_DEPENDENCY} \ ${SCCACHE_ARGS} \ + ${CCACHE_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 a0f6405960..562f9f79b6 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 From 0672024b36fa2a7cd23b84b2bf8998c3ed8db1e0 Mon Sep 17 00:00:00 2001 From: Thejaswi Rao Date: Mon, 4 Jul 2022 05:54:32 -0700 Subject: [PATCH 2/4] used a --ccache-tool option instead of separate --sccache and --ccache options --- build.sh | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/build.sh b/build.sh index e27e583b4a..0b85fedd88 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 --ccache --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=\"\"] [--ccache-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,8 +33,6 @@ HELP="$0 [ ...] [ ...] [--cmake-args=\"\"] and is: -v - verbose build mode -g - build for debug - --sccache - enable sccache - --ccache - enable ccache --compile-libs - compile shared libraries for all components --compile-nn - compile shared library for nn component --compile-dist - compile shared library for distance component @@ -46,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) + --ccache-tool= - pass the build ccache 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 @@ -70,7 +70,6 @@ ENABLE_NN_DEPENDENCIES=OFF ENABLE_thrust_DEPENDENCY=ON -SCCACHE_ARGS="" CCACHE_ARGS="" NVTX=ON CLEAN=0 @@ -115,6 +114,26 @@ function cmakeArgs { fi } +function ccacheTool { + # Check for multiple ccache options + if [[ $(echo $ARGS | { grep -Eo "\-\-ccache\-tool" || true; } | wc -l ) -gt 1 ]]; then + echo "Multiple --ccache-tool options were provided, please provide only one: ${ARGS}" + exit 1 + fi + # Check for ccache tool option + if [[ -n $(echo $ARGS | { grep -E "\-\-ccache\-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 + CCACHE_TOOL=$(echo $ARGS | sed -e 's/.*--ccache-tool=//' -e 's/ .*//') + if [[ -n ${CCACHE_TOOL} ]]; then + # Remove the full CCACHE_TOOL argument from list of args so that it passes validArgs function + ARGS=${ARGS//--ccache-tool=$CCACHE_TOOL/} + CCACHE_ARGS="-DCMAKE_CUDA_COMPILER_LAUNCHER=${CCACHE_TOOL} -DCMAKE_C_COMPILER_LAUNCHER=${CCACHE_TOOL} -DCMAKE_CXX_COMPILER_LAUNCHER=${CCACHE_TOOL}" + fi + fi +} + if hasArg -h || hasArg --help; then echo "${HELP}" exit 0 @@ -123,6 +142,7 @@ fi # Check for valid usage if (( ${NUMARGS} != 0 )); then cmakeArgs + ccacheTool for a in ${ARGS}; do if ! (echo " ${VALIDARGS} " | grep -q " ${a} "); then echo "Invalid option: ${a}" @@ -136,19 +156,6 @@ if hasArg --install; then INSTALL_TARGET="install" fi -if hasArg --sccache && hasArg --ccache; then - echo "Cannot enable both sccache and ccache at the same time!" - exit 1 -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 --ccache; then - CCACHE_ARGS="-DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache" -fi - if hasArg --minimal-deps; then ENABLE_thrust_DEPENDENCY=OFF fi @@ -268,7 +275,6 @@ 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} \ ${CCACHE_ARGS} \ ${EXTRA_CMAKE_ARGS} From c8ac076f924807d3a9794bc35043ec5a43f1fd64 Mon Sep 17 00:00:00 2001 From: "Thejaswi. N. S" Date: Wed, 6 Jul 2022 17:20:29 +0200 Subject: [PATCH 3/4] Update build.sh Co-authored-by: AJ Schmidt --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 0b85fedd88..855422e295 100755 --- a/build.sh +++ b/build.sh @@ -19,7 +19,7 @@ ARGS=$* REPODIR=$(cd $(dirname $0); pwd) 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=\"\"] [--ccache-tool=] +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 From 7e4cc5ee44f4eb18197888500939f9edf31de8d8 Mon Sep 17 00:00:00 2001 From: Thejaswi Rao Date: Wed, 6 Jul 2022 09:10:34 -0700 Subject: [PATCH 4/4] updated rest of the occurrences of ccache-tool option usages with cache-tool --- build.sh | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/build.sh b/build.sh index 855422e295..8b00fa69dd 100755 --- a/build.sh +++ b/build.sh @@ -44,7 +44,7 @@ HELP="$0 [ ...] [ ...] [--cmake-args=\"\"] [--cache-tool=\\\" - pass arbitrary list of CMake configuration options (escape all quotes in argument) - --ccache-tool= - pass the build ccache tool (eg: ccache, sccache, distcc) that will be used + --cache-tool= - pass the build cache tool (eg: ccache, sccache, distcc) that will be used to speedup the build process. -h - print this text @@ -70,7 +70,7 @@ ENABLE_NN_DEPENDENCIES=OFF ENABLE_thrust_DEPENDENCY=ON -CCACHE_ARGS="" +CACHE_ARGS="" NVTX=ON CLEAN=0 UNINSTALL=0 @@ -114,22 +114,22 @@ function cmakeArgs { fi } -function ccacheTool { - # Check for multiple ccache options - if [[ $(echo $ARGS | { grep -Eo "\-\-ccache\-tool" || true; } | wc -l ) -gt 1 ]]; then - echo "Multiple --ccache-tool options were provided, please provide only one: ${ARGS}" +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 ccache tool option - if [[ -n $(echo $ARGS | { grep -E "\-\-ccache\-tool" || true; } ) ]]; then + # 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 - CCACHE_TOOL=$(echo $ARGS | sed -e 's/.*--ccache-tool=//' -e 's/ .*//') - if [[ -n ${CCACHE_TOOL} ]]; then - # Remove the full CCACHE_TOOL argument from list of args so that it passes validArgs function - ARGS=${ARGS//--ccache-tool=$CCACHE_TOOL/} - CCACHE_ARGS="-DCMAKE_CUDA_COMPILER_LAUNCHER=${CCACHE_TOOL} -DCMAKE_C_COMPILER_LAUNCHER=${CCACHE_TOOL} -DCMAKE_CXX_COMPILER_LAUNCHER=${CCACHE_TOOL}" + 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 } @@ -142,7 +142,7 @@ fi # Check for valid usage if (( ${NUMARGS} != 0 )); then cmakeArgs - ccacheTool + cacheTool for a in ${ARGS}; do if ! (echo " ${VALIDARGS} " | grep -q " ${a} "); then echo "Invalid option: ${a}" @@ -275,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} \ - ${CCACHE_ARGS} \ + ${CACHE_ARGS} \ ${EXTRA_CMAKE_ARGS} if [[ ${CMAKE_TARGET} != "" ]]; then