gpu_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 gpu_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::gpuistl
 
namespace  Opm::gpuistl::detail
 

Macros

#define OPM_GPU_SAFE_CALL(expression)    ::Opm::gpuistl::detail::cudaSafeCall(expression, #expression, __FILE__, __func__, __LINE__)
 OPM_GPU_SAFE_CALL checks the return type of the GPU expression (function call) and throws an exception if it does not equal cudaSuccess. More...
 
#define OPM_GPU_WARN_IF_ERROR(expression)    ::Opm::gpuistl::detail::cudaWarnIfError(expression, #expression, __FILE__, __func__, __LINE__)
 OPM_GPU_WARN_IF_ERROR checks the return type of the GPU expression (function call) and issues a warning if it does not equal cudaSuccess. More...
 

Functions

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

Macro Definition Documentation

◆ OPM_GPU_SAFE_CALL

#define OPM_GPU_SAFE_CALL (   expression)     ::Opm::gpuistl::detail::cudaSafeCall(expression, #expression, __FILE__, __func__, __LINE__)

OPM_GPU_SAFE_CALL checks the return type of the GPU 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_GPU_SAFE_CALL(cudaMalloc(&somePointer, 1));
}
#define OPM_GPU_SAFE_CALL(expression)
OPM_GPU_SAFE_CALL checks the return type of the GPU expression (function call) and throws an exceptio...
Definition: gpu_safe_call.hpp:150
Note
This should be used for any call to the GPU runtime API unless you have a good reason not to.

◆ OPM_GPU_WARN_IF_ERROR

#define OPM_GPU_WARN_IF_ERROR (   expression)     ::Opm::gpuistl::detail::cudaWarnIfError(expression, #expression, __FILE__, __func__, __LINE__)

OPM_GPU_WARN_IF_ERROR checks the return type of the GPU 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_GPU_WARN_IF_ERROR(cudaMalloc(&somePointer, 1));
}
#define OPM_GPU_WARN_IF_ERROR(expression)
OPM_GPU_WARN_IF_ERROR checks the return type of the GPU expression (function call) and issues a warni...
Definition: gpu_safe_call.hpp:171
Note
Prefer the cudaSafeCall/OPM_GPU_SAFE_CALL counterpart unless you really don't want to throw an exception.