perfmodel_display.c 8.1 KB

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