annotate src/fftw-3.3.3/rdft/vrank-geq1.c @ 23:619f715526df sv_v2.1

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