starpu_perfmodel_display.c 5.1 KB

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