Chris@10: /* Chris@10: * Copyright (c) 2001 Matteo Frigo Chris@10: * Copyright (c) 2001 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: #ifndef __BENCH_USER_H__ Chris@10: #define __BENCH_USER_H__ Chris@10: Chris@10: #ifdef __cplusplus Chris@10: extern "C" { Chris@10: #endif /* __cplusplus */ Chris@10: Chris@10: /* benchmark program definitions for user code */ Chris@10: #include "config.h" Chris@10: Chris@10: #if HAVE_STDDEF_H Chris@10: #include Chris@10: #endif Chris@10: Chris@10: #if HAVE_STDLIB_H Chris@10: #include Chris@10: #endif Chris@10: Chris@10: #if defined(BENCHFFT_SINGLE) Chris@10: typedef float bench_real; Chris@10: #elif defined(BENCHFFT_LDOUBLE) Chris@10: typedef long double bench_real; Chris@10: #elif defined(BENCHFFT_QUAD) Chris@10: typedef __float128 bench_real; Chris@10: #else Chris@10: typedef double bench_real; Chris@10: #endif Chris@10: Chris@10: typedef bench_real bench_complex[2]; Chris@10: Chris@10: #define c_re(c) ((c)[0]) Chris@10: #define c_im(c) ((c)[1]) Chris@10: Chris@10: #undef DOUBLE_PRECISION Chris@10: #define DOUBLE_PRECISION (sizeof(bench_real) == sizeof(double)) Chris@10: #undef SINGLE_PRECISION Chris@10: #define SINGLE_PRECISION (!DOUBLE_PRECISION && sizeof(bench_real) == sizeof(float)) Chris@10: #undef LDOUBLE_PRECISION Chris@10: #define LDOUBLE_PRECISION (!DOUBLE_PRECISION && sizeof(bench_real) == sizeof(long double)) Chris@10: Chris@10: #undef QUAD_PRECISION Chris@10: #ifdef BENCHFFT_QUAD Chris@10: #define QUAD_PRECISION (!LDOUBLE_PRECISION && sizeof(bench_real) == sizeof(__float128)) Chris@10: #else Chris@10: #define QUAD_PRECISION 0 Chris@10: #endif Chris@10: Chris@10: typedef enum { PROBLEM_COMPLEX, PROBLEM_REAL, PROBLEM_R2R } problem_kind_t; Chris@10: Chris@10: typedef enum { Chris@10: R2R_R2HC, R2R_HC2R, R2R_DHT, Chris@10: R2R_REDFT00, R2R_REDFT01, R2R_REDFT10, R2R_REDFT11, Chris@10: R2R_RODFT00, R2R_RODFT01, R2R_RODFT10, R2R_RODFT11 Chris@10: } r2r_kind_t; Chris@10: Chris@10: typedef struct { Chris@10: int n; Chris@10: int is; /* input stride */ Chris@10: int os; /* output stride */ Chris@10: } bench_iodim; Chris@10: Chris@10: typedef struct { Chris@10: int rnk; Chris@10: bench_iodim *dims; Chris@10: } bench_tensor; Chris@10: Chris@10: bench_tensor *mktensor(int rnk); Chris@10: void tensor_destroy(bench_tensor *sz); Chris@10: int tensor_sz(const bench_tensor *sz); Chris@10: bench_tensor *tensor_compress(const bench_tensor *sz); Chris@10: int tensor_unitstridep(bench_tensor *t); Chris@10: int tensor_rowmajorp(bench_tensor *t); Chris@10: int tensor_real_rowmajorp(bench_tensor *t, int sign, int in_place); Chris@10: bench_tensor *tensor_append(const bench_tensor *a, const bench_tensor *b); Chris@10: bench_tensor *tensor_copy(const bench_tensor *sz); Chris@10: bench_tensor *tensor_copy_sub(const bench_tensor *sz, int start_dim, int rnk); Chris@10: bench_tensor *tensor_copy_swapio(const bench_tensor *sz); Chris@10: void tensor_ibounds(bench_tensor *t, int *lbp, int *ubp); Chris@10: void tensor_obounds(bench_tensor *t, int *lbp, int *ubp); Chris@10: Chris@10: /* Chris@10: Definition of rank -infinity. Chris@10: This definition has the property that if you want rank 0 or 1, Chris@10: you can simply test for rank <= 1. This is a common case. Chris@10: Chris@10: A tensor of rank -infinity has size 0. Chris@10: */ Chris@10: #define RNK_MINFTY ((int)(((unsigned) -1) >> 1)) Chris@10: #define FINITE_RNK(rnk) ((rnk) != RNK_MINFTY) Chris@10: Chris@10: typedef struct { Chris@10: problem_kind_t kind; Chris@10: r2r_kind_t *k; Chris@10: bench_tensor *sz; Chris@10: bench_tensor *vecsz; Chris@10: int sign; Chris@10: int in_place; Chris@10: int destroy_input; Chris@10: int split; Chris@10: void *in, *out; Chris@10: void *inphys, *outphys; Chris@10: int iphyssz, ophyssz; Chris@10: char *pstring; Chris@10: void *userinfo; /* user can store whatever */ Chris@10: int scrambled_in, scrambled_out; /* hack for MPI */ Chris@10: Chris@10: /* internal hack so that we can use verifier in FFTW test program */ Chris@10: void *ini, *outi; /* if nonzero, point to imag. parts for dft */ Chris@10: Chris@10: /* another internal hack to avoid passing around too many parameters */ Chris@10: double setup_time; Chris@10: } bench_problem; Chris@10: Chris@10: extern int verbose; Chris@10: Chris@10: extern int no_speed_allocation; Chris@10: Chris@10: extern int always_pad_real; Chris@10: Chris@10: #define LIBBENCH_TIMER 0 Chris@10: #define USER_TIMER 1 Chris@10: #define BENCH_NTIMERS 2 Chris@10: extern void timer_start(int which_timer); Chris@10: extern double timer_stop(int which_timer); Chris@10: Chris@10: extern int can_do(bench_problem *p); Chris@10: extern void setup(bench_problem *p); Chris@10: extern void doit(int iter, bench_problem *p); Chris@10: extern void done(bench_problem *p); Chris@10: extern void main_init(int *argc, char ***argv); Chris@10: extern void cleanup(void); Chris@10: extern void verify(const char *param, int rounds, double tol); Chris@10: extern void useropt(const char *arg); Chris@10: Chris@10: extern void verify_problem(bench_problem *p, int rounds, double tol); Chris@10: Chris@10: extern void problem_alloc(bench_problem *p); Chris@10: extern void problem_free(bench_problem *p); Chris@10: extern void problem_zero(bench_problem *p); Chris@10: extern void problem_destroy(bench_problem *p); Chris@10: Chris@10: extern int power_of_two(int n); Chris@10: extern int log_2(int n); Chris@10: Chris@10: Chris@10: #define CASSIGN(out, in) (c_re(out) = c_re(in), c_im(out) = c_im(in)) Chris@10: Chris@10: bench_tensor *verify_pack(const bench_tensor *sz, int s); Chris@10: Chris@10: typedef struct { Chris@10: double l; Chris@10: double i; Chris@10: double s; Chris@10: } errors; Chris@10: Chris@10: void verify_dft(bench_problem *p, int rounds, double tol, errors *e); Chris@10: void verify_rdft2(bench_problem *p, int rounds, double tol, errors *e); Chris@10: void verify_r2r(bench_problem *p, int rounds, double tol, errors *e); Chris@10: Chris@10: /**************************************************************/ Chris@10: /* routines to override */ Chris@10: Chris@10: extern void after_problem_ccopy_from(bench_problem *p, bench_real *ri, bench_real *ii); Chris@10: extern void after_problem_ccopy_to(bench_problem *p, bench_real *ro, bench_real *io); Chris@10: extern void after_problem_hccopy_from(bench_problem *p, bench_real *ri, bench_real *ii); Chris@10: extern void after_problem_hccopy_to(bench_problem *p, bench_real *ro, bench_real *io); Chris@10: extern void after_problem_rcopy_from(bench_problem *p, bench_real *ri); Chris@10: extern void after_problem_rcopy_to(bench_problem *p, bench_real *ro); Chris@10: extern void bench_exit(int status); Chris@10: extern double bench_cost_postprocess(double cost); Chris@10: Chris@10: /************************************************************** Chris@10: * malloc Chris@10: **************************************************************/ Chris@10: extern void *bench_malloc(size_t size); Chris@10: extern void bench_free(void *ptr); Chris@10: extern void bench_free0(void *ptr); Chris@10: Chris@10: /************************************************************** Chris@10: * alloca Chris@10: **************************************************************/ Chris@10: #ifdef HAVE_ALLOCA_H Chris@10: #include Chris@10: #endif Chris@10: Chris@10: /************************************************************** Chris@10: * assert Chris@10: **************************************************************/ Chris@10: extern void bench_assertion_failed(const char *s, int line, const char *file); Chris@10: #define BENCH_ASSERT(ex) \ Chris@10: (void)((ex) || (bench_assertion_failed(#ex, __LINE__, __FILE__), 0)) Chris@10: Chris@10: #define UNUSED(x) (void)x Chris@10: Chris@10: /*************************************** Chris@10: * Documentation strings Chris@10: ***************************************/ Chris@10: struct bench_doc { Chris@10: const char *key; Chris@10: const char *val; Chris@10: const char *(*f)(void); Chris@10: }; Chris@10: Chris@10: extern struct bench_doc bench_doc[]; Chris@10: Chris@10: #ifdef CC Chris@10: #define CC_DOC BENCH_DOC("cc", CC) Chris@10: #elif defined(BENCH_CC) Chris@10: #define CC_DOC BENCH_DOC("cc", BENCH_CC) Chris@10: #else Chris@10: #define CC_DOC /* none */ Chris@10: #endif Chris@10: Chris@10: #ifdef CXX Chris@10: #define CXX_DOC BENCH_DOC("cxx", CXX) Chris@10: #elif defined(BENCH_CXX) Chris@10: #define CXX_DOC BENCH_DOC("cxx", BENCH_CXX) Chris@10: #else Chris@10: #define CXX_DOC /* none */ Chris@10: #endif Chris@10: Chris@10: #ifdef F77 Chris@10: #define F77_DOC BENCH_DOC("f77", F77) Chris@10: #elif defined(BENCH_F77) Chris@10: #define F77_DOC BENCH_DOC("f77", BENCH_F77) Chris@10: #else Chris@10: #define F77_DOC /* none */ Chris@10: #endif Chris@10: Chris@10: #ifdef F90 Chris@10: #define F90_DOC BENCH_DOC("f90", F90) Chris@10: #elif defined(BENCH_F90) Chris@10: #define F90_DOC BENCH_DOC("f90", BENCH_F90) Chris@10: #else Chris@10: #define F90_DOC /* none */ Chris@10: #endif Chris@10: Chris@10: #define BEGIN_BENCH_DOC \ Chris@10: struct bench_doc bench_doc[] = { \ Chris@10: CC_DOC \ Chris@10: CXX_DOC \ Chris@10: F77_DOC \ Chris@10: F90_DOC Chris@10: Chris@10: #define BENCH_DOC(key, val) { key, val, 0 }, Chris@10: #define BENCH_DOCF(key, f) { key, 0, f }, Chris@10: Chris@10: #define END_BENCH_DOC \ Chris@10: {0, 0, 0}}; Chris@10: Chris@10: #ifdef __cplusplus Chris@10: } /* extern "C" */ Chris@10: #endif /* __cplusplus */ Chris@10: Chris@10: #endif /* __BENCH_USER_H__ */