cusparse_safe_call.hpp File Reference
#include <cusparse.h>
#include <exception>
#include <fmt/core.h>
#include <opm/common/ErrorMacros.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
Include dependency graph for cusparse_safe_call.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  Opm
 
namespace  Opm::cuistl
 
namespace  Opm::cuistl::detail
 

Macros

#define CHECK_CUSPARSE_ERROR_TYPE(code, x)
 
#define OPM_CUSPARSE_SAFE_CALL(expression)    ::Opm::cuistl::detail::cusparseSafeCall(expression, #expression, __FILE__, __func__, __LINE__)
 OPM_CUSPARSE_SAFE_CALL checks the return type of the cusparse expression (function call) and throws an exception if it does not equal CUSPARSE_STATUS_SUCCESS. More...
 
#define OPM_CUSPARSE_WARN_IF_ERROR(expression)    ::Opm::cuistl::detail::cusparseWarnIfError(expression, #expression, __FILE__, __func__, __LINE__)
 OPM_CUSPARSE_WARN_IF_ERROR checks the return type of the cusparse expression (function call) and issues a warning if it does not equal CUSPARSE_STATUS_SUCCESS. More...
 

Functions

std::string Opm::cuistl::detail::getCusparseErrorCodeToString (int code)
 getCusparseErrorCodeToString Converts an error code returned from a cusparse function a human readable string. More...
 
std::string Opm::cuistl::detail::getCusparseErrorMessage (cusparseStatus_t error, const std::string_view &expression, const std::string_view &filename, const std::string_view &functionName, size_t lineNumber)
 getCusparseErrorMessage generates the error message to display for a given error. More...
 
void Opm::cuistl::detail::cusparseSafeCall (cusparseStatus_t error, const std::string_view &expression, const std::string_view &filename, const std::string_view &functionName, size_t lineNumber)
 cusparseSafeCall checks the return type of the CUSPARSE expression (function call) and throws an exception if it does not equal CUSPARSE_STATUS_SUCCESS. More...
 
cusparseStatus_t Opm::cuistl::detail::cusparseWarnIfError (cusparseStatus_t error, const std::string_view &expression, const std::string_view &filename, const std::string_view &functionName, size_t lineNumber)
 cusparseWarnIfError checks the return type of the CUSPARSE expression (function call) and issues a warning if it does not equal CUSPARSE_STATUS_SUCCESS. More...
 

Macro Definition Documentation

◆ CHECK_CUSPARSE_ERROR_TYPE

#define CHECK_CUSPARSE_ERROR_TYPE (   code,
 
)
Value:
if (code == x) { \
return #x; \
}

◆ OPM_CUSPARSE_SAFE_CALL

#define OPM_CUSPARSE_SAFE_CALL (   expression)     ::Opm::cuistl::detail::cusparseSafeCall(expression, #expression, __FILE__, __func__, __LINE__)

OPM_CUSPARSE_SAFE_CALL checks the return type of the cusparse expression (function call) and throws an exception if it does not equal CUSPARSE_STATUS_SUCCESS.

Example usage:

#include <cusparse.h>
void some_function() {
cusparseHandle_t cusparseHandle;
OPM_CUSPARSE_SAFE_CALL(cusparseCreate(&cusparseHandle));
}
#define OPM_CUSPARSE_SAFE_CALL(expression)
OPM_CUSPARSE_SAFE_CALL checks the return type of the cusparse expression (function call) and throws a...
Definition: cusparse_safe_call.hpp:185
Note
This should be used for any call to cuSparse unless you have a good reason not to.

◆ OPM_CUSPARSE_WARN_IF_ERROR

#define OPM_CUSPARSE_WARN_IF_ERROR (   expression)     ::Opm::cuistl::detail::cusparseWarnIfError(expression, #expression, __FILE__, __func__, __LINE__)

OPM_CUSPARSE_WARN_IF_ERROR checks the return type of the cusparse expression (function call) and issues a warning if it does not equal CUSPARSE_STATUS_SUCCESS.

Example usage:

#include <cusparse.h>
void some_function() {
cusparseHandle_t cusparseHandle;
OPM_CUSPARSE_WARN_IF_ERROR(cusparseCreate(&cusparseHandle));
}
#define OPM_CUSPARSE_WARN_IF_ERROR(expression)
OPM_CUSPARSE_WARN_IF_ERROR checks the return type of the cusparse expression (function call) and issu...
Definition: cusparse_safe_call.hpp:206
Note
Prefer the cusparseSafeCall/OPM_CUBLAS_SAFE_CALL counterpart unless you really don't want to throw an exception.