starpu_perfmodel_display.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2013-2014 Université de Bordeaux
  4. * Copyright (C) 2011, 2012, 2013, 2014, 2016 CNRS
  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. #if defined(_WIN32) && !defined(__CYGWIN__)
  25. #include <windows.h>
  26. #endif
  27. #define PROGNAME "starpu_perfmodel_display"
  28. /* display all available models */
  29. static int plist = 0;
  30. /* display directory */
  31. static int pdirectory = 0;
  32. /* what kernel ? */
  33. static char *psymbol = NULL;
  34. /* what parameter should be displayed ? (NULL = all) */
  35. static char *pparameter = NULL;
  36. /* which architecture ? (NULL = all)*/
  37. static char *parch = NULL;
  38. /* should we display a specific footprint ? */
  39. static unsigned pdisplay_specific_footprint;
  40. static uint32_t pspecific_footprint;
  41. static void usage()
  42. {
  43. fprintf(stderr, "Display a given perfmodel\n\n");
  44. fprintf(stderr, "Usage: %s [ options ]\n", PROGNAME);
  45. fprintf(stderr, "\n");
  46. fprintf(stderr, "One must specify either -l or -s\n");
  47. fprintf(stderr, "Options:\n");
  48. fprintf(stderr, " -l display all available models\n");
  49. fprintf(stderr, " -s <symbol> specify the symbol\n");
  50. fprintf(stderr, " -p <parameter> specify the parameter (e.g. a, b, c, mean, stddev)\n");
  51. fprintf(stderr, " -a <arch> specify the architecture (e.g. cpu, cpu:k, cuda)\n");
  52. fprintf(stderr, " -f <footprint> display the history-based model for the specified footprint\n");
  53. fprintf(stderr, " -d display the directory storing performance models\n");
  54. fprintf(stderr, " -h, --help display this help and exit\n");
  55. fprintf(stderr, " -v, --version output version information and exit\n\n");
  56. fprintf(stderr, "Report bugs to <"PACKAGE_BUGREPORT">.");
  57. fprintf(stderr, "\n");
  58. }
  59. static void parse_args(int argc, char **argv)
  60. {
  61. int c;
  62. int res;
  63. static struct option long_options[] =
  64. {
  65. {"arch", required_argument, NULL, 'a'},
  66. {"footprint", required_argument, NULL, 'f'},
  67. {"help", no_argument, NULL, 'h'},
  68. /* XXX Would be cleaner to set a flag */
  69. {"list", no_argument, NULL, 'l'},
  70. {"dir", no_argument, NULL, 'd'},
  71. {"parameter", required_argument, NULL, 'p'},
  72. {"symbol", required_argument, NULL, 's'},
  73. {"version", no_argument, NULL, 'v'},
  74. {0, 0, 0, 0}
  75. };
  76. int option_index;
  77. while ((c = getopt_long(argc, argv, "dls:p:a:f:h", long_options, &option_index)) != -1)
  78. {
  79. switch (c)
  80. {
  81. case 'l':
  82. /* list all models */
  83. plist = 1;
  84. break;
  85. case 's':
  86. /* symbol */
  87. psymbol = optarg;
  88. break;
  89. case 'p':
  90. /* parameter (eg. a, b, c, mean, stddev) */
  91. pparameter = optarg;
  92. break;
  93. case 'a':
  94. /* architecture (cpu, cuda) */
  95. parch = optarg;
  96. break;
  97. case 'f':
  98. /* footprint */
  99. pdisplay_specific_footprint = 1;
  100. res = sscanf(optarg, "%08x", &pspecific_footprint);
  101. STARPU_ASSERT(res==1);
  102. break;
  103. case 'd':
  104. /* directory */
  105. pdirectory = 1;
  106. break;
  107. case 'h':
  108. usage();
  109. exit(EXIT_SUCCESS);
  110. case 'v':
  111. fputs(PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stderr);
  112. exit(EXIT_SUCCESS);
  113. case '?':
  114. default:
  115. fprintf(stderr, "Unrecognized option: -%c\n", optopt);
  116. }
  117. }
  118. if (!psymbol && !plist && !pdirectory)
  119. {
  120. fprintf(stderr, "Incorrect usage, aborting\n");
  121. usage();
  122. exit(-1);
  123. }
  124. }
  125. int main(int argc, char **argv)
  126. {
  127. #if defined(_WIN32) && !defined(__CYGWIN__)
  128. WSADATA wsadata;
  129. WSAStartup(MAKEWORD(1,0), &wsadata);
  130. #endif
  131. parse_args(argc, argv);
  132. if (plist)
  133. {
  134. starpu_perfmodel_list(stdout);
  135. }
  136. else if (pdirectory)
  137. {
  138. starpu_perfmodel_directory(stdout);
  139. }
  140. else
  141. {
  142. struct starpu_perfmodel model = { .type = STARPU_PERFMODEL_INVALID };
  143. int ret = starpu_perfmodel_load_symbol(psymbol, &model);
  144. if (ret == 1)
  145. {
  146. fprintf(stderr, "The performance model for the symbol <%s> could not be loaded\n", psymbol);
  147. return 1;
  148. }
  149. uint32_t *footprint = NULL;
  150. if (pdisplay_specific_footprint == 1)
  151. {
  152. footprint = &pspecific_footprint;
  153. }
  154. starpu_perfmodel_print_all(&model, parch, pparameter, footprint, stdout);
  155. }
  156. starpu_perfmodel_free_sampling_directories();
  157. return 0;
  158. }