annotate src/fftw-3.3.8/kernel/timer.c @ 169:223a55898ab9 tip default

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