annotate src/fftw-3.3.8/dft/indirect.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 bd3cc4d1df30
children
rev   line source
cannam@167 1 /*
cannam@167 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
cannam@167 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
cannam@167 4 *
cannam@167 5 * This program is free software; you can redistribute it and/or modify
cannam@167 6 * it under the terms of the GNU General Public License as published by
cannam@167 7 * the Free Software Foundation; either version 2 of the License, or
cannam@167 8 * (at your option) any later version.
cannam@167 9 *
cannam@167 10 * This program is distributed in the hope that it will be useful,
cannam@167 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@167 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@167 13 * GNU General Public License for more details.
cannam@167 14 *
cannam@167 15 * You should have received a copy of the GNU General Public License
cannam@167 16 * along with this program; if not, write to the Free Software
cannam@167 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
cannam@167 18 *
cannam@167 19 */
cannam@167 20
cannam@167 21
cannam@167 22
cannam@167 23 /* solvers/plans for vectors of small DFT's that cannot be done
cannam@167 24 in-place directly. Use a rank-0 plan to rearrange the data
cannam@167 25 before or after the transform. Can also change an out-of-place
cannam@167 26 plan into a copy + in-place (where the in-place transform
cannam@167 27 is e.g. unit stride). */
cannam@167 28
cannam@167 29 /* FIXME: merge with rank-geq2.c(?), since this is just a special case
cannam@167 30 of a rank split where the first/second transform has rank 0. */
cannam@167 31
cannam@167 32 #include "dft/dft.h"
cannam@167 33
cannam@167 34 typedef problem *(*mkcld_t) (const problem_dft *p);
cannam@167 35
cannam@167 36 typedef struct {
cannam@167 37 dftapply apply;
cannam@167 38 problem *(*mkcld)(const problem_dft *p);
cannam@167 39 const char *nam;
cannam@167 40 } ndrct_adt;
cannam@167 41
cannam@167 42 typedef struct {
cannam@167 43 solver super;
cannam@167 44 const ndrct_adt *adt;
cannam@167 45 } S;
cannam@167 46
cannam@167 47 typedef struct {
cannam@167 48 plan_dft super;
cannam@167 49 plan *cldcpy, *cld;
cannam@167 50 const S *slv;
cannam@167 51 } P;
cannam@167 52
cannam@167 53 /*-----------------------------------------------------------------------*/
cannam@167 54 /* first rearrange, then transform */
cannam@167 55 static void apply_before(const plan *ego_, R *ri, R *ii, R *ro, R *io)
cannam@167 56 {
cannam@167 57 const P *ego = (const P *) ego_;
cannam@167 58
cannam@167 59 {
cannam@167 60 plan_dft *cldcpy = (plan_dft *) ego->cldcpy;
cannam@167 61 cldcpy->apply(ego->cldcpy, ri, ii, ro, io);
cannam@167 62 }
cannam@167 63 {
cannam@167 64 plan_dft *cld = (plan_dft *) ego->cld;
cannam@167 65 cld->apply(ego->cld, ro, io, ro, io);
cannam@167 66 }
cannam@167 67 }
cannam@167 68
cannam@167 69 static problem *mkcld_before(const problem_dft *p)
cannam@167 70 {
cannam@167 71 return X(mkproblem_dft_d)(X(tensor_copy_inplace)(p->sz, INPLACE_OS),
cannam@167 72 X(tensor_copy_inplace)(p->vecsz, INPLACE_OS),
cannam@167 73 p->ro, p->io, p->ro, p->io);
cannam@167 74 }
cannam@167 75
cannam@167 76 static const ndrct_adt adt_before =
cannam@167 77 {
cannam@167 78 apply_before, mkcld_before, "dft-indirect-before"
cannam@167 79 };
cannam@167 80
cannam@167 81 /*-----------------------------------------------------------------------*/
cannam@167 82 /* first transform, then rearrange */
cannam@167 83
cannam@167 84 static void apply_after(const plan *ego_, R *ri, R *ii, R *ro, R *io)
cannam@167 85 {
cannam@167 86 const P *ego = (const P *) ego_;
cannam@167 87
cannam@167 88 {
cannam@167 89 plan_dft *cld = (plan_dft *) ego->cld;
cannam@167 90 cld->apply(ego->cld, ri, ii, ri, ii);
cannam@167 91 }
cannam@167 92 {
cannam@167 93 plan_dft *cldcpy = (plan_dft *) ego->cldcpy;
cannam@167 94 cldcpy->apply(ego->cldcpy, ri, ii, ro, io);
cannam@167 95 }
cannam@167 96 }
cannam@167 97
cannam@167 98 static problem *mkcld_after(const problem_dft *p)
cannam@167 99 {
cannam@167 100 return X(mkproblem_dft_d)(X(tensor_copy_inplace)(p->sz, INPLACE_IS),
cannam@167 101 X(tensor_copy_inplace)(p->vecsz, INPLACE_IS),
cannam@167 102 p->ri, p->ii, p->ri, p->ii);
cannam@167 103 }
cannam@167 104
cannam@167 105 static const ndrct_adt adt_after =
cannam@167 106 {
cannam@167 107 apply_after, mkcld_after, "dft-indirect-after"
cannam@167 108 };
cannam@167 109
cannam@167 110 /*-----------------------------------------------------------------------*/
cannam@167 111 static void destroy(plan *ego_)
cannam@167 112 {
cannam@167 113 P *ego = (P *) ego_;
cannam@167 114 X(plan_destroy_internal)(ego->cld);
cannam@167 115 X(plan_destroy_internal)(ego->cldcpy);
cannam@167 116 }
cannam@167 117
cannam@167 118 static void awake(plan *ego_, enum wakefulness wakefulness)
cannam@167 119 {
cannam@167 120 P *ego = (P *) ego_;
cannam@167 121 X(plan_awake)(ego->cldcpy, wakefulness);
cannam@167 122 X(plan_awake)(ego->cld, wakefulness);
cannam@167 123 }
cannam@167 124
cannam@167 125 static void print(const plan *ego_, printer *p)
cannam@167 126 {
cannam@167 127 const P *ego = (const P *) ego_;
cannam@167 128 const S *s = ego->slv;
cannam@167 129 p->print(p, "(%s%(%p%)%(%p%))", s->adt->nam, ego->cld, ego->cldcpy);
cannam@167 130 }
cannam@167 131
cannam@167 132 static int applicable0(const solver *ego_, const problem *p_,
cannam@167 133 const planner *plnr)
cannam@167 134 {
cannam@167 135 const S *ego = (const S *) ego_;
cannam@167 136 const problem_dft *p = (const problem_dft *) p_;
cannam@167 137 return (1
cannam@167 138 && FINITE_RNK(p->vecsz->rnk)
cannam@167 139
cannam@167 140 /* problem must be a nontrivial transform, not just a copy */
cannam@167 141 && p->sz->rnk > 0
cannam@167 142
cannam@167 143 && (0
cannam@167 144
cannam@167 145 /* problem must be in-place & require some
cannam@167 146 rearrangement of the data; to prevent
cannam@167 147 infinite loops with indirect-transpose, we
cannam@167 148 further require that at least some transform
cannam@167 149 strides must decrease */
cannam@167 150 || (p->ri == p->ro
cannam@167 151 && !X(tensor_inplace_strides2)(p->sz, p->vecsz)
cannam@167 152 && X(tensor_strides_decrease)(
cannam@167 153 p->sz, p->vecsz,
cannam@167 154 ego->adt->apply == apply_after ?
cannam@167 155 INPLACE_IS : INPLACE_OS))
cannam@167 156
cannam@167 157 /* or problem must be out of place, transforming
cannam@167 158 from stride 1/2 to bigger stride, for apply_after */
cannam@167 159 || (p->ri != p->ro && ego->adt->apply == apply_after
cannam@167 160 && !NO_DESTROY_INPUTP(plnr)
cannam@167 161 && X(tensor_min_istride)(p->sz) <= 2
cannam@167 162 && X(tensor_min_ostride)(p->sz) > 2)
cannam@167 163
cannam@167 164 /* or problem must be out of place, transforming
cannam@167 165 to stride 1/2 from bigger stride, for apply_before */
cannam@167 166 || (p->ri != p->ro && ego->adt->apply == apply_before
cannam@167 167 && X(tensor_min_ostride)(p->sz) <= 2
cannam@167 168 && X(tensor_min_istride)(p->sz) > 2)
cannam@167 169 )
cannam@167 170 );
cannam@167 171 }
cannam@167 172
cannam@167 173 static int applicable(const solver *ego_, const problem *p_,
cannam@167 174 const planner *plnr)
cannam@167 175 {
cannam@167 176 if (!applicable0(ego_, p_, plnr)) return 0;
cannam@167 177 {
cannam@167 178 const problem_dft *p = (const problem_dft *) p_;
cannam@167 179 if (NO_INDIRECT_OP_P(plnr) && p->ri != p->ro) return 0;
cannam@167 180 }
cannam@167 181 return 1;
cannam@167 182 }
cannam@167 183
cannam@167 184 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
cannam@167 185 {
cannam@167 186 const problem_dft *p = (const problem_dft *) p_;
cannam@167 187 const S *ego = (const S *) ego_;
cannam@167 188 P *pln;
cannam@167 189 plan *cld = 0, *cldcpy = 0;
cannam@167 190
cannam@167 191 static const plan_adt padt = {
cannam@167 192 X(dft_solve), awake, print, destroy
cannam@167 193 };
cannam@167 194
cannam@167 195 if (!applicable(ego_, p_, plnr))
cannam@167 196 return (plan *) 0;
cannam@167 197
cannam@167 198 cldcpy =
cannam@167 199 X(mkplan_d)(plnr,
cannam@167 200 X(mkproblem_dft_d)(X(mktensor_0d)(),
cannam@167 201 X(tensor_append)(p->vecsz, p->sz),
cannam@167 202 p->ri, p->ii, p->ro, p->io));
cannam@167 203
cannam@167 204 if (!cldcpy) goto nada;
cannam@167 205
cannam@167 206 cld = X(mkplan_f_d)(plnr, ego->adt->mkcld(p), NO_BUFFERING, 0, 0);
cannam@167 207 if (!cld) goto nada;
cannam@167 208
cannam@167 209 pln = MKPLAN_DFT(P, &padt, ego->adt->apply);
cannam@167 210 pln->cld = cld;
cannam@167 211 pln->cldcpy = cldcpy;
cannam@167 212 pln->slv = ego;
cannam@167 213 X(ops_add)(&cld->ops, &cldcpy->ops, &pln->super.super.ops);
cannam@167 214
cannam@167 215 return &(pln->super.super);
cannam@167 216
cannam@167 217 nada:
cannam@167 218 X(plan_destroy_internal)(cld);
cannam@167 219 X(plan_destroy_internal)(cldcpy);
cannam@167 220 return (plan *)0;
cannam@167 221 }
cannam@167 222
cannam@167 223 static solver *mksolver(const ndrct_adt *adt)
cannam@167 224 {
cannam@167 225 static const solver_adt sadt = { PROBLEM_DFT, mkplan, 0 };
cannam@167 226 S *slv = MKSOLVER(S, &sadt);
cannam@167 227 slv->adt = adt;
cannam@167 228 return &(slv->super);
cannam@167 229 }
cannam@167 230
cannam@167 231 void X(dft_indirect_register)(planner *p)
cannam@167 232 {
cannam@167 233 unsigned i;
cannam@167 234 static const ndrct_adt *const adts[] = {
cannam@167 235 &adt_before, &adt_after
cannam@167 236 };
cannam@167 237
cannam@167 238 for (i = 0; i < sizeof(adts) / sizeof(adts[0]); ++i)
cannam@167 239 REGISTER_SOLVER(p, mksolver(adts[i]));
cannam@167 240 }