annotate fft/fftw/fftw-3.3.4/rdft/vrank-geq1.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
Chris@19 22
Chris@19 23 /* Plans for handling vector transform loops. These are *just* the
Chris@19 24 loops, and rely on child plans for the actual RDFTs.
Chris@19 25
Chris@19 26 They form a wrapper around solvers that don't have apply functions
Chris@19 27 for non-null vectors.
Chris@19 28
Chris@19 29 vrank-geq1 plans also recursively handle the case of multi-dimensional
Chris@19 30 vectors, obviating the need for most solvers to deal with this. We
Chris@19 31 can also play games here, such as reordering the vector loops.
Chris@19 32
Chris@19 33 Each vrank-geq1 plan reduces the vector rank by 1, picking out a
Chris@19 34 dimension determined by the vecloop_dim field of the solver. */
Chris@19 35
Chris@19 36 #include "rdft.h"
Chris@19 37
Chris@19 38 typedef struct {
Chris@19 39 solver super;
Chris@19 40 int vecloop_dim;
Chris@19 41 const int *buddies;
Chris@19 42 int nbuddies;
Chris@19 43 } S;
Chris@19 44
Chris@19 45 typedef struct {
Chris@19 46 plan_rdft super;
Chris@19 47
Chris@19 48 plan *cld;
Chris@19 49 INT vl;
Chris@19 50 INT ivs, ovs;
Chris@19 51 const S *solver;
Chris@19 52 } P;
Chris@19 53
Chris@19 54 static void apply(const plan *ego_, R *I, R *O)
Chris@19 55 {
Chris@19 56 const P *ego = (const P *) ego_;
Chris@19 57 INT i, vl = ego->vl;
Chris@19 58 INT ivs = ego->ivs, ovs = ego->ovs;
Chris@19 59 rdftapply cldapply = ((plan_rdft *) ego->cld)->apply;
Chris@19 60
Chris@19 61 for (i = 0; i < vl; ++i) {
Chris@19 62 cldapply(ego->cld, I + i * ivs, O + i * ovs);
Chris@19 63 }
Chris@19 64 }
Chris@19 65
Chris@19 66 static void awake(plan *ego_, enum wakefulness wakefulness)
Chris@19 67 {
Chris@19 68 P *ego = (P *) ego_;
Chris@19 69 X(plan_awake)(ego->cld, wakefulness);
Chris@19 70 }
Chris@19 71
Chris@19 72 static void destroy(plan *ego_)
Chris@19 73 {
Chris@19 74 P *ego = (P *) ego_;
Chris@19 75 X(plan_destroy_internal)(ego->cld);
Chris@19 76 }
Chris@19 77
Chris@19 78 static void print(const plan *ego_, printer *p)
Chris@19 79 {
Chris@19 80 const P *ego = (const P *) ego_;
Chris@19 81 const S *s = ego->solver;
Chris@19 82 p->print(p, "(rdft-vrank>=1-x%D/%d%(%p%))",
Chris@19 83 ego->vl, s->vecloop_dim, ego->cld);
Chris@19 84 }
Chris@19 85
Chris@19 86 static int pickdim(const S *ego, const tensor *vecsz, int oop, int *dp)
Chris@19 87 {
Chris@19 88 return X(pickdim)(ego->vecloop_dim, ego->buddies, ego->nbuddies,
Chris@19 89 vecsz, oop, dp);
Chris@19 90 }
Chris@19 91
Chris@19 92 static int applicable0(const solver *ego_, const problem *p_, int *dp)
Chris@19 93 {
Chris@19 94 const S *ego = (const S *) ego_;
Chris@19 95 const problem_rdft *p = (const problem_rdft *) p_;
Chris@19 96
Chris@19 97 return (1
Chris@19 98 && FINITE_RNK(p->vecsz->rnk)
Chris@19 99 && p->vecsz->rnk > 0
Chris@19 100
Chris@19 101 && p->sz->rnk >= 0
Chris@19 102
Chris@19 103 && pickdim(ego, p->vecsz, p->I != p->O, dp)
Chris@19 104 );
Chris@19 105 }
Chris@19 106
Chris@19 107 static int applicable(const solver *ego_, const problem *p_,
Chris@19 108 const planner *plnr, int *dp)
Chris@19 109 {
Chris@19 110 const S *ego = (const S *)ego_;
Chris@19 111 const problem_rdft *p;
Chris@19 112
Chris@19 113 if (!applicable0(ego_, p_, dp)) return 0;
Chris@19 114
Chris@19 115 /* fftw2 behavior */
Chris@19 116 if (NO_VRANK_SPLITSP(plnr) && (ego->vecloop_dim != ego->buddies[0]))
Chris@19 117 return 0;
Chris@19 118
Chris@19 119 p = (const problem_rdft *) p_;
Chris@19 120
Chris@19 121 if (NO_UGLYP(plnr)) {
Chris@19 122 /* the rank-0 solver deals with the general case most of the
Chris@19 123 time (an exception is loops of non-square transposes) */
Chris@19 124 if (NO_SLOWP(plnr) && p->sz->rnk == 0)
Chris@19 125 return 0;
Chris@19 126
Chris@19 127 /* Heuristic: if the transform is multi-dimensional, and the
Chris@19 128 vector stride is less than the transform size, then we
Chris@19 129 probably want to use a rank>=2 plan first in order to combine
Chris@19 130 this vector with the transform-dimension vectors. */
Chris@19 131 {
Chris@19 132 iodim *d = p->vecsz->dims + *dp;
Chris@19 133 if (1
Chris@19 134 && p->sz->rnk > 1
Chris@19 135 && X(imin)(X(iabs)(d->is), X(iabs)(d->os))
Chris@19 136 < X(tensor_max_index)(p->sz)
Chris@19 137 )
Chris@19 138 return 0;
Chris@19 139 }
Chris@19 140
Chris@19 141 /* prefer threaded version */
Chris@19 142 if (NO_NONTHREADEDP(plnr)) return 0;
Chris@19 143
Chris@19 144 /* exploit built-in vecloops of (ugly) r{e,o}dft solvers */
Chris@19 145 if (p->vecsz->rnk == 1 && p->sz->rnk == 1
Chris@19 146 && REODFT_KINDP(p->kind[0]))
Chris@19 147 return 0;
Chris@19 148 }
Chris@19 149
Chris@19 150 return 1;
Chris@19 151 }
Chris@19 152
Chris@19 153 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
Chris@19 154 {
Chris@19 155 const S *ego = (const S *) ego_;
Chris@19 156 const problem_rdft *p;
Chris@19 157 P *pln;
Chris@19 158 plan *cld;
Chris@19 159 int vdim;
Chris@19 160 iodim *d;
Chris@19 161
Chris@19 162 static const plan_adt padt = {
Chris@19 163 X(rdft_solve), awake, print, destroy
Chris@19 164 };
Chris@19 165
Chris@19 166 if (!applicable(ego_, p_, plnr, &vdim))
Chris@19 167 return (plan *) 0;
Chris@19 168 p = (const problem_rdft *) p_;
Chris@19 169
Chris@19 170 d = p->vecsz->dims + vdim;
Chris@19 171
Chris@19 172 A(d->n > 1);
Chris@19 173
Chris@19 174 cld = X(mkplan_d)(plnr,
Chris@19 175 X(mkproblem_rdft_d)(
Chris@19 176 X(tensor_copy)(p->sz),
Chris@19 177 X(tensor_copy_except)(p->vecsz, vdim),
Chris@19 178 TAINT(p->I, d->is), TAINT(p->O, d->os),
Chris@19 179 p->kind));
Chris@19 180 if (!cld) return (plan *) 0;
Chris@19 181
Chris@19 182 pln = MKPLAN_RDFT(P, &padt, apply);
Chris@19 183
Chris@19 184 pln->cld = cld;
Chris@19 185 pln->vl = d->n;
Chris@19 186 pln->ivs = d->is;
Chris@19 187 pln->ovs = d->os;
Chris@19 188
Chris@19 189 pln->solver = ego;
Chris@19 190 X(ops_zero)(&pln->super.super.ops);
Chris@19 191 pln->super.super.ops.other = 3.14159; /* magic to prefer codelet loops */
Chris@19 192 X(ops_madd2)(pln->vl, &cld->ops, &pln->super.super.ops);
Chris@19 193
Chris@19 194 if (p->sz->rnk != 1 || (p->sz->dims[0].n > 128))
Chris@19 195 pln->super.super.pcost = pln->vl * cld->pcost;
Chris@19 196
Chris@19 197 return &(pln->super.super);
Chris@19 198 }
Chris@19 199
Chris@19 200 static solver *mksolver(int vecloop_dim, const int *buddies, int nbuddies)
Chris@19 201 {
Chris@19 202 static const solver_adt sadt = { PROBLEM_RDFT, mkplan, 0 };
Chris@19 203 S *slv = MKSOLVER(S, &sadt);
Chris@19 204 slv->vecloop_dim = vecloop_dim;
Chris@19 205 slv->buddies = buddies;
Chris@19 206 slv->nbuddies = nbuddies;
Chris@19 207 return &(slv->super);
Chris@19 208 }
Chris@19 209
Chris@19 210 void X(rdft_vrank_geq1_register)(planner *p)
Chris@19 211 {
Chris@19 212 int i;
Chris@19 213
Chris@19 214 /* FIXME: Should we try other vecloop_dim values? */
Chris@19 215 static const int buddies[] = { 1, -1 };
Chris@19 216
Chris@19 217 const int nbuddies = (int)(sizeof(buddies) / sizeof(buddies[0]));
Chris@19 218
Chris@19 219 for (i = 0; i < nbuddies; ++i)
Chris@19 220 REGISTER_SOLVER(p, mksolver(buddies[i], buddies, nbuddies));
Chris@19 221 }