cublas_safe_call.hpp File Reference
#include <cublas_v2.h>
#include <exception>
#include <fmt/core.h>
#include <opm/common/ErrorMacros.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <string_view>
Include dependency graph for cublas_safe_call.hpp:

Go to the source code of this file.

Namespaces

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

Macros

#define CHECK_CUBLAS_ERROR_TYPE(code, x)
 
#define OPM_CUBLAS_SAFE_CALL(expression)    ::Opm::cuistl::detail::cublasSafeCall(expression, #expression, __FILE__, __func__, __LINE__)
 OPM_CUBLAS_SAFE_CALL checks the return type of the cublas expression (function call) and throws an exception if it does not equal CUBLAS_STATUS_SUCCESS. More...
 
#define OPM_CUBLAS_WARN_IF_ERROR(expression)    ::Opm::cuistl::detail::cublasWarnIfError(expression, #expression, __FILE__, __func__, __LINE__)
 OPM_CUBLAS_WARN_IF_ERROR checks the return type of the cublas expression (function call) and issues a warning if it does not equal CUBLAS_STATUS_SUCCESS. More...
 

Functions

std::string Opm::cuistl::detail::getCublasErrorMessage (cublasStatus_t error, const std::string_view &expression, const std::string_view &filename, const std::string_view &functionName, size_t lineNumber)
 getCublasErrorMessage generates the error message to display for a given error. More...
 
void Opm::cuistl::detail::cublasSafeCall (cublasStatus_t error, const std::string_view &expression, const std::string_view &filename, const std::string_view &functionName, size_t lineNumber)
 cublasSafeCall checks the return type of the CUBLAS expression (function call) and throws an exception if it does not equal CUBLAS_STATUS_SUCCESS. More...
 
cublasStatus_t Opm::cuistl::detail::cublasWarnIfError (cublasStatus_t error, const std::string_view &expression, const std::string_view &filename, const std::string_view &functionName, size_t lineNumber)
 cublasWarnIfError checks the return type of the CUBLAS expression (function call) and issues a warning if it does not equal CUBLAS_STATUS_SUCCESS. More...
 

Macro Definition Documentation

◆ CHECK_CUBLAS_ERROR_TYPE

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

◆ OPM_CUBLAS_SAFE_CALL

#define OPM_CUBLAS_SAFE_CALL (   expression)     ::Opm::cuistl::detail::cublasSafeCall(expression, #expression, __FILE__, __func__, __LINE__)

OPM_CUBLAS_SAFE_CALL checks the return type of the cublas expression (function call) and throws an exception if it does not equal CUBLAS_STATUS_SUCCESS.

Example usage:

#include <cublas_v2.h>
void some_function() {
cublasHandle_t cublasHandle;
OPM_CUBLAS_SAFE_CALL(cublasCreate(&cublasHandle));
}
#define OPM_CUBLAS_SAFE_CALL(expression)
OPM_CUBLAS_SAFE_CALL checks the return type of the cublas expression (function call) and throws an ex...
Definition: cublas_safe_call.hpp:196
Note
This should be used for any call to cuBlas unless you have a good reason not to.

◆ OPM_CUBLAS_WARN_IF_ERROR

#define OPM_CUBLAS_WARN_IF_ERROR (   expression)     ::Opm::cuistl::detail::cublasWarnIfError(expression, #expression, __FILE__, __func__, __LINE__)

OPM_CUBLAS_WARN_IF_ERROR checks the return type of the cublas expression (function call) and issues a warning if it does not equal CUBLAS_STATUS_SUCCESS.

Example usage:

#include <cublas_v2.h>
void some_function() {
cublasHandle_t cublasHandle;
OPM_CUBLAS_WARN_IF_ERROR(cublasCreate(&cublasHandle));
}
#define OPM_CUBLAS_WARN_IF_ERROR(expression)
OPM_CUBLAS_WARN_IF_ERROR checks the return type of the cublas expression (function call) and issues a...
Definition: cublas_safe_call.hpp:216
Note
Prefer the cublasSafeCall/OPM_CUBLAS_SAFE_CALL counterpart unless you really don't want to throw an exception.