/usr/share/doc/libfftw3-dev/examples/hook.c is in libfftw3-dev 3.3-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | /* fftw hook to be used in the benchmark program.
We keep it in a separate file because
1) bench.c is supposed to test the API---we do not want to #include
"ifftw.h" and accidentally use internal symbols/macros.
2) this code is a royal mess. The messiness is due to
A) confusion between internal fftw tensors and bench_tensor's
(which we want to keep separate because the benchmark
program tests other routines too)
B) despite A), our desire to recycle the libbench verifier.
*/
#include <stdio.h>
#include "bench-user.h"
#define CALLING_FFTW /* hack for Windows DLL nonsense */
#include "api.h"
#include "dft.h"
#include "rdft.h"
extern int paranoid; /* in bench.c */
extern X(plan) the_plan; /* in bench.c */
/*
transform an fftw tensor into a bench_tensor.
*/
static bench_tensor *fftw_tensor_to_bench_tensor(tensor *t)
{
bench_tensor *bt = mktensor(t->rnk);
if (FINITE_RNK(t->rnk)) {
int i;
for (i = 0; i < t->rnk; ++i) {
/* FIXME: 64-bit unclean because of INT -> int conversion */
bt->dims[i].n = t->dims[i].n;
bt->dims[i].is = t->dims[i].is;
bt->dims[i].os = t->dims[i].os;
BENCH_ASSERT(bt->dims[i].n == t->dims[i].n);
BENCH_ASSERT(bt->dims[i].is == t->dims[i].is);
BENCH_ASSERT(bt->dims[i].os == t->dims[i].os);
}
}
return bt;
}
/*
transform an fftw problem into a bench_problem.
*/
static bench_problem *fftw_problem_to_bench_problem(planner *plnr,
const problem *p_)
{
bench_problem *bp = 0;
switch (p_->adt->problem_kind) {
case PROBLEM_DFT:
{
const problem_dft *p = (const problem_dft *) p_;
if (!p->ri || !p->ii)
abort();
bp = (bench_problem *) bench_malloc(sizeof(bench_problem));
bp->kind = PROBLEM_COMPLEX;
bp->sign = FFT_SIGN;
bp->split = 1; /* tensor strides are in R's, not C's */
bp->in = UNTAINT(p->ri);
bp->out = UNTAINT(p->ro);
bp->ini = UNTAINT(p->ii);
bp->outi = UNTAINT(p->io);
bp->inphys = bp->outphys = 0;
bp->iphyssz = bp->ophyssz = 0;
bp->in_place = p->ri == p->ro;
bp->sz = fftw_tensor_to_bench_tensor(p->sz);
bp->vecsz = fftw_tensor_to_bench_tensor(p->vecsz);
bp->k = 0;
break;
}
case PROBLEM_RDFT:
{
const problem_rdft *p = (const problem_rdft *) p_;
int i;
if (!p->I || !p->O)
abort();
for (i = 0; i < p->sz->rnk; ++i)
switch (p->kind[i]) {
case R2HC01:
case R2HC10:
case R2HC11:
case HC2R01:
case HC2R10:
case HC2R11:
return bp;
default:
;
}
bp = (bench_problem *) bench_malloc(sizeof(bench_problem));
bp->kind = PROBLEM_R2R;
bp->sign = FFT_SIGN;
bp->split = 0;
bp->in = UNTAINT(p->I);
bp->out = UNTAINT(p->O);
bp->ini = bp->outi = 0;
bp->inphys = bp->outphys = 0;
bp->iphyssz = bp->ophyssz = 0;
bp->in_place = p->I == p->O;
bp->sz = fftw_tensor_to_bench_tensor(p->sz);
bp->vecsz = fftw_tensor_to_bench_tensor(p->vecsz);
bp->k = (r2r_kind_t *) bench_malloc(sizeof(r2r_kind_t) * p->sz->rnk);
for (i = 0; i < p->sz->rnk; ++i)
switch (p->kind[i]) {
case R2HC: bp->k[i] = R2R_R2HC; break;
case HC2R: bp->k[i] = R2R_HC2R; break;
case DHT: bp->k[i] = R2R_DHT; break;
case REDFT00: bp->k[i] = R2R_REDFT00; break;
case REDFT01: bp->k[i] = R2R_REDFT01; break;
case REDFT10: bp->k[i] = R2R_REDFT10; break;
case REDFT11: bp->k[i] = R2R_REDFT11; break;
case RODFT00: bp->k[i] = R2R_RODFT00; break;
case RODFT01: bp->k[i] = R2R_RODFT01; break;
case RODFT10: bp->k[i] = R2R_RODFT10; break;
case RODFT11: bp->k[i] = R2R_RODFT11; break;
default: CK(0);
}
break;
}
case PROBLEM_RDFT2:
{
const problem_rdft2 *p = (const problem_rdft2 *) p_;
int rnk = p->sz->rnk;
if (!p->r0 || !p->r1 || !p->cr || !p->ci)
abort();
/* give up verifying rdft2 R2HCII */
if (p->kind != R2HC && p->kind != HC2R)
return bp;
if (rnk > 0) {
/* can't verify separate even/odd arrays for now */
if (2 * (p->r1 - p->r0) !=
((p->kind == R2HC) ?
p->sz->dims[rnk-1].is : p->sz->dims[rnk-1].os))
return bp;
}
bp = (bench_problem *) bench_malloc(sizeof(bench_problem));
bp->kind = PROBLEM_REAL;
bp->sign = p->kind == R2HC ? FFT_SIGN : -FFT_SIGN;
bp->split = 1; /* tensor strides are in R's, not C's */
if (p->kind == R2HC) {
bp->sign = FFT_SIGN;
bp->in = UNTAINT(p->r0);
bp->out = UNTAINT(p->cr);
bp->ini = 0;
bp->outi = UNTAINT(p->ci);
}
else {
bp->sign = -FFT_SIGN;
bp->out = UNTAINT(p->r0);
bp->in = UNTAINT(p->cr);
bp->outi = 0;
bp->ini = UNTAINT(p->ci);
}
bp->inphys = bp->outphys = 0;
bp->iphyssz = bp->ophyssz = 0;
bp->in_place = p->r0 == p->cr;
bp->sz = fftw_tensor_to_bench_tensor(p->sz);
if (rnk > 0) {
if (p->kind == R2HC)
bp->sz->dims[rnk-1].is /= 2;
else
bp->sz->dims[rnk-1].os /= 2;
}
bp->vecsz = fftw_tensor_to_bench_tensor(p->vecsz);
bp->k = 0;
break;
}
default:
abort();
}
bp->userinfo = 0;
bp->pstring = 0;
bp->destroy_input = !NO_DESTROY_INPUTP(plnr);
return bp;
}
static void hook(planner *plnr, plan *pln, const problem *p_, int optimalp)
{
int rounds = 5;
double tol = SINGLE_PRECISION ? 1.0e-3 : 1.0e-10;
UNUSED(optimalp);
if (verbose > 5) {
printer *pr = X(mkprinter_file)(stdout);
pr->print(pr, "%P:%(%p%)\n", p_, pln);
X(printer_destroy)(pr);
printf("cost %g \n\n", pln->pcost);
}
if (paranoid) {
bench_problem *bp;
bp = fftw_problem_to_bench_problem(plnr, p_);
if (bp) {
X(plan) the_plan_save = the_plan;
the_plan = (apiplan *) MALLOC(sizeof(apiplan), PLANS);
the_plan->pln = pln;
the_plan->prb = (problem *) p_;
X(plan_awake)(pln, AWAKE_SQRTN_TABLE);
verify_problem(bp, rounds, tol);
X(plan_awake)(pln, SLEEPY);
X(ifree)(the_plan);
the_plan = the_plan_save;
problem_destroy(bp);
}
}
}
static void paranoid_checks(void)
{
/* FIXME: assumes char = 8 bits, which is false on at least one
DSP I know of. */
#if 0
/* if flags_t is not 64 bits i want to know it. */
CK(sizeof(flags_t) == 8);
CK(sizeof(md5uint) >= 4);
#endif
CK(sizeof(uintptr_t) >= sizeof(R *));
CK(sizeof(INT) >= sizeof(R *));
}
void install_hook(void)
{
planner *plnr = X(the_planner)();
plnr->hook = hook;
paranoid_checks();
}
void uninstall_hook(void)
{
planner *plnr = X(the_planner)();
plnr->hook = 0;
}
|