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