-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcuda_errorcheck.cuh
More file actions
54 lines (37 loc) · 1.48 KB
/
cuda_errorcheck.cuh
File metadata and controls
54 lines (37 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef CUDA_ERRORCHECK_CUH
#define CUDA_ERRORCHECK_CUH
#include <string>
#include <iostream>
// void cudaCheck(cudaError_t status, const char *file, int line, bool abort=true){
// using namespace std::string_literals;
// if (status != cudaSuccess){
// std::string msg = "CUDA Error: "s + cudaGetErrorString(status) + " "s + file + " "s + std::to_string(line);
// std::cerr << msg << "\n";
// if(abort){
// throw std::runtime_error(msg);
// }
// }
// }
//#define CUDACHECK(ans) { cudaCheck((ans), __FILE__, __LINE__); }
//#define CUDACHECKASYNC { CUDACHECK((cudaPeekAtLastError()), __FILE__, __LINE__); }
#ifdef __CUDACC__
#define CUDACHECKIMPL(ans, async) { \
using namespace std::string_literals; \
constexpr bool abort = true; \
cudaError_t MY_CUDA_CHECK_status = (ans); \
if (MY_CUDA_CHECK_status != cudaSuccess){ \
cudaGetLastError(); \
std::string msg = (async ? "Asynchronous "s : "Synchronous "s) + "CUDA Error: "s + cudaGetErrorString(MY_CUDA_CHECK_status) + " "s + __FILE__ + " "s + std::to_string(__LINE__); \
std::cerr << msg << "\n"; \
if(abort){ \
throw std::runtime_error(msg); \
} \
} \
}
#define CUDACHECK(ans) { CUDACHECKIMPL((ans), false); }
#define CUDACHECKASYNC { CUDACHECKIMPL((cudaPeekAtLastError()), true); }
#else
#define CUDACHECK(ANS) (ANS)
#define CUDACHECKASYNC
#endif
#endif