-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsafecuda.h
47 lines (40 loc) · 1.66 KB
/
safecuda.h
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
// This file contains a composite of the different types of CUDA error check wrappers I have seen over the years.
#pragma once
#include <cuda_runtime.h>
#include <nvrtc.h>
#include <cstdio>
#define NVRTC_SAFE_CALL(x) \
do { \
nvrtcResult result = x; \
if (result != NVRTC_SUCCESS) { \
std::cerr << "\nerror: " #x " failed with error " \
<< nvrtcGetErrorString(result) << '\n'; \
} \
} while(0)
#define CUDA_SAFE_CALL(x) \
do { \
CUresult result = x; \
if (result != CUDA_SUCCESS) { \
const char *msg; \
cuGetErrorName(result, &msg); \
std::cerr << "\nerror: " #x " failed with error " \
<< msg << '\n'; \
exit(1);\
} \
} while(0)
#define CUDA_CHECK(status) \
if (status != cudaSuccess) \
{ \
printf("%s:%d CudaError: %s\n", __FILE__, __LINE__, cudaGetErrorString(status)); \
assert(0); \
}
#define CHECK_CUDA_ERROR() \
{ \
cudaError_t err = cudaGetLastError(); \
if (err != cudaSuccess) \
{ \
printf("error=%d name=%s at " \
"ln: %d\n ",err,cudaGetErrorString(err),__LINE__); \
exit(1);\
} \
}