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