Chris@10: /* Chris@10: * Copyright (c) 2003, 2007-11 Matteo Frigo Chris@10: * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology Chris@10: * Chris@10: * This program is free software; you can redistribute it and/or modify Chris@10: * it under the terms of the GNU General Public License as published by Chris@10: * the Free Software Foundation; either version 2 of the License, or Chris@10: * (at your option) any later version. Chris@10: * Chris@10: * This program is distributed in the hope that it will be useful, Chris@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@10: * GNU General Public License for more details. Chris@10: * Chris@10: * You should have received a copy of the GNU General Public License Chris@10: * along with this program; if not, write to the Free Software Chris@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Chris@10: * Chris@10: */ Chris@10: Chris@10: Chris@10: #include "verify.h" Chris@10: Chris@10: /* copy A into B, using output stride of A and input stride of B */ Chris@10: typedef struct { Chris@10: dotens2_closure k; Chris@10: R *ra; R *ia; Chris@10: R *rb; R *ib; Chris@10: int scalea, scaleb; Chris@10: } cpy_closure; Chris@10: Chris@10: static void cpy0(dotens2_closure *k_, Chris@10: int indxa, int ondxa, int indxb, int ondxb) Chris@10: { Chris@10: cpy_closure *k = (cpy_closure *)k_; Chris@10: k->rb[indxb * k->scaleb] = k->ra[ondxa * k->scalea]; Chris@10: k->ib[indxb * k->scaleb] = k->ia[ondxa * k->scalea]; Chris@10: UNUSED(indxa); UNUSED(ondxb); Chris@10: } Chris@10: Chris@10: static void cpy(R *ra, R *ia, const bench_tensor *sza, int scalea, Chris@10: R *rb, R *ib, const bench_tensor *szb, int scaleb) Chris@10: { Chris@10: cpy_closure k; Chris@10: k.k.apply = cpy0; Chris@10: k.ra = ra; k.ia = ia; k.rb = rb; k.ib = ib; Chris@10: k.scalea = scalea; k.scaleb = scaleb; Chris@10: bench_dotens2(sza, szb, &k.k); Chris@10: } Chris@10: Chris@10: typedef struct { Chris@10: dofft_closure k; Chris@10: bench_problem *p; Chris@10: } dofft_dft_closure; Chris@10: Chris@10: static void dft_apply(dofft_closure *k_, bench_complex *in, bench_complex *out) Chris@10: { Chris@10: dofft_dft_closure *k = (dofft_dft_closure *)k_; Chris@10: bench_problem *p = k->p; Chris@10: bench_tensor *totalsz, *pckdsz; Chris@10: bench_tensor *totalsz_swap, *pckdsz_swap; Chris@10: bench_real *ri, *ii, *ro, *io; Chris@10: int totalscale; Chris@10: Chris@10: totalsz = tensor_append(p->vecsz, p->sz); Chris@10: pckdsz = verify_pack(totalsz, 2); Chris@10: ri = (bench_real *) p->in; Chris@10: ro = (bench_real *) p->out; Chris@10: Chris@10: totalsz_swap = tensor_copy_swapio(totalsz); Chris@10: pckdsz_swap = tensor_copy_swapio(pckdsz); Chris@10: Chris@10: /* confusion: the stride is the distance between complex elements Chris@10: when using interleaved format, but it is the distance between Chris@10: real elements when using split format */ Chris@10: if (p->split) { Chris@10: ii = p->ini ? (bench_real *) p->ini : ri + p->iphyssz; Chris@10: io = p->outi ? (bench_real *) p->outi : ro + p->ophyssz; Chris@10: totalscale = 1; Chris@10: } else { Chris@10: ii = p->ini ? (bench_real *) p->ini : ri + 1; Chris@10: io = p->outi ? (bench_real *) p->outi : ro + 1; Chris@10: totalscale = 2; Chris@10: } Chris@10: Chris@10: cpy(&c_re(in[0]), &c_im(in[0]), pckdsz, 1, Chris@10: ri, ii, totalsz, totalscale); Chris@10: after_problem_ccopy_from(p, ri, ii); Chris@10: doit(1, p); Chris@10: after_problem_ccopy_to(p, ro, io); Chris@10: if (k->k.recopy_input) Chris@10: cpy(ri, ii, totalsz_swap, totalscale, Chris@10: &c_re(in[0]), &c_im(in[0]), pckdsz_swap, 1); Chris@10: cpy(ro, io, totalsz, totalscale, Chris@10: &c_re(out[0]), &c_im(out[0]), pckdsz, 1); Chris@10: Chris@10: tensor_destroy(totalsz); Chris@10: tensor_destroy(pckdsz); Chris@10: tensor_destroy(totalsz_swap); Chris@10: tensor_destroy(pckdsz_swap); Chris@10: } Chris@10: Chris@10: void verify_dft(bench_problem *p, int rounds, double tol, errors *e) Chris@10: { Chris@10: C *inA, *inB, *inC, *outA, *outB, *outC, *tmp; Chris@10: int n, vecn, N; Chris@10: dofft_dft_closure k; Chris@10: Chris@10: BENCH_ASSERT(p->kind == PROBLEM_COMPLEX); Chris@10: Chris@10: k.k.apply = dft_apply; Chris@10: k.k.recopy_input = 0; Chris@10: k.p = p; Chris@10: Chris@10: if (rounds == 0) Chris@10: rounds = 20; /* default value */ Chris@10: Chris@10: n = tensor_sz(p->sz); Chris@10: vecn = tensor_sz(p->vecsz); Chris@10: N = n * vecn; Chris@10: Chris@10: inA = (C *) bench_malloc(N * sizeof(C)); Chris@10: inB = (C *) bench_malloc(N * sizeof(C)); Chris@10: inC = (C *) bench_malloc(N * sizeof(C)); Chris@10: outA = (C *) bench_malloc(N * sizeof(C)); Chris@10: outB = (C *) bench_malloc(N * sizeof(C)); Chris@10: outC = (C *) bench_malloc(N * sizeof(C)); Chris@10: tmp = (C *) bench_malloc(N * sizeof(C)); Chris@10: Chris@10: e->i = impulse(&k.k, n, vecn, inA, inB, inC, outA, outB, outC, Chris@10: tmp, rounds, tol); Chris@10: e->l = linear(&k.k, 0, N, inA, inB, inC, outA, outB, outC, Chris@10: tmp, rounds, tol); Chris@10: Chris@10: e->s = 0.0; Chris@10: e->s = dmax(e->s, tf_shift(&k.k, 0, p->sz, n, vecn, p->sign, Chris@10: inA, inB, outA, outB, Chris@10: tmp, rounds, tol, TIME_SHIFT)); Chris@10: e->s = dmax(e->s, tf_shift(&k.k, 0, p->sz, n, vecn, p->sign, Chris@10: inA, inB, outA, outB, Chris@10: tmp, rounds, tol, FREQ_SHIFT)); Chris@10: Chris@10: if (!p->in_place && !p->destroy_input) Chris@10: preserves_input(&k.k, 0, N, inA, inB, outB, rounds); Chris@10: Chris@10: bench_free(tmp); Chris@10: bench_free(outC); Chris@10: bench_free(outB); Chris@10: bench_free(outA); Chris@10: bench_free(inC); Chris@10: bench_free(inB); Chris@10: bench_free(inA); Chris@10: } Chris@10: Chris@10: Chris@10: void accuracy_dft(bench_problem *p, int rounds, int impulse_rounds, Chris@10: double t[6]) Chris@10: { Chris@10: dofft_dft_closure k; Chris@10: int n; Chris@10: C *a, *b; Chris@10: Chris@10: BENCH_ASSERT(p->kind == PROBLEM_COMPLEX); Chris@10: BENCH_ASSERT(p->sz->rnk == 1); Chris@10: BENCH_ASSERT(p->vecsz->rnk == 0); Chris@10: Chris@10: k.k.apply = dft_apply; Chris@10: k.k.recopy_input = 0; Chris@10: k.p = p; Chris@10: n = tensor_sz(p->sz); Chris@10: Chris@10: a = (C *) bench_malloc(n * sizeof(C)); Chris@10: b = (C *) bench_malloc(n * sizeof(C)); Chris@10: accuracy_test(&k.k, 0, p->sign, n, a, b, rounds, impulse_rounds, t); Chris@10: bench_free(b); Chris@10: bench_free(a); Chris@10: }