annotate src/fftw-3.3.3/tools/fftw-wisdom.c @ 23:619f715526df sv_v2.1

Update Vamp plugin SDK to 2.5
author Chris Cannam
date Thu, 09 May 2013 10:52:46 +0100
parents 37bf6b4a2645
children
rev   line source
Chris@10 1 /* Re-use libbench2 and the test program, but override bench_main so that
Chris@10 2 we can have different command-line syntax. */
Chris@10 3 #include "my-getopt.h"
Chris@10 4 #include "bench.h"
Chris@10 5
Chris@10 6 #include <stdio.h>
Chris@10 7 #include <stdlib.h>
Chris@10 8 #include <ctype.h>
Chris@10 9 #include <fftw3.h>
Chris@10 10 #include <string.h>
Chris@10 11 #include <time.h>
Chris@10 12
Chris@10 13 #if defined(HAVE_THREADS) || defined(HAVE_OPENMP)
Chris@10 14 # define HAVE_SMP
Chris@10 15 extern int threads_ok;
Chris@10 16 #endif
Chris@10 17
Chris@10 18 #define CONCAT(prefix, name) prefix ## name
Chris@10 19 #if defined(BENCHFFT_SINGLE)
Chris@10 20 #define FFTW(x) CONCAT(fftwf_, x)
Chris@10 21 #elif defined(BENCHFFT_LDOUBLE)
Chris@10 22 #define FFTW(x) CONCAT(fftwl_, x)
Chris@10 23 #elif defined(BENCHFFT_QUAD)
Chris@10 24 #define FFTW(x) CONCAT(fftwq_, x)
Chris@10 25 #else
Chris@10 26 #define FFTW(x) CONCAT(fftw_, x)
Chris@10 27 #endif
Chris@10 28
Chris@10 29 /* from bench.c: */
Chris@10 30 extern unsigned the_flags;
Chris@10 31 extern int usewisdom;
Chris@10 32 extern int nthreads;
Chris@10 33
Chris@10 34 /* dummy routines to replace those in hook.c */
Chris@10 35 void install_hook(void) {}
Chris@10 36 void uninstall_hook(void) {}
Chris@10 37
Chris@10 38 int verbose;
Chris@10 39
Chris@10 40 static void do_problem(bench_problem *p)
Chris@10 41 {
Chris@10 42 if (verbose)
Chris@10 43 printf("PLANNING PROBLEM: %s\n", p->pstring);
Chris@10 44 /* BENCH_ASSERT(can_do(p)); */
Chris@10 45 problem_alloc(p);
Chris@10 46 setup(p);
Chris@10 47 done(p);
Chris@10 48 }
Chris@10 49
Chris@10 50 static void add_problem(const char *pstring,
Chris@10 51 bench_problem ***p, int *ip, int *np)
Chris@10 52 {
Chris@10 53 if (*ip >= *np) {
Chris@10 54 *np = *np * 2 + 1;
Chris@10 55 *p = (bench_problem **) realloc(*p, sizeof(bench_problem *) * *np);
Chris@10 56 }
Chris@10 57 (*p)[(*ip)++] = problem_parse(pstring);
Chris@10 58 }
Chris@10 59
Chris@10 60 static int sz(const bench_problem *p)
Chris@10 61 {
Chris@10 62 return tensor_sz(p->sz) * tensor_sz(p->vecsz);
Chris@10 63 }
Chris@10 64
Chris@10 65 static int prob_size_cmp(const void *p1_, const void *p2_)
Chris@10 66 {
Chris@10 67 const bench_problem * const *p1 = (const bench_problem * const *) p1_;
Chris@10 68 const bench_problem * const *p2 = (const bench_problem * const *) p2_;
Chris@10 69 return (sz(*p1) - sz(*p2));
Chris@10 70 }
Chris@10 71
Chris@10 72 static struct my_option options[] =
Chris@10 73 {
Chris@10 74 {"help", NOARG, 'h'},
Chris@10 75 {"version", NOARG, 'V'},
Chris@10 76 {"verbose", NOARG, 'v'},
Chris@10 77
Chris@10 78 {"canonical", NOARG, 'c'},
Chris@10 79 {"time-limit", REQARG, 't'},
Chris@10 80
Chris@10 81 {"output-file", REQARG, 'o'},
Chris@10 82
Chris@10 83 {"impatient", NOARG, 'i'},
Chris@10 84 {"measure", NOARG, 'm'},
Chris@10 85 {"estimate", NOARG, 'e'},
Chris@10 86 {"exhaustive", NOARG, 'x'},
Chris@10 87
Chris@10 88 {"no-system-wisdom", NOARG, 'n'},
Chris@10 89 {"wisdom-file", REQARG, 'w'},
Chris@10 90
Chris@10 91 #ifdef HAVE_SMP
Chris@10 92 {"threads", REQARG, 'T'},
Chris@10 93 #endif
Chris@10 94
Chris@10 95 /* options to restrict configuration to rdft-only, etcetera? */
Chris@10 96
Chris@10 97 {0, NOARG, 0}
Chris@10 98 };
Chris@10 99
Chris@10 100 static void help(FILE *f, const char *program_name)
Chris@10 101 {
Chris@10 102 fprintf(
Chris@10 103 f,
Chris@10 104 "Usage: %s [options] [sizes]\n"
Chris@10 105 " Create wisdom (pre-planned/optimized transforms) for specified sizes,\n"
Chris@10 106 " writing wisdom to stdout (or to a file, using -o).\n"
Chris@10 107 "\nOptions:\n"
Chris@10 108 " -h, --help: print this help\n"
Chris@10 109 " -V, --version: print version/copyright info\n"
Chris@10 110 " -v, --verbose: verbose output\n"
Chris@10 111 " -c, --canonical: plan/optimize canonical set of sizes\n"
Chris@10 112 " -t <h>, --time-limit=<h>: time limit in hours (default: 0, no limit)\n"
Chris@10 113 " -o FILE, --output-file=FILE: output to FILE instead of stdout\n"
Chris@10 114 " -m, --measure: plan in MEASURE mode (PATIENT is default)\n"
Chris@10 115 " -e, --estimate: plan in ESTIMATE mode (not recommended)\n"
Chris@10 116 " -x, --exhaustive: plan in EXHAUSTIVE mode (may be slow)\n"
Chris@10 117 " -n, --no-system-wisdom: don't read /etc/fftw/ system wisdom file\n"
Chris@10 118 " -w FILE, --wisdom-file=FILE: read wisdom from FILE (stdin if -)\n"
Chris@10 119 #ifdef HAVE_SMP
Chris@10 120 " -T N, --threads=N: plan with N threads\n"
Chris@10 121 #endif
Chris@10 122 "\nSize syntax: <type><inplace><direction><geometry>\n"
Chris@10 123 " <type> = c/r/k for complex/real(r2c,c2r)/r2r\n"
Chris@10 124 " <inplace> = i/o for in/out-of place\n"
Chris@10 125 " <direction> = f/b for forward/backward, omitted for k transforms\n"
Chris@10 126 " <geometry> = <n1>[x<n2>[x...]], e.g. 10x12x14\n"
Chris@10 127 " -- for k transforms, after each dimension is a <kind>:\n"
Chris@10 128 " <kind> = f/b/h/e00/e01/e10/e11/o00/o01/o10/o11\n"
Chris@10 129 " for R2HC/HC2R/DHT/REDFT00/.../RODFT11\n"
Chris@10 130 , program_name);
Chris@10 131 }
Chris@10 132
Chris@10 133 /* powers of two and ten up to 2^20, for now */
Chris@10 134 static char canonical_sizes[][32] = {
Chris@10 135 "1", "2", "4", "8", "16", "32", "64", "128", "256", "512", "1024",
Chris@10 136 "2048", "4096", "8192", "16384", "32768", "65536", "131072",
Chris@10 137 "262144", "524288", "1048576",
Chris@10 138
Chris@10 139 "10", "100", "1000", "10000", "100000", "1000000",
Chris@10 140
Chris@10 141 "2x2", "4x4", "8x8", "10x10", "16x16", "32x32", "64x64", "100x100",
Chris@10 142 "128x128", "256x256", "512x512", "1000x1000", "1024x1024",
Chris@10 143
Chris@10 144 "2x2x2", "4x4x4", "8x8x8", "10x10x10", "16x16x16", "32x32x32",
Chris@10 145 "64x64x64", "100x100x100"
Chris@10 146 };
Chris@10 147
Chris@10 148 #define NELEM(array)(sizeof(array) / sizeof((array)[0]))
Chris@10 149
Chris@10 150 int bench_main(int argc, char *argv[])
Chris@10 151 {
Chris@10 152 int c;
Chris@10 153 unsigned i;
Chris@10 154 int impatient = 0;
Chris@10 155 int system_wisdom = 1;
Chris@10 156 int canonical = 0;
Chris@10 157 double hours = 0;
Chris@10 158 FILE *output_file;
Chris@10 159 char *output_fname = 0;
Chris@10 160 bench_problem **problems = 0;
Chris@10 161 int nproblems = 0, iproblem = 0;
Chris@10 162 time_t begin;
Chris@10 163
Chris@10 164 verbose = 0;
Chris@10 165 usewisdom = 0;
Chris@10 166
Chris@10 167 bench_srand(1);
Chris@10 168 #ifdef HAVE_SMP
Chris@10 169 /* do not configure FFTW with threads, unless the
Chris@10 170 user requests -T */
Chris@10 171 threads_ok = 0;
Chris@10 172 #endif
Chris@10 173
Chris@10 174 while ((c = my_getopt(argc, argv, options)) != -1) {
Chris@10 175 switch (c) {
Chris@10 176 case 'h':
Chris@10 177 help(stdout, argv[0]);
Chris@10 178 exit(EXIT_SUCCESS);
Chris@10 179 break;
Chris@10 180
Chris@10 181 case 'V':
Chris@10 182 printf("fftw-wisdom tool for FFTW version " VERSION ".\n");
Chris@10 183 printf(
Chris@10 184 "\n"
Chris@10 185 "Copyright (c) 2003, 2007-11 Matteo Frigo\n"
Chris@10 186 "Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology\n"
Chris@10 187 "\n"
Chris@10 188 "This program is free software; you can redistribute it and/or modify\n"
Chris@10 189 "it under the terms of the GNU General Public License as published by\n"
Chris@10 190 "the Free Software Foundation; either version 2 of the License, or\n"
Chris@10 191 "(at your option) any later version.\n"
Chris@10 192 "\n"
Chris@10 193 "This program is distributed in the hope that it will be useful,\n"
Chris@10 194 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
Chris@10 195 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
Chris@10 196 "GNU General Public License for more details.\n"
Chris@10 197 "\n"
Chris@10 198 "You should have received a copy of the GNU General Public License\n"
Chris@10 199 "along with this program; if not, write to the Free Software\n"
Chris@10 200 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n"
Chris@10 201 );
Chris@10 202 exit(EXIT_SUCCESS);
Chris@10 203 break;
Chris@10 204
Chris@10 205 case 'v':
Chris@10 206 verbose = 1;
Chris@10 207 break;
Chris@10 208
Chris@10 209 case 'c':
Chris@10 210 canonical = 1;
Chris@10 211 break;
Chris@10 212
Chris@10 213 case 't':
Chris@10 214 hours = atof(my_optarg);
Chris@10 215 break;
Chris@10 216
Chris@10 217 case 'o':
Chris@10 218 if (output_fname)
Chris@10 219 bench_free(output_fname);
Chris@10 220
Chris@10 221 if (!strcmp(my_optarg, "-"))
Chris@10 222 output_fname = 0;
Chris@10 223 else {
Chris@10 224 output_fname = (char *) bench_malloc(sizeof(char) *
Chris@10 225 (strlen(my_optarg) + 1));
Chris@10 226 strcpy(output_fname, my_optarg);
Chris@10 227 }
Chris@10 228 break;
Chris@10 229
Chris@10 230 case 'm':
Chris@10 231 case 'i':
Chris@10 232 impatient = 1;
Chris@10 233 break;
Chris@10 234
Chris@10 235 case 'e':
Chris@10 236 the_flags |= FFTW_ESTIMATE;
Chris@10 237 break;
Chris@10 238
Chris@10 239 case 'x':
Chris@10 240 the_flags |= FFTW_EXHAUSTIVE;
Chris@10 241 break;
Chris@10 242
Chris@10 243 case 'n':
Chris@10 244 system_wisdom = 0;
Chris@10 245 break;
Chris@10 246
Chris@10 247 case 'w': {
Chris@10 248 FILE *w = stdin;
Chris@10 249 if (strcmp(my_optarg, "-") && !(w = fopen(my_optarg, "r"))) {
Chris@10 250 fprintf(stderr,
Chris@10 251 "fftw-wisdom: error opening \"%s\": ", my_optarg);
Chris@10 252 perror("");
Chris@10 253 exit(EXIT_FAILURE);
Chris@10 254 }
Chris@10 255 if (!FFTW(import_wisdom_from_file)(w)) {
Chris@10 256 fprintf(stderr, "fftw_wisdom: error reading wisdom "
Chris@10 257 "from \"%s\"\n", my_optarg);
Chris@10 258 exit(EXIT_FAILURE);
Chris@10 259 }
Chris@10 260 if (w != stdin)
Chris@10 261 fclose(w);
Chris@10 262 break;
Chris@10 263 }
Chris@10 264
Chris@10 265 #ifdef HAVE_SMP
Chris@10 266 case 'T':
Chris@10 267 nthreads = atoi(my_optarg);
Chris@10 268 if (nthreads < 1) nthreads = 1;
Chris@10 269 threads_ok = 1;
Chris@10 270 BENCH_ASSERT(FFTW(init_threads)());
Chris@10 271 break;
Chris@10 272 #endif
Chris@10 273
Chris@10 274 case '?':
Chris@10 275 /* `my_getopt' already printed an error message. */
Chris@10 276 cleanup();
Chris@10 277 return EXIT_FAILURE;
Chris@10 278
Chris@10 279 default:
Chris@10 280 abort ();
Chris@10 281 }
Chris@10 282 }
Chris@10 283
Chris@10 284 if (!impatient)
Chris@10 285 the_flags |= FFTW_PATIENT;
Chris@10 286
Chris@10 287 if (system_wisdom)
Chris@10 288 if (!FFTW(import_system_wisdom)() && verbose)
Chris@10 289 fprintf(stderr, "fftw-wisdom: system-wisdom import failed\n");
Chris@10 290
Chris@10 291 if (canonical) {
Chris@10 292 for (i = 0; i < NELEM(canonical_sizes); ++i) {
Chris@10 293 unsigned j;
Chris@10 294 char types[][8] = {
Chris@10 295 "cof", "cob", "cif", "cib", "rof", "rob", "rif", "rib"
Chris@10 296 };
Chris@10 297
Chris@10 298 for (j = 0; j < NELEM(types); ++j) {
Chris@10 299 char ps[64];
Chris@10 300 if (!strchr(canonical_sizes[i],'x')
Chris@10 301 || !strchr(types[j],'o')) {
Chris@10 302 #ifdef HAVE_SNPRINTF
Chris@10 303 snprintf(ps, sizeof(ps), "%s%s", types[j], canonical_sizes[i]);
Chris@10 304 #else
Chris@10 305 sprintf(ps, "%s%s", types[j], canonical_sizes[i]);
Chris@10 306 #endif
Chris@10 307 add_problem(ps, &problems, &iproblem, &nproblems);
Chris@10 308 }
Chris@10 309 }
Chris@10 310 }
Chris@10 311 }
Chris@10 312
Chris@10 313 while (my_optind < argc) {
Chris@10 314 if (!strcmp(argv[my_optind], "-")) {
Chris@10 315 char s[1025];
Chris@10 316 while (1 == fscanf(stdin, "%1024s", s))
Chris@10 317 add_problem(s, &problems, &iproblem, &nproblems);
Chris@10 318 }
Chris@10 319 else
Chris@10 320 add_problem(argv[my_optind], &problems, &iproblem, &nproblems);
Chris@10 321 ++my_optind;
Chris@10 322 }
Chris@10 323
Chris@10 324 nproblems = iproblem;
Chris@10 325 qsort(problems, nproblems, sizeof(bench_problem *), prob_size_cmp);
Chris@10 326
Chris@10 327 if (!output_fname)
Chris@10 328 output_file = stdout;
Chris@10 329 else
Chris@10 330 if (!(output_file = fopen(output_fname, "w"))) {
Chris@10 331 fprintf(stderr,
Chris@10 332 "fftw-wisdom: error creating \"%s\"", output_fname);
Chris@10 333 perror("");
Chris@10 334 exit(EXIT_FAILURE);
Chris@10 335 }
Chris@10 336
Chris@10 337 begin = time((time_t*)0);
Chris@10 338 for (iproblem = 0; iproblem < nproblems; ++iproblem) {
Chris@10 339 if (hours <= 0
Chris@10 340 || hours > (time((time_t*)0) - begin) / 3600.0)
Chris@10 341 do_problem(problems[iproblem]);
Chris@10 342 problem_destroy(problems[iproblem]);
Chris@10 343
Chris@10 344 }
Chris@10 345 free(problems);
Chris@10 346
Chris@10 347 if (verbose && hours > 0
Chris@10 348 && hours < (time((time_t*)0) - begin) / 3600.0)
Chris@10 349 fprintf(stderr, "EXCEEDED TIME LIMIT OF %g HOURS.\n", hours);
Chris@10 350
Chris@10 351 FFTW(export_wisdom_to_file)(output_file);
Chris@10 352 if (output_file != stdout)
Chris@10 353 fclose(output_file);
Chris@10 354 if (output_fname)
Chris@10 355 bench_free(output_fname);
Chris@10 356
Chris@10 357 cleanup();
Chris@10 358
Chris@10 359 return EXIT_SUCCESS;
Chris@10 360 }