Block-Structured AMR Software Framework
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
AMReX_GpuError.H
Go to the documentation of this file.
1#ifndef AMREX_GPU_ERROR_H_
2#define AMREX_GPU_ERROR_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_Utility.H>
6#include <string>
7
8#ifdef AMREX_USE_HIP
9#include <hip/hip_runtime.h>
10#endif
11
12#if defined(AMREX_USE_GPU) && !defined(AMREX_GPU_NO_ERROR_CHECK) && !defined(AMREX_USE_SYCL)
13
14namespace amrex {
15
16#ifdef AMREX_USE_HIP
17
18using gpuError_t = hipError_t;
19constexpr gpuError_t gpuSuccess = hipSuccess;
20
21inline gpuError_t
23 return hipGetLastError();
24}
25
26inline const char*
28 return hipGetErrorString(error);
29}
30
31#else
32
33using gpuError_t = cudaError_t;
34constexpr gpuError_t gpuSuccess = cudaSuccess;
35
36inline gpuError_t
38 return cudaGetLastError();
39}
40
41inline const char*
43 return cudaGetErrorString(error);
44}
45
46#endif
47
48namespace Gpu {
49
50 inline void ErrorCheck (const char* file, int line) noexcept
51 {
53 if (gpuSuccess != err) {
54 std::string errStr(std::string("GPU last error detected in file ") + file
55 + " line " + std::to_string(line)
56 + ": " + std::string(gpuGetErrorString(err)));
57 amrex::Abort(errStr);
58 }
59 }
60}
61}
62
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); \
70 }}
71
72#ifdef AMREX_USE_CUDA
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); \
81 }}
82
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); \
90 }}
91
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); \
99 }}
100
101#endif
102
103#ifdef AMREX_USE_HIP
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); \
111 }}
112
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); \
120 }}
121
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); \
129 }}
130
131#endif
132
133#define AMREX_GPU_ERROR_CHECK() amrex::Gpu::ErrorCheck(__FILE__, __LINE__)
134
135#else
136
137#define AMREX_GPU_SAFE_CALL(call) (call)
138#define AMREX_GPU_ERROR_CHECK() ((void)0)
139
140#endif
141
142#endif
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