comparison src/fftw-3.3.8/threads/dft-vrank-geq1.c @ 167:bd3cc4d1df30

Add FFTW 3.3.8 source, and a Linux build
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 19 Nov 2019 14:52:55 +0000
parents
children
comparison
equal deleted inserted replaced
166:cbd6d7e562c7 167:bd3cc4d1df30
1 /*
2 * Copyright (c) 2003, 2007-14 Matteo Frigo
3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21
22 #include "threads/threads.h"
23
24 typedef struct {
25 solver super;
26 int vecloop_dim;
27 const int *buddies;
28 size_t nbuddies;
29 } S;
30
31 typedef struct {
32 plan_dft super;
33 plan **cldrn;
34 INT its, ots;
35 int nthr;
36 const S *solver;
37 } P;
38
39 typedef struct {
40 INT its, ots;
41 R *ri, *ii, *ro, *io;
42 plan **cldrn;
43 } PD;
44
45 static void *spawn_apply(spawn_data *d)
46 {
47 PD *ego = (PD *) d->data;
48 INT its = ego->its;
49 INT ots = ego->ots;
50 int thr_num = d->thr_num;
51 plan_dft *cld = (plan_dft *) ego->cldrn[thr_num];
52
53 cld->apply((plan *) cld,
54 ego->ri + thr_num * its, ego->ii + thr_num * its,
55 ego->ro + thr_num * ots, ego->io + thr_num * ots);
56 return 0;
57 }
58
59 static void apply(const plan *ego_, R *ri, R *ii, R *ro, R *io)
60 {
61 const P *ego = (const P *) ego_;
62 PD d;
63
64 d.its = ego->its;
65 d.ots = ego->ots;
66 d.cldrn = ego->cldrn;
67 d.ri = ri; d.ii = ii; d.ro = ro; d.io = io;
68
69 X(spawn_loop)(ego->nthr, ego->nthr, spawn_apply, (void*) &d);
70 }
71
72 static void awake(plan *ego_, enum wakefulness wakefulness)
73 {
74 P *ego = (P *) ego_;
75 int i;
76 for (i = 0; i < ego->nthr; ++i)
77 X(plan_awake)(ego->cldrn[i], wakefulness);
78 }
79
80 static void destroy(plan *ego_)
81 {
82 P *ego = (P *) ego_;
83 int i;
84 for (i = 0; i < ego->nthr; ++i)
85 X(plan_destroy_internal)(ego->cldrn[i]);
86 X(ifree)(ego->cldrn);
87 }
88
89 static void print(const plan *ego_, printer *p)
90 {
91 const P *ego = (const P *) ego_;
92 const S *s = ego->solver;
93 int i;
94 p->print(p, "(dft-thr-vrank>=1-x%d/%d", ego->nthr, s->vecloop_dim);
95 for (i = 0; i < ego->nthr; ++i)
96 if (i == 0 || (ego->cldrn[i] != ego->cldrn[i-1] &&
97 (i <= 1 || ego->cldrn[i] != ego->cldrn[i-2])))
98 p->print(p, "%(%p%)", ego->cldrn[i]);
99 p->putchr(p, ')');
100 }
101
102 static int pickdim(const S *ego, const tensor *vecsz, int oop, int *dp)
103 {
104 return X(pickdim)(ego->vecloop_dim, ego->buddies, ego->nbuddies,
105 vecsz, oop, dp);
106 }
107
108 static int applicable0(const solver *ego_, const problem *p_,
109 const planner *plnr, int *dp)
110 {
111 const S *ego = (const S *) ego_;
112 const problem_dft *p = (const problem_dft *) p_;
113
114 return (1
115 && plnr->nthr > 1
116 && FINITE_RNK(p->vecsz->rnk)
117 && p->vecsz->rnk > 0
118 && pickdim(ego, p->vecsz, p->ri != p->ro, dp)
119 );
120 }
121
122 static int applicable(const solver *ego_, const problem *p_,
123 const planner *plnr, int *dp)
124 {
125 const S *ego = (const S *)ego_;
126
127 if (!applicable0(ego_, p_, plnr, dp)) return 0;
128
129 /* fftw2 behavior */
130 if (NO_VRANK_SPLITSP(plnr) && (ego->vecloop_dim != ego->buddies[0]))
131 return 0;
132
133 return 1;
134 }
135
136 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
137 {
138 const S *ego = (const S *) ego_;
139 const problem_dft *p;
140 P *pln;
141 problem *cldp;
142 int vdim;
143 iodim *d;
144 plan **cldrn = (plan **) 0;
145 int i, nthr;
146 INT its, ots, block_size;
147 tensor *vecsz = 0;
148
149 static const plan_adt padt = {
150 X(dft_solve), awake, print, destroy
151 };
152
153 if (!applicable(ego_, p_, plnr, &vdim))
154 return (plan *) 0;
155 p = (const problem_dft *) p_;
156 d = p->vecsz->dims + vdim;
157
158 block_size = (d->n + plnr->nthr - 1) / plnr->nthr;
159 nthr = (int)((d->n + block_size - 1) / block_size);
160 plnr->nthr = (plnr->nthr + nthr - 1) / nthr;
161 its = d->is * block_size;
162 ots = d->os * block_size;
163
164 cldrn = (plan **)MALLOC(sizeof(plan *) * nthr, PLANS);
165 for (i = 0; i < nthr; ++i) cldrn[i] = (plan *) 0;
166
167 vecsz = X(tensor_copy)(p->vecsz);
168 for (i = 0; i < nthr; ++i) {
169 vecsz->dims[vdim].n =
170 (i == nthr - 1) ? (d->n - i*block_size) : block_size;
171 cldp = X(mkproblem_dft)(p->sz, vecsz,
172 p->ri + i*its, p->ii + i*its,
173 p->ro + i*ots, p->io + i*ots);
174 cldrn[i] = X(mkplan_d)(plnr, cldp);
175 if (!cldrn[i]) goto nada;
176 }
177 X(tensor_destroy)(vecsz);
178
179 pln = MKPLAN_DFT(P, &padt, apply);
180
181 pln->cldrn = cldrn;
182 pln->its = its;
183 pln->ots = ots;
184 pln->nthr = nthr;
185
186 pln->solver = ego;
187 X(ops_zero)(&pln->super.super.ops);
188 pln->super.super.pcost = 0;
189 for (i = 0; i < nthr; ++i) {
190 X(ops_add2)(&cldrn[i]->ops, &pln->super.super.ops);
191 pln->super.super.pcost += cldrn[i]->pcost;
192 }
193
194 return &(pln->super.super);
195
196 nada:
197 if (cldrn) {
198 for (i = 0; i < nthr; ++i)
199 X(plan_destroy_internal)(cldrn[i]);
200 X(ifree)(cldrn);
201 }
202 X(tensor_destroy)(vecsz);
203 return (plan *) 0;
204 }
205
206 static solver *mksolver(int vecloop_dim, const int *buddies, size_t nbuddies)
207 {
208 static const solver_adt sadt = { PROBLEM_DFT, mkplan, 0 };
209 S *slv = MKSOLVER(S, &sadt);
210 slv->vecloop_dim = vecloop_dim;
211 slv->buddies = buddies;
212 slv->nbuddies = nbuddies;
213 return &(slv->super);
214 }
215
216 void X(dft_thr_vrank_geq1_register)(planner *p)
217 {
218 /* FIXME: Should we try other vecloop_dim values? */
219 static const int buddies[] = { 1, -1 };
220 size_t i;
221
222 for (i = 0; i < NELEM(buddies); ++i)
223 REGISTER_SOLVER(p, mksolver(buddies[i], buddies, NELEM(buddies)));
224 }