19#ifndef OPM_GPU_SAFE_CALL_HPP
20#define OPM_GPU_SAFE_CALL_HPP
21#include <cuda_runtime.h>
22#if CUDA_VERSION >= 12100
27#include <opm/common/ErrorMacros.hpp>
28#include <opm/common/OpmLog/OpmLog.hpp>
50 const std::string_view& expression,
51 const std::string_view& filename,
52 const std::string_view& functionName,
55#if CUDA_VERSION >= 12100
56 return fmt::format(fmt::runtime(
"GPU expression did not execute correctly. Expression was: \n"
59 "in function {}, in {}, at line {}\n"),
61 cudaGetErrorString(error),
66 std::stringstream str;
67 str <<
"GPU expression did not execute correctly. Expression was: \n"
69 <<
"\nGPU error was " << cudaGetErrorString(error)
70 <<
"\nin function " << functionName <<
", in " << filename
71 <<
", at line " << lineNumber <<
'\n';
97 const std::string_view& expression,
98 const std::string_view& filename,
99 const std::string_view& functionName,
102 if (error != cudaSuccess) {
103 OPM_THROW(std::runtime_error,
getCudaErrorMessage(error, expression, filename, functionName, lineNumber));
136 const std::string_view& expression,
137 const std::string_view& filename,
138 const std::string_view& functionName,
141 if (error != cudaSuccess) {
142 OpmLog::warning(
getCudaErrorMessage(error, expression, filename, functionName, lineNumber));
164#define OPM_GPU_SAFE_CALL(expression) \
165 ::Opm::gpuistl::detail::cudaSafeCall(expression, #expression, __FILE__, __func__, __LINE__)
185#define OPM_GPU_WARN_IF_ERROR(expression) \
186 ::Opm::gpuistl::detail::cudaWarnIfError(expression, #expression, __FILE__, __func__, __LINE__)
Contains wrappers to make the CuBLAS library behave as a modern C++ library with function overlading.
Definition autotuner.hpp:30
std::string getCudaErrorMessage(cudaError_t error, const std::string_view &expression, const std::string_view &filename, const std::string_view &functionName, size_t lineNumber)
getCudaErrorMessage generates the error message to display for a given error.
Definition gpu_safe_call.hpp:49
void cudaSafeCall(cudaError_t error, const std::string_view &expression, const std::string_view &filename, const std::string_view &functionName, size_t lineNumber)
cudaSafeCall checks the return type of the GPU expression (function call) and throws an exception if ...
Definition gpu_safe_call.hpp:96
void cudaWarnIfError(cudaError_t error, const std::string_view &expression, const std::string_view &filename, const std::string_view &functionName, size_t lineNumber)
cudaWarnIfError checks the return type of the GPU expression (function call) and issues a warning if ...
Definition gpu_safe_call.hpp:135