annotate src/fftw-3.3.3/libbench2/verify-rdft2.c @ 10:37bf6b4a2645

Add FFTW3
author Chris Cannam
date Wed, 20 Mar 2013 15:35:50 +0000
parents
children
rev   line source
Chris@10 1 /*
Chris@10 2 * Copyright (c) 2003, 2007-11 Matteo Frigo
Chris@10 3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
Chris@10 4 *
Chris@10 5 * This program is free software; you can redistribute it and/or modify
Chris@10 6 * it under the terms of the GNU General Public License as published by
Chris@10 7 * the Free Software Foundation; either version 2 of the License, or
Chris@10 8 * (at your option) any later version.
Chris@10 9 *
Chris@10 10 * This program is distributed in the hope that it will be useful,
Chris@10 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@10 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@10 13 * GNU General Public License for more details.
Chris@10 14 *
Chris@10 15 * You should have received a copy of the GNU General Public License
Chris@10 16 * along with this program; if not, write to the Free Software
Chris@10 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@10 18 *
Chris@10 19 */
Chris@10 20
Chris@10 21
Chris@10 22 #include "verify.h"
Chris@10 23
Chris@10 24 /* copy real A into real B, using output stride of A and input stride of B */
Chris@10 25 typedef struct {
Chris@10 26 dotens2_closure k;
Chris@10 27 R *ra;
Chris@10 28 R *rb;
Chris@10 29 } cpyr_closure;
Chris@10 30
Chris@10 31 static void cpyr0(dotens2_closure *k_,
Chris@10 32 int indxa, int ondxa, int indxb, int ondxb)
Chris@10 33 {
Chris@10 34 cpyr_closure *k = (cpyr_closure *)k_;
Chris@10 35 k->rb[indxb] = k->ra[ondxa];
Chris@10 36 UNUSED(indxa); UNUSED(ondxb);
Chris@10 37 }
Chris@10 38
Chris@10 39 static void cpyr(R *ra, const bench_tensor *sza,
Chris@10 40 R *rb, const bench_tensor *szb)
Chris@10 41 {
Chris@10 42 cpyr_closure k;
Chris@10 43 k.k.apply = cpyr0;
Chris@10 44 k.ra = ra; k.rb = rb;
Chris@10 45 bench_dotens2(sza, szb, &k.k);
Chris@10 46 }
Chris@10 47
Chris@10 48 /* copy unpacked halfcomplex A[n] into packed-complex B[n], using output stride
Chris@10 49 of A and input stride of B. Only copies non-redundant half; other
Chris@10 50 half must be copied via mkhermitian. */
Chris@10 51 typedef struct {
Chris@10 52 dotens2_closure k;
Chris@10 53 int n;
Chris@10 54 int as;
Chris@10 55 int scalea;
Chris@10 56 R *ra, *ia;
Chris@10 57 R *rb, *ib;
Chris@10 58 } cpyhc2_closure;
Chris@10 59
Chris@10 60 static void cpyhc20(dotens2_closure *k_,
Chris@10 61 int indxa, int ondxa, int indxb, int ondxb)
Chris@10 62 {
Chris@10 63 cpyhc2_closure *k = (cpyhc2_closure *)k_;
Chris@10 64 int i, n = k->n;
Chris@10 65 int scalea = k->scalea;
Chris@10 66 int as = k->as * scalea;
Chris@10 67 R *ra = k->ra + ondxa * scalea, *ia = k->ia + ondxa * scalea;
Chris@10 68 R *rb = k->rb + indxb, *ib = k->ib + indxb;
Chris@10 69 UNUSED(indxa); UNUSED(ondxb);
Chris@10 70
Chris@10 71 for (i = 0; i < n/2 + 1; ++i) {
Chris@10 72 rb[2*i] = ra[as*i];
Chris@10 73 ib[2*i] = ia[as*i];
Chris@10 74 }
Chris@10 75 }
Chris@10 76
Chris@10 77 static void cpyhc2(R *ra, R *ia,
Chris@10 78 const bench_tensor *sza, const bench_tensor *vecsza,
Chris@10 79 int scalea,
Chris@10 80 R *rb, R *ib, const bench_tensor *szb)
Chris@10 81 {
Chris@10 82 cpyhc2_closure k;
Chris@10 83 BENCH_ASSERT(sza->rnk <= 1);
Chris@10 84 k.k.apply = cpyhc20;
Chris@10 85 k.n = tensor_sz(sza);
Chris@10 86 k.scalea = scalea;
Chris@10 87 if (!FINITE_RNK(sza->rnk) || sza->rnk == 0)
Chris@10 88 k.as = 0;
Chris@10 89 else
Chris@10 90 k.as = sza->dims[0].os;
Chris@10 91 k.ra = ra; k.ia = ia; k.rb = rb; k.ib = ib;
Chris@10 92 bench_dotens2(vecsza, szb, &k.k);
Chris@10 93 }
Chris@10 94
Chris@10 95 /* icpyhc2 is the inverse of cpyhc2 */
Chris@10 96
Chris@10 97 static void icpyhc20(dotens2_closure *k_,
Chris@10 98 int indxa, int ondxa, int indxb, int ondxb)
Chris@10 99 {
Chris@10 100 cpyhc2_closure *k = (cpyhc2_closure *)k_;
Chris@10 101 int i, n = k->n;
Chris@10 102 int scalea = k->scalea;
Chris@10 103 int as = k->as * scalea;
Chris@10 104 R *ra = k->ra + indxa * scalea, *ia = k->ia + indxa * scalea;
Chris@10 105 R *rb = k->rb + ondxb, *ib = k->ib + ondxb;
Chris@10 106 UNUSED(ondxa); UNUSED(indxb);
Chris@10 107
Chris@10 108 for (i = 0; i < n/2 + 1; ++i) {
Chris@10 109 ra[as*i] = rb[2*i];
Chris@10 110 ia[as*i] = ib[2*i];
Chris@10 111 }
Chris@10 112 }
Chris@10 113
Chris@10 114 static void icpyhc2(R *ra, R *ia,
Chris@10 115 const bench_tensor *sza, const bench_tensor *vecsza,
Chris@10 116 int scalea,
Chris@10 117 R *rb, R *ib, const bench_tensor *szb)
Chris@10 118 {
Chris@10 119 cpyhc2_closure k;
Chris@10 120 BENCH_ASSERT(sza->rnk <= 1);
Chris@10 121 k.k.apply = icpyhc20;
Chris@10 122 k.n = tensor_sz(sza);
Chris@10 123 k.scalea = scalea;
Chris@10 124 if (!FINITE_RNK(sza->rnk) || sza->rnk == 0)
Chris@10 125 k.as = 0;
Chris@10 126 else
Chris@10 127 k.as = sza->dims[0].is;
Chris@10 128 k.ra = ra; k.ia = ia; k.rb = rb; k.ib = ib;
Chris@10 129 bench_dotens2(vecsza, szb, &k.k);
Chris@10 130 }
Chris@10 131
Chris@10 132 typedef struct {
Chris@10 133 dofft_closure k;
Chris@10 134 bench_problem *p;
Chris@10 135 } dofft_rdft2_closure;
Chris@10 136
Chris@10 137 static void rdft2_apply(dofft_closure *k_,
Chris@10 138 bench_complex *in, bench_complex *out)
Chris@10 139 {
Chris@10 140 dofft_rdft2_closure *k = (dofft_rdft2_closure *)k_;
Chris@10 141 bench_problem *p = k->p;
Chris@10 142 bench_tensor *totalsz, *pckdsz, *totalsz_swap, *pckdsz_swap;
Chris@10 143 bench_tensor *probsz2, *totalsz2, *pckdsz2;
Chris@10 144 bench_tensor *probsz2_swap, *totalsz2_swap, *pckdsz2_swap;
Chris@10 145 bench_real *ri, *ii, *ro, *io;
Chris@10 146 int n2, totalscale;
Chris@10 147
Chris@10 148 totalsz = tensor_append(p->vecsz, p->sz);
Chris@10 149 pckdsz = verify_pack(totalsz, 2);
Chris@10 150 n2 = tensor_sz(totalsz);
Chris@10 151 if (FINITE_RNK(p->sz->rnk) && p->sz->rnk > 0)
Chris@10 152 n2 = (n2 / p->sz->dims[p->sz->rnk - 1].n) *
Chris@10 153 (p->sz->dims[p->sz->rnk - 1].n / 2 + 1);
Chris@10 154 ri = (bench_real *) p->in;
Chris@10 155 ro = (bench_real *) p->out;
Chris@10 156
Chris@10 157 if (FINITE_RNK(p->sz->rnk) && p->sz->rnk > 0 && n2 > 0) {
Chris@10 158 probsz2 = tensor_copy_sub(p->sz, p->sz->rnk - 1, 1);
Chris@10 159 totalsz2 = tensor_copy_sub(totalsz, 0, totalsz->rnk - 1);
Chris@10 160 pckdsz2 = tensor_copy_sub(pckdsz, 0, pckdsz->rnk - 1);
Chris@10 161 }
Chris@10 162 else {
Chris@10 163 probsz2 = mktensor(0);
Chris@10 164 totalsz2 = tensor_copy(totalsz);
Chris@10 165 pckdsz2 = tensor_copy(pckdsz);
Chris@10 166 }
Chris@10 167
Chris@10 168 totalsz_swap = tensor_copy_swapio(totalsz);
Chris@10 169 pckdsz_swap = tensor_copy_swapio(pckdsz);
Chris@10 170 totalsz2_swap = tensor_copy_swapio(totalsz2);
Chris@10 171 pckdsz2_swap = tensor_copy_swapio(pckdsz2);
Chris@10 172 probsz2_swap = tensor_copy_swapio(probsz2);
Chris@10 173
Chris@10 174 /* confusion: the stride is the distance between complex elements
Chris@10 175 when using interleaved format, but it is the distance between
Chris@10 176 real elements when using split format */
Chris@10 177 if (p->split) {
Chris@10 178 ii = p->ini ? (bench_real *) p->ini : ri + n2;
Chris@10 179 io = p->outi ? (bench_real *) p->outi : ro + n2;
Chris@10 180 totalscale = 1;
Chris@10 181 } else {
Chris@10 182 ii = p->ini ? (bench_real *) p->ini : ri + 1;
Chris@10 183 io = p->outi ? (bench_real *) p->outi : ro + 1;
Chris@10 184 totalscale = 2;
Chris@10 185 }
Chris@10 186
Chris@10 187 if (p->sign < 0) { /* R2HC */
Chris@10 188 int N, vN, i;
Chris@10 189 cpyr(&c_re(in[0]), pckdsz, ri, totalsz);
Chris@10 190 after_problem_rcopy_from(p, ri);
Chris@10 191 doit(1, p);
Chris@10 192 after_problem_hccopy_to(p, ro, io);
Chris@10 193 if (k->k.recopy_input)
Chris@10 194 cpyr(ri, totalsz_swap, &c_re(in[0]), pckdsz_swap);
Chris@10 195 cpyhc2(ro, io, probsz2, totalsz2, totalscale,
Chris@10 196 &c_re(out[0]), &c_im(out[0]), pckdsz2);
Chris@10 197 N = tensor_sz(p->sz);
Chris@10 198 vN = tensor_sz(p->vecsz);
Chris@10 199 for (i = 0; i < vN; ++i)
Chris@10 200 mkhermitian(out + i*N, p->sz->rnk, p->sz->dims, 1);
Chris@10 201 }
Chris@10 202 else { /* HC2R */
Chris@10 203 icpyhc2(ri, ii, probsz2, totalsz2, totalscale,
Chris@10 204 &c_re(in[0]), &c_im(in[0]), pckdsz2);
Chris@10 205 after_problem_hccopy_from(p, ri, ii);
Chris@10 206 doit(1, p);
Chris@10 207 after_problem_rcopy_to(p, ro);
Chris@10 208 if (k->k.recopy_input)
Chris@10 209 cpyhc2(ri, ii, probsz2_swap, totalsz2_swap, totalscale,
Chris@10 210 &c_re(in[0]), &c_im(in[0]), pckdsz2_swap);
Chris@10 211 mkreal(out, tensor_sz(pckdsz));
Chris@10 212 cpyr(ro, totalsz, &c_re(out[0]), pckdsz);
Chris@10 213 }
Chris@10 214
Chris@10 215 tensor_destroy(totalsz);
Chris@10 216 tensor_destroy(pckdsz);
Chris@10 217 tensor_destroy(totalsz_swap);
Chris@10 218 tensor_destroy(pckdsz_swap);
Chris@10 219 tensor_destroy(probsz2);
Chris@10 220 tensor_destroy(totalsz2);
Chris@10 221 tensor_destroy(pckdsz2);
Chris@10 222 tensor_destroy(probsz2_swap);
Chris@10 223 tensor_destroy(totalsz2_swap);
Chris@10 224 tensor_destroy(pckdsz2_swap);
Chris@10 225 }
Chris@10 226
Chris@10 227 void verify_rdft2(bench_problem *p, int rounds, double tol, errors *e)
Chris@10 228 {
Chris@10 229 C *inA, *inB, *inC, *outA, *outB, *outC, *tmp;
Chris@10 230 int n, vecn, N;
Chris@10 231 dofft_rdft2_closure k;
Chris@10 232
Chris@10 233 BENCH_ASSERT(p->kind == PROBLEM_REAL);
Chris@10 234
Chris@10 235 if (!FINITE_RNK(p->sz->rnk) || !FINITE_RNK(p->vecsz->rnk))
Chris@10 236 return; /* give up */
Chris@10 237
Chris@10 238 k.k.apply = rdft2_apply;
Chris@10 239 k.k.recopy_input = 0;
Chris@10 240 k.p = p;
Chris@10 241
Chris@10 242 if (rounds == 0)
Chris@10 243 rounds = 20; /* default value */
Chris@10 244
Chris@10 245 n = tensor_sz(p->sz);
Chris@10 246 vecn = tensor_sz(p->vecsz);
Chris@10 247 N = n * vecn;
Chris@10 248
Chris@10 249 inA = (C *) bench_malloc(N * sizeof(C));
Chris@10 250 inB = (C *) bench_malloc(N * sizeof(C));
Chris@10 251 inC = (C *) bench_malloc(N * sizeof(C));
Chris@10 252 outA = (C *) bench_malloc(N * sizeof(C));
Chris@10 253 outB = (C *) bench_malloc(N * sizeof(C));
Chris@10 254 outC = (C *) bench_malloc(N * sizeof(C));
Chris@10 255 tmp = (C *) bench_malloc(N * sizeof(C));
Chris@10 256
Chris@10 257 e->i = impulse(&k.k, n, vecn, inA, inB, inC, outA, outB, outC,
Chris@10 258 tmp, rounds, tol);
Chris@10 259 e->l = linear(&k.k, 1, N, inA, inB, inC, outA, outB, outC,
Chris@10 260 tmp, rounds, tol);
Chris@10 261
Chris@10 262 e->s = 0.0;
Chris@10 263 if (p->sign < 0)
Chris@10 264 e->s = dmax(e->s, tf_shift(&k.k, 1, p->sz, n, vecn, p->sign,
Chris@10 265 inA, inB, outA, outB,
Chris@10 266 tmp, rounds, tol, TIME_SHIFT));
Chris@10 267 else
Chris@10 268 e->s = dmax(e->s, tf_shift(&k.k, 1, p->sz, n, vecn, p->sign,
Chris@10 269 inA, inB, outA, outB,
Chris@10 270 tmp, rounds, tol, FREQ_SHIFT));
Chris@10 271
Chris@10 272 if (!p->in_place && !p->destroy_input)
Chris@10 273 preserves_input(&k.k, p->sign < 0 ? mkreal : mkhermitian1,
Chris@10 274 N, inA, inB, outB, rounds);
Chris@10 275
Chris@10 276 bench_free(tmp);
Chris@10 277 bench_free(outC);
Chris@10 278 bench_free(outB);
Chris@10 279 bench_free(outA);
Chris@10 280 bench_free(inC);
Chris@10 281 bench_free(inB);
Chris@10 282 bench_free(inA);
Chris@10 283 }
Chris@10 284
Chris@10 285 void accuracy_rdft2(bench_problem *p, int rounds, int impulse_rounds,
Chris@10 286 double t[6])
Chris@10 287 {
Chris@10 288 dofft_rdft2_closure k;
Chris@10 289 int n;
Chris@10 290 C *a, *b;
Chris@10 291
Chris@10 292 BENCH_ASSERT(p->kind == PROBLEM_REAL);
Chris@10 293 BENCH_ASSERT(p->sz->rnk == 1);
Chris@10 294 BENCH_ASSERT(p->vecsz->rnk == 0);
Chris@10 295
Chris@10 296 k.k.apply = rdft2_apply;
Chris@10 297 k.k.recopy_input = 0;
Chris@10 298 k.p = p;
Chris@10 299 n = tensor_sz(p->sz);
Chris@10 300
Chris@10 301 a = (C *) bench_malloc(n * sizeof(C));
Chris@10 302 b = (C *) bench_malloc(n * sizeof(C));
Chris@10 303 accuracy_test(&k.k, p->sign < 0 ? mkreal : mkhermitian1, p->sign,
Chris@10 304 n, a, b, rounds, impulse_rounds, t);
Chris@10 305 bench_free(b);
Chris@10 306 bench_free(a);
Chris@10 307 }