annotate src/fftw-3.3.3/libbench2/verify-dft.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 A into 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; R *ia;
Chris@10 28 R *rb; R *ib;
Chris@10 29 int scalea, scaleb;
Chris@10 30 } cpy_closure;
Chris@10 31
Chris@10 32 static void cpy0(dotens2_closure *k_,
Chris@10 33 int indxa, int ondxa, int indxb, int ondxb)
Chris@10 34 {
Chris@10 35 cpy_closure *k = (cpy_closure *)k_;
Chris@10 36 k->rb[indxb * k->scaleb] = k->ra[ondxa * k->scalea];
Chris@10 37 k->ib[indxb * k->scaleb] = k->ia[ondxa * k->scalea];
Chris@10 38 UNUSED(indxa); UNUSED(ondxb);
Chris@10 39 }
Chris@10 40
Chris@10 41 static void cpy(R *ra, R *ia, const bench_tensor *sza, int scalea,
Chris@10 42 R *rb, R *ib, const bench_tensor *szb, int scaleb)
Chris@10 43 {
Chris@10 44 cpy_closure k;
Chris@10 45 k.k.apply = cpy0;
Chris@10 46 k.ra = ra; k.ia = ia; k.rb = rb; k.ib = ib;
Chris@10 47 k.scalea = scalea; k.scaleb = scaleb;
Chris@10 48 bench_dotens2(sza, szb, &k.k);
Chris@10 49 }
Chris@10 50
Chris@10 51 typedef struct {
Chris@10 52 dofft_closure k;
Chris@10 53 bench_problem *p;
Chris@10 54 } dofft_dft_closure;
Chris@10 55
Chris@10 56 static void dft_apply(dofft_closure *k_, bench_complex *in, bench_complex *out)
Chris@10 57 {
Chris@10 58 dofft_dft_closure *k = (dofft_dft_closure *)k_;
Chris@10 59 bench_problem *p = k->p;
Chris@10 60 bench_tensor *totalsz, *pckdsz;
Chris@10 61 bench_tensor *totalsz_swap, *pckdsz_swap;
Chris@10 62 bench_real *ri, *ii, *ro, *io;
Chris@10 63 int totalscale;
Chris@10 64
Chris@10 65 totalsz = tensor_append(p->vecsz, p->sz);
Chris@10 66 pckdsz = verify_pack(totalsz, 2);
Chris@10 67 ri = (bench_real *) p->in;
Chris@10 68 ro = (bench_real *) p->out;
Chris@10 69
Chris@10 70 totalsz_swap = tensor_copy_swapio(totalsz);
Chris@10 71 pckdsz_swap = tensor_copy_swapio(pckdsz);
Chris@10 72
Chris@10 73 /* confusion: the stride is the distance between complex elements
Chris@10 74 when using interleaved format, but it is the distance between
Chris@10 75 real elements when using split format */
Chris@10 76 if (p->split) {
Chris@10 77 ii = p->ini ? (bench_real *) p->ini : ri + p->iphyssz;
Chris@10 78 io = p->outi ? (bench_real *) p->outi : ro + p->ophyssz;
Chris@10 79 totalscale = 1;
Chris@10 80 } else {
Chris@10 81 ii = p->ini ? (bench_real *) p->ini : ri + 1;
Chris@10 82 io = p->outi ? (bench_real *) p->outi : ro + 1;
Chris@10 83 totalscale = 2;
Chris@10 84 }
Chris@10 85
Chris@10 86 cpy(&c_re(in[0]), &c_im(in[0]), pckdsz, 1,
Chris@10 87 ri, ii, totalsz, totalscale);
Chris@10 88 after_problem_ccopy_from(p, ri, ii);
Chris@10 89 doit(1, p);
Chris@10 90 after_problem_ccopy_to(p, ro, io);
Chris@10 91 if (k->k.recopy_input)
Chris@10 92 cpy(ri, ii, totalsz_swap, totalscale,
Chris@10 93 &c_re(in[0]), &c_im(in[0]), pckdsz_swap, 1);
Chris@10 94 cpy(ro, io, totalsz, totalscale,
Chris@10 95 &c_re(out[0]), &c_im(out[0]), pckdsz, 1);
Chris@10 96
Chris@10 97 tensor_destroy(totalsz);
Chris@10 98 tensor_destroy(pckdsz);
Chris@10 99 tensor_destroy(totalsz_swap);
Chris@10 100 tensor_destroy(pckdsz_swap);
Chris@10 101 }
Chris@10 102
Chris@10 103 void verify_dft(bench_problem *p, int rounds, double tol, errors *e)
Chris@10 104 {
Chris@10 105 C *inA, *inB, *inC, *outA, *outB, *outC, *tmp;
Chris@10 106 int n, vecn, N;
Chris@10 107 dofft_dft_closure k;
Chris@10 108
Chris@10 109 BENCH_ASSERT(p->kind == PROBLEM_COMPLEX);
Chris@10 110
Chris@10 111 k.k.apply = dft_apply;
Chris@10 112 k.k.recopy_input = 0;
Chris@10 113 k.p = p;
Chris@10 114
Chris@10 115 if (rounds == 0)
Chris@10 116 rounds = 20; /* default value */
Chris@10 117
Chris@10 118 n = tensor_sz(p->sz);
Chris@10 119 vecn = tensor_sz(p->vecsz);
Chris@10 120 N = n * vecn;
Chris@10 121
Chris@10 122 inA = (C *) bench_malloc(N * sizeof(C));
Chris@10 123 inB = (C *) bench_malloc(N * sizeof(C));
Chris@10 124 inC = (C *) bench_malloc(N * sizeof(C));
Chris@10 125 outA = (C *) bench_malloc(N * sizeof(C));
Chris@10 126 outB = (C *) bench_malloc(N * sizeof(C));
Chris@10 127 outC = (C *) bench_malloc(N * sizeof(C));
Chris@10 128 tmp = (C *) bench_malloc(N * sizeof(C));
Chris@10 129
Chris@10 130 e->i = impulse(&k.k, n, vecn, inA, inB, inC, outA, outB, outC,
Chris@10 131 tmp, rounds, tol);
Chris@10 132 e->l = linear(&k.k, 0, N, inA, inB, inC, outA, outB, outC,
Chris@10 133 tmp, rounds, tol);
Chris@10 134
Chris@10 135 e->s = 0.0;
Chris@10 136 e->s = dmax(e->s, tf_shift(&k.k, 0, p->sz, n, vecn, p->sign,
Chris@10 137 inA, inB, outA, outB,
Chris@10 138 tmp, rounds, tol, TIME_SHIFT));
Chris@10 139 e->s = dmax(e->s, tf_shift(&k.k, 0, p->sz, n, vecn, p->sign,
Chris@10 140 inA, inB, outA, outB,
Chris@10 141 tmp, rounds, tol, FREQ_SHIFT));
Chris@10 142
Chris@10 143 if (!p->in_place && !p->destroy_input)
Chris@10 144 preserves_input(&k.k, 0, N, inA, inB, outB, rounds);
Chris@10 145
Chris@10 146 bench_free(tmp);
Chris@10 147 bench_free(outC);
Chris@10 148 bench_free(outB);
Chris@10 149 bench_free(outA);
Chris@10 150 bench_free(inC);
Chris@10 151 bench_free(inB);
Chris@10 152 bench_free(inA);
Chris@10 153 }
Chris@10 154
Chris@10 155
Chris@10 156 void accuracy_dft(bench_problem *p, int rounds, int impulse_rounds,
Chris@10 157 double t[6])
Chris@10 158 {
Chris@10 159 dofft_dft_closure k;
Chris@10 160 int n;
Chris@10 161 C *a, *b;
Chris@10 162
Chris@10 163 BENCH_ASSERT(p->kind == PROBLEM_COMPLEX);
Chris@10 164 BENCH_ASSERT(p->sz->rnk == 1);
Chris@10 165 BENCH_ASSERT(p->vecsz->rnk == 0);
Chris@10 166
Chris@10 167 k.k.apply = dft_apply;
Chris@10 168 k.k.recopy_input = 0;
Chris@10 169 k.p = p;
Chris@10 170 n = tensor_sz(p->sz);
Chris@10 171
Chris@10 172 a = (C *) bench_malloc(n * sizeof(C));
Chris@10 173 b = (C *) bench_malloc(n * sizeof(C));
Chris@10 174 accuracy_test(&k.k, 0, p->sign, n, a, b, rounds, impulse_rounds, t);
Chris@10 175 bench_free(b);
Chris@10 176 bench_free(a);
Chris@10 177 }