Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.8/threads/rdft-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_rdft 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 *I, *O; | |
42 plan **cldrn; | |
43 } PD; | |
44 | |
45 static void *spawn_apply(spawn_data *d) | |
46 { | |
47 PD *ego = (PD *) d->data; | |
48 int thr_num = d->thr_num; | |
49 plan_rdft *cld = (plan_rdft *) ego->cldrn[d->thr_num]; | |
50 | |
51 cld->apply((plan *) cld, | |
52 ego->I + thr_num * ego->its, ego->O + thr_num * ego->ots); | |
53 return 0; | |
54 } | |
55 | |
56 static void apply(const plan *ego_, R *I, R *O) | |
57 { | |
58 const P *ego = (const P *) ego_; | |
59 PD d; | |
60 | |
61 d.its = ego->its; | |
62 d.ots = ego->ots; | |
63 d.cldrn = ego->cldrn; | |
64 d.I = I; d.O = O; | |
65 | |
66 X(spawn_loop)(ego->nthr, ego->nthr, spawn_apply, (void*) &d); | |
67 } | |
68 | |
69 static void awake(plan *ego_, enum wakefulness wakefulness) | |
70 { | |
71 P *ego = (P *) ego_; | |
72 int i; | |
73 for (i = 0; i < ego->nthr; ++i) | |
74 X(plan_awake)(ego->cldrn[i], wakefulness); | |
75 } | |
76 | |
77 static void destroy(plan *ego_) | |
78 { | |
79 P *ego = (P *) ego_; | |
80 int i; | |
81 for (i = 0; i < ego->nthr; ++i) | |
82 X(plan_destroy_internal)(ego->cldrn[i]); | |
83 X(ifree)(ego->cldrn); | |
84 } | |
85 | |
86 static void print(const plan *ego_, printer *p) | |
87 { | |
88 const P *ego = (const P *) ego_; | |
89 const S *s = ego->solver; | |
90 int i; | |
91 p->print(p, "(rdft-thr-vrank>=1-x%d/%d", ego->nthr, s->vecloop_dim); | |
92 for (i = 0; i < ego->nthr; ++i) | |
93 if (i == 0 || (ego->cldrn[i] != ego->cldrn[i-1] && | |
94 (i <= 1 || ego->cldrn[i] != ego->cldrn[i-2]))) | |
95 p->print(p, "%(%p%)", ego->cldrn[i]); | |
96 p->putchr(p, ')'); | |
97 } | |
98 | |
99 static int pickdim(const S *ego, const tensor *vecsz, int oop, int *dp) | |
100 { | |
101 return X(pickdim)(ego->vecloop_dim, ego->buddies, ego->nbuddies, | |
102 vecsz, oop, dp); | |
103 } | |
104 | |
105 static int applicable0(const solver *ego_, const problem *p_, | |
106 const planner *plnr, int *dp) | |
107 { | |
108 const S *ego = (const S *) ego_; | |
109 const problem_rdft *p = (const problem_rdft *) p_; | |
110 | |
111 return (1 | |
112 && plnr->nthr > 1 | |
113 && FINITE_RNK(p->vecsz->rnk) | |
114 && p->vecsz->rnk > 0 | |
115 && pickdim(ego, p->vecsz, p->I != p->O, dp) | |
116 ); | |
117 } | |
118 | |
119 static int applicable(const solver *ego_, const problem *p_, | |
120 const planner *plnr, int *dp) | |
121 { | |
122 const S *ego = (const S *)ego_; | |
123 | |
124 if (!applicable0(ego_, p_, plnr, dp)) return 0; | |
125 | |
126 /* fftw2 behavior */ | |
127 if (NO_VRANK_SPLITSP(plnr) && (ego->vecloop_dim != ego->buddies[0])) | |
128 return 0; | |
129 | |
130 return 1; | |
131 } | |
132 | |
133 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr) | |
134 { | |
135 const S *ego = (const S *) ego_; | |
136 const problem_rdft *p; | |
137 P *pln; | |
138 problem *cldp; | |
139 int vdim; | |
140 iodim *d; | |
141 plan **cldrn = (plan **) 0; | |
142 int i, nthr; | |
143 INT its, ots, block_size; | |
144 tensor *vecsz; | |
145 | |
146 static const plan_adt padt = { | |
147 X(rdft_solve), awake, print, destroy | |
148 }; | |
149 | |
150 if (!applicable(ego_, p_, plnr, &vdim)) | |
151 return (plan *) 0; | |
152 p = (const problem_rdft *) p_; | |
153 | |
154 d = p->vecsz->dims + vdim; | |
155 | |
156 block_size = (d->n + plnr->nthr - 1) / plnr->nthr; | |
157 nthr = (int)((d->n + block_size - 1) / block_size); | |
158 plnr->nthr = (plnr->nthr + nthr - 1) / nthr; | |
159 its = d->is * block_size; | |
160 ots = d->os * block_size; | |
161 | |
162 cldrn = (plan **)MALLOC(sizeof(plan *) * nthr, PLANS); | |
163 for (i = 0; i < nthr; ++i) cldrn[i] = (plan *) 0; | |
164 | |
165 vecsz = X(tensor_copy)(p->vecsz); | |
166 for (i = 0; i < nthr; ++i) { | |
167 vecsz->dims[vdim].n = | |
168 (i == nthr - 1) ? (d->n - i*block_size) : block_size; | |
169 cldp = X(mkproblem_rdft)(p->sz, vecsz, | |
170 p->I + i*its, p->O + i*ots, p->kind); | |
171 cldrn[i] = X(mkplan_d)(plnr, cldp); | |
172 if (!cldrn[i]) goto nada; | |
173 } | |
174 X(tensor_destroy)(vecsz); | |
175 | |
176 pln = MKPLAN_RDFT(P, &padt, apply); | |
177 | |
178 pln->cldrn = cldrn; | |
179 pln->its = its; | |
180 pln->ots = ots; | |
181 pln->nthr = nthr; | |
182 | |
183 pln->solver = ego; | |
184 X(ops_zero)(&pln->super.super.ops); | |
185 pln->super.super.pcost = 0; | |
186 for (i = 0; i < nthr; ++i) { | |
187 X(ops_add2)(&cldrn[i]->ops, &pln->super.super.ops); | |
188 pln->super.super.pcost += cldrn[i]->pcost; | |
189 } | |
190 | |
191 return &(pln->super.super); | |
192 | |
193 nada: | |
194 if (cldrn) { | |
195 for (i = 0; i < nthr; ++i) | |
196 X(plan_destroy_internal)(cldrn[i]); | |
197 X(ifree)(cldrn); | |
198 } | |
199 X(tensor_destroy)(vecsz); | |
200 return (plan *) 0; | |
201 } | |
202 | |
203 static solver *mksolver(int vecloop_dim, const int *buddies, size_t nbuddies) | |
204 { | |
205 static const solver_adt sadt = { PROBLEM_RDFT, mkplan, 0 }; | |
206 S *slv = MKSOLVER(S, &sadt); | |
207 slv->vecloop_dim = vecloop_dim; | |
208 slv->buddies = buddies; | |
209 slv->nbuddies = nbuddies; | |
210 return &(slv->super); | |
211 } | |
212 | |
213 void X(rdft_thr_vrank_geq1_register)(planner *p) | |
214 { | |
215 size_t i; | |
216 | |
217 /* FIXME: Should we try other vecloop_dim values? */ | |
218 static const int buddies[] = { 1, -1 }; | |
219 | |
220 for (i = 0; i < NELEM(buddies); ++i) | |
221 REGISTER_SOLVER(p, mksolver(buddies[i], buddies, NELEM(buddies))); | |
222 } |