starpu_perfmodel_display.c 4.5 KB

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