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