starpu_perfmodel_display.c 5.4 KB

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