starpu_perfmodel_display.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 Université de Bordeaux 1
  4. * Copyright (C) 2011, 2012 Centre National de la Recherche Scientifique
  5. * Copyright (C) 2011 Télécom-SudParis
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <config.h>
  19. #include <assert.h>
  20. #include <getopt.h>
  21. #include <unistd.h>
  22. #include <stdio.h>
  23. #include <starpu.h>
  24. #include <starpu_perfmodel.h>
  25. #ifdef __MINGW32__
  26. #include <windows.h>
  27. #endif
  28. #define PROGNAME "starpu_perfmodel_display"
  29. /* display all available models */
  30. static int plist = 0;
  31. /* what kernel ? */
  32. static char *psymbol = NULL;
  33. /* what parameter should be displayed ? (NULL = all) */
  34. static char *pparameter = NULL;
  35. /* which architecture ? (NULL = all)*/
  36. static char *parch = NULL;
  37. /* should we display a specific footprint ? */
  38. static unsigned pdisplay_specific_footprint;
  39. static uint32_t pspecific_footprint;
  40. static void usage(char **argv)
  41. {
  42. fprintf(stderr, "Display a given perfmodel\n\n");
  43. fprintf(stderr, "Usage: %s [ options ]\n", PROGNAME);
  44. fprintf(stderr, "\n");
  45. fprintf(stderr, "One must specify either -l or -s\n");
  46. fprintf(stderr, "Options:\n");
  47. fprintf(stderr, " -l display all available models\n");
  48. fprintf(stderr, " -s <symbol> specify the symbol\n");
  49. fprintf(stderr, " -p <parameter> specify the parameter (e.g. a, b, c, mean, stddev)\n");
  50. fprintf(stderr, " -a <arch> specify the architecture (e.g. cpu, cpu:k, cuda, gordon)\n");
  51. fprintf(stderr, " -f <footprint> display the history-based model for the specified footprint\n");
  52. fprintf(stderr, " -h, --help display this help and exit\n");
  53. fprintf(stderr, " -v, --version output version information and exit\n\n");
  54. fprintf(stderr, "Reports bugs to <"PACKAGE_BUGREPORT">.");
  55. fprintf(stderr, "\n");
  56. }
  57. static void parse_args(int argc, char **argv)
  58. {
  59. int c;
  60. static struct option long_options[] =
  61. {
  62. {"arch", required_argument, NULL, 'a'},
  63. {"footprint", required_argument, NULL, 'f'},
  64. {"help", no_argument, NULL, 'h'},
  65. /* XXX Would be cleaner to set a flag */
  66. {"list", no_argument, NULL, 'l'},
  67. {"parameter", required_argument, NULL, 'p'},
  68. {"symbol", required_argument, NULL, 's'},
  69. {"version", no_argument, NULL, 'v'},
  70. {0, 0, 0, 0}
  71. };
  72. int option_index;
  73. while ((c = getopt_long(argc, argv, "ls:p:a:f:h", long_options, &option_index)) != -1)
  74. {
  75. switch (c)
  76. {
  77. case 'l':
  78. /* list all models */
  79. plist = 1;
  80. break;
  81. case 's':
  82. /* symbol */
  83. psymbol = optarg;
  84. break;
  85. case 'p':
  86. /* parameter (eg. a, b, c, mean, stddev) */
  87. pparameter = optarg;
  88. break;
  89. case 'a':
  90. /* architecture (cpu, cuda, gordon) */
  91. parch = optarg;
  92. break;
  93. case 'f':
  94. /* footprint */
  95. pdisplay_specific_footprint = 1;
  96. sscanf(optarg, "%08x", &pspecific_footprint);
  97. break;
  98. case 'h':
  99. usage(argv);
  100. exit(EXIT_SUCCESS);
  101. case 'v':
  102. (void) fprintf(stdout, "%s %d.%d\n",
  103. PROGNAME, STARPU_MAJOR_VERSION,
  104. STARPU_MINOR_VERSION);
  105. exit(EXIT_SUCCESS);
  106. case '?':
  107. default:
  108. fprintf(stderr, "Unrecognized option: -%c\n", optopt);
  109. }
  110. }
  111. if (!psymbol && !plist)
  112. {
  113. fprintf(stderr, "Incorrect usage, aborting\n");
  114. usage(argv);
  115. exit(-1);
  116. }
  117. }
  118. int main(int argc, char **argv)
  119. {
  120. #ifdef __MINGW32__
  121. WSADATA wsadata;
  122. WSAStartup(MAKEWORD(1,0), &wsadata);
  123. #endif
  124. parse_args(argc, argv);
  125. if (plist)
  126. {
  127. int ret = starpu_perfmodel_list(stdout);
  128. if (ret)
  129. {
  130. fprintf(stderr, "The performance model directory is invalid\n");
  131. return 1;
  132. }
  133. }
  134. else
  135. {
  136. struct starpu_perfmodel model;
  137. int ret = starpu_perfmodel_load_symbol(psymbol, &model);
  138. if (ret == 1)
  139. {
  140. fprintf(stderr, "The performance model for the symbol <%s> could not be loaded\n", psymbol);
  141. return 1;
  142. }
  143. uint32_t *footprint = NULL;
  144. if (pdisplay_specific_footprint == 1)
  145. {
  146. footprint = &pspecific_footprint;
  147. }
  148. starpu_perfmodel_print_all(&model, parch, pparameter, footprint, stdout);
  149. }
  150. return 0;
  151. }