19 #ifndef OPM_CUBLAS_SAFE_CALL_HPP 20 #define OPM_CUBLAS_SAFE_CALL_HPP 21 #include <cublas_v2.h> 24 #include <opm/common/ErrorMacros.hpp> 25 #include <opm/common/OpmLog/OpmLog.hpp> 26 #include <string_view> 34 #define CHECK_CUBLAS_ERROR_TYPE(code, x) \ 46 inline std::string getCublasErrorCodeToString(
int code)
48 CHECK_CUBLAS_ERROR_TYPE(code, CUBLAS_STATUS_SUCCESS);
49 CHECK_CUBLAS_ERROR_TYPE(code, CUBLAS_STATUS_NOT_INITIALIZED);
50 CHECK_CUBLAS_ERROR_TYPE(code, CUBLAS_STATUS_ALLOC_FAILED);
51 CHECK_CUBLAS_ERROR_TYPE(code, CUBLAS_STATUS_INVALID_VALUE);
52 CHECK_CUBLAS_ERROR_TYPE(code, CUBLAS_STATUS_ARCH_MISMATCH);
53 CHECK_CUBLAS_ERROR_TYPE(code, CUBLAS_STATUS_MAPPING_ERROR);
54 CHECK_CUBLAS_ERROR_TYPE(code, CUBLAS_STATUS_EXECUTION_FAILED);
55 CHECK_CUBLAS_ERROR_TYPE(code, CUBLAS_STATUS_INTERNAL_ERROR);
56 CHECK_CUBLAS_ERROR_TYPE(code, CUBLAS_STATUS_NOT_SUPPORTED);
57 CHECK_CUBLAS_ERROR_TYPE(code, CUBLAS_STATUS_LICENSE_ERROR);
59 return fmt::format(fmt::runtime(
"UNKNOWN CUBLAS ERROR {}."), code);
62 #undef CHECK_CUBLAS_ERROR_TYPE 83 const std::string_view& expression,
84 const std::string_view& filename,
85 const std::string_view& functionName,
88 return fmt::format(fmt::runtime(
"cuBLAS expression did not execute correctly. Expression was: \n\n" 90 "in function {}, in {}, at line {}.\n" 91 "CuBLAS error code was: {}\n"),
96 getCublasErrorCodeToString(error));
126 const std::string_view& expression,
127 const std::string_view& filename,
128 const std::string_view& functionName,
131 if (error != CUBLAS_STATUS_SUCCESS) {
132 OPM_THROW(std::runtime_error,
getCublasErrorMessage(error, expression, filename, functionName, lineNumber));
164 inline cublasStatus_t
166 const std::string_view& expression,
167 const std::string_view& filename,
168 const std::string_view& functionName,
171 if (error != CUBLAS_STATUS_SUCCESS) {
196 #define OPM_CUBLAS_SAFE_CALL(expression) \ 197 ::Opm::gpuistl::detail::cublasSafeCall(expression, #expression, __FILE__, __func__, __LINE__) 216 #define OPM_CUBLAS_WARN_IF_ERROR(expression) \ 217 ::Opm::gpuistl::detail::cublasWarnIfError(expression, #expression, __FILE__, __func__, __LINE__) 219 #endif // OPM_CUBLAS_SAFE_CALL_HPP std::string 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.
Definition: cublas_safe_call.hpp:82
void 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 exceptio...
Definition: cublas_safe_call.hpp:125
Contains wrappers to make the CuBLAS library behave as a modern C++ library with function overlading...
Definition: autotuner.hpp:29
cublasStatus_t 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 warnin...
Definition: cublas_safe_call.hpp:165