cuda_safe_call.hpp File Reference
#include <cuda_runtime.h>
#include <fmt/core.h>
#include <opm/common/ErrorMacros.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <string_view>
Include dependency graph for cuda_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 OPM_CUDA_SAFE_CALL(expression)    ::Opm::cuistl::detail::cudaSafeCall(expression, #expression, __FILE__, __func__, __LINE__)
 OPM_CUDA_SAFE_CALL checks the return type of the CUDA expression (function call) and throws an exception if it does not equal cudaSuccess. More...
 
#define OPM_CUDA_WARN_IF_ERROR(expression)    ::Opm::cuistl::detail::cudaWarnIfError(expression, #expression, __FILE__, __func__, __LINE__)
 OPM_CUDA_WARN_IF_ERROR checks the return type of the CUDA expression (function call) and issues a warning if it does not equal cudaSuccess. More...
 

Functions

std::string Opm::cuistl::detail::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. More...
 
void Opm::cuistl::detail::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 CUDA expression (function call) and throws an exception if it does not equal cudaSuccess. More...
 
cudaError_t Opm::cuistl::detail::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 CUDA expression (function call) and issues a warning if it does not equal cudaSuccess. More...
 

Macro Definition Documentation

◆ OPM_CUDA_SAFE_CALL

#define OPM_CUDA_SAFE_CALL (   expression)     ::Opm::cuistl::detail::cudaSafeCall(expression, #expression, __FILE__, __func__, __LINE__)

OPM_CUDA_SAFE_CALL checks the return type of the CUDA expression (function call) and throws an exception if it does not equal cudaSuccess.

Example usage:

#include <cuda_runtime.h>
void some_function() {
void* somePointer;
OPM_CUDA_SAFE_CALL(cudaMalloc(&somePointer, 1));
}
#define OPM_CUDA_SAFE_CALL(expression)
OPM_CUDA_SAFE_CALL checks the return type of the CUDA expression (function call) and throws an except...
Definition: cuda_safe_call.hpp:154
Note
This should be used for any call to the CUDA runtime API unless you have a good reason not to.

◆ OPM_CUDA_WARN_IF_ERROR

#define OPM_CUDA_WARN_IF_ERROR (   expression)     ::Opm::cuistl::detail::cudaWarnIfError(expression, #expression, __FILE__, __func__, __LINE__)

OPM_CUDA_WARN_IF_ERROR checks the return type of the CUDA expression (function call) and issues a warning if it does not equal cudaSuccess.

Example usage:

#include <cuda_runtime.h>
void some_function() {
void* somePointer;
OPM_CUDA_WARN_IF_ERROR(cudaMalloc(&somePointer, 1));
}
#define OPM_CUDA_WARN_IF_ERROR(expression)
OPM_CUDA_WARN_IF_ERROR checks the return type of the CUDA expression (function call) and issues a war...
Definition: cuda_safe_call.hpp:175
Note
Prefer the cudaSafeCall/OPM_CUDA_SAFE_CALL counterpart unless you really don't want to throw an exception.