2
* Copyright (c) 2003, 2006 Matteo Frigo
3
* Copyright (c) 2003, 2006 Massachusetts Institute of Technology
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
/* $Id: vrank-geq1.c,v 1.40 2006-01-27 02:10:50 athena Exp $ */
24
/* Plans for handling vector transform loops. These are *just* the
25
loops, and rely on child plans for the actual RDFTs.
27
They form a wrapper around solvers that don't have apply functions
30
vrank-geq1 plans also recursively handle the case of multi-dimensional
31
vectors, obviating the need for most solvers to deal with this. We
32
can also play games here, such as reordering the vector loops.
34
Each vrank-geq1 plan reduces the vector rank by 1, picking out a
35
dimension determined by the vecloop_dim field of the solver. */
55
static void apply(const plan *ego_, R *I, R *O)
57
const P *ego = (const P *) ego_;
59
INT ivs = ego->ivs, ovs = ego->ovs;
60
rdftapply cldapply = ((plan_rdft *) ego->cld)->apply;
62
for (i = 0; i < vl; ++i) {
63
cldapply(ego->cld, I + i * ivs, O + i * ovs);
67
static void awake(plan *ego_, enum wakefulness wakefulness)
70
X(plan_awake)(ego->cld, wakefulness);
73
static void destroy(plan *ego_)
76
X(plan_destroy_internal)(ego->cld);
79
static void print(const plan *ego_, printer *p)
81
const P *ego = (const P *) ego_;
82
const S *s = ego->solver;
83
p->print(p, "(rdft-vrank>=1-x%D/%d%(%p%))",
84
ego->vl, s->vecloop_dim, ego->cld);
87
static int pickdim(const S *ego, const tensor *vecsz, int oop, int *dp)
89
return X(pickdim)(ego->vecloop_dim, ego->buddies, ego->nbuddies,
93
static int applicable0(const solver *ego_, const problem *p_, int *dp)
95
const S *ego = (const S *) ego_;
96
const problem_rdft *p = (const problem_rdft *) p_;
99
&& FINITE_RNK(p->vecsz->rnk)
102
/* the rank-0 solver deals with the general case */
105
&& pickdim(ego, p->vecsz, p->I != p->O, dp)
109
static int applicable(const solver *ego_, const problem *p_,
110
const planner *plnr, int *dp)
112
const S *ego = (const S *)ego_;
113
const problem_rdft *p;
115
if (!applicable0(ego_, p_, dp)) return 0;
118
if (NO_VRANK_SPLITSP(plnr) && (ego->vecloop_dim != ego->buddies[0]))
121
if (NO_UGLYP(plnr)) {
122
p = (const problem_rdft *) p_;
124
/* Heuristic: if the transform is multi-dimensional, and the
125
vector stride is less than the transform size, then we
126
probably want to use a rank>=2 plan first in order to combine
127
this vector with the transform-dimension vectors. */
129
iodim *d = p->vecsz->dims + *dp;
132
&& X(imin)(X(iabs)(d->is), X(iabs)(d->os))
133
< X(tensor_max_index)(p->sz)
138
/* prefer threaded version */
139
if (NO_NONTHREADEDP(plnr)) return 0;
141
/* exploit built-in vecloops of (ugly) r{e,o}dft solvers */
142
if (p->vecsz->rnk == 1 && p->sz->rnk == 1
143
&& REODFT_KINDP(p->kind[0]))
150
static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
152
const S *ego = (const S *) ego_;
153
const problem_rdft *p;
159
static const plan_adt padt = {
160
X(rdft_solve), awake, print, destroy
163
if (!applicable(ego_, p_, plnr, &vdim))
165
p = (const problem_rdft *) p_;
167
d = p->vecsz->dims + vdim;
171
cld = X(mkplan_d)(plnr,
173
X(tensor_copy)(p->sz),
174
X(tensor_copy_except)(p->vecsz, vdim),
175
TAINT(p->I, d->is), TAINT(p->O, d->os),
177
if (!cld) return (plan *) 0;
179
pln = MKPLAN_RDFT(P, &padt, apply);
187
X(ops_zero)(&pln->super.super.ops);
188
pln->super.super.ops.other = 3.14159; /* magic to prefer codelet loops */
189
X(ops_madd2)(pln->vl, &cld->ops, &pln->super.super.ops);
191
if (p->sz->rnk != 1 || (p->sz->dims[0].n > 128))
192
pln->super.super.pcost = pln->vl * cld->pcost;
194
return &(pln->super.super);
197
static solver *mksolver(int vecloop_dim, const int *buddies, int nbuddies)
199
static const solver_adt sadt = { PROBLEM_RDFT, mkplan };
200
S *slv = MKSOLVER(S, &sadt);
201
slv->vecloop_dim = vecloop_dim;
202
slv->buddies = buddies;
203
slv->nbuddies = nbuddies;
204
return &(slv->super);
207
void X(rdft_vrank_geq1_register)(planner *p)
211
/* FIXME: Should we try other vecloop_dim values? */
212
static const int buddies[] = { 1, -1 };
214
const int nbuddies = (int)(sizeof(buddies) / sizeof(buddies[0]));
216
for (i = 0; i < nbuddies; ++i)
217
REGISTER_SOLVER(p, mksolver(buddies[i], buddies, nbuddies));