annotate fft/fftw/fftw-3.3.4/api/apiplan.c @ 40:223f770b5341 kissfft-double tip

Try a double-precision kissfft
author Chris Cannam
date Wed, 07 Sep 2016 10:40:32 +0100
parents 26056e866c29
children
rev   line source
Chris@19 1 /*
Chris@19 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
Chris@19 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
Chris@19 4 *
Chris@19 5 * This program is free software; you can redistribute it and/or modify
Chris@19 6 * it under the terms of the GNU General Public License as published by
Chris@19 7 * the Free Software Foundation; either version 2 of the License, or
Chris@19 8 * (at your option) any later version.
Chris@19 9 *
Chris@19 10 * This program is distributed in the hope that it will be useful,
Chris@19 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@19 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@19 13 * GNU General Public License for more details.
Chris@19 14 *
Chris@19 15 * You should have received a copy of the GNU General Public License
Chris@19 16 * along with this program; if not, write to the Free Software
Chris@19 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@19 18 *
Chris@19 19 */
Chris@19 20
Chris@19 21 #include "api.h"
Chris@19 22
Chris@19 23 static plan *mkplan0(planner *plnr, unsigned flags,
Chris@19 24 const problem *prb, int hash_info,
Chris@19 25 wisdom_state_t wisdom_state)
Chris@19 26 {
Chris@19 27 /* map API flags into FFTW flags */
Chris@19 28 X(mapflags)(plnr, flags);
Chris@19 29
Chris@19 30 plnr->flags.hash_info = hash_info;
Chris@19 31 plnr->wisdom_state = wisdom_state;
Chris@19 32
Chris@19 33 /* create plan */
Chris@19 34 return plnr->adt->mkplan(plnr, prb);
Chris@19 35 }
Chris@19 36
Chris@19 37 static unsigned force_estimator(unsigned flags)
Chris@19 38 {
Chris@19 39 flags &= ~(FFTW_MEASURE | FFTW_PATIENT | FFTW_EXHAUSTIVE);
Chris@19 40 return (flags | FFTW_ESTIMATE);
Chris@19 41 }
Chris@19 42
Chris@19 43 static plan *mkplan(planner *plnr, unsigned flags,
Chris@19 44 const problem *prb, int hash_info)
Chris@19 45 {
Chris@19 46 plan *pln;
Chris@19 47
Chris@19 48 pln = mkplan0(plnr, flags, prb, hash_info, WISDOM_NORMAL);
Chris@19 49
Chris@19 50 if (plnr->wisdom_state == WISDOM_NORMAL && !pln) {
Chris@19 51 /* maybe the planner failed because of inconsistent wisdom;
Chris@19 52 plan again ignoring infeasible wisdom */
Chris@19 53 pln = mkplan0(plnr, force_estimator(flags), prb,
Chris@19 54 hash_info, WISDOM_IGNORE_INFEASIBLE);
Chris@19 55 }
Chris@19 56
Chris@19 57 if (plnr->wisdom_state == WISDOM_IS_BOGUS) {
Chris@19 58 /* if the planner detected a wisdom inconsistency,
Chris@19 59 forget all wisdom and plan again */
Chris@19 60 plnr->adt->forget(plnr, FORGET_EVERYTHING);
Chris@19 61
Chris@19 62 A(!pln);
Chris@19 63 pln = mkplan0(plnr, flags, prb, hash_info, WISDOM_NORMAL);
Chris@19 64
Chris@19 65 if (plnr->wisdom_state == WISDOM_IS_BOGUS) {
Chris@19 66 /* if it still fails, plan without wisdom */
Chris@19 67 plnr->adt->forget(plnr, FORGET_EVERYTHING);
Chris@19 68
Chris@19 69 A(!pln);
Chris@19 70 pln = mkplan0(plnr, force_estimator(flags),
Chris@19 71 prb, hash_info, WISDOM_IGNORE_ALL);
Chris@19 72 }
Chris@19 73 }
Chris@19 74
Chris@19 75 return pln;
Chris@19 76 }
Chris@19 77
Chris@19 78 apiplan *X(mkapiplan)(int sign, unsigned flags, problem *prb)
Chris@19 79 {
Chris@19 80 apiplan *p = 0;
Chris@19 81 plan *pln;
Chris@19 82 unsigned flags_used_for_planning;
Chris@19 83 planner *plnr = X(the_planner)();
Chris@19 84 unsigned int pats[] = {FFTW_ESTIMATE, FFTW_MEASURE,
Chris@19 85 FFTW_PATIENT, FFTW_EXHAUSTIVE};
Chris@19 86 int pat, pat_max;
Chris@19 87 double pcost = 0;
Chris@19 88
Chris@19 89 if (flags & FFTW_WISDOM_ONLY) {
Chris@19 90 /* Special mode that returns a plan only if wisdom is present,
Chris@19 91 and returns 0 otherwise. This is now documented in the manual,
Chris@19 92 as a way to detect whether wisdom is available for a problem. */
Chris@19 93 flags_used_for_planning = flags;
Chris@19 94 pln = mkplan0(plnr, flags, prb, 0, WISDOM_ONLY);
Chris@19 95 } else {
Chris@19 96 pat_max = flags & FFTW_ESTIMATE ? 0 :
Chris@19 97 (flags & FFTW_EXHAUSTIVE ? 3 :
Chris@19 98 (flags & FFTW_PATIENT ? 2 : 1));
Chris@19 99 pat = plnr->timelimit >= 0 ? 0 : pat_max;
Chris@19 100
Chris@19 101 flags &= ~(FFTW_ESTIMATE | FFTW_MEASURE |
Chris@19 102 FFTW_PATIENT | FFTW_EXHAUSTIVE);
Chris@19 103
Chris@19 104 plnr->start_time = X(get_crude_time)();
Chris@19 105
Chris@19 106 /* plan at incrementally increasing patience until we run
Chris@19 107 out of time */
Chris@19 108 for (pln = 0, flags_used_for_planning = 0; pat <= pat_max; ++pat) {
Chris@19 109 plan *pln1;
Chris@19 110 unsigned tmpflags = flags | pats[pat];
Chris@19 111 pln1 = mkplan(plnr, tmpflags, prb, 0);
Chris@19 112
Chris@19 113 if (!pln1) {
Chris@19 114 /* don't bother continuing if planner failed or timed out */
Chris@19 115 A(!pln || plnr->timed_out);
Chris@19 116 break;
Chris@19 117 }
Chris@19 118
Chris@19 119 X(plan_destroy_internal)(pln);
Chris@19 120 pln = pln1;
Chris@19 121 flags_used_for_planning = tmpflags;
Chris@19 122 pcost = pln->pcost;
Chris@19 123 }
Chris@19 124 }
Chris@19 125
Chris@19 126 if (pln) {
Chris@19 127 /* build apiplan */
Chris@19 128 p = (apiplan *) MALLOC(sizeof(apiplan), PLANS);
Chris@19 129 p->prb = prb;
Chris@19 130 p->sign = sign; /* cache for execute_dft */
Chris@19 131
Chris@19 132 /* re-create plan from wisdom, adding blessing */
Chris@19 133 p->pln = mkplan(plnr, flags_used_for_planning, prb, BLESSING);
Chris@19 134
Chris@19 135 /* record pcost from most recent measurement for use in X(cost) */
Chris@19 136 p->pln->pcost = pcost;
Chris@19 137
Chris@19 138 if (sizeof(trigreal) > sizeof(R)) {
Chris@19 139 /* this is probably faster, and we have enough trigreal
Chris@19 140 bits to maintain accuracy */
Chris@19 141 X(plan_awake)(p->pln, AWAKE_SQRTN_TABLE);
Chris@19 142 } else {
Chris@19 143 /* more accurate */
Chris@19 144 X(plan_awake)(p->pln, AWAKE_SINCOS);
Chris@19 145 }
Chris@19 146
Chris@19 147 /* we don't use pln for p->pln, above, since by re-creating the
Chris@19 148 plan we might use more patient wisdom from a timed-out mkplan */
Chris@19 149 X(plan_destroy_internal)(pln);
Chris@19 150 } else
Chris@19 151 X(problem_destroy)(prb);
Chris@19 152
Chris@19 153 /* discard all information not necessary to reconstruct the plan */
Chris@19 154 plnr->adt->forget(plnr, FORGET_ACCURSED);
Chris@19 155
Chris@19 156 #ifdef FFTW_RANDOM_ESTIMATOR
Chris@19 157 X(random_estimate_seed)++; /* subsequent "random" plans are distinct */
Chris@19 158 #endif
Chris@19 159
Chris@19 160 return p;
Chris@19 161 }
Chris@19 162
Chris@19 163 void X(destroy_plan)(X(plan) p)
Chris@19 164 {
Chris@19 165 if (p) {
Chris@19 166 X(plan_awake)(p->pln, SLEEPY);
Chris@19 167 X(plan_destroy_internal)(p->pln);
Chris@19 168 X(problem_destroy)(p->prb);
Chris@19 169 X(ifree)(p);
Chris@19 170 }
Chris@19 171 }