starpu_perfmodel_display.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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, cpu:k, 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\n",
  129. arch_model->regression.nsample);
  130. /* Only display the regression model if we could actually build a model */
  131. if (arch_model->regression.valid)
  132. {
  133. fprintf(stderr, "\tLinear: y = alpha size ^ beta\n");
  134. fprintf(stderr, "\t\talpha = %le\n", arch_model->regression.alpha);
  135. fprintf(stderr, "\t\tbeta = %le\n", arch_model->regression.beta);
  136. }
  137. else {
  138. fprintf(stderr, "\tLinear model is INVALID\n");
  139. }
  140. if (arch_model->regression.nl_valid)
  141. {
  142. fprintf(stderr, "\tNon-Linear: y = a size ^b + c\n");
  143. fprintf(stderr, "\t\ta = %le\n", arch_model->regression.a);
  144. fprintf(stderr, "\t\tb = %le\n", arch_model->regression.b);
  145. fprintf(stderr, "\t\tc = %le\n", arch_model->regression.c);
  146. }
  147. else {
  148. fprintf(stderr, "\tNon-Linear model is INVALID\n");
  149. }
  150. display_history_based_perf_model(arch_model);
  151. char debugname[1024];
  152. starpu_perfmodel_debugfilepath(model, arch, debugname, 1024);
  153. printf("\t debug file path : %s\n", debugname);
  154. }
  155. else {
  156. /* only display the parameter that was specifically requested */
  157. if (strcmp(parameter, "a") == 0) {
  158. printf("%le\n", arch_model->regression.a);
  159. return;
  160. }
  161. if (strcmp(parameter, "b") == 0) {
  162. printf("%le\n", arch_model->regression.b);
  163. return;
  164. }
  165. if (strcmp(parameter, "c") == 0) {
  166. printf("%le\n", arch_model->regression.c);
  167. return;
  168. }
  169. if (strcmp(parameter, "alpha") == 0) {
  170. printf("%le\n", arch_model->regression.alpha);
  171. return;
  172. }
  173. if (strcmp(parameter, "beta") == 0) {
  174. printf("%le\n", arch_model->regression.beta);
  175. return;
  176. }
  177. if (strcmp(parameter, "path-file-debug") == 0) {
  178. char debugname[256];
  179. starpu_perfmodel_debugfilepath(model, arch, debugname, 1024);
  180. printf("%s\n", debugname);
  181. return;
  182. }
  183. if ((strcmp(parameter, "mean") == 0) || (strcmp(parameter, "stddev"))) {
  184. display_history_based_perf_model(arch_model);
  185. return;
  186. }
  187. /* TODO display if it's valid ? */
  188. fprintf(stderr, "Unknown parameter requested, aborting.\n");
  189. exit(-1);
  190. }
  191. }
  192. static void display_all_perf_models(struct starpu_perfmodel_t *model)
  193. {
  194. if (arch == NULL)
  195. {
  196. /* display all architectures */
  197. unsigned archid;
  198. for (archid = 0; archid < STARPU_NARCH_VARIATIONS; archid++)
  199. {
  200. char archname[32];
  201. starpu_perfmodel_get_arch_name(archid, archname, 32);
  202. fprintf(stderr, "performance model for %s\n", archname);
  203. display_perf_model(model, archid);
  204. }
  205. }
  206. else {
  207. if (strcmp(arch, "cpu") == 0) {
  208. display_perf_model(model, STARPU_CPU_DEFAULT);
  209. return;
  210. }
  211. int k;
  212. if (sscanf(arch, "cpu:%d", &k) == 1)
  213. {
  214. /* For combined CPU workers */
  215. if ((k < 1) || (k > STARPU_NMAXCPUS))
  216. {
  217. fprintf(stderr, "Invalid CPU size\n");
  218. exit(-1);
  219. }
  220. display_perf_model(model, STARPU_CPU_DEFAULT + k - 1);
  221. return;
  222. }
  223. if (strcmp(arch, "cuda") == 0) {
  224. unsigned archid;
  225. for (archid = STARPU_CUDA_DEFAULT; archid < STARPU_CUDA_DEFAULT + STARPU_MAXCUDADEVS; archid++)
  226. {
  227. char archname[32];
  228. starpu_perfmodel_get_arch_name(archid, archname, 32);
  229. fprintf(stderr, "performance model for %s\n", archname);
  230. display_perf_model(model, archid);
  231. }
  232. return;
  233. }
  234. /* There must be a cleaner way ! */
  235. int gpuid;
  236. int nmatched;
  237. nmatched = sscanf(arch, "cuda_%d", &gpuid);
  238. if (nmatched == 1)
  239. {
  240. unsigned archid = STARPU_CUDA_DEFAULT+ gpuid;
  241. display_perf_model(model, archid);
  242. return;
  243. }
  244. if (strcmp(arch, "gordon") == 0) {
  245. fprintf(stderr, "performance model for gordon\n");
  246. display_perf_model(model, STARPU_GORDON_DEFAULT);
  247. return;
  248. }
  249. fprintf(stderr, "Unknown architecture requested, aborting.\n");
  250. exit(-1);
  251. }
  252. }
  253. int main(int argc, char **argv)
  254. {
  255. // assert(argc == 2);
  256. #ifdef __MINGW32__
  257. WSADATA wsadata;
  258. WSAStartup(MAKEWORD(1,0), &wsadata);
  259. #endif
  260. parse_args(argc, argv);
  261. if (list) {
  262. int ret = starpu_list_models();
  263. if (ret) {
  264. fprintf(stderr, "The performance model directory is invalid\n");
  265. return 1;
  266. }
  267. }
  268. else {
  269. int ret = starpu_load_history_debug(symbol, &model);
  270. if (ret == 1)
  271. {
  272. fprintf(stderr, "The performance model could not be loaded\n");
  273. return 1;
  274. }
  275. display_all_perf_models(&model);
  276. }
  277. return 0;
  278. }