1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
/*
* Copyright (c) 2003 Matteo Frigo
* Copyright (c) 2003 Massachusetts Institute of Technology
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/* $Id: vrank-geq1-rdft2.c,v 1.1 2008/10/17 06:11:29 scuri Exp $ */
/* Plans for handling vector transform loops. These are *just* the
loops, and rely on child plans for the actual RDFT2s.
They form a wrapper around solvers that don't have apply functions
for non-null vectors.
vrank-geq1-rdft2 plans also recursively handle the case of
multi-dimensional vectors, obviating the need for most solvers to
deal with this. We can also play games here, such as reordering
the vector loops.
Each vrank-geq1-rdft2 plan reduces the vector rank by 1, picking out a
dimension determined by the vecloop_dim field of the solver. */
#include "rdft.h"
typedef struct {
solver super;
int vecloop_dim;
const int *buddies;
int nbuddies;
} S;
typedef struct {
plan_rdft2 super;
plan *cld;
int vl;
int ivs, ovs;
const S *solver;
} P;
static void apply(const plan *ego_, R *r, R *rio, R *iio)
{
const P *ego = (const P *) ego_;
int i, vl = ego->vl;
int ivs = ego->ivs, ovs = ego->ovs;
rdft2apply cldapply = ((plan_rdft2 *) ego->cld)->apply;
for (i = 0; i < vl; ++i) {
cldapply(ego->cld, r + i * ivs, rio + i * ovs, iio + i * ovs);
}
}
static void awake(plan *ego_, int flg)
{
P *ego = (P *) ego_;
AWAKE(ego->cld, flg);
}
static void destroy(plan *ego_)
{
P *ego = (P *) ego_;
X(plan_destroy_internal)(ego->cld);
}
static void print(const plan *ego_, printer *p)
{
const P *ego = (const P *) ego_;
const S *s = ego->solver;
p->print(p, "(rdft2-vrank>=1-x%d/%d%(%p%))",
ego->vl, s->vecloop_dim, ego->cld);
}
static int pickdim(const S *ego, const tensor *vecsz, int oop, int *dp)
{
return X(pickdim)(ego->vecloop_dim, ego->buddies, ego->nbuddies,
vecsz, oop, dp);
}
static int applicable0(const solver *ego_, const problem *p_, int *dp)
{
if (RDFT2P(p_)) {
const S *ego = (const S *) ego_;
const problem_rdft2 *p = (const problem_rdft2 *) p_;
if (FINITE_RNK(p->vecsz->rnk)
&& p->vecsz->rnk > 0
&& pickdim(ego, p->vecsz,
p->r != p->rio && p->r != p->iio, dp)) {
if (p->r != p->rio && p->r != p->iio)
return 1; /* can always operate out-of-place */
return(X(rdft2_inplace_strides)(p, *dp));
}
}
return 0;
}
static int applicable(const solver *ego_, const problem *p_,
const planner *plnr, int *dp)
{
const S *ego = (const S *)ego_;
if (!applicable0(ego_, p_, dp)) return 0;
/* fftw2 behavior */
if (NO_VRANK_SPLITSP(plnr) && (ego->vecloop_dim != ego->buddies[0]))
return 0;
if (NO_UGLYP(plnr)) {
const problem_rdft2 *p = (const problem_rdft2 *) p_;
iodim *d = p->vecsz->dims + *dp;
/* Heuristic: if the transform is multi-dimensional, and the
vector stride is less than the transform size, then we
probably want to use a rank>=2 plan first in order to combine
this vector with the transform-dimension vectors. */
if (p->sz->rnk > 1
&& X(imin)(X(iabs)(d->is), X(iabs)(d->os))
< X(rdft2_tensor_max_index)(p->sz, p->kind)
)
return 0;
/* Heuristic: don't use a vrank-geq1 for rank-0 vrank-1
transforms, since this case is better handled by rank-0
solvers. */
if (p->sz->rnk == 0 && p->vecsz->rnk == 1) return 0;
if (NONTHREADED_ICKYP(plnr))
return 0; /* prefer threaded version */
}
return 1;
}
static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
{
const S *ego = (const S *) ego_;
const problem_rdft2 *p;
P *pln;
plan *cld;
int vdim;
iodim *d;
int ivs, ovs;
static const plan_adt padt = {
X(rdft2_solve), awake, print, destroy
};
if (!applicable(ego_, p_, plnr, &vdim))
return (plan *) 0;
p = (const problem_rdft2 *) p_;
d = p->vecsz->dims + vdim;
A(d->n > 1); /* or else, p->ri + d->is etc. are invalid */
X(rdft2_strides)(p->kind, d, &ivs, &ovs);
cld = X(mkplan_d)(plnr,
X(mkproblem_rdft2_d)(
X(tensor_copy)(p->sz),
X(tensor_copy_except)(p->vecsz, vdim),
TAINT(p->r, ivs),
TAINT(p->rio, ovs), TAINT(p->iio, ovs),
p->kind));
if (!cld) return (plan *) 0;
pln = MKPLAN_RDFT2(P, &padt, apply);
pln->cld = cld;
pln->vl = d->n;
pln->ivs = ivs;
pln->ovs = ovs;
pln->solver = ego;
X(ops_zero)(&pln->super.super.ops);
pln->super.super.ops.other = 3.14159; /* magic to prefer codelet loops */
X(ops_madd2)(pln->vl, &cld->ops, &pln->super.super.ops);
pln->super.super.pcost = pln->vl * cld->pcost;
return &(pln->super.super);
}
static solver *mksolver(int vecloop_dim, const int *buddies, int nbuddies)
{
static const solver_adt sadt = { mkplan };
S *slv = MKSOLVER(S, &sadt);
slv->vecloop_dim = vecloop_dim;
slv->buddies = buddies;
slv->nbuddies = nbuddies;
return &(slv->super);
}
void X(rdft2_vrank_geq1_register)(planner *p)
{
int i;
/* FIXME: Should we try other vecloop_dim values? */
static const int buddies[] = { 1, -1 };
const int nbuddies = sizeof(buddies) / sizeof(buddies[0]);
for (i = 0; i < nbuddies; ++i)
REGISTER_SOLVER(p, mksolver(buddies[i], buddies, nbuddies));
}
|