starpu_perfmodel_display.c 10 KB

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