From 242fc573b413592149d8401799d176bd39684ea6 Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Tue, 30 Jun 2026 07:10:03 +0000 Subject: [PATCH] Add build option to overwrite libraft logging level --- build.sh | 21 ++++++++++++++++++++- cpp/CMakeLists.txt | 12 +----------- cpp/cmake/thirdparty/get_raft.cmake | 25 ++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/build.sh b/build.sh index f5260ecd59..613e918c7f 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,6 @@ #!/bin/bash -# SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION. +# SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 # cuvs build scripts @@ -62,6 +62,8 @@ HELP="$0 [ ...] [ ...] [--cmake-args=\"\"] [--cache-tool= - overwrite the macro \"RAFT_LOG_ACTIVE_LEVEL\" to RAPIDS_LOGGER_LOG_LEVEL_{given_value}. + Valid values are (TRACE, DEBUG, INFO, WARN, ERROR, CRITICAL, OFF) -h - print this text default action (no args) is to build libcuvs, tests and cuvs targets @@ -95,6 +97,7 @@ CLEAN=0 DISABLE_DEPRECATION_WARNINGS=ON CMAKE_TARGET=() EXTRA_CMAKE_ARGS="" +LIBRAFT_LOGGING_LEVEL=INFO # Set defaults for vars that may not have been defined externally INSTALL_PREFIX=${INSTALL_PREFIX:=${PREFIX:=${CONDA_PREFIX:=$LIBCUVS_BUILD_DIR/install}}} @@ -236,6 +239,20 @@ function gpuArch { fi } +function loggingLevel { + if [[ -n $(echo "$ARGS" | { grep -E "\-\-logging\-level" || true; } ) ]]; then + LIBRAFT_LOGGING_LEVEL=$(echo "$ARGS" | sed -e 's/.*--logging-level[= ]//' -e 's/ .*//') + if [[ -n ${LIBRAFT_LOGGING_LEVEL} ]]; then + ARGS="${ARGS//--logging-level[= ]${LIBRAFT_LOGGING_LEVEL}/}" + VALID_LEVELS="TRACE DEBUG INFO WARN ERROR CRITICAL OFF" + if [[ ! " ${VALID_LEVELS} " == *" ${LIBRAFT_LOGGING_LEVEL} "* ]]; then + echo "Invalid --logging-level value: '${LIBRAFT_LOGGING_LEVEL}'. Valid values are: ${VALID_LEVELS}" + exit 1 + fi + fi + fi +} + if hasArg -h || hasArg --help; then echo "${HELP}" exit 0 @@ -249,6 +266,7 @@ if (( NUMARGS != 0 )); then limitAnnBench buildMetrics gpuArch + loggingLevel for a in ${ARGS}; do if ! (echo " ${VALIDARGS} " | grep -q " ${a} "); then echo "Invalid option: ${a}" @@ -415,6 +433,7 @@ if (( NUMARGS == 0 )) || hasArg libcuvs || hasArg tests || hasArg bench-prims || -DBUILD_MG_ALGOS=${BUILD_MG_ALGOS} \ -DCMAKE_MESSAGE_LOG_LEVEL=${CMAKE_LOG_LEVEL} \ -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} \ + -DLIBRAFT_LOGGING_LEVEL="${LIBRAFT_LOGGING_LEVEL}" \ "${CACHE_ARGS[@]}" \ "${EXTRA_CMAKE_ARGS[@]}" diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 89cbadfcfc..54b0b7c682 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -1,6 +1,6 @@ # ============================================================================= # cmake-format: off -# SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION. +# SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 # cmake-format: on cmake_minimum_required(VERSION 4.0 FATAL_ERROR) @@ -118,16 +118,6 @@ message(VERBOSE "cuVS: Enable nvtx markers: ${CUVS_NVTX}") message(VERBOSE "cuVS: Statically link the CUDA math libraries: ${CUDA_STATIC_MATH_LIBRARIES}") message(VERBOSE "cuVS: Build and statically link RAPIDS libraries: ${CUVS_STATIC_RAPIDS_LIBRARIES}") -# Set RMM logging level -set(RMM_LOGGING_LEVEL - "INFO" - CACHE STRING "Choose the logging level." -) -set_property( - CACHE RMM_LOGGING_LEVEL PROPERTY STRINGS "TRACE" "DEBUG" "INFO" "WARN" "ERROR" "CRITICAL" "OFF" -) -message(VERBOSE "cuVS: RMM_LOGGING_LEVEL = '${RMM_LOGGING_LEVEL}'.") - # ################################################################################################## # * Conda environment detection ---------------------------------------------- diff --git a/cpp/cmake/thirdparty/get_raft.cmake b/cpp/cmake/thirdparty/get_raft.cmake index 8ecf3686be..d39e2b59a8 100644 --- a/cpp/cmake/thirdparty/get_raft.cmake +++ b/cpp/cmake/thirdparty/get_raft.cmake @@ -1,6 +1,6 @@ # ============================================================================= # cmake-format: off -# SPDX-FileCopyrightText: Copyright (c) 2023-2025, NVIDIA CORPORATION. +# SPDX-FileCopyrightText: Copyright (c) 2023-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 # cmake-format: on @@ -8,6 +8,9 @@ set(RAFT_VERSION "${RAPIDS_VERSION_MAJOR_MINOR}") set(RAFT_FORK "rapidsai") set(RAFT_PINNED_TAG "${rapids-cmake-checkout-tag}") +set(LIBRAFT_LOGGING_LEVEL "INFO" + CACHE STRING "Choose the RAFT logging level compiled into cuVS." +) function(find_and_configure_raft) set(oneValueArgs VERSION FORK PINNED_TAG BUILD_STATIC_DEPS ENABLE_NVTX ENABLE_MNMG_DEPENDENCIES CLONE_ON_PIN) @@ -55,6 +58,24 @@ function(find_and_configure_raft) ) endfunction() +# RAFT target is shipped together with the RAFT_LOG_ACTIVE_LEVEL macro. Simply redefining the macro +# would yield a redefine error. We instead query and modify the definition list of the RAFT target manually. +function(overwrite_raft_log_active_level) + set(oneValueArgs LEVEL) + cmake_parse_arguments(PKG "" "${oneValueArgs}" "" ${ARGN}) + if(TARGET raft::raft) + get_target_property(_defs raft::raft INTERFACE_COMPILE_DEFINITIONS) + if(_defs) + # Get definitions without previous logging level + list(FILTER _defs EXCLUDE REGEX "^RAFT_LOG_ACTIVE_LEVEL=") + # Append the new logging level + list(APPEND _defs "RAFT_LOG_ACTIVE_LEVEL=RAPIDS_LOGGER_LOG_LEVEL_${PKG_LEVEL}") + # Set the modified definitions back to the raft target + set_target_properties(raft::raft PROPERTIES INTERFACE_COMPILE_DEFINITIONS "${_defs}") + message(STATUS "cuVS: set RAFT_LOG_ACTIVE_LEVEL=RAPIDS_LOGGER_LOG_LEVEL_${PKG_LEVEL}") + endif() + endif() +endfunction() # Change pinned tag here to test a commit in CI # To use a different RAFT locally, set the CMake variable @@ -71,3 +92,5 @@ find_and_configure_raft(VERSION ${RAFT_VERSION}.00 CLONE_ON_PIN ${CUVS_RAFT_CLONE_ON_PIN} ) + +overwrite_raft_log_active_level(LEVEL ${LIBRAFT_LOGGING_LEVEL})