QUDA  1.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 
77 #ifdef MULTI_GPU
78 
79 #define printfQuda(...) do { \
80  sprintf(getPrintBuffer(), __VA_ARGS__); \
81  if (getRankVerbosity()) { \
82  fprintf(getOutputFile(), "%s", getOutputPrefix()); \
83  fprintf(getOutputFile(), "%s", getPrintBuffer()); \
84  fflush(getOutputFile()); \
85  } \
86 } while (0)
87 
88 #define errorQuda(...) do { \
89  fprintf(getOutputFile(), "%sERROR: ", getOutputPrefix()); \
90  fprintf(getOutputFile(), __VA_ARGS__); \
91  fprintf(getOutputFile(), " (rank %d, host %s, " __FILE__ ":%d in %s())\n", \
92  comm_rank(), comm_hostname(), __LINE__, __func__); \
93  fprintf(getOutputFile(), "%s last kernel called was (name=%s,volume=%s,aux=%s)\n", \
94  getOutputPrefix(), getLastTuneKey().name, \
95  getLastTuneKey().volume, getLastTuneKey().aux); \
96  fflush(getOutputFile()); \
97  quda::saveTuneCache(true); \
98  comm_abort(1); \
99 } while (0)
100 
101 #define warningQuda(...) do { \
102  if (getVerbosity() > QUDA_SILENT) { \
103  sprintf(getPrintBuffer(), __VA_ARGS__); \
104  if (getRankVerbosity()) { \
105  fprintf(getOutputFile(), "%sWARNING: ", getOutputPrefix()); \
106  fprintf(getOutputFile(), "%s", getPrintBuffer()); \
107  fprintf(getOutputFile(), "\n"); \
108  fflush(getOutputFile()); \
109  } \
110  } \
111 } while (0)
112 
113 #else
114 
115 #define printfQuda(...) do { \
116  fprintf(getOutputFile(), "%s", getOutputPrefix()); \
117  fprintf(getOutputFile(), __VA_ARGS__); \
118  fflush(getOutputFile()); \
119 } while (0)
120 
121 #define errorQuda(...) do { \
122  fprintf(getOutputFile(), "%sERROR: ", getOutputPrefix()); \
123  fprintf(getOutputFile(), __VA_ARGS__); \
124  fprintf(getOutputFile(), " (" __FILE__ ":%d in %s())\n", \
125  __LINE__, __func__); \
126  fprintf(getOutputFile(), "%s last kernel called was (name=%s,volume=%s,aux=%s)\n", \
127  getOutputPrefix(), getLastTuneKey().name, \
128  getLastTuneKey().volume, getLastTuneKey().aux); \
129  quda::saveTuneCache(true); \
130  comm_abort(1); \
131 } while (0)
132 
133 #define warningQuda(...) do { \
134  if (getVerbosity() > QUDA_SILENT) { \
135  fprintf(getOutputFile(), "%sWARNING: ", getOutputPrefix()); \
136  fprintf(getOutputFile(), __VA_ARGS__); \
137  fprintf(getOutputFile(), "\n"); \
138  fflush(getOutputFile()); \
139  } \
140 } while (0)
141 
142 #endif // MULTI_GPU
143 
144 
145 #define checkCudaErrorNoSync() do { \
146  cudaError_t error = cudaGetLastError(); \
147  if (error != cudaSuccess) \
148  errorQuda("(CUDA) %s", cudaGetErrorString(error)); \
149 } while (0)
150 
151 
152 #ifdef HOST_DEBUG
153 
154 #define checkCudaError() do { \
155  cudaDeviceSynchronize(); \
156  checkCudaErrorNoSync(); \
157 } while (0)
158 
159 #else
160 
161 #define checkCudaError() checkCudaErrorNoSync()
162 
163 #endif // HOST_DEBUG
164 
165 
166 #endif // _UTIL_QUDA_H
QudaVerbosity getVerbosity()
Definition: util_quda.cpp:21
void setOutputPrefix(const char *prefix)
Definition: util_quda.cpp:69
void saveTuneCache(bool error=false)
Definition: tune.cpp:426
char * getOutputPrefix()
Definition: util_quda.cpp:22
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
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
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
void pushVerbosity(QudaVerbosity verbosity)
Push a new verbosity onto the stack.
Definition: util_quda.cpp:83
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:30
void popVerbosity()
Pop the verbosity restoring the prior one on the stack.
Definition: util_quda.cpp:94
enum QudaVerbosity_s QudaVerbosity
void setOutputFile(FILE *outfile)
Definition: util_quda.cpp:75
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 setVerbosity(QudaVerbosity verbosity)
Definition: util_quda.cpp:25
QudaVerbosity verbosity
Definition: test_util.cpp:1614