QUDA  0.9.0
util_quda.h
Go to the documentation of this file.
1 #ifndef _UTIL_QUDA_H
2 #define _UTIL_QUDA_H
3 
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <enum_quda.h>
7 #include <comm_quda.h>
8 #include <tune_key.h>
9 
15 
17 char *getOutputPrefix();
19 
21 void setOutputPrefix(const char *prefix);
22 void setOutputFile(FILE *outfile);
23 
25 void popVerbosity();
26 
33 bool getRankVerbosity();
34 
35 char *getPrintBuffer();
36 
37 
38 #define zeroThread (threadIdx.x + blockDim.x*blockIdx.x==0 && \
39  threadIdx.y + blockDim.y*blockIdx.y==0 && \
40  threadIdx.z + blockDim.z*blockIdx.z==0)
41 
42 #define printfZero(...) do { \
43  if (zeroThread) printf(__VA_ARGS__); \
44  } while (0)
45 
46 
47 #ifdef MULTI_GPU
48 
49 #define printfQuda(...) do { \
50  sprintf(getPrintBuffer(), __VA_ARGS__); \
51  if (getRankVerbosity()) { \
52  fprintf(getOutputFile(), "%s", getOutputPrefix()); \
53  fprintf(getOutputFile(), "%s", getPrintBuffer()); \
54  fflush(getOutputFile()); \
55  } \
56 } while (0)
57 
58 #define errorQuda(...) do { \
59  fprintf(getOutputFile(), "%sERROR: ", getOutputPrefix()); \
60  fprintf(getOutputFile(), __VA_ARGS__); \
61  fprintf(getOutputFile(), " (rank %d, host %s, " __FILE__ ":%d in %s())\n", \
62  comm_rank(), comm_hostname(), __LINE__, __func__); \
63  fprintf(getOutputFile(), "%s last kernel called was (name=%s,volume=%s,aux=%s)\n", \
64  getOutputPrefix(), getLastTuneKey().name, \
65  getLastTuneKey().volume, getLastTuneKey().aux); \
66  fflush(getOutputFile()); \
67  comm_abort(1); \
68 } while (0)
69 
70 #define warningQuda(...) do { \
71  if (getVerbosity() > QUDA_SILENT) { \
72  sprintf(getPrintBuffer(), __VA_ARGS__); \
73  if (getRankVerbosity()) { \
74  fprintf(getOutputFile(), "%sWARNING: ", getOutputPrefix()); \
75  fprintf(getOutputFile(), "%s", getPrintBuffer()); \
76  fprintf(getOutputFile(), "\n"); \
77  fflush(getOutputFile()); \
78  } \
79  } \
80 } while (0)
81 
82 #else
83 
84 #define printfQuda(...) do { \
85  fprintf(getOutputFile(), "%s", getOutputPrefix()); \
86  fprintf(getOutputFile(), __VA_ARGS__); \
87  fflush(getOutputFile()); \
88 } while (0)
89 
90 #define errorQuda(...) do { \
91  fprintf(getOutputFile(), "%sERROR: ", getOutputPrefix()); \
92  fprintf(getOutputFile(), __VA_ARGS__); \
93  fprintf(getOutputFile(), " (" __FILE__ ":%d in %s())\n", \
94  __LINE__, __func__); \
95  fprintf(getOutputFile(), "%s last kernel called was (name=%s,volume=%s,aux=%s)\n", \
96  getOutputPrefix(), getLastTuneKey().name, \
97  getLastTuneKey().volume, getLastTuneKey().aux); \
98  comm_abort(1); \
99 } while (0)
100 
101 #define warningQuda(...) do { \
102  if (getVerbosity() > QUDA_SILENT) { \
103  fprintf(getOutputFile(), "%sWARNING: ", getOutputPrefix()); \
104  fprintf(getOutputFile(), __VA_ARGS__); \
105  fprintf(getOutputFile(), "\n"); \
106  fflush(getOutputFile()); \
107  } \
108 } while (0)
109 
110 #endif // MULTI_GPU
111 
112 
113 #define checkCudaErrorNoSync() do { \
114  cudaError_t error = cudaGetLastError(); \
115  if (error != cudaSuccess) \
116  errorQuda("(CUDA) %s", cudaGetErrorString(error)); \
117 } while (0)
118 
119 
120 #ifdef HOST_DEBUG
121 
122 #define checkCudaError() do { \
123  cudaDeviceSynchronize(); \
124  checkCudaErrorNoSync(); \
125 } while (0)
126 
127 #else
128 
129 #define checkCudaError() checkCudaErrorNoSync()
130 
131 #endif // HOST_DEBUG
132 
133 
134 #endif // _UTIL_QUDA_H
QudaVerbosity verbosity
QudaVerbosity getVerbosity()
Definition: util_quda.cpp:20
void setOutputPrefix(const char *prefix)
Definition: util_quda.cpp:68
char * getOutputPrefix()
Definition: util_quda.cpp:21
FILE * getOutputFile()
Definition: util_quda.cpp:22
char * getPrintBuffer()
Definition: util_quda.cpp:102
void pushVerbosity(QudaVerbosity verbosity)
Definition: util_quda.cpp:82
enum QudaTune_s QudaTune
bool getRankVerbosity()
This function returns true if the calling rank is enabled for verbosity (e.g., whether printQuda and ...
Definition: util_quda.cpp:29
void popVerbosity()
Definition: util_quda.cpp:93
enum QudaVerbosity_s QudaVerbosity
void setOutputFile(FILE *outfile)
Definition: util_quda.cpp:74
QudaTune getTuning()
Query whether autotuning is enabled or not. Default is enabled but can be overridden by setting QUDA_...
Definition: util_quda.cpp:51
void setVerbosity(const QudaVerbosity verbosity)
Definition: util_quda.cpp:24