From 7904ff07d4a9a9b567193e46f9a6ed50ab6649f2 Mon Sep 17 00:00:00 2001 From: Naim <110031745+naimnv@users.noreply.github.com> Date: Mon, 18 Mar 2024 03:53:24 +0100 Subject: [PATCH] update example build script with targets and options/help (#4254) update example build script with targets and options/help Authors: - Naim (https://github.com/naimnv) Approvers: - Brad Rees (https://github.com/BradReesWork) - Chuck Hastings (https://github.com/ChuckHastings) URL: https://github.com/rapidsai/cugraph/pull/4254 --- cpp/examples/README.md | 4 +- cpp/examples/build.sh | 101 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 92 insertions(+), 13 deletions(-) diff --git a/cpp/examples/README.md b/cpp/examples/README.md index 2859d05c692..3d8a1674c2e 100644 --- a/cpp/examples/README.md +++ b/cpp/examples/README.md @@ -17,10 +17,10 @@ ## Build instructions: -Run `build.sh` from the examples dir to build the above listed examples. +Run `build.sh all` from the examples dir to build the above listed examples. ```sh -~/cugraph/cpp/examples$./build.sh +~/cugraph/cpp/examples$./build.sh all ``` ## Run instructions diff --git a/cpp/examples/build.sh b/cpp/examples/build.sh index 050ac3771d8..37b0a8bb391 100755 --- a/cpp/examples/build.sh +++ b/cpp/examples/build.sh @@ -4,29 +4,108 @@ # script for building libcugraph examples +set -e + +NUMARGS=$# +ARGS=$* + +VALIDARGS=" + clean + all + -v + -h + --help +" + +VERBOSE_FLAG="" +CMAKE_VERBOSE_OPTION="" + # Parallelism control PARALLEL_LEVEL=${PARALLEL_LEVEL:-8} # Root of examples -EXAMPLES_DIR=$(dirname "$(realpath "$0")") +EXAMPLES_ROOT_DIR=$(dirname "$(realpath "$0")") +EXAMPLES=( + "users/single_gpu_application" + "users/multi_gpu_application" + "developers/vertex_and_edge_partition" + "developers/graph_operations") + +CUGRAPH_BUILD_DIR=${CUGRAPH_BUILD_DIR:-$(readlink -f "${EXAMPLES_ROOT_DIR}/../build")} + +HELP="$0 [ ...] [ ...] + where is: + clean - remove all existing build artifacts and configuration (start over) + all - build all of the examples from the following directories + ${EXAMPLES_ROOT_DIR}/users + ${EXAMPLES_ROOT_DIR}/developers + where is: + -v - verbose build mode + -h - print this text + --help - print this text +" + +if (( ${NUMARGS} == 0 )); then + echo "${HELP}" +fi + +# Check for valid usage +if (( ${NUMARGS} != 0 )); then + for a in ${ARGS}; do + if ! (echo "${VALIDARGS}" | grep -q "^[[:blank:]]*${a}$"); then + echo "Invalid option: ${a}" + exit 1 + fi + done +fi + +function hasArg { + (( ${NUMARGS} != 0 )) && (echo " ${ARGS} " | grep -q " $1 ") +} + +if hasArg -h || hasArg --help; then + echo "${HELP}" + exit 0 +fi -LIB_BUILD_DIR=${LIB_BUILD_DIR:-$(readlink -f "${EXAMPLES_DIR}/../build")} +if hasArg -v; then + VERBOSE_FLAG="-v" + CMAKE_VERBOSE_OPTION="--log-level=VERBOSE" +fi -################################################################################ -# Add individual libcudf examples build scripts down below +if hasArg clean; then + # Ignore errors for clean since missing files, etc. are not failures + set +e + for idx in ${!EXAMPLES[@]} + do + current_example=${EXAMPLES[$idx]} + build_dir="${EXAMPLES_ROOT_DIR}/${current_example}/build" + if [ -d ${build_dir} ]; then + find ${build_dir} -mindepth 1 -delete + rmdir ${build_dir} || true + echo "Removed ${build_dir}" + fi + done + # Go back to failing on first error for all other operations + set -e +fi build_example() { + echo "building ${1}" example_dir=${1} - example_dir="${EXAMPLES_DIR}/${example_dir}" + example_dir="${EXAMPLES_ROOT_DIR}/${example_dir}" build_dir="${example_dir}/build" # Configure - cmake -S ${example_dir} -B ${build_dir} -Dcugraph_ROOT="${LIB_BUILD_DIR}" + cmake -S ${example_dir} -B ${build_dir} -Dcugraph_ROOT="${CUGRAPH_BUILD_DIR}" ${CMAKE_VERBOSE_OPTION} # Build - cmake --build ${build_dir} -j${PARALLEL_LEVEL} + cmake --build ${build_dir} -j${PARALLEL_LEVEL} ${VERBOSE_FLAG} } -build_example users/single_gpu_application -build_example users/multi_gpu_application -build_example developers/vertex_and_edge_partition -build_example developers/graph_operations +if hasArg all; then + for idx in ${!EXAMPLES[@]} + do + current_example=${EXAMPLES[$idx]} + build_example $current_example + done +fi