From ee91565d69c81428281479723b135af9e1e8f744 Mon Sep 17 00:00:00 2001 From: Wint3rNight Date: Fri, 7 Aug 2026 01:45:50 +0530 Subject: [PATCH 1/2] Fix RAFT_LOG_TRACE_VEC after the rapids-logger migration --- cpp/include/raft/core/logger.hpp | 12 ++++---- cpp/tests/CMakeLists.txt | 1 + cpp/tests/core/logger.cu | 52 ++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 cpp/tests/core/logger.cu diff --git a/cpp/include/raft/core/logger.hpp b/cpp/include/raft/core/logger.hpp index 43bfb385a5..9ce6272328 100644 --- a/cpp/include/raft/core/logger.hpp +++ b/cpp/include/raft/core/logger.hpp @@ -56,12 +56,12 @@ inline rapids_logger::logger& default_logger() } // namespace RAFT_EXPORT raft #if (RAFT_LOG_ACTIVE_LEVEL <= RAPIDS_LOGGER_LOG_LEVEL_TRACE) -#define RAFT_LOG_TRACE_VEC(ptr, len) \ - do { \ - std::stringstream ss; \ - ss << raft::detail::format("%s:%d ", __FILE__, __LINE__); \ - print_vector(#ptr, ptr, len, ss); \ - raft::default_logger().log(RAPIDS_LOGGER_LOG_LEVEL_TRACE, ss.str().c_str()); \ +#define RAFT_LOG_TRACE_VEC(ptr, len) \ + do { \ + std::stringstream ss; \ + ss << __FILE__ << ":" << __LINE__ << " "; \ + raft::print_vector(#ptr, ptr, len, ss); \ + raft::default_logger().log(rapids_logger::level_enum::trace, ss.str()); \ } while (0) #else #define RAFT_LOG_TRACE_VEC(ptr, len) void(0) diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt index fce5a0ea47..5320c4ac36 100644 --- a/cpp/tests/CMakeLists.txt +++ b/cpp/tests/CMakeLists.txt @@ -101,6 +101,7 @@ if(BUILD_TESTS) core/operators_host.cpp core/handle.cpp core/interruptible.cu + core/logger.cu core/nvtx.cpp core/mdarray.cu core/mdbuffer.cu diff --git a/cpp/tests/core/logger.cu b/cpp/tests/core/logger.cu new file mode 100644 index 0000000000..c2a0c0cca9 --- /dev/null +++ b/cpp/tests/core/logger.cu @@ -0,0 +1,52 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * RAFT_LOG_TRACE_VEC expands to void(0) unless RAFT_LOG_ACTIVE_LEVEL is TRACE, + * so a build at the default logging level never compiles its body. Raise the + * level for this translation unit only, so the macro is actually instantiated. + */ +#include + +#undef RAFT_LOG_ACTIVE_LEVEL +#define RAFT_LOG_ACTIVE_LEVEL RAPIDS_LOGGER_LOG_LEVEL_TRACE + +#include +#include + +#include + +#include + +#include + +namespace raft { + +// Compiling these at all is the point: the macro previously referenced +// raft::detail::format, which no longer exists, an unqualified print_vector, +// and a log level constant where the enumerator is expected. + +TEST(Logger, TraceVecHostPointer) +{ + const std::vector host_data{1, 2, 3, 4}; + ASSERT_NO_THROW(RAFT_LOG_TRACE_VEC(host_data.data(), host_data.size())); +} + +TEST(Logger, TraceVecDevicePointer) +{ + // print_vector inspects the pointer with cudaPointerGetAttributes and copies + // device memory back to the host, so cover that branch as well. + const std::vector host_data{5, 6, 7, 8}; + int* device_data = nullptr; + RAFT_CUDA_TRY(cudaMalloc(&device_data, host_data.size() * sizeof(int))); + RAFT_CUDA_TRY(cudaMemcpy( + device_data, host_data.data(), host_data.size() * sizeof(int), cudaMemcpyHostToDevice)); + + ASSERT_NO_THROW(RAFT_LOG_TRACE_VEC(device_data, host_data.size())); + + RAFT_CUDA_TRY(cudaFree(device_data)); +} + +} // namespace raft From cea540599abfcce3f3133da362aa9a6925b8393d Mon Sep 17 00:00:00 2001 From: Wint3rNight Date: Fri, 7 Aug 2026 02:16:00 +0530 Subject: [PATCH 2/2] Use rmm::device_uvector in the logger test --- cpp/tests/core/logger.cu | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/cpp/tests/core/logger.cu b/cpp/tests/core/logger.cu index c2a0c0cca9..812f84c21e 100644 --- a/cpp/tests/core/logger.cu +++ b/cpp/tests/core/logger.cu @@ -14,9 +14,11 @@ #define RAFT_LOG_ACTIVE_LEVEL RAPIDS_LOGGER_LOG_LEVEL_TRACE #include +#include +#include #include -#include +#include #include @@ -38,15 +40,15 @@ TEST(Logger, TraceVecDevicePointer) { // print_vector inspects the pointer with cudaPointerGetAttributes and copies // device memory back to the host, so cover that branch as well. - const std::vector host_data{5, 6, 7, 8}; - int* device_data = nullptr; - RAFT_CUDA_TRY(cudaMalloc(&device_data, host_data.size() * sizeof(int))); - RAFT_CUDA_TRY(cudaMemcpy( - device_data, host_data.data(), host_data.size() * sizeof(int), cudaMemcpyHostToDevice)); + raft::resources handle; + auto stream = resource::get_cuda_stream(handle); - ASSERT_NO_THROW(RAFT_LOG_TRACE_VEC(device_data, host_data.size())); + const std::vector host_data{5, 6, 7, 8}; + rmm::device_uvector device_data(host_data.size(), stream); + raft::update_device(device_data.data(), host_data.data(), host_data.size(), stream); + resource::sync_stream(handle, stream); - RAFT_CUDA_TRY(cudaFree(device_data)); + ASSERT_NO_THROW(RAFT_LOG_TRACE_VEC(device_data.data(), device_data.size())); } } // namespace raft