starpu_perfmodel_display.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 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. static struct option long_options[] =
  63. {
  64. {"arch", required_argument, NULL, 'a'},
  65. {"footprint", required_argument, NULL, 'f'},
  66. {"help", no_argument, NULL, 'h'},
  67. /* XXX Would be cleaner to set a flag */
  68. {"list", no_argument, NULL, 'l'},
  69. {"dir", no_argument, NULL, 'd'},
  70. {"parameter", required_argument, NULL, 'p'},
  71. {"symbol", required_argument, NULL, 's'},
  72. {"version", no_argument, NULL, 'v'},
  73. {0, 0, 0, 0}
  74. };
  75. int option_index;
  76. while ((c = getopt_long(argc, argv, "dls:p:a:f:h", long_options, &option_index)) != -1)
  77. {
  78. switch (c)
  79. {
  80. case 'l':
  81. /* list all models */
  82. plist = 1;
  83. break;
  84. case 's':
  85. /* symbol */
  86. psymbol = optarg;
  87. break;
  88. case 'p':
  89. /* parameter (eg. a, b, c, mean, stddev) */
  90. pparameter = optarg;
  91. break;
  92. case 'a':
  93. /* architecture (cpu, cuda) */
  94. parch = optarg;
  95. break;
  96. case 'f':
  97. /* footprint */
  98. pdisplay_specific_footprint = 1;
  99. sscanf(optarg, "%08x", &pspecific_footprint);
  100. break;
  101. case 'd':
  102. /* directory */
  103. pdirectory = 1;
  104. break;
  105. case 'h':
  106. usage();
  107. exit(EXIT_SUCCESS);
  108. case 'v':
  109. fputs(PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stderr);
  110. exit(EXIT_SUCCESS);
  111. case '?':
  112. default:
  113. fprintf(stderr, "Unrecognized option: -%c\n", optopt);
  114. }
  115. }
  116. if (!psymbol && !plist && !pdirectory)
  117. {
  118. fprintf(stderr, "Incorrect usage, aborting\n");
  119. usage();
  120. exit(-1);
  121. }
  122. }
  123. int main(int argc, char **argv)
  124. {
  125. #if defined(_WIN32) && !defined(__CYGWIN__)
  126. WSADATA wsadata;
  127. WSAStartup(MAKEWORD(1,0), &wsadata);
  128. #endif
  129. parse_args(argc, argv);
  130. if (plist)
  131. {
  132. starpu_perfmodel_list(stdout);
  133. }
  134. else if (pdirectory)
  135. {
  136. starpu_perfmodel_directory(stdout);
  137. }
  138. else
  139. {
  140. struct starpu_perfmodel model = { .type = STARPU_PERFMODEL_INVALID };
  141. int ret = starpu_perfmodel_load_symbol(psymbol, &model);
  142. if (ret == 1)
  143. {
  144. fprintf(stderr, "The performance model for the symbol <%s> could not be loaded\n", psymbol);
  145. return 1;
  146. }
  147. uint32_t *footprint = NULL;
  148. if (pdisplay_specific_footprint == 1)
  149. {
  150. footprint = &pspecific_footprint;
  151. }
  152. starpu_perfmodel_print_all(&model, parch, pparameter, footprint, stdout);
  153. }
  154. starpu_perfmodel_free_sampling_directories();
  155. return 0;
  156. }