annotate fft/fftw/fftw-3.3.4/dft/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 DFTs.
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 "dft.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_dft 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 *ri, R *ii, R *ro, R *io)
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 dftapply cldapply = ((plan_dft *) ego->cld)->apply;
Chris@19 60
Chris@19 61 for (i = 0; i < vl; ++i) {
Chris@19 62 cldapply(ego->cld,
Chris@19 63 ri + i * ivs, ii + i * ivs, ro + i * ovs, io + i * ovs);
Chris@19 64 }
Chris@19 65 }
Chris@19 66
Chris@19 67 static void awake(plan *ego_, enum wakefulness wakefulness)
Chris@19 68 {
Chris@19 69 P *ego = (P *) ego_;
Chris@19 70 X(plan_awake)(ego->cld, wakefulness);
Chris@19 71 }
Chris@19 72
Chris@19 73 static void destroy(plan *ego_)
Chris@19 74 {
Chris@19 75 P *ego = (P *) ego_;
Chris@19 76 X(plan_destroy_internal)(ego->cld);
Chris@19 77 }
Chris@19 78
Chris@19 79 static void print(const plan *ego_, printer *p)
Chris@19 80 {
Chris@19 81 const P *ego = (const P *) ego_;
Chris@19 82 const S *s = ego->solver;
Chris@19 83 p->print(p, "(dft-vrank>=1-x%D/%d%(%p%))",
Chris@19 84 ego->vl, s->vecloop_dim, ego->cld);
Chris@19 85 }
Chris@19 86
Chris@19 87 static int pickdim(const S *ego, const tensor *vecsz, int oop, int *dp)
Chris@19 88 {
Chris@19 89 return X(pickdim)(ego->vecloop_dim, ego->buddies, ego->nbuddies,
Chris@19 90 vecsz, oop, dp);
Chris@19 91 }
Chris@19 92
Chris@19 93 static int applicable0(const solver *ego_, const problem *p_, int *dp)
Chris@19 94 {
Chris@19 95 const S *ego = (const S *) ego_;
Chris@19 96 const problem_dft *p = (const problem_dft *) p_;
Chris@19 97
Chris@19 98 return (1
Chris@19 99 && FINITE_RNK(p->vecsz->rnk)
Chris@19 100 && p->vecsz->rnk > 0
Chris@19 101
Chris@19 102 /* do not bother looping over rank-0 problems,
Chris@19 103 since they are handled via rdft */
Chris@19 104 && p->sz->rnk > 0
Chris@19 105
Chris@19 106 && pickdim(ego, p->vecsz, p->ri != p->ro, dp)
Chris@19 107 );
Chris@19 108 }
Chris@19 109
Chris@19 110 static int applicable(const solver *ego_, const problem *p_,
Chris@19 111 const planner *plnr, int *dp)
Chris@19 112 {
Chris@19 113 const S *ego = (const S *)ego_;
Chris@19 114 const problem_dft *p;
Chris@19 115
Chris@19 116 if (!applicable0(ego_, p_, dp)) return 0;
Chris@19 117
Chris@19 118 /* fftw2 behavior */
Chris@19 119 if (NO_VRANK_SPLITSP(plnr) && (ego->vecloop_dim != ego->buddies[0]))
Chris@19 120 return 0;
Chris@19 121
Chris@19 122 p = (const problem_dft *) p_;
Chris@19 123
Chris@19 124 if (NO_UGLYP(plnr)) {
Chris@19 125 /* Heuristic: if the transform is multi-dimensional, and the
Chris@19 126 vector stride is less than the transform size, then we
Chris@19 127 probably want to use a rank>=2 plan first in order to combine
Chris@19 128 this vector with the transform-dimension vectors. */
Chris@19 129 {
Chris@19 130 iodim *d = p->vecsz->dims + *dp;
Chris@19 131 if (1
Chris@19 132 && p->sz->rnk > 1
Chris@19 133 && X(imin)(X(iabs)(d->is), X(iabs)(d->os))
Chris@19 134 < X(tensor_max_index)(p->sz)
Chris@19 135 )
Chris@19 136 return 0;
Chris@19 137 }
Chris@19 138
Chris@19 139 if (NO_NONTHREADEDP(plnr)) return 0; /* prefer threaded version */
Chris@19 140 }
Chris@19 141
Chris@19 142 return 1;
Chris@19 143 }
Chris@19 144
Chris@19 145 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
Chris@19 146 {
Chris@19 147 const S *ego = (const S *) ego_;
Chris@19 148 const problem_dft *p;
Chris@19 149 P *pln;
Chris@19 150 plan *cld;
Chris@19 151 int vdim;
Chris@19 152 iodim *d;
Chris@19 153
Chris@19 154 static const plan_adt padt = {
Chris@19 155 X(dft_solve), awake, print, destroy
Chris@19 156 };
Chris@19 157
Chris@19 158 if (!applicable(ego_, p_, plnr, &vdim))
Chris@19 159 return (plan *) 0;
Chris@19 160 p = (const problem_dft *) p_;
Chris@19 161
Chris@19 162 d = p->vecsz->dims + vdim;
Chris@19 163
Chris@19 164 A(d->n > 1);
Chris@19 165 cld = X(mkplan_d)(plnr,
Chris@19 166 X(mkproblem_dft_d)(
Chris@19 167 X(tensor_copy)(p->sz),
Chris@19 168 X(tensor_copy_except)(p->vecsz, vdim),
Chris@19 169 TAINT(p->ri, d->is), TAINT(p->ii, d->is),
Chris@19 170 TAINT(p->ro, d->os), TAINT(p->io, d->os)));
Chris@19 171 if (!cld) return (plan *) 0;
Chris@19 172
Chris@19 173 pln = MKPLAN_DFT(P, &padt, apply);
Chris@19 174
Chris@19 175 pln->cld = cld;
Chris@19 176 pln->vl = d->n;
Chris@19 177 pln->ivs = d->is;
Chris@19 178 pln->ovs = d->os;
Chris@19 179
Chris@19 180 pln->solver = ego;
Chris@19 181 X(ops_zero)(&pln->super.super.ops);
Chris@19 182 pln->super.super.ops.other = 3.14159; /* magic to prefer codelet loops */
Chris@19 183 X(ops_madd2)(pln->vl, &cld->ops, &pln->super.super.ops);
Chris@19 184
Chris@19 185 if (p->sz->rnk != 1 || (p->sz->dims[0].n > 64))
Chris@19 186 pln->super.super.pcost = pln->vl * cld->pcost;
Chris@19 187
Chris@19 188 return &(pln->super.super);
Chris@19 189 }
Chris@19 190
Chris@19 191 static solver *mksolver(int vecloop_dim, const int *buddies, int nbuddies)
Chris@19 192 {
Chris@19 193 static const solver_adt sadt = { PROBLEM_DFT, mkplan, 0 };
Chris@19 194 S *slv = MKSOLVER(S, &sadt);
Chris@19 195 slv->vecloop_dim = vecloop_dim;
Chris@19 196 slv->buddies = buddies;
Chris@19 197 slv->nbuddies = nbuddies;
Chris@19 198 return &(slv->super);
Chris@19 199 }
Chris@19 200
Chris@19 201 void X(dft_vrank_geq1_register)(planner *p)
Chris@19 202 {
Chris@19 203 int i;
Chris@19 204
Chris@19 205 /* FIXME: Should we try other vecloop_dim values? */
Chris@19 206 static const int buddies[] = { 1, -1 };
Chris@19 207
Chris@19 208 const int nbuddies = (int)(sizeof(buddies) / sizeof(buddies[0]));
Chris@19 209
Chris@19 210 for (i = 0; i < nbuddies; ++i)
Chris@19 211 REGISTER_SOLVER(p, mksolver(buddies[i], buddies, nbuddies));
Chris@19 212 }