annotate src/fftw-3.3.8/dft/vrank-geq1.c @ 84:08ae793730bd

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