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