16 void Reset_(
const char *func,
const char *file,
int line);
28 #if QUDA_NVTX_VERSION == 3 29 #include "nvtx3/nvToolsExt.h" 31 #include "nvToolsExt.h" 61 Timer() : time(0.0), last(0.0), running(false), count(0) { ; }
63 void Start(
const char *func,
const char *file,
int line) {
65 printfQuda(
"ERROR: Cannot start an already running timer (%s:%d in %s())\n", file, line, func);
68 gettimeofday(&start, NULL);
72 void Stop(
const char *func,
const char *file,
int line) {
74 printfQuda(
"ERROR: Cannot stop an unstarted timer (%s:%d in %s())\n", file, line, func);
77 gettimeofday(&stop, NULL);
79 long ds = stop.tv_sec - start.tv_sec;
80 long dus = stop.tv_usec - start.tv_usec;
81 last = ds + 0.000001*dus;
88 double Last() {
return last; }
90 void Reset(
const char *func,
const char *file,
int line) {
92 printfQuda(
"ERROR: Cannot reset a started timer (%s:%d in %s())\n", file, line, func);
148 #ifdef INTERFACE_NVTX 152 #define PUSH_RANGE(name,cid) { \ 153 int color_id = cid; \ 154 color_id = color_id%nvtx_num_colors;\ 155 nvtxEventAttributes_t eventAttrib = {0}; \ 156 eventAttrib.version = NVTX_VERSION; \ 157 eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; \ 158 eventAttrib.colorType = NVTX_COLOR_ARGB; \ 159 eventAttrib.color = nvtx_colors[color_id]; \ 160 eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; \ 161 eventAttrib.message.ascii = name; \ 162 eventAttrib.category = cid;\ 163 nvtxRangePushEx(&eventAttrib); \ 165 #define POP_RANGE nvtxRangePop(); 167 #define PUSH_RANGE(name,cid) 173 #ifdef INTERFACE_NVTX 174 static const uint32_t nvtx_colors[];
175 static const int nvtx_num_colors;
190 global_total_level[idx]--;
191 if (global_total_level[idx]==0) global_profile[idx].
Stop(func,file,line);
194 if (global_switchOff[idx]) {
195 global_total_level[idx]--;
196 if (global_total_level[idx]==0) global_profile[idx].
Stop(func,file,line);
197 global_switchOff[idx] =
false;
203 if (!global_profile[idx].running) {
204 global_profile[idx].
Start(func,file,line);
205 global_total_level[idx]++;
206 global_switchOff[idx] =
true;
209 if (global_total_level[idx]==0) global_profile[idx].
Start(func,file,line);
210 global_total_level[idx]++;
214 TimeProfile(std::string fname) : fname(fname), switchOff(false), use_global(true) { ; }
216 TimeProfile(std::string fname,
bool use_global) : fname(fname), switchOff(false), use_global(use_global) { ; }
228 profile[idx].
Start(func, file, line);
235 profile[idx].
Stop(func, file, line);
243 if (use_global)
StopGlobal(func,file,line,idx);
246 void Reset_(
const char *func,
const char *file,
int line) {
248 profile[idx].Reset(func, file, line);
252 return profile[idx].
last;
269 #define TPSTART(idx) Start_(__func__, __FILE__, __LINE__, idx) 270 #define TPSTOP(idx) Stop_(__func__, __FILE__, __LINE__, idx) 271 #define TPRESET() Reset_(__func__, __FILE__, __LINE__) void Stop_(const char *func, const char *file, int line, QudaProfileType idx)
static std::string pname[]
void Start_(const char *func, const char *file, int line, QudaProfileType idx)
static void StartGlobal(const char *func, const char *file, int line, QudaProfileType idx)
static int global_total_level[QUDA_PROFILE_COUNT]
bool isRunning(QudaProfileType idx)
double Last(QudaProfileType idx)
Timer profile[QUDA_PROFILE_COUNT]
static void StopGlobal(const char *func, const char *file, int line, QudaProfileType idx)
void Start(const char *func, const char *file, int line)
void Reset_(const char *func, const char *file, int line)
static bool global_switchOff[QUDA_PROFILE_COUNT]
static Timer global_profile[QUDA_PROFILE_COUNT]
TimeProfile(std::string fname)
#define PUSH_RANGE(name, cid)
static void PrintGlobal()
void Stop(const char *func, const char *file, int line)
void Reset(const char *func, const char *file, int line)
TimeProfile(std::string fname, bool use_global)