GENIE
cuda_macros.h
Go to the documentation of this file.
1 
6 #ifndef GENIE_UTILITY_CUDAMACROS_H_
7 #define GENIE_UTILITY_CUDAMACROS_H_
8 
9 #include <stdio.h>
11 #include <genie/utility/Logger.h>
12 
23 #define cudaCheckErrors( err ) __cudaSafeCall( err, __FILE__, __LINE__ )
24 #define CUDA_CHECK_ERROR( err ) __cudaSafeCall( err, __FILE__, __LINE__ )
25 
26 
33 #define CUDA_LAST_ERROR() __cudaGetLastError (__FILE__, __LINE__)
34 
49 inline void __cudaSafeCall(cudaError err, const char *file, const int line)
50 {
51 
52  if (cudaSuccess != err)
53  {
54  char errstr[1000];
55  snprintf(errstr, 1000, "cudaSafeCall() failed at %s:%i : %s", file, line, cudaGetErrorString(err));
58  }
59 
60  return;
61 }
62 
63 
64 inline void __cudaGetLastError(const char *file, const int line)
65 {
66  cudaError_t err = cudaGetLastError();
67 
68  if (cudaSuccess != err)
69  {
70  char errstr[1000];
71  snprintf(errstr, 1000, "cudaGetLastError() failed at %s:%i : ERR %d - %s.\n",
72  file, line, (int)err, cudaGetErrorString(err));
75  }
76 }
77 
78 #endif
79 
void __cudaSafeCall(cudaError err, const char *file, const int line)
The hidden wrapper function to validate CUDA calls.
Definition: cuda_macros.h:49
void __cudaGetLastError(const char *file, const int line)
Definition: cuda_macros.h:64
static const int ALERT
Definition: Logger.h:47
static int log(int level, const char *fmt,...)
Record and print a message into log file.
Definition: Logger.cc:99
Record run-time information.