starpu_perfmodel_display.c 10 KB

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