isce3 0.25.0
Loading...
Searching...
No Matches
cudaError.h
Go to the documentation of this file.
1
6
7// code guard
8#ifndef _CUDAERROR_CUH
9#define _CUDAERROR_CUH
10
11#pragma once
12
13#include <cstdlib>
14#include <cstdio>
15#include <cstring>
16#include <cufft.h>
17#include "debug.h"
18#include <cuda.h>
19
20
21#ifdef __DRIVER_TYPES_H__
22#ifndef DEVICE_RESET
23#define DEVICE_RESET cudaDeviceReset();
24#endif
25#else
26#ifndef DEVICE_RESET
27#define DEVICE_RESET
28#endif
29#endif
30
31template<typename T >
32void check(T result, char const *const func, const char *const file, int const line)
33{
34 if (result)
35 {
36
37 fprintf(stderr, "CUDA error at %s:%d code=%d(%s) \n",
38 file, line, static_cast<unsigned int>(result), func);
39 DEVICE_RESET
40 // Make sure we call CUDA Device Reset before exiting
41 exit(EXIT_FAILURE);
42 }
43}
44
45// This will output the proper error string when calling cudaGetLastError
46inline void __getLastCudaError(const char *errorMessage, const char *file, const int line)
47{
48 cudaError_t err = cudaGetLastError();
49
50 if (cudaSuccess != err)
51 {
52 fprintf(stderr, "%s(%i) : CUDA error : %s : (%d) %s.\n",
53 file, line, errorMessage, (int)err, cudaGetErrorString(err));
54 DEVICE_RESET
55 exit(EXIT_FAILURE);
56 }
57}
58
59// This will output the proper CUDA error strings in the event that a CUDA host call returns an error
60#ifdef CUDA_ERROR_CHECK
61#define checkCudaErrors(val) check ( (val), #val, __FILE__, __LINE__ )
62#define cufft_Error(val) check ( (val), #val, __FILE__, __LINE__ )
63#define getLastCudaError(var) __getLastCudaError (var, __FILE__, __LINE__)
64#else
65#define checkCudaErrors(val) val
66#define cufft_Error(val) val
67#define getLastCudaError(val)
68#endif //CUDA_ERROR_CHECK
69
70#endif //__CUDAERROR_CUH
Define flags to control the debugging.

Generated for ISCE3.0 by doxygen 1.13.2.