annotate fft/fftw/fftw-3.3.4/libbench2/verify-dft.c @ 40:223f770b5341 kissfft-double tip

Try a double-precision kissfft
author Chris Cannam
date Wed, 07 Sep 2016 10:40:32 +0100
parents 26056e866c29
children
rev   line source
Chris@19 1 /*
Chris@19 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
Chris@19 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
Chris@19 4 *
Chris@19 5 * This program is free software; you can redistribute it and/or modify
Chris@19 6 * it under the terms of the GNU General Public License as published by
Chris@19 7 * the Free Software Foundation; either version 2 of the License, or
Chris@19 8 * (at your option) any later version.
Chris@19 9 *
Chris@19 10 * This program is distributed in the hope that it will be useful,
Chris@19 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@19 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@19 13 * GNU General Public License for more details.
Chris@19 14 *
Chris@19 15 * You should have received a copy of the GNU General Public License
Chris@19 16 * along with this program; if not, write to the Free Software
Chris@19 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@19 18 *
Chris@19 19 */
Chris@19 20
Chris@19 21
Chris@19 22 #include "verify.h"
Chris@19 23
Chris@19 24 /* copy A into B, using output stride of A and input stride of B */
Chris@19 25 typedef struct {
Chris@19 26 dotens2_closure k;
Chris@19 27 R *ra; R *ia;
Chris@19 28 R *rb; R *ib;
Chris@19 29 int scalea, scaleb;
Chris@19 30 } cpy_closure;
Chris@19 31
Chris@19 32 static void cpy0(dotens2_closure *k_,
Chris@19 33 int indxa, int ondxa, int indxb, int ondxb)
Chris@19 34 {
Chris@19 35 cpy_closure *k = (cpy_closure *)k_;
Chris@19 36 k->rb[indxb * k->scaleb] = k->ra[ondxa * k->scalea];
Chris@19 37 k->ib[indxb * k->scaleb] = k->ia[ondxa * k->scalea];
Chris@19 38 UNUSED(indxa); UNUSED(ondxb);
Chris@19 39 }
Chris@19 40
Chris@19 41 static void cpy(R *ra, R *ia, const bench_tensor *sza, int scalea,
Chris@19 42 R *rb, R *ib, const bench_tensor *szb, int scaleb)
Chris@19 43 {
Chris@19 44 cpy_closure k;
Chris@19 45 k.k.apply = cpy0;
Chris@19 46 k.ra = ra; k.ia = ia; k.rb = rb; k.ib = ib;
Chris@19 47 k.scalea = scalea; k.scaleb = scaleb;
Chris@19 48 bench_dotens2(sza, szb, &k.k);
Chris@19 49 }
Chris@19 50
Chris@19 51 typedef struct {
Chris@19 52 dofft_closure k;
Chris@19 53 bench_problem *p;
Chris@19 54 } dofft_dft_closure;
Chris@19 55
Chris@19 56 static void dft_apply(dofft_closure *k_, bench_complex *in, bench_complex *out)
Chris@19 57 {
Chris@19 58 dofft_dft_closure *k = (dofft_dft_closure *)k_;
Chris@19 59 bench_problem *p = k->p;
Chris@19 60 bench_tensor *totalsz, *pckdsz;
Chris@19 61 bench_tensor *totalsz_swap, *pckdsz_swap;
Chris@19 62 bench_real *ri, *ii, *ro, *io;
Chris@19 63 int totalscale;
Chris@19 64
Chris@19 65 totalsz = tensor_append(p->vecsz, p->sz);
Chris@19 66 pckdsz = verify_pack(totalsz, 2);
Chris@19 67 ri = (bench_real *) p->in;
Chris@19 68 ro = (bench_real *) p->out;
Chris@19 69
Chris@19 70 totalsz_swap = tensor_copy_swapio(totalsz);
Chris@19 71 pckdsz_swap = tensor_copy_swapio(pckdsz);
Chris@19 72
Chris@19 73 /* confusion: the stride is the distance between complex elements
Chris@19 74 when using interleaved format, but it is the distance between
Chris@19 75 real elements when using split format */
Chris@19 76 if (p->split) {
Chris@19 77 ii = p->ini ? (bench_real *) p->ini : ri + p->iphyssz;
Chris@19 78 io = p->outi ? (bench_real *) p->outi : ro + p->ophyssz;
Chris@19 79 totalscale = 1;
Chris@19 80 } else {
Chris@19 81 ii = p->ini ? (bench_real *) p->ini : ri + 1;
Chris@19 82 io = p->outi ? (bench_real *) p->outi : ro + 1;
Chris@19 83 totalscale = 2;
Chris@19 84 }
Chris@19 85
Chris@19 86 cpy(&c_re(in[0]), &c_im(in[0]), pckdsz, 1,
Chris@19 87 ri, ii, totalsz, totalscale);
Chris@19 88 after_problem_ccopy_from(p, ri, ii);
Chris@19 89 doit(1, p);
Chris@19 90 after_problem_ccopy_to(p, ro, io);
Chris@19 91 if (k->k.recopy_input)
Chris@19 92 cpy(ri, ii, totalsz_swap, totalscale,
Chris@19 93 &c_re(in[0]), &c_im(in[0]), pckdsz_swap, 1);
Chris@19 94 cpy(ro, io, totalsz, totalscale,
Chris@19 95 &c_re(out[0]), &c_im(out[0]), pckdsz, 1);
Chris@19 96
Chris@19 97 tensor_destroy(totalsz);
Chris@19 98 tensor_destroy(pckdsz);
Chris@19 99 tensor_destroy(totalsz_swap);
Chris@19 100 tensor_destroy(pckdsz_swap);
Chris@19 101 }
Chris@19 102
Chris@19 103 void verify_dft(bench_problem *p, int rounds, double tol, errors *e)
Chris@19 104 {
Chris@19 105 C *inA, *inB, *inC, *outA, *outB, *outC, *tmp;
Chris@19 106 int n, vecn, N;
Chris@19 107 dofft_dft_closure k;
Chris@19 108
Chris@19 109 BENCH_ASSERT(p->kind == PROBLEM_COMPLEX);
Chris@19 110
Chris@19 111 k.k.apply = dft_apply;
Chris@19 112 k.k.recopy_input = 0;
Chris@19 113 k.p = p;
Chris@19 114
Chris@19 115 if (rounds == 0)
Chris@19 116 rounds = 20; /* default value */
Chris@19 117
Chris@19 118 n = tensor_sz(p->sz);
Chris@19 119 vecn = tensor_sz(p->vecsz);
Chris@19 120 N = n * vecn;
Chris@19 121
Chris@19 122 inA = (C *) bench_malloc(N * sizeof(C));
Chris@19 123 inB = (C *) bench_malloc(N * sizeof(C));
Chris@19 124 inC = (C *) bench_malloc(N * sizeof(C));
Chris@19 125 outA = (C *) bench_malloc(N * sizeof(C));
Chris@19 126 outB = (C *) bench_malloc(N * sizeof(C));
Chris@19 127 outC = (C *) bench_malloc(N * sizeof(C));
Chris@19 128 tmp = (C *) bench_malloc(N * sizeof(C));
Chris@19 129
Chris@19 130 e->i = impulse(&k.k, n, vecn, inA, inB, inC, outA, outB, outC,
Chris@19 131 tmp, rounds, tol);
Chris@19 132 e->l = linear(&k.k, 0, N, inA, inB, inC, outA, outB, outC,
Chris@19 133 tmp, rounds, tol);
Chris@19 134
Chris@19 135 e->s = 0.0;
Chris@19 136 e->s = dmax(e->s, tf_shift(&k.k, 0, p->sz, n, vecn, p->sign,
Chris@19 137 inA, inB, outA, outB,
Chris@19 138 tmp, rounds, tol, TIME_SHIFT));
Chris@19 139 e->s = dmax(e->s, tf_shift(&k.k, 0, p->sz, n, vecn, p->sign,
Chris@19 140 inA, inB, outA, outB,
Chris@19 141 tmp, rounds, tol, FREQ_SHIFT));
Chris@19 142
Chris@19 143 if (!p->in_place && !p->destroy_input)
Chris@19 144 preserves_input(&k.k, 0, N, inA, inB, outB, rounds);
Chris@19 145
Chris@19 146 bench_free(tmp);
Chris@19 147 bench_free(outC);
Chris@19 148 bench_free(outB);
Chris@19 149 bench_free(outA);
Chris@19 150 bench_free(inC);
Chris@19 151 bench_free(inB);
Chris@19 152 bench_free(inA);
Chris@19 153 }
Chris@19 154
Chris@19 155
Chris@19 156 void accuracy_dft(bench_problem *p, int rounds, int impulse_rounds,
Chris@19 157 double t[6])
Chris@19 158 {
Chris@19 159 dofft_dft_closure k;
Chris@19 160 int n;
Chris@19 161 C *a, *b;
Chris@19 162
Chris@19 163 BENCH_ASSERT(p->kind == PROBLEM_COMPLEX);
Chris@19 164 BENCH_ASSERT(p->sz->rnk == 1);
Chris@19 165 BENCH_ASSERT(p->vecsz->rnk == 0);
Chris@19 166
Chris@19 167 k.k.apply = dft_apply;
Chris@19 168 k.k.recopy_input = 0;
Chris@19 169 k.p = p;
Chris@19 170 n = tensor_sz(p->sz);
Chris@19 171
Chris@19 172 a = (C *) bench_malloc(n * sizeof(C));
Chris@19 173 b = (C *) bench_malloc(n * sizeof(C));
Chris@19 174 accuracy_test(&k.k, 0, p->sign, n, a, b, rounds, impulse_rounds, t);
Chris@19 175 bench_free(b);
Chris@19 176 bench_free(a);
Chris@19 177 }