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