starpu_perfmodel_display.c 9.5 KB

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