From e45620793d902dded692b1250c610b747c41b9a7 Mon Sep 17 00:00:00 2001 From: Divye Gala Date: Thu, 30 Mar 2023 14:38:50 -0400 Subject: [PATCH] Add Options to Generate Build Metrics Report (#1369) This PR will also automatically generate an HTML report in `conda-cpp-build` CI runs under the task `Upload Additional Artifacts` Authors: - Divye Gala (https://github.com/divyegala) Approvers: - AJ Schmidt (https://github.com/ajschmidt8) - Corey J. Nolet (https://github.com/cjnolet) URL: https://github.com/rapidsai/raft/pull/1369 --- build.sh | 64 +++++++++++++++++++++++++- conda/recipes/libraft/build_libraft.sh | 2 +- conda/recipes/libraft/meta.yaml | 1 + 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/build.sh b/build.sh index 7e1a3e7e36..270c75de93 100755 --- a/build.sh +++ b/build.sh @@ -18,7 +18,7 @@ ARGS=$* # scripts, and that this script resides in the repo dir! REPODIR=$(cd $(dirname $0); pwd) -VALIDARGS="clean libraft pylibraft raft-dask docs tests template bench-prims bench-ann clean --uninstall -v -g -n --compile-lib --allgpuarch --no-nvtx --show_depr_warn --time -h" +VALIDARGS="clean libraft pylibraft raft-dask docs tests template bench-prims bench-ann clean --uninstall -v -g -n --compile-lib --allgpuarch --no-nvtx --show_depr_warn --build-metrics --incl-cache-stats --time -h" HELP="$0 [ ...] [ ...] [--cmake-args=\"\"] [--cache-tool=] [--limit-tests=] [--limit-bench-prims=] [--limit-bench-ann=] where is: clean - remove all existing build artifacts and configuration (start over) @@ -45,6 +45,8 @@ HELP="$0 [ ...] [ ...] [--cmake-args=\"\"] [--cache-tool=\\\" - 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. @@ -71,6 +73,8 @@ BUILD_PRIMS_BENCH=OFF BUILD_ANN_BENCH=OFF COMPILE_LIBRARY=OFF INSTALL_TARGET=install +BUILD_REPORT_METRICS=OFF +BUILD_REPORT_INCL_CACHE_STATS=OFF TEST_TARGETS="CLUSTER_TEST;CORE_TEST;DISTANCE_TEST;LABEL_TEST;LINALG_TEST;MATRIX_TEST;RANDOM_TEST;SOLVERS_TEST;SPARSE_TEST;SPARSE_DIST_TEST;SPARSE_NEIGHBORS_TEST;NEIGHBORS_TEST;STATS_TEST;UTILS_TEST" BENCH_TARGETS="CLUSTER_BENCH;NEIGHBORS_BENCH;DISTANCE_BENCH;LINALG_BENCH;MATRIX_BENCH;SPARSE_BENCH;RANDOM_BENCH" @@ -335,7 +339,12 @@ fi if hasArg clean; then CLEAN=1 fi - +if hasArg --build-metrics; then + BUILD_REPORT_METRICS=ON +fi +if hasArg --incl-cache-stats; then + BUILD_REPORT_INCL_CACHE_STATS=ON +fi if [[ ${CMAKE_TARGET} == "" ]]; then CMAKE_TARGET="all" fi @@ -378,6 +387,12 @@ if (( ${NUMARGS} == 0 )) || hasArg libraft || hasArg docs || hasArg tests || has echo "Building for *ALL* supported GPU architectures..." fi + # get the current count before the compile starts + CACHE_TOOL=${CACHE_TOOL:-sccache} + if [[ "$BUILD_REPORT_INCL_CACHE_STATS" == "ON" && -x "$(command -v ${CACHE_TOOL})" ]]; then + "${CACHE_TOOL}" --zero-stats + fi + mkdir -p ${LIBRAFT_BUILD_DIR} cd ${LIBRAFT_BUILD_DIR} cmake -S ${REPODIR}/cpp -B ${LIBRAFT_BUILD_DIR} \ @@ -395,6 +410,7 @@ if (( ${NUMARGS} == 0 )) || hasArg libraft || hasArg docs || hasArg tests || has ${CACHE_ARGS} \ ${EXTRA_CMAKE_ARGS} + compile_start=$(date +%s) if [[ ${CMAKE_TARGET} != "" ]]; then echo "-- Compiling targets: ${CMAKE_TARGET}, verbose=${VERBOSE_FLAG}" if [[ ${INSTALL_TARGET} != "" ]]; then @@ -403,6 +419,50 @@ if (( ${NUMARGS} == 0 )) || hasArg libraft || hasArg docs || hasArg tests || has cmake --build "${LIBRAFT_BUILD_DIR}" ${VERBOSE_FLAG} -j${PARALLEL_LEVEL} --target ${CMAKE_TARGET} fi fi + compile_end=$(date +%s) + compile_total=$(( compile_end - compile_start )) + + if [[ "$BUILD_REPORT_METRICS" == "ON" && -f "${LIBRAFT_BUILD_DIR}/.ninja_log" ]]; then + if ! rapids-build-metrics-reporter.py 2> /dev/null && [ ! -f rapids-build-metrics-reporter.py ]; then + echo "Downloading rapids-build-metrics-reporter.py" + curl -sO https://raw.githubusercontent.com/rapidsai/build-metrics-reporter/v1/rapids-build-metrics-reporter.py + fi + + echo "Formatting build metrics" + MSG="" + # get some sccache/ccache stats after the compile + if [[ "$BUILD_REPORT_INCL_CACHE_STATS" == "ON" ]]; then + if [[ ${CACHE_TOOL} == "sccache" && -x "$(command -v sccache)" ]]; then + COMPILE_REQUESTS=$(sccache -s | grep "Compile requests \+ [0-9]\+$" | awk '{ print $NF }') + CACHE_HITS=$(sccache -s | grep "Cache hits \+ [0-9]\+$" | awk '{ print $NF }') + HIT_RATE=$(echo - | awk "{printf \"%.2f\n\", $CACHE_HITS / $COMPILE_REQUESTS * 100}") + MSG="${MSG}
cache hit rate ${HIT_RATE} %" + elif [[ ${CACHE_TOOL} == "ccache" && -x "$(command -v ccache)" ]]; then + CACHE_STATS_LINE=$(ccache -s | grep "Hits: \+ [0-9]\+ / [0-9]\+" | tail -n1) + if [[ ! -z "$CACHE_STATS_LINE" ]]; then + CACHE_HITS=$(echo "$CACHE_STATS_LINE" - | awk '{ print $2 }') + COMPILE_REQUESTS=$(echo "$CACHE_STATS_LINE" - | awk '{ print $4 }') + HIT_RATE=$(echo - | awk "{printf \"%.2f\n\", $CACHE_HITS / $COMPILE_REQUESTS * 100}") + MSG="${MSG}
cache hit rate ${HIT_RATE} %" + fi + fi + fi + MSG="${MSG}
parallel setting: $PARALLEL_LEVEL" + MSG="${MSG}
parallel build time: $compile_total seconds" + if [[ -f "${LIBRAFT_BUILD_DIR}/libraft.so" ]]; then + LIBRAFT_FS=$(ls -lh ${LIBRAFT_BUILD_DIR}/libraft.so | awk '{print $5}') + MSG="${MSG}
libraft.so size: $LIBRAFT_FS" + fi + BMR_DIR=${RAPIDS_ARTIFACTS_DIR:-"${LIBRAFT_BUILD_DIR}"} + echo "The HTML report can be found at [${BMR_DIR}/ninja_log.html]. In CI, this report" + echo "will also be uploaded to the appropriate subdirectory of https://downloads.rapids.ai/ci/raft/, and" + echo "the entire URL can be found in \"conda-cpp-build\" runs under the task \"Upload additional artifacts\"" + mkdir -p ${BMR_DIR} + MSG_OUTFILE="$(mktemp)" + echo "$MSG" > "${MSG_OUTFILE}" + PATH=".:$PATH" python rapids-build-metrics-reporter.py ${LIBRAFT_BUILD_DIR}/.ninja_log --fmt html --msg "${MSG_OUTFILE}" > ${BMR_DIR}/ninja_log.html + cp ${LIBRAFT_BUILD_DIR}/.ninja_log ${BMR_DIR}/ninja.log + fi fi # Build and (optionally) install the pylibraft Python package diff --git a/conda/recipes/libraft/build_libraft.sh b/conda/recipes/libraft/build_libraft.sh index 237e47eb26..2bf9b428cb 100644 --- a/conda/recipes/libraft/build_libraft.sh +++ b/conda/recipes/libraft/build_libraft.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash # Copyright (c) 2022-2023, NVIDIA CORPORATION. -./build.sh libraft --allgpuarch --compile-lib --no-nvtx +./build.sh libraft --allgpuarch --compile-lib --build-metrics --incl-cache-stats --no-nvtx diff --git a/conda/recipes/libraft/meta.yaml b/conda/recipes/libraft/meta.yaml index 7859807777..ccd7314484 100644 --- a/conda/recipes/libraft/meta.yaml +++ b/conda/recipes/libraft/meta.yaml @@ -29,6 +29,7 @@ outputs: - CMAKE_CXX_COMPILER_LAUNCHER - CMAKE_GENERATOR - PARALLEL_LEVEL + - RAPIDS_ARTIFACTS_DIR - SCCACHE_BUCKET - SCCACHE_IDLE_TIMEOUT - SCCACHE_REGION