perfmodel_display.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2010 (see AUTHORS file)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <assert.h>
  17. #include <unistd.h>
  18. #include <stdio.h>
  19. #include <starpu.h>
  20. #include <starpu_perfmodel.h>
  21. #include <core/perfmodel/perfmodel.h> // we need to browse the list associated to history-based models
  22. static struct starpu_perfmodel_t model;
  23. /* display all available models */
  24. static int list = 0;
  25. /* what kernel ? */
  26. static char *symbol = NULL;
  27. /* what parameter should be displayed ? (NULL = all) */
  28. static char *parameter = NULL;
  29. /* which architecture ? (NULL = all)*/
  30. static char *arch = NULL;
  31. /* should we display a specific footprint ? */
  32. unsigned display_specific_footprint;
  33. uint32_t specific_footprint;
  34. static void usage(char **argv)
  35. {
  36. fprintf(stderr, "Usage: %s [ options ]\n", argv[0]);
  37. fprintf(stderr, "\n");
  38. fprintf(stderr, "One must specify either -l or -s\n");
  39. fprintf(stderr, "Options:\n");
  40. fprintf(stderr, " -l display all available models\n");
  41. fprintf(stderr, " -s <symbol> specify the symbol\n");
  42. fprintf(stderr, " -p <parameter> specify the parameter (e.g. a, b, c, mean, stddev)\n");
  43. fprintf(stderr, " -a <arch> specify the architecture (e.g. cpu, cuda, gordon)\n");
  44. fprintf(stderr, " -f <footprint> display the history-based model for the specified footprint\n");
  45. fprintf(stderr, "\n");
  46. exit(-1);
  47. }
  48. static void parse_args(int argc, char **argv)
  49. {
  50. int c;
  51. while ((c = getopt(argc, argv, "ls:p:a:f:h")) != -1) {
  52. switch (c) {
  53. case 'l':
  54. /* list all models */
  55. list = 1;
  56. break;
  57. case 's':
  58. /* symbol */
  59. symbol = optarg;
  60. break;
  61. case 'p':
  62. /* parameter (eg. a, b, c, mean, stddev) */
  63. parameter = optarg;
  64. break;
  65. case 'a':
  66. /* architecture (cpu, cuda, gordon) */
  67. arch = optarg;
  68. break;
  69. case 'f':
  70. /* footprint */
  71. display_specific_footprint = 1;
  72. sscanf(optarg, "%08x", &specific_footprint);
  73. break;
  74. case 'h':
  75. usage(argv);
  76. break;
  77. case '?':
  78. default:
  79. fprintf(stderr, "Unrecognized option: -%c\n", optopt);
  80. }
  81. }
  82. if (!symbol && !list)
  83. {
  84. fprintf(stderr, "Incorrect usage, aborting\n");
  85. usage(argv);
  86. exit(-1);
  87. }
  88. }
  89. static void display_history_based_perf_model(struct starpu_per_arch_perfmodel_t *per_arch_model)
  90. {
  91. struct starpu_history_list_t *ptr;
  92. if (!parameter)
  93. fprintf(stderr, "# hash\t\tsize\t\tmean\t\tdev\t\tn\n");
  94. ptr = per_arch_model->list;
  95. while (ptr) {
  96. struct starpu_history_entry_t *entry = ptr->entry;
  97. if (!display_specific_footprint || (entry->footprint == specific_footprint))
  98. {
  99. if (!parameter)
  100. {
  101. /* There isn't a parameter that is explicitely requested, so we display all parameters */
  102. printf("%08x\t%-15lu\t%-15le\t%-15le\t%u\n", entry->footprint,
  103. (unsigned long) entry->size, entry->mean, entry->deviation, entry->nsample);
  104. }
  105. else {
  106. /* only display the parameter that was specifically requested */
  107. if (strcmp(parameter, "mean") == 0) {
  108. printf("%-15le\n", entry->mean);
  109. }
  110. if (strcmp(parameter, "stddev") == 0) {
  111. printf("%-15le\n", entry->deviation);
  112. return;
  113. }
  114. }
  115. }
  116. ptr = ptr->next;
  117. }
  118. }
  119. static void display_perf_model(struct starpu_perfmodel_t *model, enum starpu_perf_archtype arch)
  120. {
  121. struct starpu_per_arch_perfmodel_t *arch_model = &model->per_arch[arch];
  122. if (parameter == NULL)
  123. {
  124. /* no specific parameter was requested, so we display everything */
  125. fprintf(stderr, "\tRegression : #sample = %d (%s)\n",
  126. arch_model->regression.nsample,
  127. arch_model->regression.valid?"VALID":"STARPU_INVALID");
  128. /* Only display the regression model if we could actually build a model */
  129. if (arch_model->regression.valid)
  130. {
  131. fprintf(stderr, "\tLinear: y = alpha size ^ beta\n");
  132. fprintf(stderr, "\t\talpha = %le\n", arch_model->regression.alpha);
  133. fprintf(stderr, "\t\tbeta = %le\n", arch_model->regression.beta);
  134. fprintf(stderr, "\tNon-Linear: y = a size ^b + c\n");
  135. fprintf(stderr, "\t\ta = %le\n", arch_model->regression.a);
  136. fprintf(stderr, "\t\tb = %le\n", arch_model->regression.b);
  137. fprintf(stderr, "\t\tc = %le\n", arch_model->regression.c);
  138. }
  139. display_history_based_perf_model(arch_model);
  140. char debugname[1024];
  141. starpu_perfmodel_debugfilepath(model, arch, debugname, 1024);
  142. printf("\t debug file path : %s\n", debugname);
  143. }
  144. else {
  145. /* only display the parameter that was specifically requested */
  146. if (strcmp(parameter, "a") == 0) {
  147. printf("%le\n", arch_model->regression.a);
  148. return;
  149. }
  150. if (strcmp(parameter, "b") == 0) {
  151. printf("%le\n", arch_model->regression.b);
  152. return;
  153. }
  154. if (strcmp(parameter, "c") == 0) {
  155. printf("%le\n", arch_model->regression.c);
  156. return;
  157. }
  158. if (strcmp(parameter, "alpha") == 0) {
  159. printf("%le\n", arch_model->regression.alpha);
  160. return;
  161. }
  162. if (strcmp(parameter, "beta") == 0) {
  163. printf("%le\n", arch_model->regression.beta);
  164. return;
  165. }
  166. if (strcmp(parameter, "path-file-debug") == 0) {
  167. char debugname[256];
  168. starpu_perfmodel_debugfilepath(model, arch, debugname, 1024);
  169. printf("%s\n", debugname);
  170. return;
  171. }
  172. if ((strcmp(parameter, "mean") == 0) || (strcmp(parameter, "stddev"))) {
  173. display_history_based_perf_model(arch_model);
  174. return;
  175. }
  176. /* TODO display if it's valid ? */
  177. fprintf(stderr, "Unknown parameter requested, aborting.\n");
  178. exit(-1);
  179. }
  180. }
  181. static void display_all_perf_models(struct starpu_perfmodel_t *model)
  182. {
  183. if (arch == NULL)
  184. {
  185. /* display all architectures */
  186. unsigned archid;
  187. for (archid = 0; archid < STARPU_NARCH_VARIATIONS; archid++)
  188. {
  189. char archname[32];
  190. starpu_perfmodel_get_arch_name(archid, archname, 32);
  191. fprintf(stderr, "performance model for %s\n", archname);
  192. display_perf_model(model, archid);
  193. }
  194. }
  195. else {
  196. if (strcmp(arch, "cpu") == 0) {
  197. display_perf_model(model, STARPU_CPU_DEFAULT);
  198. return;
  199. }
  200. if (strcmp(arch, "cuda") == 0) {
  201. unsigned archid;
  202. for (archid = STARPU_CUDA_DEFAULT; archid < STARPU_CUDA_DEFAULT + STARPU_MAXCUDADEVS; archid++)
  203. {
  204. char archname[32];
  205. starpu_perfmodel_get_arch_name(archid, archname, 32);
  206. fprintf(stderr, "performance model for %s\n", archname);
  207. display_perf_model(model, archid);
  208. }
  209. return;
  210. }
  211. /* There must be a cleaner way ! */
  212. int gpuid;
  213. int nmatched;
  214. nmatched = sscanf(arch, "cuda_%d", &gpuid);
  215. if (nmatched == 1)
  216. {
  217. unsigned archid = STARPU_CUDA_DEFAULT+ gpuid;
  218. display_perf_model(model, archid);
  219. return;
  220. }
  221. if (strcmp(arch, "gordon") == 0) {
  222. fprintf(stderr, "performance model for gordon\n");
  223. display_perf_model(model, STARPU_GORDON_DEFAULT);
  224. return;
  225. }
  226. fprintf(stderr, "Unknown architecture requested, aborting.\n");
  227. exit(-1);
  228. }
  229. }
  230. int main(int argc, char **argv)
  231. {
  232. // assert(argc == 2);
  233. parse_args(argc, argv);
  234. if (list) {
  235. int ret = starpu_list_models();
  236. if (ret) {
  237. fprintf(stderr, "The performance model directory is invalid\n");
  238. return 1;
  239. }
  240. }
  241. else {
  242. int ret = starpu_load_history_debug(symbol, &model);
  243. if (ret == 1)
  244. {
  245. fprintf(stderr, "The performance model could not be loaded\n");
  246. return 1;
  247. }
  248. display_all_perf_models(&model);
  249. }
  250. return 0;
  251. }