annotate src/fftw-3.3.3/api/apiplan.c @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +0000
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 #include "api.h"
Chris@10 22
Chris@10 23 static plan *mkplan0(planner *plnr, unsigned flags,
Chris@10 24 const problem *prb, int hash_info,
Chris@10 25 wisdom_state_t wisdom_state)
Chris@10 26 {
Chris@10 27 /* map API flags into FFTW flags */
Chris@10 28 X(mapflags)(plnr, flags);
Chris@10 29
Chris@10 30 plnr->flags.hash_info = hash_info;
Chris@10 31 plnr->wisdom_state = wisdom_state;
Chris@10 32
Chris@10 33 /* create plan */
Chris@10 34 return plnr->adt->mkplan(plnr, prb);
Chris@10 35 }
Chris@10 36
Chris@10 37 static unsigned force_estimator(unsigned flags)
Chris@10 38 {
Chris@10 39 flags &= ~(FFTW_MEASURE | FFTW_PATIENT | FFTW_EXHAUSTIVE);
Chris@10 40 return (flags | FFTW_ESTIMATE);
Chris@10 41 }
Chris@10 42
Chris@10 43 static plan *mkplan(planner *plnr, unsigned flags,
Chris@10 44 const problem *prb, int hash_info)
Chris@10 45 {
Chris@10 46 plan *pln;
Chris@10 47
Chris@10 48 pln = mkplan0(plnr, flags, prb, hash_info, WISDOM_NORMAL);
Chris@10 49
Chris@10 50 if (plnr->wisdom_state == WISDOM_NORMAL && !pln) {
Chris@10 51 /* maybe the planner failed because of inconsistent wisdom;
Chris@10 52 plan again ignoring infeasible wisdom */
Chris@10 53 pln = mkplan0(plnr, force_estimator(flags), prb,
Chris@10 54 hash_info, WISDOM_IGNORE_INFEASIBLE);
Chris@10 55 }
Chris@10 56
Chris@10 57 if (plnr->wisdom_state == WISDOM_IS_BOGUS) {
Chris@10 58 /* if the planner detected a wisdom inconsistency,
Chris@10 59 forget all wisdom and plan again */
Chris@10 60 plnr->adt->forget(plnr, FORGET_EVERYTHING);
Chris@10 61
Chris@10 62 A(!pln);
Chris@10 63 pln = mkplan0(plnr, flags, prb, hash_info, WISDOM_NORMAL);
Chris@10 64
Chris@10 65 if (plnr->wisdom_state == WISDOM_IS_BOGUS) {
Chris@10 66 /* if it still fails, plan without wisdom */
Chris@10 67 plnr->adt->forget(plnr, FORGET_EVERYTHING);
Chris@10 68
Chris@10 69 A(!pln);
Chris@10 70 pln = mkplan0(plnr, force_estimator(flags),
Chris@10 71 prb, hash_info, WISDOM_IGNORE_ALL);
Chris@10 72 }
Chris@10 73 }
Chris@10 74
Chris@10 75 return pln;
Chris@10 76 }
Chris@10 77
Chris@10 78 apiplan *X(mkapiplan)(int sign, unsigned flags, problem *prb)
Chris@10 79 {
Chris@10 80 apiplan *p = 0;
Chris@10 81 plan *pln;
Chris@10 82 unsigned flags_used_for_planning;
Chris@10 83 planner *plnr = X(the_planner)();
Chris@10 84 unsigned int pats[] = {FFTW_ESTIMATE, FFTW_MEASURE,
Chris@10 85 FFTW_PATIENT, FFTW_EXHAUSTIVE};
Chris@10 86 int pat, pat_max;
Chris@10 87 double pcost = 0;
Chris@10 88
Chris@10 89 if (flags & FFTW_WISDOM_ONLY) {
Chris@10 90 /* Special mode that returns a plan only if wisdom is present,
Chris@10 91 and returns 0 otherwise. This is now documented in the manual,
Chris@10 92 as a way to detect whether wisdom is available for a problem. */
Chris@10 93 flags_used_for_planning = flags;
Chris@10 94 pln = mkplan0(plnr, flags, prb, 0, WISDOM_ONLY);
Chris@10 95 } else {
Chris@10 96 pat_max = flags & FFTW_ESTIMATE ? 0 :
Chris@10 97 (flags & FFTW_EXHAUSTIVE ? 3 :
Chris@10 98 (flags & FFTW_PATIENT ? 2 : 1));
Chris@10 99 pat = plnr->timelimit >= 0 ? 0 : pat_max;
Chris@10 100
Chris@10 101 flags &= ~(FFTW_ESTIMATE | FFTW_MEASURE |
Chris@10 102 FFTW_PATIENT | FFTW_EXHAUSTIVE);
Chris@10 103
Chris@10 104 plnr->start_time = X(get_crude_time)();
Chris@10 105
Chris@10 106 /* plan at incrementally increasing patience until we run
Chris@10 107 out of time */
Chris@10 108 for (pln = 0, flags_used_for_planning = 0; pat <= pat_max; ++pat) {
Chris@10 109 plan *pln1;
Chris@10 110 unsigned tmpflags = flags | pats[pat];
Chris@10 111 pln1 = mkplan(plnr, tmpflags, prb, 0);
Chris@10 112
Chris@10 113 if (!pln1) {
Chris@10 114 /* don't bother continuing if planner failed or timed out */
Chris@10 115 A(!pln || plnr->timed_out);
Chris@10 116 break;
Chris@10 117 }
Chris@10 118
Chris@10 119 X(plan_destroy_internal)(pln);
Chris@10 120 pln = pln1;
Chris@10 121 flags_used_for_planning = tmpflags;
Chris@10 122 pcost = pln->pcost;
Chris@10 123 }
Chris@10 124 }
Chris@10 125
Chris@10 126 if (pln) {
Chris@10 127 /* build apiplan */
Chris@10 128 p = (apiplan *) MALLOC(sizeof(apiplan), PLANS);
Chris@10 129 p->prb = prb;
Chris@10 130 p->sign = sign; /* cache for execute_dft */
Chris@10 131
Chris@10 132 /* re-create plan from wisdom, adding blessing */
Chris@10 133 p->pln = mkplan(plnr, flags_used_for_planning, prb, BLESSING);
Chris@10 134
Chris@10 135 /* record pcost from most recent measurement for use in X(cost) */
Chris@10 136 p->pln->pcost = pcost;
Chris@10 137
Chris@10 138 if (sizeof(trigreal) > sizeof(R)) {
Chris@10 139 /* this is probably faster, and we have enough trigreal
Chris@10 140 bits to maintain accuracy */
Chris@10 141 X(plan_awake)(p->pln, AWAKE_SQRTN_TABLE);
Chris@10 142 } else {
Chris@10 143 /* more accurate */
Chris@10 144 X(plan_awake)(p->pln, AWAKE_SINCOS);
Chris@10 145 }
Chris@10 146
Chris@10 147 /* we don't use pln for p->pln, above, since by re-creating the
Chris@10 148 plan we might use more patient wisdom from a timed-out mkplan */
Chris@10 149 X(plan_destroy_internal)(pln);
Chris@10 150 } else
Chris@10 151 X(problem_destroy)(prb);
Chris@10 152
Chris@10 153 /* discard all information not necessary to reconstruct the plan */
Chris@10 154 plnr->adt->forget(plnr, FORGET_ACCURSED);
Chris@10 155
Chris@10 156 #ifdef FFTW_RANDOM_ESTIMATOR
Chris@10 157 X(random_estimate_seed)++; /* subsequent "random" plans are distinct */
Chris@10 158 #endif
Chris@10 159
Chris@10 160 return p;
Chris@10 161 }
Chris@10 162
Chris@10 163 void X(destroy_plan)(X(plan) p)
Chris@10 164 {
Chris@10 165 if (p) {
Chris@10 166 X(plan_awake)(p->pln, SLEEPY);
Chris@10 167 X(plan_destroy_internal)(p->pln);
Chris@10 168 X(problem_destroy)(p->prb);
Chris@10 169 X(ifree)(p);
Chris@10 170 }
Chris@10 171 }