Skip to content

Commit 242fc57

Browse files
committed
Add build option to overwrite libraft logging level
1 parent 0e94a8c commit 242fc57

3 files changed

Lines changed: 45 additions & 13 deletions

File tree

build.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION.
3+
# SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
44
# SPDX-License-Identifier: Apache-2.0
55

66
# cuvs build scripts
@@ -62,6 +62,8 @@ HELP="$0 [<target> ...] [<flag> ...] [--cmake-args=\"<args>\"] [--cache-tool=<to
6262
to speedup the build process.
6363
--time - Enable nvcc compilation time logging into cpp/build/nvcc_compile_log.csv.
6464
Results can be interpreted with cpp/scripts/analyze_nvcc_log.py
65+
--logging-level=<level> - overwrite the macro \"RAFT_LOG_ACTIVE_LEVEL\" to RAPIDS_LOGGER_LOG_LEVEL_{given_value}.
66+
Valid values are (TRACE, DEBUG, INFO, WARN, ERROR, CRITICAL, OFF)
6567
-h - print this text
6668
6769
default action (no args) is to build libcuvs, tests and cuvs targets
@@ -95,6 +97,7 @@ CLEAN=0
9597
DISABLE_DEPRECATION_WARNINGS=ON
9698
CMAKE_TARGET=()
9799
EXTRA_CMAKE_ARGS=""
100+
LIBRAFT_LOGGING_LEVEL=INFO
98101

99102
# Set defaults for vars that may not have been defined externally
100103
INSTALL_PREFIX=${INSTALL_PREFIX:=${PREFIX:=${CONDA_PREFIX:=$LIBCUVS_BUILD_DIR/install}}}
@@ -236,6 +239,20 @@ function gpuArch {
236239
fi
237240
}
238241

242+
function loggingLevel {
243+
if [[ -n $(echo "$ARGS" | { grep -E "\-\-logging\-level" || true; } ) ]]; then
244+
LIBRAFT_LOGGING_LEVEL=$(echo "$ARGS" | sed -e 's/.*--logging-level[= ]//' -e 's/ .*//')
245+
if [[ -n ${LIBRAFT_LOGGING_LEVEL} ]]; then
246+
ARGS="${ARGS//--logging-level[= ]${LIBRAFT_LOGGING_LEVEL}/}"
247+
VALID_LEVELS="TRACE DEBUG INFO WARN ERROR CRITICAL OFF"
248+
if [[ ! " ${VALID_LEVELS} " == *" ${LIBRAFT_LOGGING_LEVEL} "* ]]; then
249+
echo "Invalid --logging-level value: '${LIBRAFT_LOGGING_LEVEL}'. Valid values are: ${VALID_LEVELS}"
250+
exit 1
251+
fi
252+
fi
253+
fi
254+
}
255+
239256
if hasArg -h || hasArg --help; then
240257
echo "${HELP}"
241258
exit 0
@@ -249,6 +266,7 @@ if (( NUMARGS != 0 )); then
249266
limitAnnBench
250267
buildMetrics
251268
gpuArch
269+
loggingLevel
252270
for a in ${ARGS}; do
253271
if ! (echo " ${VALIDARGS} " | grep -q " ${a} "); then
254272
echo "Invalid option: ${a}"
@@ -415,6 +433,7 @@ if (( NUMARGS == 0 )) || hasArg libcuvs || hasArg tests || hasArg bench-prims ||
415433
-DBUILD_MG_ALGOS=${BUILD_MG_ALGOS} \
416434
-DCMAKE_MESSAGE_LOG_LEVEL=${CMAKE_LOG_LEVEL} \
417435
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} \
436+
-DLIBRAFT_LOGGING_LEVEL="${LIBRAFT_LOGGING_LEVEL}" \
418437
"${CACHE_ARGS[@]}" \
419438
"${EXTRA_CMAKE_ARGS[@]}"
420439

cpp/CMakeLists.txt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# =============================================================================
22
# cmake-format: off
3-
# SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION.
3+
# SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
44
# SPDX-License-Identifier: Apache-2.0
55
# cmake-format: on
66
cmake_minimum_required(VERSION 4.0 FATAL_ERROR)
@@ -118,16 +118,6 @@ message(VERBOSE "cuVS: Enable nvtx markers: ${CUVS_NVTX}")
118118
message(VERBOSE "cuVS: Statically link the CUDA math libraries: ${CUDA_STATIC_MATH_LIBRARIES}")
119119
message(VERBOSE "cuVS: Build and statically link RAPIDS libraries: ${CUVS_STATIC_RAPIDS_LIBRARIES}")
120120

121-
# Set RMM logging level
122-
set(RMM_LOGGING_LEVEL
123-
"INFO"
124-
CACHE STRING "Choose the logging level."
125-
)
126-
set_property(
127-
CACHE RMM_LOGGING_LEVEL PROPERTY STRINGS "TRACE" "DEBUG" "INFO" "WARN" "ERROR" "CRITICAL" "OFF"
128-
)
129-
message(VERBOSE "cuVS: RMM_LOGGING_LEVEL = '${RMM_LOGGING_LEVEL}'.")
130-
131121
# ##################################################################################################
132122
# * Conda environment detection ----------------------------------------------
133123

cpp/cmake/thirdparty/get_raft.cmake

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# =============================================================================
22
# cmake-format: off
3-
# SPDX-FileCopyrightText: Copyright (c) 2023-2025, NVIDIA CORPORATION.
3+
# SPDX-FileCopyrightText: Copyright (c) 2023-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
44
# SPDX-License-Identifier: Apache-2.0
55
# cmake-format: on
66

77
# Use RAPIDS_VERSION_MAJOR_MINOR from rapids_config.cmake
88
set(RAFT_VERSION "${RAPIDS_VERSION_MAJOR_MINOR}")
99
set(RAFT_FORK "rapidsai")
1010
set(RAFT_PINNED_TAG "${rapids-cmake-checkout-tag}")
11+
set(LIBRAFT_LOGGING_LEVEL "INFO"
12+
CACHE STRING "Choose the RAFT logging level compiled into cuVS."
13+
)
1114

1215
function(find_and_configure_raft)
1316
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)
5558
)
5659
endfunction()
5760

61+
# RAFT target is shipped together with the RAFT_LOG_ACTIVE_LEVEL macro. Simply redefining the macro
62+
# would yield a redefine error. We instead query and modify the definition list of the RAFT target manually.
63+
function(overwrite_raft_log_active_level)
64+
set(oneValueArgs LEVEL)
65+
cmake_parse_arguments(PKG "" "${oneValueArgs}" "" ${ARGN})
66+
if(TARGET raft::raft)
67+
get_target_property(_defs raft::raft INTERFACE_COMPILE_DEFINITIONS)
68+
if(_defs)
69+
# Get definitions without previous logging level
70+
list(FILTER _defs EXCLUDE REGEX "^RAFT_LOG_ACTIVE_LEVEL=")
71+
# Append the new logging level
72+
list(APPEND _defs "RAFT_LOG_ACTIVE_LEVEL=RAPIDS_LOGGER_LOG_LEVEL_${PKG_LEVEL}")
73+
# Set the modified definitions back to the raft target
74+
set_target_properties(raft::raft PROPERTIES INTERFACE_COMPILE_DEFINITIONS "${_defs}")
75+
message(STATUS "cuVS: set RAFT_LOG_ACTIVE_LEVEL=RAPIDS_LOGGER_LOG_LEVEL_${PKG_LEVEL}")
76+
endif()
77+
endif()
78+
endfunction()
5879

5980
# Change pinned tag here to test a commit in CI
6081
# To use a different RAFT locally, set the CMake variable
@@ -71,3 +92,5 @@ find_and_configure_raft(VERSION ${RAFT_VERSION}.00
7192
CLONE_ON_PIN ${CUVS_RAFT_CLONE_ON_PIN}
7293

7394
)
95+
96+
overwrite_raft_log_active_level(LEVEL ${LIBRAFT_LOGGING_LEVEL})

0 commit comments

Comments
 (0)