starpu_perfmodel_display.c 9.6 KB

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