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