/src/fftw3/rdft/vrank-geq1-rdft2.c
Line | Count | Source (jump to first uncovered line) |
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 | | |
23 | | /* Plans for handling vector transform loops. These are *just* the |
24 | | loops, and rely on child plans for the actual RDFT2s. |
25 | | |
26 | | They form a wrapper around solvers that don't have apply functions |
27 | | for non-null vectors. |
28 | | |
29 | | vrank-geq1-rdft2 plans also recursively handle the case of |
30 | | multi-dimensional vectors, obviating the need for most solvers to |
31 | | deal with this. We can also play games here, such as reordering |
32 | | the vector loops. |
33 | | |
34 | | Each vrank-geq1-rdft2 plan reduces the vector rank by 1, picking out a |
35 | | dimension determined by the vecloop_dim field of the solver. */ |
36 | | |
37 | | #include "rdft/rdft.h" |
38 | | |
39 | | typedef struct { |
40 | | solver super; |
41 | | int vecloop_dim; |
42 | | const int *buddies; |
43 | | size_t nbuddies; |
44 | | } S; |
45 | | |
46 | | typedef struct { |
47 | | plan_rdft2 super; |
48 | | |
49 | | plan *cld; |
50 | | INT vl; |
51 | | INT rvs, cvs; |
52 | | const S *solver; |
53 | | } P; |
54 | | |
55 | | static void apply(const plan *ego_, R *r0, R *r1, R *cr, R *ci) |
56 | 0 | { |
57 | 0 | const P *ego = (const P *) ego_; |
58 | 0 | INT i, vl = ego->vl; |
59 | 0 | INT rvs = ego->rvs, cvs = ego->cvs; |
60 | 0 | rdft2apply cldapply = ((plan_rdft2 *) ego->cld)->apply; |
61 | |
|
62 | 0 | for (i = 0; i < vl; ++i) { |
63 | 0 | cldapply(ego->cld, r0 + i * rvs, r1 + i * rvs, |
64 | 0 | cr + i * cvs, ci + i * cvs); |
65 | 0 | } |
66 | 0 | } |
67 | | |
68 | | static void awake(plan *ego_, enum wakefulness wakefulness) |
69 | 0 | { |
70 | 0 | P *ego = (P *) ego_; |
71 | 0 | X(plan_awake)(ego->cld, wakefulness); |
72 | 0 | } |
73 | | |
74 | | static void destroy(plan *ego_) |
75 | 0 | { |
76 | 0 | P *ego = (P *) ego_; |
77 | 0 | X(plan_destroy_internal)(ego->cld); |
78 | 0 | } |
79 | | |
80 | | static void print(const plan *ego_, printer *p) |
81 | 0 | { |
82 | 0 | const P *ego = (const P *) ego_; |
83 | 0 | const S *s = ego->solver; |
84 | 0 | p->print(p, "(rdft2-vrank>=1-x%D/%d%(%p%))", |
85 | 0 | ego->vl, s->vecloop_dim, ego->cld); |
86 | 0 | } |
87 | | |
88 | | static int pickdim(const S *ego, const tensor *vecsz, int oop, int *dp) |
89 | 0 | { |
90 | 0 | return X(pickdim)(ego->vecloop_dim, ego->buddies, ego->nbuddies, |
91 | 0 | vecsz, oop, dp); |
92 | 0 | } |
93 | | |
94 | | static int applicable0(const solver *ego_, const problem *p_, int *dp) |
95 | 0 | { |
96 | 0 | const S *ego = (const S *) ego_; |
97 | 0 | const problem_rdft2 *p = (const problem_rdft2 *) p_; |
98 | 0 | if (FINITE_RNK(p->vecsz->rnk) |
99 | 0 | && p->vecsz->rnk > 0 |
100 | 0 | && pickdim(ego, p->vecsz, p->r0 != p->cr, dp)) { |
101 | 0 | if (p->r0 != p->cr) |
102 | 0 | return 1; /* can always operate out-of-place */ |
103 | | |
104 | 0 | return(X(rdft2_inplace_strides)(p, *dp)); |
105 | 0 | } |
106 | | |
107 | 0 | return 0; |
108 | 0 | } |
109 | | |
110 | | |
111 | | static int applicable(const solver *ego_, const problem *p_, |
112 | | const planner *plnr, int *dp) |
113 | 0 | { |
114 | 0 | const S *ego = (const S *)ego_; |
115 | 0 | if (!applicable0(ego_, p_, dp)) return 0; |
116 | | |
117 | | /* fftw2 behavior */ |
118 | 0 | if (NO_VRANK_SPLITSP(plnr) && (ego->vecloop_dim != ego->buddies[0])) |
119 | 0 | return 0; |
120 | | |
121 | 0 | if (NO_UGLYP(plnr)) { |
122 | 0 | const problem_rdft2 *p = (const problem_rdft2 *) p_; |
123 | 0 | iodim *d = p->vecsz->dims + *dp; |
124 | | |
125 | | /* Heuristic: if the transform is multi-dimensional, and the |
126 | | vector stride is less than the transform size, then we |
127 | | probably want to use a rank>=2 plan first in order to combine |
128 | | this vector with the transform-dimension vectors. */ |
129 | 0 | if (p->sz->rnk > 1 |
130 | 0 | && X(imin)(X(iabs)(d->is), X(iabs)(d->os)) |
131 | 0 | < X(rdft2_tensor_max_index)(p->sz, p->kind) |
132 | 0 | ) |
133 | 0 | return 0; |
134 | | |
135 | | /* Heuristic: don't use a vrank-geq1 for rank-0 vrank-1 |
136 | | transforms, since this case is better handled by rank-0 |
137 | | solvers. */ |
138 | 0 | if (p->sz->rnk == 0 && p->vecsz->rnk == 1) return 0; |
139 | | |
140 | 0 | if (NO_NONTHREADEDP(plnr)) |
141 | 0 | return 0; /* prefer threaded version */ |
142 | 0 | } |
143 | | |
144 | 0 | return 1; |
145 | 0 | } |
146 | | |
147 | | static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr) |
148 | 0 | { |
149 | 0 | const S *ego = (const S *) ego_; |
150 | 0 | const problem_rdft2 *p; |
151 | 0 | P *pln; |
152 | 0 | plan *cld; |
153 | 0 | int vdim; |
154 | 0 | iodim *d; |
155 | 0 | INT rvs, cvs; |
156 | |
|
157 | 0 | static const plan_adt padt = { |
158 | 0 | X(rdft2_solve), awake, print, destroy |
159 | 0 | }; |
160 | |
|
161 | 0 | if (!applicable(ego_, p_, plnr, &vdim)) |
162 | 0 | return (plan *) 0; |
163 | 0 | p = (const problem_rdft2 *) p_; |
164 | |
|
165 | 0 | d = p->vecsz->dims + vdim; |
166 | |
|
167 | 0 | A(d->n > 1); /* or else, p->ri + d->is etc. are invalid */ |
168 | |
|
169 | 0 | X(rdft2_strides)(p->kind, d, &rvs, &cvs); |
170 | |
|
171 | 0 | cld = X(mkplan_d)(plnr, |
172 | 0 | X(mkproblem_rdft2_d)( |
173 | 0 | X(tensor_copy)(p->sz), |
174 | 0 | X(tensor_copy_except)(p->vecsz, vdim), |
175 | 0 | TAINT(p->r0, rvs), TAINT(p->r1, rvs), |
176 | 0 | TAINT(p->cr, cvs), TAINT(p->ci, cvs), |
177 | 0 | p->kind)); |
178 | 0 | if (!cld) return (plan *) 0; |
179 | | |
180 | 0 | pln = MKPLAN_RDFT2(P, &padt, apply); |
181 | |
|
182 | 0 | pln->cld = cld; |
183 | 0 | pln->vl = d->n; |
184 | 0 | pln->rvs = rvs; |
185 | 0 | pln->cvs = cvs; |
186 | |
|
187 | 0 | pln->solver = ego; |
188 | 0 | X(ops_zero)(&pln->super.super.ops); |
189 | 0 | pln->super.super.ops.other = 3.14159; /* magic to prefer codelet loops */ |
190 | 0 | X(ops_madd2)(pln->vl, &cld->ops, &pln->super.super.ops); |
191 | |
|
192 | 0 | if (p->sz->rnk != 1 || (p->sz->dims[0].n > 128)) |
193 | 0 | pln->super.super.pcost = pln->vl * cld->pcost; |
194 | |
|
195 | 0 | return &(pln->super.super); |
196 | 0 | } |
197 | | |
198 | | static solver *mksolver(int vecloop_dim, const int *buddies, size_t nbuddies) |
199 | 2 | { |
200 | 2 | static const solver_adt sadt = { PROBLEM_RDFT2, mkplan, 0 }; |
201 | 2 | S *slv = MKSOLVER(S, &sadt); |
202 | 2 | slv->vecloop_dim = vecloop_dim; |
203 | 2 | slv->buddies = buddies; |
204 | 2 | slv->nbuddies = nbuddies; |
205 | 2 | return &(slv->super); |
206 | 2 | } |
207 | | |
208 | | void X(rdft2_vrank_geq1_register)(planner *p) |
209 | 1 | { |
210 | | /* FIXME: Should we try other vecloop_dim values? */ |
211 | 1 | static const int buddies[] = { 1, -1 }; |
212 | 1 | size_t i; |
213 | | |
214 | 3 | for (i = 0; i < NELEM(buddies); ++i) |
215 | 2 | REGISTER_SOLVER(p, mksolver(buddies[i], buddies, NELEM(buddies))); |
216 | 1 | } |