annotate src/fftw-3.3.8/rdft/hc2hc-direct.c @ 82:d0c2a83c1364

Add FFTW 3.3.8 source, and a Linux build
author Chris Cannam
date Tue, 19 Nov 2019 14:52:55 +0000
parents
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 #include "rdft/hc2hc.h"
Chris@82 23
Chris@82 24 typedef struct {
Chris@82 25 hc2hc_solver super;
Chris@82 26 const hc2hc_desc *desc;
Chris@82 27 khc2hc k;
Chris@82 28 int bufferedp;
Chris@82 29 } S;
Chris@82 30
Chris@82 31 typedef struct {
Chris@82 32 plan_hc2hc super;
Chris@82 33 khc2hc k;
Chris@82 34 plan *cld0, *cldm; /* children for 0th and middle butterflies */
Chris@82 35 INT r, m, v;
Chris@82 36 INT ms, vs, mb, me;
Chris@82 37 stride rs, brs;
Chris@82 38 twid *td;
Chris@82 39 const S *slv;
Chris@82 40 } P;
Chris@82 41
Chris@82 42 /*************************************************************
Chris@82 43 Nonbuffered code
Chris@82 44 *************************************************************/
Chris@82 45 static void apply(const plan *ego_, R *IO)
Chris@82 46 {
Chris@82 47 const P *ego = (const P *) ego_;
Chris@82 48 plan_rdft *cld0 = (plan_rdft *) ego->cld0;
Chris@82 49 plan_rdft *cldm = (plan_rdft *) ego->cldm;
Chris@82 50 INT i, m = ego->m, v = ego->v;
Chris@82 51 INT mb = ego->mb, me = ego->me;
Chris@82 52 INT ms = ego->ms, vs = ego->vs;
Chris@82 53
Chris@82 54 for (i = 0; i < v; ++i, IO += vs) {
Chris@82 55 cld0->apply((plan *) cld0, IO, IO);
Chris@82 56 ego->k(IO + ms * mb, IO + (m - mb) * ms,
Chris@82 57 ego->td->W, ego->rs, mb, me, ms);
Chris@82 58 cldm->apply((plan *) cldm, IO + (m/2) * ms, IO + (m/2) * ms);
Chris@82 59 }
Chris@82 60 }
Chris@82 61
Chris@82 62 /*************************************************************
Chris@82 63 Buffered code
Chris@82 64 *************************************************************/
Chris@82 65
Chris@82 66 /* should not be 2^k to avoid associativity conflicts */
Chris@82 67 static INT compute_batchsize(INT radix)
Chris@82 68 {
Chris@82 69 /* round up to multiple of 4 */
Chris@82 70 radix += 3;
Chris@82 71 radix &= -4;
Chris@82 72
Chris@82 73 return (radix + 2);
Chris@82 74 }
Chris@82 75
Chris@82 76 static void dobatch(const P *ego, R *IOp, R *IOm,
Chris@82 77 INT mb, INT me, R *bufp)
Chris@82 78 {
Chris@82 79 INT b = WS(ego->brs, 1);
Chris@82 80 INT rs = WS(ego->rs, 1);
Chris@82 81 INT r = ego->r;
Chris@82 82 INT ms = ego->ms;
Chris@82 83 R *bufm = bufp + b - 1;
Chris@82 84
Chris@82 85 X(cpy2d_ci)(IOp + mb * ms, bufp, r, rs, b, me - mb, ms, 1, 1);
Chris@82 86 X(cpy2d_ci)(IOm - mb * ms, bufm, r, rs, b, me - mb, -ms, -1, 1);
Chris@82 87
Chris@82 88 ego->k(bufp, bufm, ego->td->W, ego->brs, mb, me, 1);
Chris@82 89
Chris@82 90 X(cpy2d_co)(bufp, IOp + mb * ms, r, b, rs, me - mb, 1, ms, 1);
Chris@82 91 X(cpy2d_co)(bufm, IOm - mb * ms, r, b, rs, me - mb, -1, -ms, 1);
Chris@82 92 }
Chris@82 93
Chris@82 94 static void apply_buf(const plan *ego_, R *IO)
Chris@82 95 {
Chris@82 96 const P *ego = (const P *) ego_;
Chris@82 97 plan_rdft *cld0 = (plan_rdft *) ego->cld0;
Chris@82 98 plan_rdft *cldm = (plan_rdft *) ego->cldm;
Chris@82 99 INT i, j, m = ego->m, v = ego->v, r = ego->r;
Chris@82 100 INT mb = ego->mb, me = ego->me, ms = ego->ms;
Chris@82 101 INT batchsz = compute_batchsize(r);
Chris@82 102 R *buf;
Chris@82 103 size_t bufsz = r * batchsz * 2 * sizeof(R);
Chris@82 104
Chris@82 105 BUF_ALLOC(R *, buf, bufsz);
Chris@82 106
Chris@82 107 for (i = 0; i < v; ++i, IO += ego->vs) {
Chris@82 108 R *IOp = IO;
Chris@82 109 R *IOm = IO + m * ms;
Chris@82 110
Chris@82 111 cld0->apply((plan *) cld0, IO, IO);
Chris@82 112
Chris@82 113 for (j = mb; j + batchsz < me; j += batchsz)
Chris@82 114 dobatch(ego, IOp, IOm, j, j + batchsz, buf);
Chris@82 115
Chris@82 116 dobatch(ego, IOp, IOm, j, me, buf);
Chris@82 117
Chris@82 118 cldm->apply((plan *) cldm, IO + ms * (m/2), IO + ms * (m/2));
Chris@82 119 }
Chris@82 120
Chris@82 121 BUF_FREE(buf, bufsz);
Chris@82 122 }
Chris@82 123
Chris@82 124 static void awake(plan *ego_, enum wakefulness wakefulness)
Chris@82 125 {
Chris@82 126 P *ego = (P *) ego_;
Chris@82 127
Chris@82 128 X(plan_awake)(ego->cld0, wakefulness);
Chris@82 129 X(plan_awake)(ego->cldm, wakefulness);
Chris@82 130 X(twiddle_awake)(wakefulness, &ego->td, ego->slv->desc->tw,
Chris@82 131 ego->r * ego->m, ego->r, (ego->m - 1) / 2);
Chris@82 132 }
Chris@82 133
Chris@82 134 static void destroy(plan *ego_)
Chris@82 135 {
Chris@82 136 P *ego = (P *) ego_;
Chris@82 137 X(plan_destroy_internal)(ego->cld0);
Chris@82 138 X(plan_destroy_internal)(ego->cldm);
Chris@82 139 X(stride_destroy)(ego->rs);
Chris@82 140 X(stride_destroy)(ego->brs);
Chris@82 141 }
Chris@82 142
Chris@82 143 static void print(const plan *ego_, printer *p)
Chris@82 144 {
Chris@82 145 const P *ego = (const P *) ego_;
Chris@82 146 const S *slv = ego->slv;
Chris@82 147 const hc2hc_desc *e = slv->desc;
Chris@82 148 INT batchsz = compute_batchsize(ego->r);
Chris@82 149
Chris@82 150 if (slv->bufferedp)
Chris@82 151 p->print(p, "(hc2hc-directbuf/%D-%D/%D%v \"%s\"%(%p%)%(%p%))",
Chris@82 152 batchsz, ego->r, X(twiddle_length)(ego->r, e->tw),
Chris@82 153 ego->v, e->nam, ego->cld0, ego->cldm);
Chris@82 154 else
Chris@82 155 p->print(p, "(hc2hc-direct-%D/%D%v \"%s\"%(%p%)%(%p%))",
Chris@82 156 ego->r, X(twiddle_length)(ego->r, e->tw), ego->v, e->nam,
Chris@82 157 ego->cld0, ego->cldm);
Chris@82 158 }
Chris@82 159
Chris@82 160 static int applicable0(const S *ego, rdft_kind kind, INT r)
Chris@82 161 {
Chris@82 162 const hc2hc_desc *e = ego->desc;
Chris@82 163
Chris@82 164 return (1
Chris@82 165 && r == e->radix
Chris@82 166 && kind == e->genus->kind
Chris@82 167 );
Chris@82 168 }
Chris@82 169
Chris@82 170 static int applicable(const S *ego, rdft_kind kind, INT r, INT m, INT v,
Chris@82 171 const planner *plnr)
Chris@82 172 {
Chris@82 173 if (!applicable0(ego, kind, r))
Chris@82 174 return 0;
Chris@82 175
Chris@82 176 if (NO_UGLYP(plnr) && X(ct_uglyp)((ego->bufferedp? (INT)512 : (INT)16),
Chris@82 177 v, m * r, r))
Chris@82 178 return 0;
Chris@82 179
Chris@82 180 return 1;
Chris@82 181 }
Chris@82 182
Chris@82 183 #define CLDMP(m, mstart, mcount) (2 * ((mstart) + (mcount)) == (m) + 2)
Chris@82 184 #define CLD0P(mstart) ((mstart) == 0)
Chris@82 185
Chris@82 186 static plan *mkcldw(const hc2hc_solver *ego_,
Chris@82 187 rdft_kind kind, INT r, INT m, INT ms, INT v, INT vs,
Chris@82 188 INT mstart, INT mcount,
Chris@82 189 R *IO, planner *plnr)
Chris@82 190 {
Chris@82 191 const S *ego = (const S *) ego_;
Chris@82 192 P *pln;
Chris@82 193 const hc2hc_desc *e = ego->desc;
Chris@82 194 plan *cld0 = 0, *cldm = 0;
Chris@82 195 INT imid = (m / 2) * ms;
Chris@82 196 INT rs = m * ms;
Chris@82 197
Chris@82 198 static const plan_adt padt = {
Chris@82 199 0, awake, print, destroy
Chris@82 200 };
Chris@82 201
Chris@82 202 if (!applicable(ego, kind, r, m, v, plnr))
Chris@82 203 return (plan *)0;
Chris@82 204
Chris@82 205 cld0 = X(mkplan_d)(
Chris@82 206 plnr,
Chris@82 207 X(mkproblem_rdft_1_d)((CLD0P(mstart) ?
Chris@82 208 X(mktensor_1d)(r, rs, rs) : X(mktensor_0d)()),
Chris@82 209 X(mktensor_0d)(),
Chris@82 210 TAINT(IO, vs), TAINT(IO, vs),
Chris@82 211 kind));
Chris@82 212 if (!cld0) goto nada;
Chris@82 213
Chris@82 214 cldm = X(mkplan_d)(
Chris@82 215 plnr,
Chris@82 216 X(mkproblem_rdft_1_d)((CLDMP(m, mstart, mcount) ?
Chris@82 217 X(mktensor_1d)(r, rs, rs) : X(mktensor_0d)()),
Chris@82 218 X(mktensor_0d)(),
Chris@82 219 TAINT(IO + imid, vs), TAINT(IO + imid, vs),
Chris@82 220 kind == R2HC ? R2HCII : HC2RIII));
Chris@82 221 if (!cldm) goto nada;
Chris@82 222
Chris@82 223 pln = MKPLAN_HC2HC(P, &padt, ego->bufferedp ? apply_buf : apply);
Chris@82 224
Chris@82 225 pln->k = ego->k;
Chris@82 226 pln->td = 0;
Chris@82 227 pln->r = r; pln->rs = X(mkstride)(r, rs);
Chris@82 228 pln->m = m; pln->ms = ms;
Chris@82 229 pln->v = v; pln->vs = vs;
Chris@82 230 pln->slv = ego;
Chris@82 231 pln->brs = X(mkstride)(r, 2 * compute_batchsize(r));
Chris@82 232 pln->cld0 = cld0;
Chris@82 233 pln->cldm = cldm;
Chris@82 234 pln->mb = mstart + CLD0P(mstart);
Chris@82 235 pln->me = mstart + mcount - CLDMP(m, mstart, mcount);
Chris@82 236
Chris@82 237 X(ops_zero)(&pln->super.super.ops);
Chris@82 238 X(ops_madd2)(v * ((pln->me - pln->mb) / e->genus->vl),
Chris@82 239 &e->ops, &pln->super.super.ops);
Chris@82 240 X(ops_madd2)(v, &cld0->ops, &pln->super.super.ops);
Chris@82 241 X(ops_madd2)(v, &cldm->ops, &pln->super.super.ops);
Chris@82 242
Chris@82 243 if (ego->bufferedp)
Chris@82 244 pln->super.super.ops.other += 4 * r * (pln->me - pln->mb) * v;
Chris@82 245
Chris@82 246 pln->super.super.could_prune_now_p =
Chris@82 247 (!ego->bufferedp && r >= 5 && r < 64 && m >= r);
Chris@82 248
Chris@82 249 return &(pln->super.super);
Chris@82 250
Chris@82 251 nada:
Chris@82 252 X(plan_destroy_internal)(cld0);
Chris@82 253 X(plan_destroy_internal)(cldm);
Chris@82 254 return 0;
Chris@82 255 }
Chris@82 256
Chris@82 257 static void regone(planner *plnr, khc2hc codelet, const hc2hc_desc *desc,
Chris@82 258 int bufferedp)
Chris@82 259 {
Chris@82 260 S *slv = (S *)X(mksolver_hc2hc)(sizeof(S), desc->radix, mkcldw);
Chris@82 261 slv->k = codelet;
Chris@82 262 slv->desc = desc;
Chris@82 263 slv->bufferedp = bufferedp;
Chris@82 264 REGISTER_SOLVER(plnr, &(slv->super.super));
Chris@82 265 if (X(mksolver_hc2hc_hook)) {
Chris@82 266 slv = (S *)X(mksolver_hc2hc_hook)(sizeof(S), desc->radix, mkcldw);
Chris@82 267 slv->k = codelet;
Chris@82 268 slv->desc = desc;
Chris@82 269 slv->bufferedp = bufferedp;
Chris@82 270 REGISTER_SOLVER(plnr, &(slv->super.super));
Chris@82 271 }
Chris@82 272 }
Chris@82 273
Chris@82 274 void X(regsolver_hc2hc_direct)(planner *plnr, khc2hc codelet,
Chris@82 275 const hc2hc_desc *desc)
Chris@82 276 {
Chris@82 277 regone(plnr, codelet, desc, /* bufferedp */0);
Chris@82 278 regone(plnr, codelet, desc, /* bufferedp */1);
Chris@82 279 }