Chris@82: /* Chris@82: * Copyright (c) 2003, 2007-14 Matteo Frigo Chris@82: * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology Chris@82: * Chris@82: * This program is free software; you can redistribute it and/or modify Chris@82: * it under the terms of the GNU General Public License as published by Chris@82: * the Free Software Foundation; either version 2 of the License, or Chris@82: * (at your option) any later version. Chris@82: * Chris@82: * This program is distributed in the hope that it will be useful, Chris@82: * but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@82: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@82: * GNU General Public License for more details. Chris@82: * Chris@82: * You should have received a copy of the GNU General Public License Chris@82: * along with this program; if not, write to the Free Software Chris@82: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Chris@82: * Chris@82: */ Chris@82: Chris@82: Chris@82: #include "verify.h" Chris@82: Chris@82: /* copy real A into real B, using output stride of A and input stride of B */ Chris@82: typedef struct { Chris@82: dotens2_closure k; Chris@82: R *ra; Chris@82: R *rb; Chris@82: } cpyr_closure; Chris@82: Chris@82: static void cpyr0(dotens2_closure *k_, Chris@82: int indxa, int ondxa, int indxb, int ondxb) Chris@82: { Chris@82: cpyr_closure *k = (cpyr_closure *)k_; Chris@82: k->rb[indxb] = k->ra[ondxa]; Chris@82: UNUSED(indxa); UNUSED(ondxb); Chris@82: } Chris@82: Chris@82: static void cpyr(R *ra, const bench_tensor *sza, Chris@82: R *rb, const bench_tensor *szb) Chris@82: { Chris@82: cpyr_closure k; Chris@82: k.k.apply = cpyr0; Chris@82: k.ra = ra; k.rb = rb; Chris@82: bench_dotens2(sza, szb, &k.k); Chris@82: } Chris@82: Chris@82: /* copy unpacked halfcomplex A[n] into packed-complex B[n], using output stride Chris@82: of A and input stride of B. Only copies non-redundant half; other Chris@82: half must be copied via mkhermitian. */ Chris@82: typedef struct { Chris@82: dotens2_closure k; Chris@82: int n; Chris@82: int as; Chris@82: int scalea; Chris@82: R *ra, *ia; Chris@82: R *rb, *ib; Chris@82: } cpyhc2_closure; Chris@82: Chris@82: static void cpyhc20(dotens2_closure *k_, Chris@82: int indxa, int ondxa, int indxb, int ondxb) Chris@82: { Chris@82: cpyhc2_closure *k = (cpyhc2_closure *)k_; Chris@82: int i, n = k->n; Chris@82: int scalea = k->scalea; Chris@82: int as = k->as * scalea; Chris@82: R *ra = k->ra + ondxa * scalea, *ia = k->ia + ondxa * scalea; Chris@82: R *rb = k->rb + indxb, *ib = k->ib + indxb; Chris@82: UNUSED(indxa); UNUSED(ondxb); Chris@82: Chris@82: for (i = 0; i < n/2 + 1; ++i) { Chris@82: rb[2*i] = ra[as*i]; Chris@82: ib[2*i] = ia[as*i]; Chris@82: } Chris@82: } Chris@82: Chris@82: static void cpyhc2(R *ra, R *ia, Chris@82: const bench_tensor *sza, const bench_tensor *vecsza, Chris@82: int scalea, Chris@82: R *rb, R *ib, const bench_tensor *szb) Chris@82: { Chris@82: cpyhc2_closure k; Chris@82: BENCH_ASSERT(sza->rnk <= 1); Chris@82: k.k.apply = cpyhc20; Chris@82: k.n = tensor_sz(sza); Chris@82: k.scalea = scalea; Chris@82: if (!BENCH_FINITE_RNK(sza->rnk) || sza->rnk == 0) Chris@82: k.as = 0; Chris@82: else Chris@82: k.as = sza->dims[0].os; Chris@82: k.ra = ra; k.ia = ia; k.rb = rb; k.ib = ib; Chris@82: bench_dotens2(vecsza, szb, &k.k); Chris@82: } Chris@82: Chris@82: /* icpyhc2 is the inverse of cpyhc2 */ Chris@82: Chris@82: static void icpyhc20(dotens2_closure *k_, Chris@82: int indxa, int ondxa, int indxb, int ondxb) Chris@82: { Chris@82: cpyhc2_closure *k = (cpyhc2_closure *)k_; Chris@82: int i, n = k->n; Chris@82: int scalea = k->scalea; Chris@82: int as = k->as * scalea; Chris@82: R *ra = k->ra + indxa * scalea, *ia = k->ia + indxa * scalea; Chris@82: R *rb = k->rb + ondxb, *ib = k->ib + ondxb; Chris@82: UNUSED(ondxa); UNUSED(indxb); Chris@82: Chris@82: for (i = 0; i < n/2 + 1; ++i) { Chris@82: ra[as*i] = rb[2*i]; Chris@82: ia[as*i] = ib[2*i]; Chris@82: } Chris@82: } Chris@82: Chris@82: static void icpyhc2(R *ra, R *ia, Chris@82: const bench_tensor *sza, const bench_tensor *vecsza, Chris@82: int scalea, Chris@82: R *rb, R *ib, const bench_tensor *szb) Chris@82: { Chris@82: cpyhc2_closure k; Chris@82: BENCH_ASSERT(sza->rnk <= 1); Chris@82: k.k.apply = icpyhc20; Chris@82: k.n = tensor_sz(sza); Chris@82: k.scalea = scalea; Chris@82: if (!BENCH_FINITE_RNK(sza->rnk) || sza->rnk == 0) Chris@82: k.as = 0; Chris@82: else Chris@82: k.as = sza->dims[0].is; Chris@82: k.ra = ra; k.ia = ia; k.rb = rb; k.ib = ib; Chris@82: bench_dotens2(vecsza, szb, &k.k); Chris@82: } Chris@82: Chris@82: typedef struct { Chris@82: dofft_closure k; Chris@82: bench_problem *p; Chris@82: } dofft_rdft2_closure; Chris@82: Chris@82: static void rdft2_apply(dofft_closure *k_, Chris@82: bench_complex *in, bench_complex *out) Chris@82: { Chris@82: dofft_rdft2_closure *k = (dofft_rdft2_closure *)k_; Chris@82: bench_problem *p = k->p; Chris@82: bench_tensor *totalsz, *pckdsz, *totalsz_swap, *pckdsz_swap; Chris@82: bench_tensor *probsz2, *totalsz2, *pckdsz2; Chris@82: bench_tensor *probsz2_swap, *totalsz2_swap, *pckdsz2_swap; Chris@82: bench_real *ri, *ii, *ro, *io; Chris@82: int n2, totalscale; Chris@82: Chris@82: totalsz = tensor_append(p->vecsz, p->sz); Chris@82: pckdsz = verify_pack(totalsz, 2); Chris@82: n2 = tensor_sz(totalsz); Chris@82: if (BENCH_FINITE_RNK(p->sz->rnk) && p->sz->rnk > 0) Chris@82: n2 = (n2 / p->sz->dims[p->sz->rnk - 1].n) * Chris@82: (p->sz->dims[p->sz->rnk - 1].n / 2 + 1); Chris@82: ri = (bench_real *) p->in; Chris@82: ro = (bench_real *) p->out; Chris@82: Chris@82: if (BENCH_FINITE_RNK(p->sz->rnk) && p->sz->rnk > 0 && n2 > 0) { Chris@82: probsz2 = tensor_copy_sub(p->sz, p->sz->rnk - 1, 1); Chris@82: totalsz2 = tensor_copy_sub(totalsz, 0, totalsz->rnk - 1); Chris@82: pckdsz2 = tensor_copy_sub(pckdsz, 0, pckdsz->rnk - 1); Chris@82: } Chris@82: else { Chris@82: probsz2 = mktensor(0); Chris@82: totalsz2 = tensor_copy(totalsz); Chris@82: pckdsz2 = tensor_copy(pckdsz); Chris@82: } Chris@82: Chris@82: totalsz_swap = tensor_copy_swapio(totalsz); Chris@82: pckdsz_swap = tensor_copy_swapio(pckdsz); Chris@82: totalsz2_swap = tensor_copy_swapio(totalsz2); Chris@82: pckdsz2_swap = tensor_copy_swapio(pckdsz2); Chris@82: probsz2_swap = tensor_copy_swapio(probsz2); Chris@82: Chris@82: /* confusion: the stride is the distance between complex elements Chris@82: when using interleaved format, but it is the distance between Chris@82: real elements when using split format */ Chris@82: if (p->split) { Chris@82: ii = p->ini ? (bench_real *) p->ini : ri + n2; Chris@82: io = p->outi ? (bench_real *) p->outi : ro + n2; Chris@82: totalscale = 1; Chris@82: } else { Chris@82: ii = p->ini ? (bench_real *) p->ini : ri + 1; Chris@82: io = p->outi ? (bench_real *) p->outi : ro + 1; Chris@82: totalscale = 2; Chris@82: } Chris@82: Chris@82: if (p->sign < 0) { /* R2HC */ Chris@82: int N, vN, i; Chris@82: cpyr(&c_re(in[0]), pckdsz, ri, totalsz); Chris@82: after_problem_rcopy_from(p, ri); Chris@82: doit(1, p); Chris@82: after_problem_hccopy_to(p, ro, io); Chris@82: if (k->k.recopy_input) Chris@82: cpyr(ri, totalsz_swap, &c_re(in[0]), pckdsz_swap); Chris@82: cpyhc2(ro, io, probsz2, totalsz2, totalscale, Chris@82: &c_re(out[0]), &c_im(out[0]), pckdsz2); Chris@82: N = tensor_sz(p->sz); Chris@82: vN = tensor_sz(p->vecsz); Chris@82: for (i = 0; i < vN; ++i) Chris@82: mkhermitian(out + i*N, p->sz->rnk, p->sz->dims, 1); Chris@82: } Chris@82: else { /* HC2R */ Chris@82: icpyhc2(ri, ii, probsz2, totalsz2, totalscale, Chris@82: &c_re(in[0]), &c_im(in[0]), pckdsz2); Chris@82: after_problem_hccopy_from(p, ri, ii); Chris@82: doit(1, p); Chris@82: after_problem_rcopy_to(p, ro); Chris@82: if (k->k.recopy_input) Chris@82: cpyhc2(ri, ii, probsz2_swap, totalsz2_swap, totalscale, Chris@82: &c_re(in[0]), &c_im(in[0]), pckdsz2_swap); Chris@82: mkreal(out, tensor_sz(pckdsz)); Chris@82: cpyr(ro, totalsz, &c_re(out[0]), pckdsz); Chris@82: } Chris@82: Chris@82: tensor_destroy(totalsz); Chris@82: tensor_destroy(pckdsz); Chris@82: tensor_destroy(totalsz_swap); Chris@82: tensor_destroy(pckdsz_swap); Chris@82: tensor_destroy(probsz2); Chris@82: tensor_destroy(totalsz2); Chris@82: tensor_destroy(pckdsz2); Chris@82: tensor_destroy(probsz2_swap); Chris@82: tensor_destroy(totalsz2_swap); Chris@82: tensor_destroy(pckdsz2_swap); Chris@82: } Chris@82: Chris@82: void verify_rdft2(bench_problem *p, int rounds, double tol, errors *e) Chris@82: { Chris@82: C *inA, *inB, *inC, *outA, *outB, *outC, *tmp; Chris@82: int n, vecn, N; Chris@82: dofft_rdft2_closure k; Chris@82: Chris@82: BENCH_ASSERT(p->kind == PROBLEM_REAL); Chris@82: Chris@82: if (!BENCH_FINITE_RNK(p->sz->rnk) || !BENCH_FINITE_RNK(p->vecsz->rnk)) Chris@82: return; /* give up */ Chris@82: Chris@82: k.k.apply = rdft2_apply; Chris@82: k.k.recopy_input = 0; Chris@82: k.p = p; Chris@82: Chris@82: if (rounds == 0) Chris@82: rounds = 20; /* default value */ Chris@82: Chris@82: n = tensor_sz(p->sz); Chris@82: vecn = tensor_sz(p->vecsz); Chris@82: N = n * vecn; Chris@82: Chris@82: inA = (C *) bench_malloc(N * sizeof(C)); Chris@82: inB = (C *) bench_malloc(N * sizeof(C)); Chris@82: inC = (C *) bench_malloc(N * sizeof(C)); Chris@82: outA = (C *) bench_malloc(N * sizeof(C)); Chris@82: outB = (C *) bench_malloc(N * sizeof(C)); Chris@82: outC = (C *) bench_malloc(N * sizeof(C)); Chris@82: tmp = (C *) bench_malloc(N * sizeof(C)); Chris@82: Chris@82: e->i = impulse(&k.k, n, vecn, inA, inB, inC, outA, outB, outC, Chris@82: tmp, rounds, tol); Chris@82: e->l = linear(&k.k, 1, N, inA, inB, inC, outA, outB, outC, Chris@82: tmp, rounds, tol); Chris@82: Chris@82: e->s = 0.0; Chris@82: if (p->sign < 0) Chris@82: e->s = dmax(e->s, tf_shift(&k.k, 1, p->sz, n, vecn, p->sign, Chris@82: inA, inB, outA, outB, Chris@82: tmp, rounds, tol, TIME_SHIFT)); Chris@82: else Chris@82: e->s = dmax(e->s, tf_shift(&k.k, 1, p->sz, n, vecn, p->sign, Chris@82: inA, inB, outA, outB, Chris@82: tmp, rounds, tol, FREQ_SHIFT)); Chris@82: Chris@82: if (!p->in_place && !p->destroy_input) Chris@82: preserves_input(&k.k, p->sign < 0 ? mkreal : mkhermitian1, Chris@82: N, inA, inB, outB, rounds); Chris@82: Chris@82: bench_free(tmp); Chris@82: bench_free(outC); Chris@82: bench_free(outB); Chris@82: bench_free(outA); Chris@82: bench_free(inC); Chris@82: bench_free(inB); Chris@82: bench_free(inA); Chris@82: } Chris@82: Chris@82: void accuracy_rdft2(bench_problem *p, int rounds, int impulse_rounds, Chris@82: double t[6]) Chris@82: { Chris@82: dofft_rdft2_closure k; Chris@82: int n; Chris@82: C *a, *b; Chris@82: Chris@82: BENCH_ASSERT(p->kind == PROBLEM_REAL); Chris@82: BENCH_ASSERT(p->sz->rnk == 1); Chris@82: BENCH_ASSERT(p->vecsz->rnk == 0); Chris@82: Chris@82: k.k.apply = rdft2_apply; Chris@82: k.k.recopy_input = 0; Chris@82: k.p = p; Chris@82: n = tensor_sz(p->sz); Chris@82: Chris@82: a = (C *) bench_malloc(n * sizeof(C)); Chris@82: b = (C *) bench_malloc(n * sizeof(C)); Chris@82: accuracy_test(&k.k, p->sign < 0 ? mkreal : mkhermitian1, p->sign, Chris@82: n, a, b, rounds, impulse_rounds, t); Chris@82: bench_free(b); Chris@82: bench_free(a); Chris@82: }