annotate src/fftw-3.3.5/rdft/vrank-geq1-rdft2.c @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +0000
parents 2cd0e3b3e1fd
children
rev   line source
Chris@42 1 /*
Chris@42 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
Chris@42 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
Chris@42 4 *
Chris@42 5 * This program is free software; you can redistribute it and/or modify
Chris@42 6 * it under the terms of the GNU General Public License as published by
Chris@42 7 * the Free Software Foundation; either version 2 of the License, or
Chris@42 8 * (at your option) any later version.
Chris@42 9 *
Chris@42 10 * This program is distributed in the hope that it will be useful,
Chris@42 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@42 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@42 13 * GNU General Public License for more details.
Chris@42 14 *
Chris@42 15 * You should have received a copy of the GNU General Public License
Chris@42 16 * along with this program; if not, write to the Free Software
Chris@42 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@42 18 *
Chris@42 19 */
Chris@42 20
Chris@42 21
Chris@42 22
Chris@42 23 /* Plans for handling vector transform loops. These are *just* the
Chris@42 24 loops, and rely on child plans for the actual RDFT2s.
Chris@42 25
Chris@42 26 They form a wrapper around solvers that don't have apply functions
Chris@42 27 for non-null vectors.
Chris@42 28
Chris@42 29 vrank-geq1-rdft2 plans also recursively handle the case of
Chris@42 30 multi-dimensional vectors, obviating the need for most solvers to
Chris@42 31 deal with this. We can also play games here, such as reordering
Chris@42 32 the vector loops.
Chris@42 33
Chris@42 34 Each vrank-geq1-rdft2 plan reduces the vector rank by 1, picking out a
Chris@42 35 dimension determined by the vecloop_dim field of the solver. */
Chris@42 36
Chris@42 37 #include "rdft.h"
Chris@42 38
Chris@42 39 typedef struct {
Chris@42 40 solver super;
Chris@42 41 int vecloop_dim;
Chris@42 42 const int *buddies;
Chris@42 43 size_t nbuddies;
Chris@42 44 } S;
Chris@42 45
Chris@42 46 typedef struct {
Chris@42 47 plan_rdft2 super;
Chris@42 48
Chris@42 49 plan *cld;
Chris@42 50 INT vl;
Chris@42 51 INT rvs, cvs;
Chris@42 52 const S *solver;
Chris@42 53 } P;
Chris@42 54
Chris@42 55 static void apply(const plan *ego_, R *r0, R *r1, R *cr, R *ci)
Chris@42 56 {
Chris@42 57 const P *ego = (const P *) ego_;
Chris@42 58 INT i, vl = ego->vl;
Chris@42 59 INT rvs = ego->rvs, cvs = ego->cvs;
Chris@42 60 rdft2apply cldapply = ((plan_rdft2 *) ego->cld)->apply;
Chris@42 61
Chris@42 62 for (i = 0; i < vl; ++i) {
Chris@42 63 cldapply(ego->cld, r0 + i * rvs, r1 + i * rvs,
Chris@42 64 cr + i * cvs, ci + i * cvs);
Chris@42 65 }
Chris@42 66 }
Chris@42 67
Chris@42 68 static void awake(plan *ego_, enum wakefulness wakefulness)
Chris@42 69 {
Chris@42 70 P *ego = (P *) ego_;
Chris@42 71 X(plan_awake)(ego->cld, wakefulness);
Chris@42 72 }
Chris@42 73
Chris@42 74 static void destroy(plan *ego_)
Chris@42 75 {
Chris@42 76 P *ego = (P *) ego_;
Chris@42 77 X(plan_destroy_internal)(ego->cld);
Chris@42 78 }
Chris@42 79
Chris@42 80 static void print(const plan *ego_, printer *p)
Chris@42 81 {
Chris@42 82 const P *ego = (const P *) ego_;
Chris@42 83 const S *s = ego->solver;
Chris@42 84 p->print(p, "(rdft2-vrank>=1-x%D/%d%(%p%))",
Chris@42 85 ego->vl, s->vecloop_dim, ego->cld);
Chris@42 86 }
Chris@42 87
Chris@42 88 static int pickdim(const S *ego, const tensor *vecsz, int oop, int *dp)
Chris@42 89 {
Chris@42 90 return X(pickdim)(ego->vecloop_dim, ego->buddies, ego->nbuddies,
Chris@42 91 vecsz, oop, dp);
Chris@42 92 }
Chris@42 93
Chris@42 94 static int applicable0(const solver *ego_, const problem *p_, int *dp)
Chris@42 95 {
Chris@42 96 const S *ego = (const S *) ego_;
Chris@42 97 const problem_rdft2 *p = (const problem_rdft2 *) p_;
Chris@42 98 if (FINITE_RNK(p->vecsz->rnk)
Chris@42 99 && p->vecsz->rnk > 0
Chris@42 100 && pickdim(ego, p->vecsz, p->r0 != p->cr, dp)) {
Chris@42 101 if (p->r0 != p->cr)
Chris@42 102 return 1; /* can always operate out-of-place */
Chris@42 103
Chris@42 104 return(X(rdft2_inplace_strides)(p, *dp));
Chris@42 105 }
Chris@42 106
Chris@42 107 return 0;
Chris@42 108 }
Chris@42 109
Chris@42 110
Chris@42 111 static int applicable(const solver *ego_, const problem *p_,
Chris@42 112 const planner *plnr, int *dp)
Chris@42 113 {
Chris@42 114 const S *ego = (const S *)ego_;
Chris@42 115 if (!applicable0(ego_, p_, dp)) return 0;
Chris@42 116
Chris@42 117 /* fftw2 behavior */
Chris@42 118 if (NO_VRANK_SPLITSP(plnr) && (ego->vecloop_dim != ego->buddies[0]))
Chris@42 119 return 0;
Chris@42 120
Chris@42 121 if (NO_UGLYP(plnr)) {
Chris@42 122 const problem_rdft2 *p = (const problem_rdft2 *) p_;
Chris@42 123 iodim *d = p->vecsz->dims + *dp;
Chris@42 124
Chris@42 125 /* Heuristic: if the transform is multi-dimensional, and the
Chris@42 126 vector stride is less than the transform size, then we
Chris@42 127 probably want to use a rank>=2 plan first in order to combine
Chris@42 128 this vector with the transform-dimension vectors. */
Chris@42 129 if (p->sz->rnk > 1
Chris@42 130 && X(imin)(X(iabs)(d->is), X(iabs)(d->os))
Chris@42 131 < X(rdft2_tensor_max_index)(p->sz, p->kind)
Chris@42 132 )
Chris@42 133 return 0;
Chris@42 134
Chris@42 135 /* Heuristic: don't use a vrank-geq1 for rank-0 vrank-1
Chris@42 136 transforms, since this case is better handled by rank-0
Chris@42 137 solvers. */
Chris@42 138 if (p->sz->rnk == 0 && p->vecsz->rnk == 1) return 0;
Chris@42 139
Chris@42 140 if (NO_NONTHREADEDP(plnr))
Chris@42 141 return 0; /* prefer threaded version */
Chris@42 142 }
Chris@42 143
Chris@42 144 return 1;
Chris@42 145 }
Chris@42 146
Chris@42 147 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
Chris@42 148 {
Chris@42 149 const S *ego = (const S *) ego_;
Chris@42 150 const problem_rdft2 *p;
Chris@42 151 P *pln;
Chris@42 152 plan *cld;
Chris@42 153 int vdim;
Chris@42 154 iodim *d;
Chris@42 155 INT rvs, cvs;
Chris@42 156
Chris@42 157 static const plan_adt padt = {
Chris@42 158 X(rdft2_solve), awake, print, destroy
Chris@42 159 };
Chris@42 160
Chris@42 161 if (!applicable(ego_, p_, plnr, &vdim))
Chris@42 162 return (plan *) 0;
Chris@42 163 p = (const problem_rdft2 *) p_;
Chris@42 164
Chris@42 165 d = p->vecsz->dims + vdim;
Chris@42 166
Chris@42 167 A(d->n > 1); /* or else, p->ri + d->is etc. are invalid */
Chris@42 168
Chris@42 169 X(rdft2_strides)(p->kind, d, &rvs, &cvs);
Chris@42 170
Chris@42 171 cld = X(mkplan_d)(plnr,
Chris@42 172 X(mkproblem_rdft2_d)(
Chris@42 173 X(tensor_copy)(p->sz),
Chris@42 174 X(tensor_copy_except)(p->vecsz, vdim),
Chris@42 175 TAINT(p->r0, rvs), TAINT(p->r1, rvs),
Chris@42 176 TAINT(p->cr, cvs), TAINT(p->ci, cvs),
Chris@42 177 p->kind));
Chris@42 178 if (!cld) return (plan *) 0;
Chris@42 179
Chris@42 180 pln = MKPLAN_RDFT2(P, &padt, apply);
Chris@42 181
Chris@42 182 pln->cld = cld;
Chris@42 183 pln->vl = d->n;
Chris@42 184 pln->rvs = rvs;
Chris@42 185 pln->cvs = cvs;
Chris@42 186
Chris@42 187 pln->solver = ego;
Chris@42 188 X(ops_zero)(&pln->super.super.ops);
Chris@42 189 pln->super.super.ops.other = 3.14159; /* magic to prefer codelet loops */
Chris@42 190 X(ops_madd2)(pln->vl, &cld->ops, &pln->super.super.ops);
Chris@42 191
Chris@42 192 if (p->sz->rnk != 1 || (p->sz->dims[0].n > 128))
Chris@42 193 pln->super.super.pcost = pln->vl * cld->pcost;
Chris@42 194
Chris@42 195 return &(pln->super.super);
Chris@42 196 }
Chris@42 197
Chris@42 198 static solver *mksolver(int vecloop_dim, const int *buddies, size_t nbuddies)
Chris@42 199 {
Chris@42 200 static const solver_adt sadt = { PROBLEM_RDFT2, mkplan, 0 };
Chris@42 201 S *slv = MKSOLVER(S, &sadt);
Chris@42 202 slv->vecloop_dim = vecloop_dim;
Chris@42 203 slv->buddies = buddies;
Chris@42 204 slv->nbuddies = nbuddies;
Chris@42 205 return &(slv->super);
Chris@42 206 }
Chris@42 207
Chris@42 208 void X(rdft2_vrank_geq1_register)(planner *p)
Chris@42 209 {
Chris@42 210 /* FIXME: Should we try other vecloop_dim values? */
Chris@42 211 static const int buddies[] = { 1, -1 };
Chris@42 212 size_t i;
Chris@42 213
Chris@42 214 for (i = 0; i < NELEM(buddies); ++i)
Chris@42 215 REGISTER_SOLVER(p, mksolver(buddies[i], buddies, NELEM(buddies)));
Chris@42 216 }