annotate src/fftw-3.3.8/rdft/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 RDFT'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 "rdft/rdft.h"
cannam@167 33
cannam@167 34 typedef problem *(*mkcld_t) (const problem_rdft *p);
cannam@167 35
cannam@167 36 typedef struct {
cannam@167 37 rdftapply apply;
cannam@167 38 problem *(*mkcld)(const problem_rdft *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_rdft 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 *I, R *O)
cannam@167 56 {
cannam@167 57 const P *ego = (const P *) ego_;
cannam@167 58
cannam@167 59 {
cannam@167 60 plan_rdft *cldcpy = (plan_rdft *) ego->cldcpy;
cannam@167 61 cldcpy->apply(ego->cldcpy, I, O);
cannam@167 62 }
cannam@167 63 {
cannam@167 64 plan_rdft *cld = (plan_rdft *) ego->cld;
cannam@167 65 cld->apply(ego->cld, O, O);
cannam@167 66 }
cannam@167 67 }
cannam@167 68
cannam@167 69 static problem *mkcld_before(const problem_rdft *p)
cannam@167 70 {
cannam@167 71 return X(mkproblem_rdft_d)(X(tensor_copy_inplace)(p->sz, INPLACE_OS),
cannam@167 72 X(tensor_copy_inplace)(p->vecsz, INPLACE_OS),
cannam@167 73 p->O, p->O, p->kind);
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, "rdft-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 *I, R *O)
cannam@167 85 {
cannam@167 86 const P *ego = (const P *) ego_;
cannam@167 87
cannam@167 88 {
cannam@167 89 plan_rdft *cld = (plan_rdft *) ego->cld;
cannam@167 90 cld->apply(ego->cld, I, I);
cannam@167 91 }
cannam@167 92 {
cannam@167 93 plan_rdft *cldcpy = (plan_rdft *) ego->cldcpy;
cannam@167 94 cldcpy->apply(ego->cldcpy, I, O);
cannam@167 95 }
cannam@167 96 }
cannam@167 97
cannam@167 98 static problem *mkcld_after(const problem_rdft *p)
cannam@167 99 {
cannam@167 100 return X(mkproblem_rdft_d)(X(tensor_copy_inplace)(p->sz, INPLACE_IS),
cannam@167 101 X(tensor_copy_inplace)(p->vecsz, INPLACE_IS),
cannam@167 102 p->I, p->I, p->kind);
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, "rdft-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_rdft *p = (const problem_rdft *) 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 */
cannam@167 147 || (p->I == p->O
cannam@167 148 && !(X(tensor_inplace_strides2)(p->sz, p->vecsz)))
cannam@167 149
cannam@167 150 /* or problem must be out of place, transforming
cannam@167 151 from stride 1/2 to bigger stride, for apply_after */
cannam@167 152 || (p->I != p->O && ego->adt->apply == apply_after
cannam@167 153 && !NO_DESTROY_INPUTP(plnr)
cannam@167 154 && X(tensor_min_istride)(p->sz) <= 2
cannam@167 155 && X(tensor_min_ostride)(p->sz) > 2)
cannam@167 156
cannam@167 157 /* or problem must be out of place, transforming
cannam@167 158 to stride 1/2 from bigger stride, for apply_before */
cannam@167 159 || (p->I != p->O && ego->adt->apply == apply_before
cannam@167 160 && X(tensor_min_ostride)(p->sz) <= 2
cannam@167 161 && X(tensor_min_istride)(p->sz) > 2)
cannam@167 162
cannam@167 163 )
cannam@167 164 );
cannam@167 165 }
cannam@167 166
cannam@167 167 static int applicable(const solver *ego_, const problem *p_,
cannam@167 168 const planner *plnr)
cannam@167 169 {
cannam@167 170 if (!applicable0(ego_, p_, plnr)) return 0;
cannam@167 171
cannam@167 172 if (NO_INDIRECT_OP_P(plnr)) {
cannam@167 173 const problem_rdft *p = (const problem_rdft *)p_;
cannam@167 174 if (p->I != p->O) return 0;
cannam@167 175 }
cannam@167 176
cannam@167 177 return 1;
cannam@167 178 }
cannam@167 179
cannam@167 180 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
cannam@167 181 {
cannam@167 182 const problem_rdft *p = (const problem_rdft *) p_;
cannam@167 183 const S *ego = (const S *) ego_;
cannam@167 184 P *pln;
cannam@167 185 plan *cld = 0, *cldcpy = 0;
cannam@167 186
cannam@167 187 static const plan_adt padt = {
cannam@167 188 X(rdft_solve), awake, print, destroy
cannam@167 189 };
cannam@167 190
cannam@167 191 if (!applicable(ego_, p_, plnr))
cannam@167 192 return (plan *) 0;
cannam@167 193
cannam@167 194 cldcpy = X(mkplan_d)(plnr,
cannam@167 195 X(mkproblem_rdft_0_d)(
cannam@167 196 X(tensor_append)(p->vecsz, p->sz),
cannam@167 197 p->I, p->O));
cannam@167 198 if (!cldcpy) goto nada;
cannam@167 199
cannam@167 200 cld = X(mkplan_f_d)(plnr, ego->adt->mkcld(p), NO_BUFFERING, 0, 0);
cannam@167 201 if (!cld) goto nada;
cannam@167 202
cannam@167 203 pln = MKPLAN_RDFT(P, &padt, ego->adt->apply);
cannam@167 204 pln->cld = cld;
cannam@167 205 pln->cldcpy = cldcpy;
cannam@167 206 pln->slv = ego;
cannam@167 207 X(ops_add)(&cld->ops, &cldcpy->ops, &pln->super.super.ops);
cannam@167 208
cannam@167 209 return &(pln->super.super);
cannam@167 210
cannam@167 211 nada:
cannam@167 212 X(plan_destroy_internal)(cld);
cannam@167 213 X(plan_destroy_internal)(cldcpy);
cannam@167 214 return (plan *)0;
cannam@167 215 }
cannam@167 216
cannam@167 217 static solver *mksolver(const ndrct_adt *adt)
cannam@167 218 {
cannam@167 219 static const solver_adt sadt = { PROBLEM_RDFT, mkplan, 0 };
cannam@167 220 S *slv = MKSOLVER(S, &sadt);
cannam@167 221 slv->adt = adt;
cannam@167 222 return &(slv->super);
cannam@167 223 }
cannam@167 224
cannam@167 225 void X(rdft_indirect_register)(planner *p)
cannam@167 226 {
cannam@167 227 unsigned i;
cannam@167 228 static const ndrct_adt *const adts[] = {
cannam@167 229 &adt_before, &adt_after
cannam@167 230 };
cannam@167 231
cannam@167 232 for (i = 0; i < sizeof(adts) / sizeof(adts[0]); ++i)
cannam@167 233 REGISTER_SOLVER(p, mksolver(adts[i]));
cannam@167 234 }