Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions cpp/include/raft/common/nccl_macros.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -9,19 +9,17 @@
* Invokes a NCCL runtime API function call, if the call does not return ncclSuccess, throws an
* exception detailing the NCCL error that occurred
*/
#define RAFT_NCCL_TRY(call) \
do { \
ncclResult_t const status = (call); \
if (ncclSuccess != status) { \
std::string msg{}; \
SET_ERROR_MSG(msg, \
"NCCL error encountered at: ", \
"call='%s', Reason=%d:%s", \
#call, \
status, \
ncclGetErrorString(status)); \
throw raft::logic_error(msg); \
} \
#define RAFT_NCCL_TRY(call) \
do { \
ncclResult_t const status = (call); \
if (ncclSuccess != status) { \
throw raft::logic_error(raft::format_error_message(std::source_location::current(), \
"NCCL error encountered at: ", \
"call='%s', Reason=%d:%s", \
#call, \
status, \
ncclGetErrorString(status))); \
} \
} while (0);

// FIXME: Remove after consumer rename
Expand Down
27 changes: 13 additions & 14 deletions cpp/include/raft/core/cublas_macros.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2022-2026, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2022-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

Expand Down Expand Up @@ -77,19 +77,18 @@ inline const char* cublas_error_to_string(cublasStatus_t err)
* Invokes a cuBLAS runtime API function call, if the call does not return
* CUBLAS_STATUS_SUCCESS, throws an exception detailing the cuBLAS error that occurred
*/
#define RAFT_CUBLAS_TRY(call) \
do { \
cublasStatus_t const status = (call); \
if (CUBLAS_STATUS_SUCCESS != status) { \
std::string msg{}; \
SET_ERROR_MSG(msg, \
"cuBLAS error encountered at: ", \
"call='%s', Reason=%d:%s", \
#call, \
status, \
raft::linalg::detail::cublas_error_to_string(status)); \
throw raft::cublas_error(msg); \
} \
#define RAFT_CUBLAS_TRY(call) \
do { \
cublasStatus_t const status = (call); \
if (CUBLAS_STATUS_SUCCESS != status) { \
throw raft::cublas_error( \
raft::format_error_message(std::source_location::current(), \
"cuBLAS error encountered at: ", \
"call='%s', Reason=%d:%s", \
#call, \
status, \
raft::linalg::detail::cublas_error_to_string(status))); \
} \
} while (0)

// FIXME: Remove after consumers rename
Expand Down
27 changes: 13 additions & 14 deletions cpp/include/raft/core/cusolver_macros.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2022-2026, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2022-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

Expand Down Expand Up @@ -78,19 +78,18 @@ inline const char* cusolver_error_to_string(cusolverStatus_t err)
* Invokes a cuSOLVER runtime API function call, if the call does not return
* CUSolver_STATUS_SUCCESS, throws an exception detailing the cuSOLVER error that occurred
*/
#define RAFT_CUSOLVER_TRY(call) \
do { \
cusolverStatus_t const status = (call); \
if (CUSOLVER_STATUS_SUCCESS != status) { \
std::string msg{}; \
SET_ERROR_MSG(msg, \
"cuSOLVER error encountered at: ", \
"call='%s', Reason=%d:%s", \
#call, \
status, \
raft::linalg::detail::cusolver_error_to_string(status)); \
throw raft::cusolver_error(msg); \
} \
#define RAFT_CUSOLVER_TRY(call) \
do { \
cusolverStatus_t const status = (call); \
if (CUSOLVER_STATUS_SUCCESS != status) { \
throw raft::cusolver_error( \
raft::format_error_message(std::source_location::current(), \
"cuSOLVER error encountered at: ", \
"call='%s', Reason=%d:%s", \
#call, \
status, \
raft::linalg::detail::cusolver_error_to_string(status))); \
} \
} while (0)

// FIXME: remove after consumer rename
Expand Down
27 changes: 13 additions & 14 deletions cpp/include/raft/core/cusparse_macros.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

Expand Down Expand Up @@ -70,19 +70,18 @@ inline const char* cusparse_error_to_string(cusparseStatus_t err)
* Invokes a cuSparse runtime API function call, if the call does not return
* CUSPARSE_STATUS_SUCCESS, throws an exception detailing the cuSparse error that occurred
*/
#define RAFT_CUSPARSE_TRY(call) \
do { \
cusparseStatus_t const status = (call); \
if (CUSPARSE_STATUS_SUCCESS != status) { \
std::string msg{}; \
SET_ERROR_MSG(msg, \
"cuSparse error encountered at: ", \
"call='%s', Reason=%d:%s", \
#call, \
status, \
raft::sparse::detail::cusparse_error_to_string(status)); \
throw raft::cusparse_error(msg); \
} \
#define RAFT_CUSPARSE_TRY(call) \
do { \
cusparseStatus_t const status = (call); \
if (CUSPARSE_STATUS_SUCCESS != status) { \
throw raft::cusparse_error( \
raft::format_error_message(std::source_location::current(), \
"cuSparse error encountered at: ", \
"call='%s', Reason=%d:%s", \
#call, \
status, \
raft::sparse::detail::cusparse_error_to_string(status))); \
} \
} while (0)

/**
Expand Down
16 changes: 15 additions & 1 deletion cpp/include/raft/core/detail/macros.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2022-2026, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2022-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

Expand Down Expand Up @@ -131,3 +131,17 @@
#define RAFT_STRINGIFY_DETAIL(...) #__VA_ARGS__
#define RAFT_STRINGIFY(...) RAFT_STRINGIFY_DETAIL(__VA_ARGS__)
#endif

// Let the compiler check the arguments of a printf-style function against its format string, the
// same way it checks calls to printf itself.
//
// `fmt_index` is the one-based index of the format string parameter and `first_arg_index` the index
// of the first variadic argument (for a non-static member function, `this` is parameter one).
#ifndef RAFT_FORMAT_PRINTF
#if defined(__GNUC__)
#define RAFT_FORMAT_PRINTF(fmt_index, first_arg_index) \
__attribute__((format(printf, fmt_index, first_arg_index)))
#else
#define RAFT_FORMAT_PRINTF(fmt_index, first_arg_index)
#endif
#endif
17 changes: 15 additions & 2 deletions cpp/include/raft/core/device_resources.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#include <memory>
#include <optional>
#include <source_location>
#include <string>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -113,13 +114,25 @@ class device_resources : public resources {

/**
* @brief synchronize a stream on the current container
*
* @param[in] stream stream to synchronize
* @param[in] location the call site to blame for the errors; leave at its default
*/
void sync_stream(rmm::cuda_stream_view stream) const { resource::sync_stream(*this, stream); }
void sync_stream(rmm::cuda_stream_view stream,
std::source_location location = std::source_location::current()) const
{
resource::sync_stream(*this, stream, location);
}

/**
* @brief synchronize main stream on the current container
*
* @param[in] location the call site to blame for the errors; leave at its default
*/
void sync_stream() const { resource::sync_stream(*this); }
void sync_stream(std::source_location location = std::source_location::current()) const
{
resource::sync_stream(*this, location);
}

/**
* @brief returns main stream on the current container
Expand Down
Loading
Loading