annotate src/fftw-3.3.3/kernel/timer.c @ 23:619f715526df sv_v2.1

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