Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.8/threads/hc2hc.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 #include "threads/threads.h" | |
22 | |
23 typedef struct { | |
24 plan_rdft super; | |
25 plan *cld; | |
26 plan **cldws; | |
27 int nthr; | |
28 INT r; | |
29 } P; | |
30 | |
31 typedef struct { | |
32 plan **cldws; | |
33 R *IO; | |
34 } PD; | |
35 | |
36 static void *spawn_apply(spawn_data *d) | |
37 { | |
38 PD *ego = (PD *) d->data; | |
39 | |
40 plan_hc2hc *cldw = (plan_hc2hc *) (ego->cldws[d->thr_num]); | |
41 cldw->apply((plan *) cldw, ego->IO); | |
42 return 0; | |
43 } | |
44 | |
45 static void apply_dit(const plan *ego_, R *I, R *O) | |
46 { | |
47 const P *ego = (const P *) ego_; | |
48 plan_rdft *cld; | |
49 | |
50 cld = (plan_rdft *) ego->cld; | |
51 cld->apply((plan *) cld, I, O); | |
52 | |
53 { | |
54 PD d; | |
55 | |
56 d.IO = O; | |
57 d.cldws = ego->cldws; | |
58 | |
59 X(spawn_loop)(ego->nthr, ego->nthr, spawn_apply, (void*)&d); | |
60 } | |
61 } | |
62 | |
63 static void apply_dif(const plan *ego_, R *I, R *O) | |
64 { | |
65 const P *ego = (const P *) ego_; | |
66 plan_rdft *cld; | |
67 | |
68 { | |
69 PD d; | |
70 | |
71 d.IO = I; | |
72 d.cldws = ego->cldws; | |
73 | |
74 X(spawn_loop)(ego->nthr, ego->nthr, spawn_apply, (void*)&d); | |
75 } | |
76 | |
77 cld = (plan_rdft *) ego->cld; | |
78 cld->apply((plan *) cld, I, O); | |
79 } | |
80 | |
81 static void awake(plan *ego_, enum wakefulness wakefulness) | |
82 { | |
83 P *ego = (P *) ego_; | |
84 int i; | |
85 X(plan_awake)(ego->cld, wakefulness); | |
86 for (i = 0; i < ego->nthr; ++i) | |
87 X(plan_awake)(ego->cldws[i], wakefulness); | |
88 } | |
89 | |
90 static void destroy(plan *ego_) | |
91 { | |
92 P *ego = (P *) ego_; | |
93 int i; | |
94 X(plan_destroy_internal)(ego->cld); | |
95 for (i = 0; i < ego->nthr; ++i) | |
96 X(plan_destroy_internal)(ego->cldws[i]); | |
97 X(ifree)(ego->cldws); | |
98 } | |
99 | |
100 static void print(const plan *ego_, printer *p) | |
101 { | |
102 const P *ego = (const P *) ego_; | |
103 int i; | |
104 p->print(p, "(rdft-thr-ct-%s-x%d/%D", | |
105 ego->super.apply == apply_dit ? "dit" : "dif", | |
106 ego->nthr, ego->r); | |
107 for (i = 0; i < ego->nthr; ++i) | |
108 if (i == 0 || (ego->cldws[i] != ego->cldws[i-1] && | |
109 (i <= 1 || ego->cldws[i] != ego->cldws[i-2]))) | |
110 p->print(p, "%(%p%)", ego->cldws[i]); | |
111 p->print(p, "%(%p%))", ego->cld); | |
112 } | |
113 | |
114 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr) | |
115 { | |
116 const hc2hc_solver *ego = (const hc2hc_solver *) ego_; | |
117 const problem_rdft *p; | |
118 P *pln = 0; | |
119 plan *cld = 0, **cldws = 0; | |
120 INT n, r, m, v, ivs, ovs, mcount; | |
121 int i, nthr, plnr_nthr_save; | |
122 INT block_size; | |
123 iodim *d; | |
124 | |
125 static const plan_adt padt = { | |
126 X(rdft_solve), awake, print, destroy | |
127 }; | |
128 | |
129 if (plnr->nthr <= 1 || !X(hc2hc_applicable)(ego, p_, plnr)) | |
130 return (plan *) 0; | |
131 | |
132 p = (const problem_rdft *) p_; | |
133 d = p->sz->dims; | |
134 n = d[0].n; | |
135 r = X(choose_radix)(ego->r, n); | |
136 m = n / r; | |
137 mcount = (m + 2) / 2; | |
138 | |
139 X(tensor_tornk1)(p->vecsz, &v, &ivs, &ovs); | |
140 | |
141 block_size = (mcount + plnr->nthr - 1) / plnr->nthr; | |
142 nthr = (int)((mcount + block_size - 1) / block_size); | |
143 plnr_nthr_save = plnr->nthr; | |
144 plnr->nthr = (plnr->nthr + nthr - 1) / nthr; | |
145 | |
146 cldws = (plan **) MALLOC(sizeof(plan *) * nthr, PLANS); | |
147 for (i = 0; i < nthr; ++i) cldws[i] = (plan *) 0; | |
148 | |
149 switch (p->kind[0]) { | |
150 case R2HC: | |
151 for (i = 0; i < nthr; ++i) { | |
152 cldws[i] = ego->mkcldw(ego, | |
153 R2HC, r, m, d[0].os, v, ovs, | |
154 i*block_size, | |
155 (i == nthr - 1) ? | |
156 (mcount - i*block_size) : block_size, | |
157 p->O, plnr); | |
158 if (!cldws[i]) goto nada; | |
159 } | |
160 | |
161 plnr->nthr = plnr_nthr_save; | |
162 | |
163 cld = X(mkplan_d)(plnr, | |
164 X(mkproblem_rdft_d)( | |
165 X(mktensor_1d)(m, r * d[0].is, d[0].os), | |
166 X(mktensor_2d)(r, d[0].is, m * d[0].os, | |
167 v, ivs, ovs), | |
168 p->I, p->O, p->kind) | |
169 ); | |
170 if (!cld) goto nada; | |
171 | |
172 pln = MKPLAN_RDFT(P, &padt, apply_dit); | |
173 break; | |
174 | |
175 case HC2R: | |
176 for (i = 0; i < nthr; ++i) { | |
177 cldws[i] = ego->mkcldw(ego, | |
178 HC2R, r, m, d[0].is, v, ivs, | |
179 i*block_size, | |
180 (i == nthr - 1) ? | |
181 (mcount - i*block_size) : block_size, | |
182 p->I, plnr); | |
183 if (!cldws[i]) goto nada; | |
184 } | |
185 | |
186 plnr->nthr = plnr_nthr_save; | |
187 | |
188 cld = X(mkplan_d)(plnr, | |
189 X(mkproblem_rdft_d)( | |
190 X(mktensor_1d)(m, d[0].is, r * d[0].os), | |
191 X(mktensor_2d)(r, m * d[0].is, d[0].os, | |
192 v, ivs, ovs), | |
193 p->I, p->O, p->kind) | |
194 ); | |
195 if (!cld) goto nada; | |
196 | |
197 pln = MKPLAN_RDFT(P, &padt, apply_dif); | |
198 break; | |
199 | |
200 default: | |
201 A(0); | |
202 } | |
203 | |
204 pln->cld = cld; | |
205 pln->cldws = cldws; | |
206 pln->nthr = nthr; | |
207 pln->r = r; | |
208 X(ops_zero)(&pln->super.super.ops); | |
209 for (i = 0; i < nthr; ++i) { | |
210 X(ops_add2)(&cldws[i]->ops, &pln->super.super.ops); | |
211 pln->super.super.could_prune_now_p |= cldws[i]->could_prune_now_p; | |
212 } | |
213 X(ops_add2)(&cld->ops, &pln->super.super.ops); | |
214 return &(pln->super.super); | |
215 | |
216 nada: | |
217 if (cldws) { | |
218 for (i = 0; i < nthr; ++i) | |
219 X(plan_destroy_internal)(cldws[i]); | |
220 X(ifree)(cldws); | |
221 } | |
222 X(plan_destroy_internal)(cld); | |
223 return (plan *) 0; | |
224 } | |
225 | |
226 hc2hc_solver *X(mksolver_hc2hc_threads)(size_t size, INT r, | |
227 hc2hc_mkinferior mkcldw) | |
228 { | |
229 static const solver_adt sadt = { PROBLEM_RDFT, mkplan, 0 }; | |
230 hc2hc_solver *slv = (hc2hc_solver *)X(mksolver)(size, &sadt); | |
231 slv->r = r; | |
232 slv->mkcldw = mkcldw; | |
233 return slv; | |
234 } |