starpu_perfmodel_display.c 9.9 KB

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