QUDA  v1.1.0
A library for QCD on GPUs
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 
10 
16 
18 char *getOutputPrefix();
19 FILE *getOutputFile();
20 
22 void setOutputPrefix(const char *prefix);
23 void setOutputFile(FILE *outfile);
24 
29 
33 void popVerbosity();
34 
38 void pushOutputPrefix(const char *prefix);
39 
43 void popOutputPrefix();
44 
51 bool getRankVerbosity();
52 
53 char *getPrintBuffer();
54 
61 char* getOmpThreadStr();
62 
63 namespace quda {
64  // forward declaration
65  void saveTuneCache(bool error);
66 }
67 
68 #define zeroThread (threadIdx.x + blockDim.x*blockIdx.x==0 && \
69  threadIdx.y + blockDim.y*blockIdx.y==0 && \
70  threadIdx.z + blockDim.z*blockIdx.z==0)
71 
72 #define printfZero(...) do { \
73  if (zeroThread) printf(__VA_ARGS__); \
74  } while (0)
75 
76 #ifdef MULTI_GPU
77 
78 #define printfQuda(...) do { \
79  sprintf(getPrintBuffer(), __VA_ARGS__); \
80  if (getRankVerbosity()) { \
81  fprintf(getOutputFile(), "%s", getOutputPrefix()); \
82  fprintf(getOutputFile(), "%s", getPrintBuffer()); \
83  fflush(getOutputFile()); \
84  } \
85 } while (0)
86 
87 #define errorQuda(...) \
88  do { \
89  fprintf(getOutputFile(), "%sERROR: ", getOutputPrefix()); \
90  fprintf(getOutputFile(), __VA_ARGS__); \
91  fprintf(getOutputFile(), " (rank %d, host %s, " __FILE__ ":%d in %s())\n", comm_rank_global(), comm_hostname(), \
92  __LINE__, __func__); \
93  fprintf(getOutputFile(), "%s last kernel called was (name=%s,volume=%s,aux=%s)\n", getOutputPrefix(), \
94  getLastTuneKey().name, getLastTuneKey().volume, getLastTuneKey().aux); \
95  fflush(getOutputFile()); \
96  quda::saveTuneCache(true); \
97  comm_abort(1); \
98  } while (0)
99 
100 #define warningQuda(...) do { \
101  if (getVerbosity() > QUDA_SILENT) { \
102  sprintf(getPrintBuffer(), __VA_ARGS__); \
103  if (getRankVerbosity()) { \
104  fprintf(getOutputFile(), "%sWARNING: ", getOutputPrefix()); \
105  fprintf(getOutputFile(), "%s", getPrintBuffer()); \
106  fprintf(getOutputFile(), "\n"); \
107  fflush(getOutputFile()); \
108  } \
109  } \
110 } while (0)
111 
112 #else
113 
114 #define printfQuda(...) do { \
115  fprintf(getOutputFile(), "%s", getOutputPrefix()); \
116  fprintf(getOutputFile(), __VA_ARGS__); \
117  fflush(getOutputFile()); \
118 } while (0)
119 
120 #define errorQuda(...) do { \
121  fprintf(getOutputFile(), "%sERROR: ", getOutputPrefix()); \
122  fprintf(getOutputFile(), __VA_ARGS__); \
123  fprintf(getOutputFile(), " (" __FILE__ ":%d in %s())\n", \
124  __LINE__, __func__); \
125  fprintf(getOutputFile(), "%s last kernel called was (name=%s,volume=%s,aux=%s)\n", \
126  getOutputPrefix(), getLastTuneKey().name, \
127  getLastTuneKey().volume, getLastTuneKey().aux); \
128  quda::saveTuneCache(true); \
129  comm_abort(1); \
130 } while (0)
131 
132 #define warningQuda(...) do { \
133  if (getVerbosity() > QUDA_SILENT) { \
134  fprintf(getOutputFile(), "%sWARNING: ", getOutputPrefix()); \
135  fprintf(getOutputFile(), __VA_ARGS__); \
136  fprintf(getOutputFile(), "\n"); \
137  fflush(getOutputFile()); \
138  } \
139 } while (0)
140 
141 #endif // MULTI_GPU
142 
143 #define checkCudaErrorNoSync() \
144  do { \
145  cudaError_t error = cudaGetLastError(); \
146  if (error != cudaSuccess) errorQuda("(CUDA) %s", cudaGetErrorString(error)); \
147  } while (0)
148 
149 #ifdef HOST_DEBUG
150 
151 #define checkCudaError() do { \
152  cudaDeviceSynchronize(); \
153  checkCudaErrorNoSync(); \
154 } while (0)
155 
156 #else
157 
158 #define checkCudaError() checkCudaErrorNoSync()
159 
160 #endif // HOST_DEBUG
161 
162 #ifdef __CUDA_ARCH__
163 // hide from device code
164 #undef errorQuda
165 #define errorQuda(...)
166 
167 #endif
168 
169 #endif // _UTIL_QUDA_H
QudaVerbosity verbosity
enum QudaTune_s QudaTune
enum QudaVerbosity_s QudaVerbosity
void saveTuneCache(bool error=false)
Definition: tune.cpp:439
void pushVerbosity(QudaVerbosity verbosity)
Push a new verbosity onto the stack.
Definition: util_quda.cpp:83
QudaTune getTuning()
Query whether autotuning is enabled or not. Default is enabled but can be overridden by setting QUDA_...
Definition: util_quda.cpp:52
void popOutputPrefix()
Pop the output prefix restoring the prior one on the stack.
Definition: util_quda.cpp:121
char * getPrintBuffer()
Definition: util_quda.cpp:132
void popVerbosity()
Pop the verbosity restoring the prior one on the stack.
Definition: util_quda.cpp:94
char * getOmpThreadStr()
Returns a string of the form ",omp_threads=$OMP_NUM_THREADS", which can be used for storing the numbe...
Definition: util_quda.cpp:134
bool getRankVerbosity()
This function returns true if the calling rank is enabled for verbosity (e.g., whether printQuda and ...
Definition: util_quda.cpp:30
FILE * getOutputFile()
Definition: util_quda.cpp:23
void pushOutputPrefix(const char *prefix)
Push a new output prefix onto the stack.
Definition: util_quda.cpp:105
QudaVerbosity getVerbosity()
Definition: util_quda.cpp:21
char * getOutputPrefix()
Definition: util_quda.cpp:22
void setVerbosity(QudaVerbosity verbosity)
Definition: util_quda.cpp:25
void setOutputPrefix(const char *prefix)
Definition: util_quda.cpp:69
void setOutputFile(FILE *outfile)
Definition: util_quda.cpp:75