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(x) do { if((x)!=CURAND_STATUS_SUCCESS) { \
84 std::string errStr(std::string("CURAND error in file ") + __FILE__ \
85 + " line " + std::to_string(__LINE__)); \
86 amrex::Abort(errStr); }} while(0)
88 #define AMREX_CUFFT_SAFE_CALL(call) { \
89 cufftResult_t amrex_i_err = call; \
90 if (CUFFT_SUCCESS != amrex_i_err) { \
91 std::string errStr(std::string("CUFFT error ")+std::to_string(amrex_i_err) \
92 + std::string(" in file ") + __FILE__ \
93 + " line " + std::to_string(__LINE__)); \
94 amrex::Abort(errStr); \
100 #define AMREX_HIP_SAFE_CALL(call) { \
101 hipError_t amrex_i_err = call; \
102 if (hipSuccess != amrex_i_err) { \
103 std::string errStr(std::string("HIP error in file ") + __FILE__ \
104 + " line " + std::to_string(__LINE__) \
105 + " " + hipGetErrorString(amrex_i_err)); \
106 amrex::Abort(errStr); \
109 #define AMREX_HIPRAND_SAFE_CALL(x) do { if((x)!=HIPRAND_STATUS_SUCCESS) { \
110 std::string errStr(std::string("HIPRAND error in file ") + __FILE__ \
111 + " line " + std::to_string(__LINE__)); \
112 amrex::Abort(errStr); }} while(0)
114 #define AMREX_ROCFFT_SAFE_CALL(call) { \
115 auto amrex_i_err = call; \
116 if (rocfft_status_success != amrex_i_err) { \
117 std::string errStr(std::string("rocFFT error ")+std::to_string(amrex_i_err) \
118 + std::string(" in file ") + __FILE__ \
119 + " line " + std::to_string(__LINE__)); \
120 amrex::Abort(errStr); \
125 #define AMREX_GPU_ERROR_CHECK() amrex::Gpu::ErrorCheck(__FILE__, __LINE__)
129 #define AMREX_GPU_SAFE_CALL(call) (call)
130 #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:225
constexpr gpuError_t gpuSuccess
Definition: AMReX_GpuError.H:34