annotate src/fftw-3.3.5/kernel/timer.c @ 84:08ae793730bd

Add null config files
author Chris Cannam
date Mon, 02 Mar 2020 14:03:47 +0000
parents 2cd0e3b3e1fd
children
rev   line source
Chris@42 1 /*
Chris@42 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
Chris@42 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
Chris@42 4 *
Chris@42 5 * This program is free software; you can redistribute it and/or modify
Chris@42 6 * it under the terms of the GNU General Public License as published by
Chris@42 7 * the Free Software Foundation; either version 2 of the License, or
Chris@42 8 * (at your option) any later version.
Chris@42 9 *
Chris@42 10 * This program is distributed in the hope that it will be useful,
Chris@42 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@42 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@42 13 * GNU General Public License for more details.
Chris@42 14 *
Chris@42 15 * You should have received a copy of the GNU General Public License
Chris@42 16 * along with this program; if not, write to the Free Software
Chris@42 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@42 18 *
Chris@42 19 */
Chris@42 20
Chris@42 21
Chris@42 22 #include "ifftw.h"
Chris@42 23
Chris@42 24 #ifdef HAVE_UNISTD_H
Chris@42 25 # include <unistd.h>
Chris@42 26 #endif
Chris@42 27
Chris@42 28 #ifndef WITH_SLOW_TIMER
Chris@42 29 # include "cycle.h"
Chris@42 30 #endif
Chris@42 31
Chris@42 32 #ifndef FFTW_TIME_LIMIT
Chris@42 33 #define FFTW_TIME_LIMIT 2.0 /* don't run for more than two seconds */
Chris@42 34 #endif
Chris@42 35
Chris@42 36 /* the following code is disabled for now, because it seems to
Chris@42 37 require that we #include <windows.h> in ifftw.h to
Chris@42 38 typedef LARGE_INTEGER crude_time, and this pulls in the whole
Chris@42 39 Windows universe and leads to namespace conflicts (unless
Chris@42 40 we did some hack like assuming sizeof(LARGE_INTEGER) == sizeof(long long).
Chris@42 41 gettimeofday is provided by MinGW, which we use to cross-compile
Chris@42 42 FFTW for Windows, and this seems to work well enough */
Chris@42 43 #if 0 && (defined(__WIN32__) || defined(_WIN32) || defined(_WIN64))
Chris@42 44 crude_time X(get_crude_time)(void)
Chris@42 45 {
Chris@42 46 crude_time tv;
Chris@42 47 QueryPerformanceCounter(&tv);
Chris@42 48 return tv;
Chris@42 49 }
Chris@42 50
Chris@42 51 static double elapsed_since(crude_time t0)
Chris@42 52 {
Chris@42 53 crude_time t1, freq;
Chris@42 54 QueryPerformanceCounter(&t1);
Chris@42 55 QueryPerformanceFrequency(&freq);
Chris@42 56 return (((double) (t1.QuadPart - t0.QuadPart))) /
Chris@42 57 ((double) freq.QuadPart);
Chris@42 58 }
Chris@42 59
Chris@42 60 # define TIME_MIN_SEC 1.0e-2
Chris@42 61
Chris@42 62 #elif defined(HAVE_GETTIMEOFDAY)
Chris@42 63 crude_time X(get_crude_time)(void)
Chris@42 64 {
Chris@42 65 crude_time tv;
Chris@42 66 gettimeofday(&tv, 0);
Chris@42 67 return tv;
Chris@42 68 }
Chris@42 69
Chris@42 70 #define elapsed_sec(t1,t0) ((double)(t1.tv_sec - t0.tv_sec) + \
Chris@42 71 (double)(t1.tv_usec - t0.tv_usec) * 1.0E-6)
Chris@42 72
Chris@42 73 static double elapsed_since(crude_time t0)
Chris@42 74 {
Chris@42 75 crude_time t1;
Chris@42 76 gettimeofday(&t1, 0);
Chris@42 77 return elapsed_sec(t1, t0);
Chris@42 78 }
Chris@42 79
Chris@42 80 # define TIME_MIN_SEC 1.0e-3
Chris@42 81
Chris@42 82 #else /* !HAVE_GETTIMEOFDAY */
Chris@42 83
Chris@42 84 /* Note that the only system where we are likely to need to fall back
Chris@42 85 on the clock() function is Windows, for which CLOCKS_PER_SEC is 1000
Chris@42 86 and thus the clock wraps once every 50 days. This should hopefully
Chris@42 87 be longer than the time required to create any single plan! */
Chris@42 88 crude_time X(get_crude_time)(void) { return clock(); }
Chris@42 89
Chris@42 90 #define elapsed_sec(t1,t0) ((double) ((t1) - (t0)) / CLOCKS_PER_SEC)
Chris@42 91
Chris@42 92 static double elapsed_since(crude_time t0)
Chris@42 93 {
Chris@42 94 return elapsed_sec(clock(), t0);
Chris@42 95 }
Chris@42 96
Chris@42 97 # define TIME_MIN_SEC 2.0e-1 /* from fftw2 */
Chris@42 98
Chris@42 99 #endif /* !HAVE_GETTIMEOFDAY */
Chris@42 100
Chris@42 101 double X(elapsed_since)(const planner *plnr, const problem *p, crude_time t0)
Chris@42 102 {
Chris@42 103 double t = elapsed_since(t0);
Chris@42 104 if (plnr->cost_hook)
Chris@42 105 t = plnr->cost_hook(p, t, COST_MAX);
Chris@42 106 return t;
Chris@42 107 }
Chris@42 108
Chris@42 109 #ifdef WITH_SLOW_TIMER
Chris@42 110 /* excruciatingly slow; only use this if there is no choice! */
Chris@42 111 typedef crude_time ticks;
Chris@42 112 # define getticks X(get_crude_time)
Chris@42 113 # define elapsed(t1,t0) elapsed_sec(t1,t0)
Chris@42 114 # define TIME_MIN TIME_MIN_SEC
Chris@42 115 # define TIME_REPEAT 4 /* from fftw2 */
Chris@42 116 # define HAVE_TICK_COUNTER
Chris@42 117 #endif
Chris@42 118
Chris@42 119 #ifdef HAVE_TICK_COUNTER
Chris@42 120
Chris@42 121 # ifndef TIME_MIN
Chris@42 122 # define TIME_MIN 100.0
Chris@42 123 # endif
Chris@42 124
Chris@42 125 # ifndef TIME_REPEAT
Chris@42 126 # define TIME_REPEAT 8
Chris@42 127 # endif
Chris@42 128
Chris@42 129 static double measure(plan *pln, const problem *p, int iter)
Chris@42 130 {
Chris@42 131 ticks t0, t1;
Chris@42 132 int i;
Chris@42 133
Chris@42 134 t0 = getticks();
Chris@42 135 for (i = 0; i < iter; ++i)
Chris@42 136 pln->adt->solve(pln, p);
Chris@42 137 t1 = getticks();
Chris@42 138 return elapsed(t1, t0);
Chris@42 139 }
Chris@42 140
Chris@42 141
Chris@42 142 double X(measure_execution_time)(const planner *plnr,
Chris@42 143 plan *pln, const problem *p)
Chris@42 144 {
Chris@42 145 int iter;
Chris@42 146 int repeat;
Chris@42 147
Chris@42 148 X(plan_awake)(pln, AWAKE_ZERO);
Chris@42 149 p->adt->zero(p);
Chris@42 150
Chris@42 151 start_over:
Chris@42 152 for (iter = 1; iter; iter *= 2) {
Chris@42 153 double tmin = 0;
Chris@42 154 int first = 1;
Chris@42 155 crude_time begin = X(get_crude_time)();
Chris@42 156
Chris@42 157 /* repeat the measurement TIME_REPEAT times */
Chris@42 158 for (repeat = 0; repeat < TIME_REPEAT; ++repeat) {
Chris@42 159 double t = measure(pln, p, iter);
Chris@42 160
Chris@42 161 if (plnr->cost_hook)
Chris@42 162 t = plnr->cost_hook(p, t, COST_MAX);
Chris@42 163 if (t < 0)
Chris@42 164 goto start_over;
Chris@42 165
Chris@42 166 if (first || t < tmin)
Chris@42 167 tmin = t;
Chris@42 168 first = 0;
Chris@42 169
Chris@42 170 /* do not run for too long */
Chris@42 171 if (X(elapsed_since)(plnr, p, begin) > FFTW_TIME_LIMIT)
Chris@42 172 break;
Chris@42 173 }
Chris@42 174
Chris@42 175 if (tmin >= TIME_MIN) {
Chris@42 176 X(plan_awake)(pln, SLEEPY);
Chris@42 177 return tmin / (double) iter;
Chris@42 178 }
Chris@42 179 }
Chris@42 180 goto start_over; /* may happen if timer is screwed up */
Chris@42 181 }
Chris@42 182
Chris@42 183 #else /* no cycle counter */
Chris@42 184
Chris@42 185 double X(measure_execution_time)(const planner *plnr,
Chris@42 186 plan *pln, const problem *p)
Chris@42 187 {
Chris@42 188 UNUSED(plnr);
Chris@42 189 UNUSED(p);
Chris@42 190 UNUSED(pln);
Chris@42 191 return -1.0;
Chris@42 192 }
Chris@42 193
Chris@42 194 #endif