-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCudaErrorHandler.cuh
52 lines (39 loc) · 1.23 KB
/
CudaErrorHandler.cuh
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
#ifndef CUDA_ERROR_HANDLER_H
#define CUDA_ERROR_HANDLER_H
#include <stdio.h>
#include <stdlib.h>
#include <cuda_runtime.h>
inline cudaError_t __checkCudaError(cudaError_t error_code, const char* const file, const int line)
{
#if defined(DEBUG) || defined(_DEBUG)
if(error_code != cudaSuccess)
{
fprintf(stderr, "[file : %s line : %d] CUDA Runtime Error : %s\n", file, line, cudaGetErrorString(error_code));
cudaDeviceReset();
exit(EXIT_FAILURE);
}
#endif
return error_code;
}
inline void __checkForLastCudaError(const char* const file, const int line)
{
#if defined(DEBUG) || defined(_DEBUG)
cudaError_t error_code = cudaGetLastError();
if(error_code != cudaSuccess)
{
fprintf(stderr, "[file : %s, line : %d] CUDA Error : %s\n", file, line, cudaGetErrorString(error_code));
cudaDeviceReset();
exit(EXIT_FAILURE);
}
error_code = cudaDeviceSynchronize();
if(error_code != cudaSuccess)
{
fprintf(stderr, "[file %s, line : %d] CUDA Sync Error : %s\n", file, line, cudaGetErrorString(error_code));
cudaDeviceReset();
exit(EXIT_FAILURE);
}
#endif
}
#define checkCudaError(val) __checkCudaError((val), __FILE__, __LINE__)
#define checkForLastCudaError() __checkForLastCudaError(__FILE__, __LINE__)
#endif //CUDA_ERROR_HANDLER_H