starpu_perfmodel_display.c 5.2 KB

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