QUDA  v0.7.0
A library for QCD on GPUs
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
11 
15 void setTuning(QudaTune tune);
16 
18 char *getOutputPrefix();
19 FILE *getOutputFile();
20 
21 void setVerbosity(const QudaVerbosity verbosity);
22 void setOutputPrefix(const char *prefix);
23 void setOutputFile(FILE *outfile);
24 
25 void pushVerbosity(QudaVerbosity verbosity);
26 void popVerbosity();
27 
28 char *getPrintBuffer();
29 
30 // Note that __func__ is part of C++11 and has long been supported by GCC.
31 
32 #ifdef MULTI_GPU
33 
34 #define printfQuda(...) do { \
35  sprintf(getPrintBuffer(), __VA_ARGS__); \
36  if (comm_rank() == 0) { \
37  fprintf(getOutputFile(), "%s", getOutputPrefix()); \
38  fprintf(getOutputFile(), "%s", getPrintBuffer()); \
39  fflush(getOutputFile()); \
40  } \
41 } while (0)
42 
43 #define errorQuda(...) do { \
44  fprintf(getOutputFile(), "%sERROR: ", getOutputPrefix()); \
45  fprintf(getOutputFile(), __VA_ARGS__); \
46  fprintf(getOutputFile(), " (rank %d, host %s, " __FILE__ ":%d in %s())\n", \
47  comm_rank(), comm_hostname(), __LINE__, __func__); \
48  fprintf(getOutputFile(), "%s last kernel called was (name=%s,volume=%s,aux=%s)\n", \
49  getOutputPrefix(), getLastTuneKey().name, \
50  getLastTuneKey().volume, getLastTuneKey().aux); \
51  fflush(getOutputFile()); \
52  comm_abort(1); \
53 } while (0)
54 
55 #define warningQuda(...) do { \
56  sprintf(getPrintBuffer(), __VA_ARGS__); \
57  if (comm_rank() == 0) { \
58  fprintf(getOutputFile(), "%sWARNING: ", getOutputPrefix()); \
59  fprintf(getOutputFile(), "%s", getPrintBuffer()); \
60  fprintf(getOutputFile(), "\n"); \
61  fflush(getOutputFile()); \
62  } \
63 } while (0)
64 
65 #else
66 
67 #define printfQuda(...) do { \
68  fprintf(getOutputFile(), "%s", getOutputPrefix()); \
69  fprintf(getOutputFile(), __VA_ARGS__); \
70  fflush(getOutputFile()); \
71 } while (0)
72 
73 #define errorQuda(...) do { \
74  fprintf(getOutputFile(), "%sERROR: ", getOutputPrefix()); \
75  fprintf(getOutputFile(), __VA_ARGS__); \
76  fprintf(getOutputFile(), " (" __FILE__ ":%d in %s())\n", \
77  __LINE__, __func__); \
78  fprintf(getOutputFile(), "%s last kernel called was (name=%s,volume=%s,aux=%s)\n", \
79  getOutputPrefix(), getLastTuneKey().name, \
80  getLastTuneKey().volume, getLastTuneKey().aux); \
81  exit(1); \
82 } while (0)
83 
84 #define warningQuda(...) do { \
85  fprintf(getOutputFile(), "%sWARNING: ", getOutputPrefix()); \
86  fprintf(getOutputFile(), __VA_ARGS__); \
87  fprintf(getOutputFile(), "\n"); \
88  fflush(getOutputFile()); \
89 } while (0)
90 
91 #endif // MULTI_GPU
92 
93 
94 #define checkCudaErrorNoSync() do { \
95  cudaError_t error = cudaGetLastError(); \
96  if (error != cudaSuccess) \
97  errorQuda("(CUDA) %s", cudaGetErrorString(error)); \
98 } while (0)
99 
100 
101 #ifdef HOST_DEBUG
102 
103 #define checkCudaError() do { \
104  cudaDeviceSynchronize(); \
105  checkCudaErrorNoSync(); \
106 } while (0)
107 
108 #else
109 
110 #define checkCudaError() checkCudaErrorNoSync()
111 
112 #endif // HOST_DEBUG
113 
114 
115 #endif // _UTIL_QUDA_H
QudaVerbosity getVerbosity()
Definition: util_quda.cpp:20
void setOutputPrefix(const char *prefix)
Definition: util_quda.cpp:38
char * getOutputPrefix()
Definition: util_quda.cpp:21
FILE * getOutputFile()
Definition: util_quda.cpp:22
void setTuning(QudaTune tune)
Definition: util_quda.cpp:33
char * getPrintBuffer()
Definition: util_quda.cpp:72
void pushVerbosity(QudaVerbosity verbosity)
Definition: util_quda.cpp:52
bool tune
Definition: blas_test.cu:28
enum QudaTune_s QudaTune
void popVerbosity()
Definition: util_quda.cpp:63
enum QudaVerbosity_s QudaVerbosity
void setOutputFile(FILE *outfile)
Definition: util_quda.cpp:44
QudaTune getTuning()
Definition: util_quda.cpp:32
void setVerbosity(const QudaVerbosity verbosity)
Definition: util_quda.cpp:24