annotate src/fftw-3.3.5/dft/ct.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 7867fa7e1b6b
children
rev   line source
cannam@127 1 /*
cannam@127 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
cannam@127 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
cannam@127 4 *
cannam@127 5 * This program is free software; you can redistribute it and/or modify
cannam@127 6 * it under the terms of the GNU General Public License as published by
cannam@127 7 * the Free Software Foundation; either version 2 of the License, or
cannam@127 8 * (at your option) any later version.
cannam@127 9 *
cannam@127 10 * This program is distributed in the hope that it will be useful,
cannam@127 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@127 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@127 13 * GNU General Public License for more details.
cannam@127 14 *
cannam@127 15 * You should have received a copy of the GNU General Public License
cannam@127 16 * along with this program; if not, write to the Free Software
cannam@127 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
cannam@127 18 *
cannam@127 19 */
cannam@127 20
cannam@127 21
cannam@127 22 #include "ct.h"
cannam@127 23
cannam@127 24 ct_solver *(*X(mksolver_ct_hook))(size_t, INT, int,
cannam@127 25 ct_mkinferior, ct_force_vrecursion) = 0;
cannam@127 26
cannam@127 27 typedef struct {
cannam@127 28 plan_dft super;
cannam@127 29 plan *cld;
cannam@127 30 plan *cldw;
cannam@127 31 INT r;
cannam@127 32 } P;
cannam@127 33
cannam@127 34 static void apply_dit(const plan *ego_, R *ri, R *ii, R *ro, R *io)
cannam@127 35 {
cannam@127 36 const P *ego = (const P *) ego_;
cannam@127 37 plan_dft *cld;
cannam@127 38 plan_dftw *cldw;
cannam@127 39
cannam@127 40 cld = (plan_dft *) ego->cld;
cannam@127 41 cld->apply(ego->cld, ri, ii, ro, io);
cannam@127 42
cannam@127 43 cldw = (plan_dftw *) ego->cldw;
cannam@127 44 cldw->apply(ego->cldw, ro, io);
cannam@127 45 }
cannam@127 46
cannam@127 47 static void apply_dif(const plan *ego_, R *ri, R *ii, R *ro, R *io)
cannam@127 48 {
cannam@127 49 const P *ego = (const P *) ego_;
cannam@127 50 plan_dft *cld;
cannam@127 51 plan_dftw *cldw;
cannam@127 52
cannam@127 53 cldw = (plan_dftw *) ego->cldw;
cannam@127 54 cldw->apply(ego->cldw, ri, ii);
cannam@127 55
cannam@127 56 cld = (plan_dft *) ego->cld;
cannam@127 57 cld->apply(ego->cld, ri, ii, ro, io);
cannam@127 58 }
cannam@127 59
cannam@127 60 static void awake(plan *ego_, enum wakefulness wakefulness)
cannam@127 61 {
cannam@127 62 P *ego = (P *) ego_;
cannam@127 63 X(plan_awake)(ego->cld, wakefulness);
cannam@127 64 X(plan_awake)(ego->cldw, wakefulness);
cannam@127 65 }
cannam@127 66
cannam@127 67 static void destroy(plan *ego_)
cannam@127 68 {
cannam@127 69 P *ego = (P *) ego_;
cannam@127 70 X(plan_destroy_internal)(ego->cldw);
cannam@127 71 X(plan_destroy_internal)(ego->cld);
cannam@127 72 }
cannam@127 73
cannam@127 74 static void print(const plan *ego_, printer *p)
cannam@127 75 {
cannam@127 76 const P *ego = (const P *) ego_;
cannam@127 77 p->print(p, "(dft-ct-%s/%D%(%p%)%(%p%))",
cannam@127 78 ego->super.apply == apply_dit ? "dit" : "dif",
cannam@127 79 ego->r, ego->cldw, ego->cld);
cannam@127 80 }
cannam@127 81
cannam@127 82 static int applicable0(const ct_solver *ego, const problem *p_, planner *plnr)
cannam@127 83 {
cannam@127 84 const problem_dft *p = (const problem_dft *) p_;
cannam@127 85 INT r;
cannam@127 86
cannam@127 87 return (1
cannam@127 88 && p->sz->rnk == 1
cannam@127 89 && p->vecsz->rnk <= 1
cannam@127 90
cannam@127 91 /* DIF destroys the input and we don't like it */
cannam@127 92 && (ego->dec == DECDIT ||
cannam@127 93 p->ri == p->ro ||
cannam@127 94 !NO_DESTROY_INPUTP(plnr))
cannam@127 95
cannam@127 96 && ((r = X(choose_radix)(ego->r, p->sz->dims[0].n)) > 1)
cannam@127 97 && p->sz->dims[0].n > r);
cannam@127 98 }
cannam@127 99
cannam@127 100
cannam@127 101 int X(ct_applicable)(const ct_solver *ego, const problem *p_, planner *plnr)
cannam@127 102 {
cannam@127 103 const problem_dft *p;
cannam@127 104
cannam@127 105 if (!applicable0(ego, p_, plnr))
cannam@127 106 return 0;
cannam@127 107
cannam@127 108 p = (const problem_dft *) p_;
cannam@127 109
cannam@127 110 return (0
cannam@127 111 || ego->dec == DECDIF+TRANSPOSE
cannam@127 112 || p->vecsz->rnk == 0
cannam@127 113 || !NO_VRECURSEP(plnr)
cannam@127 114 || (ego->force_vrecursionp && ego->force_vrecursionp(ego, p))
cannam@127 115 );
cannam@127 116 }
cannam@127 117
cannam@127 118
cannam@127 119 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
cannam@127 120 {
cannam@127 121 const ct_solver *ego = (const ct_solver *) ego_;
cannam@127 122 const problem_dft *p;
cannam@127 123 P *pln = 0;
cannam@127 124 plan *cld = 0, *cldw = 0;
cannam@127 125 INT n, r, m, v, ivs, ovs;
cannam@127 126 iodim *d;
cannam@127 127
cannam@127 128 static const plan_adt padt = {
cannam@127 129 X(dft_solve), awake, print, destroy
cannam@127 130 };
cannam@127 131
cannam@127 132 if ((NO_NONTHREADEDP(plnr)) || !X(ct_applicable)(ego, p_, plnr))
cannam@127 133 return (plan *) 0;
cannam@127 134
cannam@127 135 p = (const problem_dft *) p_;
cannam@127 136 d = p->sz->dims;
cannam@127 137 n = d[0].n;
cannam@127 138 r = X(choose_radix)(ego->r, n);
cannam@127 139 m = n / r;
cannam@127 140
cannam@127 141 X(tensor_tornk1)(p->vecsz, &v, &ivs, &ovs);
cannam@127 142
cannam@127 143 switch (ego->dec) {
cannam@127 144 case DECDIT:
cannam@127 145 {
cannam@127 146 cldw = ego->mkcldw(ego,
cannam@127 147 r, m * d[0].os, m * d[0].os,
cannam@127 148 m, d[0].os,
cannam@127 149 v, ovs, ovs,
cannam@127 150 0, m,
cannam@127 151 p->ro, p->io, plnr);
cannam@127 152 if (!cldw) goto nada;
cannam@127 153
cannam@127 154 cld = X(mkplan_d)(plnr,
cannam@127 155 X(mkproblem_dft_d)(
cannam@127 156 X(mktensor_1d)(m, r * d[0].is, d[0].os),
cannam@127 157 X(mktensor_2d)(r, d[0].is, m * d[0].os,
cannam@127 158 v, ivs, ovs),
cannam@127 159 p->ri, p->ii, p->ro, p->io)
cannam@127 160 );
cannam@127 161 if (!cld) goto nada;
cannam@127 162
cannam@127 163 pln = MKPLAN_DFT(P, &padt, apply_dit);
cannam@127 164 break;
cannam@127 165 }
cannam@127 166 case DECDIF:
cannam@127 167 case DECDIF+TRANSPOSE:
cannam@127 168 {
cannam@127 169 INT cors, covs; /* cldw ors, ovs */
cannam@127 170 if (ego->dec == DECDIF+TRANSPOSE) {
cannam@127 171 cors = ivs;
cannam@127 172 covs = m * d[0].is;
cannam@127 173 /* ensure that we generate well-formed dftw subproblems */
cannam@127 174 /* FIXME: too conservative */
cannam@127 175 if (!(1
cannam@127 176 && r == v
cannam@127 177 && d[0].is == r * cors))
cannam@127 178 goto nada;
cannam@127 179
cannam@127 180 /* FIXME: allow in-place only for now, like in
cannam@127 181 fftw-3.[01] */
cannam@127 182 if (!(1
cannam@127 183 && p->ri == p->ro
cannam@127 184 && d[0].is == r * d[0].os
cannam@127 185 && cors == d[0].os
cannam@127 186 && covs == ovs
cannam@127 187 ))
cannam@127 188 goto nada;
cannam@127 189 } else {
cannam@127 190 cors = m * d[0].is;
cannam@127 191 covs = ivs;
cannam@127 192 }
cannam@127 193
cannam@127 194 cldw = ego->mkcldw(ego,
cannam@127 195 r, m * d[0].is, cors,
cannam@127 196 m, d[0].is,
cannam@127 197 v, ivs, covs,
cannam@127 198 0, m,
cannam@127 199 p->ri, p->ii, plnr);
cannam@127 200 if (!cldw) goto nada;
cannam@127 201
cannam@127 202 cld = X(mkplan_d)(plnr,
cannam@127 203 X(mkproblem_dft_d)(
cannam@127 204 X(mktensor_1d)(m, d[0].is, r * d[0].os),
cannam@127 205 X(mktensor_2d)(r, cors, d[0].os,
cannam@127 206 v, covs, ovs),
cannam@127 207 p->ri, p->ii, p->ro, p->io)
cannam@127 208 );
cannam@127 209 if (!cld) goto nada;
cannam@127 210
cannam@127 211 pln = MKPLAN_DFT(P, &padt, apply_dif);
cannam@127 212 break;
cannam@127 213 }
cannam@127 214
cannam@127 215 default: A(0);
cannam@127 216
cannam@127 217 }
cannam@127 218
cannam@127 219 pln->cld = cld;
cannam@127 220 pln->cldw = cldw;
cannam@127 221 pln->r = r;
cannam@127 222 X(ops_add)(&cld->ops, &cldw->ops, &pln->super.super.ops);
cannam@127 223
cannam@127 224 /* inherit could_prune_now_p attribute from cldw */
cannam@127 225 pln->super.super.could_prune_now_p = cldw->could_prune_now_p;
cannam@127 226 return &(pln->super.super);
cannam@127 227
cannam@127 228 nada:
cannam@127 229 X(plan_destroy_internal)(cldw);
cannam@127 230 X(plan_destroy_internal)(cld);
cannam@127 231 return (plan *) 0;
cannam@127 232 }
cannam@127 233
cannam@127 234 ct_solver *X(mksolver_ct)(size_t size, INT r, int dec,
cannam@127 235 ct_mkinferior mkcldw,
cannam@127 236 ct_force_vrecursion force_vrecursionp)
cannam@127 237 {
cannam@127 238 static const solver_adt sadt = { PROBLEM_DFT, mkplan, 0 };
cannam@127 239 ct_solver *slv = (ct_solver *)X(mksolver)(size, &sadt);
cannam@127 240 slv->r = r;
cannam@127 241 slv->dec = dec;
cannam@127 242 slv->mkcldw = mkcldw;
cannam@127 243 slv->force_vrecursionp = force_vrecursionp;
cannam@127 244 return slv;
cannam@127 245 }
cannam@127 246
cannam@127 247 plan *X(mkplan_dftw)(size_t size, const plan_adt *adt, dftwapply apply)
cannam@127 248 {
cannam@127 249 plan_dftw *ego;
cannam@127 250
cannam@127 251 ego = (plan_dftw *) X(mkplan)(size, adt);
cannam@127 252 ego->apply = apply;
cannam@127 253
cannam@127 254 return &(ego->super);
cannam@127 255 }