1#ifndef AMREX_GPU_ERROR_H_
2#define AMREX_GPU_ERROR_H_
3#include <AMReX_Config.H>
9#include <hip/hip_runtime.h>
12#if defined(AMREX_USE_GPU) && !defined(AMREX_GPU_NO_ERROR_CHECK) && !defined(AMREX_USE_SYCL)
23 return hipGetLastError();
28 return hipGetErrorString(error);
38 return cudaGetLastError();
43 return cudaGetErrorString(error);
50 inline void ErrorCheck (
const char* file,
int line)
noexcept
54 std::string errStr(std::string(
"GPU last error detected in file ") + file
55 +
" line " + std::to_string(line)
63#define AMREX_GPU_SAFE_CALL(call) { \
64 amrex::gpuError_t amrex_i_err = call; \
65 if (amrex::gpuSuccess != amrex_i_err) { \
66 std::string errStr(std::string("GPU error in file ") + __FILE__ \
67 + " line " + std::to_string(__LINE__) \
68 + " " + amrex::gpuGetErrorString(amrex_i_err)); \
69 amrex::Abort(errStr); \
73#define AMREX_CUDA_SAFE_CALL(call) { \
74 cudaError_t amrex_i_err = call; \
75 if (cudaSuccess != amrex_i_err) { \
76 std::string errStr(std::string("CUDA error ") + std::to_string(amrex_i_err) \
77 + std::string(" in file ") + __FILE__ \
78 + " line " + std::to_string(__LINE__) \
79 + ": " + cudaGetErrorString(amrex_i_err)); \
80 amrex::Abort(errStr); \
83#define AMREX_CURAND_SAFE_CALL(call) { \
84 curandStatus_t amrex_i_err = call; \
85 if (CURAND_STATUS_SUCCESS != amrex_i_err) { \
86 std::string errStr(std::string("CURAND error ") + std::to_string(amrex_i_err) \
87 + std::string(" in file ") + __FILE__ \
88 + " line " + std::to_string(__LINE__)); \
89 amrex::Abort(errStr); \
92#define AMREX_CUFFT_SAFE_CALL(call) { \
93 cufftResult_t amrex_i_err = call; \
94 if (CUFFT_SUCCESS != amrex_i_err) { \
95 std::string errStr(std::string("CUFFT error ")+std::to_string(amrex_i_err) \
96 + std::string(" in file ") + __FILE__ \
97 + " line " + std::to_string(__LINE__)); \
98 amrex::Abort(errStr); \
104#define AMREX_HIP_SAFE_CALL(call) { \
105 hipError_t amrex_i_err = call; \
106 if (hipSuccess != amrex_i_err) { \
107 std::string errStr(std::string("HIP error in file ") + __FILE__ \
108 + " line " + std::to_string(__LINE__) \
109 + " " + hipGetErrorString(amrex_i_err)); \
110 amrex::Abort(errStr); \
113#define AMREX_HIPRAND_SAFE_CALL(call) { \
114 hiprandStatus_t amrex_i_err = call; \
115 if (HIPRAND_STATUS_SUCCESS != amrex_i_err) { \
116 std::string errStr(std::string("HIPRAND error ") + std::to_string(amrex_i_err) \
117 + std::string(" in file ") + __FILE__ \
118 + " line " + std::to_string(__LINE__)); \
119 amrex::Abort(errStr); \
122#define AMREX_ROCFFT_SAFE_CALL(call) { \
123 auto amrex_i_err = call; \
124 if (rocfft_status_success != amrex_i_err) { \
125 std::string errStr(std::string("rocFFT error ")+std::to_string(amrex_i_err) \
126 + std::string(" in file ") + __FILE__ \
127 + " line " + std::to_string(__LINE__)); \
128 amrex::Abort(errStr); \
133#define AMREX_GPU_ERROR_CHECK() amrex::Gpu::ErrorCheck(__FILE__, __LINE__)
137#define AMREX_GPU_SAFE_CALL(call) (call)
138#define AMREX_GPU_ERROR_CHECK() ((void)0)
void ErrorCheck(const char *file, int line) noexcept
Definition AMReX_GpuError.H:50
Definition AMReX_Amr.cpp:49
const char * gpuGetErrorString(gpuError_t error)
Definition AMReX_GpuError.H:42
gpuError_t gpuGetLastError()
Definition AMReX_GpuError.H:37
cudaError_t gpuError_t
Definition AMReX_GpuError.H:33
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition AMReX.cpp:230
constexpr gpuError_t gpuSuccess
Definition AMReX_GpuError.H:34