annotate src/fftw-3.3.3/rdft/vrank-geq1-rdft2.c @ 169:223a55898ab9 tip default

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