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 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
|
/*
* Copyright (c) 2003, 2006 Matteo Frigo
* Copyright (c) 2003, 2006 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: dftw-direct.c,v 1.13 2006-02-13 12:59:06 athena Exp $ */
#include "ct.h"
typedef struct {
ct_solver super;
const ct_desc *desc;
int bufferedp;
kdftw k;
} S;
typedef struct {
plan_dftw super;
kdftw k;
INT r, vl;
INT s, vs;
INT mcount;
stride bufstride, ios;
const R *tdW;
INT mstart, m;
twid *td;
const S *slv;
} P;
/*************************************************************
Nonbuffered code
*************************************************************/
static void apply(const plan *ego_, R *rio, R *iio)
{
const P *ego = (const P *) ego_;
INT i, vl = ego->vl, s = ego->s, vs = ego->vs, mcount = ego->mcount;
const R *W = ego->tdW;
ASSERT_ALIGNED_DOUBLE;
for (i = 0; i < vl; ++i)
ego->k(rio + i * vs, iio + i * vs, W, ego->ios, mcount, s);
}
/*************************************************************
Buffered code
*************************************************************/
static const R *dobatch(kdftw k, R *rA, R *iA, const R *W, stride ios,
INT dist, INT r, INT batchsz, R *buf, stride bufstride)
{
X(cpy2d_pair_ci)(rA, iA, buf, buf + 1,
r, WS(ios, 1), WS(bufstride, 1),
batchsz, dist, 2);
W = k(buf, buf + 1, W, bufstride, batchsz, 2);
X(cpy2d_pair_co)(buf, buf + 1, rA, iA,
r, WS(bufstride, 1), WS(ios, 1),
batchsz, 2, dist);
return W;
}
/* must be even for SIMD alignment; should not be 2^k to avoid
associativity conflicts */
static INT compute_batchsize(INT radix)
{
/* round up to multiple of 4 */
radix += 3;
radix &= -4;
return (radix + 2);
}
static void apply_buf(const plan *ego_, R *rio, R *iio)
{
const P *ego = (const P *) ego_;
INT i, j, mcount = ego->mcount, vl = ego->vl, r = ego->r;
INT batchsz = compute_batchsize(r);
R *buf;
STACK_MALLOC(R *, buf, r * batchsz * 2 * sizeof(R));
for (i = 0; i < vl; ++i) {
R *rA = rio + i * ego->vs, *iA = iio + i * ego->vs;
const R *W = ego->tdW;
for (j = 0; j < mcount - batchsz; j += batchsz) {
W = dobatch(ego->k, rA, iA, W, ego->ios, ego->s, ego->r,
batchsz, buf, ego->bufstride);
rA += ego->s * batchsz;
iA += ego->s * batchsz;
}
dobatch(ego->k, rA, iA, W, ego->ios, ego->s, ego->r, mcount - j,
buf, ego->bufstride);
}
STACK_FREE(buf);
}
/*************************************************************
common code
*************************************************************/
static void awake(plan *ego_, enum wakefulness wakefulness)
{
P *ego = (P *) ego_;
X(twiddle_awake)(wakefulness, &ego->td, ego->slv->desc->tw,
ego->r * ego->m, ego->r, ego->m);
ego->tdW = X(twiddle_shift)(ego->td, ego->mstart);
}
static void destroy(plan *ego_)
{
P *ego = (P *) ego_;
X(stride_destroy)(ego->bufstride);
X(stride_destroy)(ego->ios);
}
static void print(const plan *ego_, printer *p)
{
const P *ego = (const P *) ego_;
const S *slv = ego->slv;
const ct_desc *e = slv->desc;
if (slv->bufferedp)
p->print(p, "(dftw-directbuf/%D-%D/%D%v \"%s\")",
compute_batchsize(ego->r), ego->r,
X(twiddle_length)(ego->r, e->tw), ego->vl, e->nam);
else
p->print(p, "(dftw-direct-%D/%D%v \"%s\")",
ego->r, X(twiddle_length)(ego->r, e->tw), ego->vl, e->nam);
}
static int applicable0(const S *ego,
int dec, INT r, INT m, INT mb, INT me,
INT s, INT vl, INT vs,
R *rio, R *iio,
const planner *plnr)
{
const ct_desc *e = ego->desc;
UNUSED(vl);
return (
1
&& dec == ego->super.dec
&& r == e->radix
/* check for alignment/vector length restrictions */
&& (e->genus->okp(e, rio, iio, m * s, 0, m, mb, me, s, plnr))
&& (e->genus->okp(e, rio + vs, iio + vs, m * s, 0, m, mb, me,
s, plnr))
);
}
static int applicable0_buf(const S *ego,
int dec, INT r, INT m, INT mb, INT me,
INT s, INT vl, INT vs,
R *rio, R *iio,
const planner *plnr)
{
const ct_desc *e = ego->desc;
INT batchsz;
UNUSED(vl); UNUSED(s); UNUSED(vs); UNUSED(rio); UNUSED(iio);
return (
1
&& dec == ego->super.dec
&& r == e->radix
/* check for alignment/vector length restrictions, both for
batchsize and for the remainder */
&& (batchsz = compute_batchsize(r), 1)
&& (e->genus->okp(e, 0, ((const R *)0) + 1, 2 * batchsz, 0,
m, mb, mb + batchsz, 2, plnr))
&& (e->genus->okp(e, 0, ((const R *)0) + 1, 2 * batchsz, 0,
m, mb, me, 2, plnr))
);
}
static int applicable(const S *ego,
int dec, INT r, INT m, INT mb, INT me,
INT s, INT vl, INT vs,
R *rio, R *iio,
const planner *plnr)
{
if (ego->bufferedp) {
if (!applicable0_buf(ego, dec, r, m, mb, me, s, vl, vs,
rio, iio, plnr))
return 0;
} else {
if (!applicable0(ego, dec, r, m, mb, me, s, vl, vs, rio, iio, plnr))
return 0;
}
if (NO_UGLYP(plnr) && X(ct_uglyp)((ego->bufferedp? (INT)512 : (INT)16),
m * r, r))
return 0;
if (m * r > 262144 && NO_FIXED_RADIX_LARGE_NP(plnr))
return 0;
return 1;
}
static plan *mkcldw(const ct_solver *ego_,
int dec, INT r, INT m, INT s, INT vl, INT vs,
INT mstart, INT mcount,
R *rio, R *iio,
planner *plnr)
{
const S *ego = (const S *) ego_;
P *pln;
const ct_desc *e = ego->desc;
static const plan_adt padt = {
0, awake, print, destroy
};
A(mstart >= 0 && mstart + mcount <= m);
if (!applicable(ego, dec, r, m, mstart, mstart + mcount,
s, vl, vs, rio, iio, plnr))
return (plan *)0;
pln = MKPLAN_DFTW(P, &padt, ego->bufferedp ? apply_buf : apply);
pln->k = ego->k;
pln->ios = X(mkstride)(r, m * s);
pln->td = 0;
pln->tdW = 0;
pln->r = r;
pln->m = m;
pln->s = s;
pln->vl = vl;
pln->vs = vs;
pln->mstart = mstart;
pln->mcount = mcount;
pln->slv = ego;
pln->bufstride = X(mkstride)(r, 2 * compute_batchsize(r));
X(ops_zero)(&pln->super.super.ops);
X(ops_madd2)(vl * (mcount/e->genus->vl), &e->ops, &pln->super.super.ops);
if (ego->bufferedp) {
/* 8 load/stores * N * VL */
pln->super.super.ops.other += 8 * r * mcount * vl;
}
pln->super.super.could_prune_now_p =
(!ego->bufferedp && r >= 5 && r < 64 && m >= r);
return &(pln->super.super);
}
static void regone(planner *plnr, kdftw codelet,
const ct_desc *desc, int dec, int bufferedp)
{
S *slv = (S *)X(mksolver_ct)(sizeof(S), desc->radix, dec, mkcldw);
slv->k = codelet;
slv->desc = desc;
slv->bufferedp = bufferedp;
REGISTER_SOLVER(plnr, &(slv->super.super));
if (X(mksolver_ct_hook)) {
slv = (S *)X(mksolver_ct_hook)(sizeof(S), desc->radix,
dec, mkcldw);
slv->k = codelet;
slv->desc = desc;
slv->bufferedp = bufferedp;
REGISTER_SOLVER(plnr, &(slv->super.super));
}
}
void X(regsolver_ct_directw)(planner *plnr, kdftw codelet,
const ct_desc *desc, int dec)
{
regone(plnr, codelet, desc, dec, /* bufferedp */ 0);
regone(plnr, codelet, desc, dec, /* bufferedp */ 1);
}
|