Skip to content

Commit

Permalink
Adding no throw macro variants (#417)
Browse files Browse the repository at this point in the history
Authors:
  - Corey J. Nolet (https://github.com/cjnolet)

Approvers:
  - Divye Gala (https://github.com/divyegala)

URL: #417
  • Loading branch information
cjnolet authored Dec 10, 2021
1 parent fd54f29 commit 367688f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 10 deletions.
24 changes: 14 additions & 10 deletions cpp/include/raft/handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class handle_t {
{
std::lock_guard<std::mutex> _(mutex_);
if (!cublas_initialized_) {
RAFT_CUBLAS_TRY(cublasCreate(&cublas_handle_));
RAFT_CUBLAS_TRY_NO_THROW(cublasCreate(&cublas_handle_));
cublas_initialized_ = true;
}
return cublas_handle_;
Expand All @@ -114,7 +114,7 @@ class handle_t {
{
std::lock_guard<std::mutex> _(mutex_);
if (!cusolver_dn_initialized_) {
RAFT_CUSOLVER_TRY(cusolverDnCreate(&cusolver_dn_handle_));
RAFT_CUSOLVER_TRY_NO_THROW(cusolverDnCreate(&cusolver_dn_handle_));
cusolver_dn_initialized_ = true;
}
return cusolver_dn_handle_;
Expand All @@ -124,7 +124,7 @@ class handle_t {
{
std::lock_guard<std::mutex> _(mutex_);
if (!cusolver_sp_initialized_) {
RAFT_CUSOLVER_TRY(cusolverSpCreate(&cusolver_sp_handle_));
RAFT_CUSOLVER_TRY_NO_THROW(cusolverSpCreate(&cusolver_sp_handle_));
cusolver_sp_initialized_ = true;
}
return cusolver_sp_handle_;
Expand All @@ -134,7 +134,7 @@ class handle_t {
{
std::lock_guard<std::mutex> _(mutex_);
if (!cusparse_initialized_) {
RAFT_CUSPARSE_TRY(cusparseCreate(&cusparse_handle_));
RAFT_CUSPARSE_TRY_NO_THROW(cusparseCreate(&cusparse_handle_));
cusparse_initialized_ = true;
}
return cusparse_handle_;
Expand Down Expand Up @@ -218,7 +218,7 @@ class handle_t {
{
std::lock_guard<std::mutex> _(mutex_);
if (!device_prop_initialized_) {
RAFT_CUDA_TRY(cudaGetDeviceProperties(&prop_, dev_id_));
RAFT_CUDA_TRY_NO_THROW(cudaGetDeviceProperties(&prop_, dev_id_));
device_prop_initialized_ = true;
}
return prop_;
Expand Down Expand Up @@ -253,11 +253,15 @@ class handle_t {
void destroy_resources()
{
///@todo: enable *_NO_THROW variants once we have enabled logging
if (cusparse_initialized_) { RAFT_CUSPARSE_TRY(cusparseDestroy(cusparse_handle_)); }
if (cusolver_dn_initialized_) { RAFT_CUSOLVER_TRY(cusolverDnDestroy(cusolver_dn_handle_)); }
if (cusolver_sp_initialized_) { RAFT_CUSOLVER_TRY(cusolverSpDestroy(cusolver_sp_handle_)); }
if (cublas_initialized_) { RAFT_CUBLAS_TRY(cublasDestroy(cublas_handle_)); }
RAFT_CUDA_TRY(cudaEventDestroy(event_));
if (cusparse_initialized_) { RAFT_CUSPARSE_TRY_NO_THROW(cusparseDestroy(cusparse_handle_)); }
if (cusolver_dn_initialized_) {
RAFT_CUSOLVER_TRY_NO_THROW(cusolverDnDestroy(cusolver_dn_handle_));
}
if (cusolver_sp_initialized_) {
RAFT_CUSOLVER_TRY_NO_THROW(cusolverSpDestroy(cusolver_sp_handle_));
}
if (cublas_initialized_) { RAFT_CUBLAS_TRY_NO_THROW(cublasDestroy(cublas_handle_)); }
RAFT_CUDA_TRY_NO_THROW(cudaEventDestroy(event_));
}
}; // class handle_t

Expand Down
23 changes: 23 additions & 0 deletions cpp/include/raft/linalg/cublas_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,31 @@ inline const char* cublas_error_to_string(cublasStatus_t err)
#define CUBLAS_TRY(call) RAFT_CUBLAS_TRY(call)
#endif

// /**
// * @brief check for cuda runtime API errors but log error instead of raising
// * exception.
// */
#define RAFT_CUBLAS_TRY_NO_THROW(call) \
do { \
cublasStatus_t const status = call; \
if (CUBLAS_STATUS_SUCCESS != status) { \
printf("CUBLAS call='%s' at file=%s line=%d failed with %s\n", \
#call, \
__FILE__, \
__LINE__, \
raft::linalg::detail::cublas_error_to_string(status)); \
} \
} while (0)

/** FIXME: remove after cuml rename */
#ifndef CUBLAS_CHECK
#define CUBLAS_CHECK(call) CUBLAS_TRY(call)
#endif

/** FIXME: remove after cuml rename */
#ifndef CUBLAS_CHECK_NO_THROW
#define CUBLAS_CHECK_NO_THROW(call) RAFT_CUBLAS_TRY_NO_THROW(call)
#endif

namespace raft {
namespace linalg {
Expand Down
20 changes: 20 additions & 0 deletions cpp/include/raft/linalg/cusolver_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,31 @@ inline const char* cusolver_error_to_string(cusolverStatus_t err)
#define CUSOLVER_TRY(call) RAFT_CUSOLVER_TRY(call)
#endif

// /**
// * @brief check for cuda runtime API errors but log error instead of raising
// * exception.
// */
#define RAFT_CUSOLVER_TRY_NO_THROW(call) \
do { \
cusolverStatus_t const status = call; \
if (CUSOLVER_STATUS_SUCCESS != status) { \
printf("CUSOLVER call='%s' at file=%s line=%d failed with %s\n", \
#call, \
__FILE__, \
__LINE__, \
raft::linalg::detail::cusolver_error_to_string(status)); \
} \
} while (0)

// FIXME: remove after cuml rename
#ifndef CUSOLVER_CHECK
#define CUSOLVER_CHECK(call) CUSOLVER_TRY(call)
#endif

#ifndef CUSOLVER_CHECK_NO_THROW
#define CUSOLVER_CHECK_NO_THROW(call) CUSOLVER_TRY_NO_THROW(call)
#endif

namespace raft {
namespace linalg {

Expand Down

0 comments on commit 367688f

Please sign in to comment.