starpu_perfmodel_display.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <assert.h>
  18. #include <unistd.h>
  19. #include <stdio.h>
  20. #include <starpu.h>
  21. #include <starpu_perfmodel.h>
  22. #include <core/perfmodel/perfmodel.h> // we need to browse the list associated to history-based models
  23. #ifdef __MINGW32__
  24. #include <windows.h>
  25. #endif
  26. static struct starpu_perfmodel_t 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_t *per_arch_model)
  94. {
  95. struct starpu_history_list_t *ptr;
  96. if (!parameter)
  97. fprintf(stderr, "# hash\t\tsize\t\tmean\t\tdev\t\tn\n");
  98. ptr = per_arch_model->list;
  99. while (ptr) {
  100. struct starpu_history_entry_t *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_t *model, enum starpu_perf_archtype arch)
  124. {
  125. struct starpu_per_arch_perfmodel_t *arch_model = &model->per_arch[arch];
  126. if (parameter == NULL)
  127. {
  128. /* no specific parameter was requested, so we display everything */
  129. fprintf(stderr, "\tRegression : #sample = %d\n",
  130. arch_model->regression.nsample);
  131. /* Only display the regression model if we could actually build a model */
  132. if (arch_model->regression.valid)
  133. {
  134. fprintf(stderr, "\tLinear: y = alpha size ^ beta\n");
  135. fprintf(stderr, "\t\talpha = %le\n", arch_model->regression.alpha);
  136. fprintf(stderr, "\t\tbeta = %le\n", arch_model->regression.beta);
  137. }
  138. else {
  139. fprintf(stderr, "\tLinear model is INVALID\n");
  140. }
  141. if (arch_model->regression.nl_valid)
  142. {
  143. fprintf(stderr, "\tNon-Linear: y = a size ^b + c\n");
  144. fprintf(stderr, "\t\ta = %le\n", arch_model->regression.a);
  145. fprintf(stderr, "\t\tb = %le\n", arch_model->regression.b);
  146. fprintf(stderr, "\t\tc = %le\n", arch_model->regression.c);
  147. }
  148. else {
  149. fprintf(stderr, "\tNon-Linear model is INVALID\n");
  150. }
  151. display_history_based_perf_model(arch_model);
  152. char debugname[1024];
  153. starpu_perfmodel_debugfilepath(model, arch, debugname, 1024);
  154. printf("\t debug file path : %s\n", debugname);
  155. }
  156. else {
  157. /* only display the parameter that was specifically requested */
  158. if (strcmp(parameter, "a") == 0) {
  159. printf("%le\n", arch_model->regression.a);
  160. return;
  161. }
  162. if (strcmp(parameter, "b") == 0) {
  163. printf("%le\n", arch_model->regression.b);
  164. return;
  165. }
  166. if (strcmp(parameter, "c") == 0) {
  167. printf("%le\n", arch_model->regression.c);
  168. return;
  169. }
  170. if (strcmp(parameter, "alpha") == 0) {
  171. printf("%le\n", arch_model->regression.alpha);
  172. return;
  173. }
  174. if (strcmp(parameter, "beta") == 0) {
  175. printf("%le\n", arch_model->regression.beta);
  176. return;
  177. }
  178. if (strcmp(parameter, "path-file-debug") == 0) {
  179. char debugname[256];
  180. starpu_perfmodel_debugfilepath(model, arch, debugname, 1024);
  181. printf("%s\n", debugname);
  182. return;
  183. }
  184. if ((strcmp(parameter, "mean") == 0) || (strcmp(parameter, "stddev"))) {
  185. display_history_based_perf_model(arch_model);
  186. return;
  187. }
  188. /* TODO display if it's valid ? */
  189. fprintf(stderr, "Unknown parameter requested, aborting.\n");
  190. exit(-1);
  191. }
  192. }
  193. static void display_all_perf_models(struct starpu_perfmodel_t *model)
  194. {
  195. if (arch == NULL)
  196. {
  197. /* display all architectures */
  198. unsigned archid;
  199. for (archid = 0; archid < STARPU_NARCH_VARIATIONS; archid++)
  200. {
  201. char archname[32];
  202. starpu_perfmodel_get_arch_name(archid, archname, 32);
  203. fprintf(stderr, "performance model for %s\n", archname);
  204. display_perf_model(model, archid);
  205. }
  206. }
  207. else {
  208. if (strcmp(arch, "cpu") == 0) {
  209. display_perf_model(model, STARPU_CPU_DEFAULT);
  210. return;
  211. }
  212. int k;
  213. if (sscanf(arch, "cpu:%d", &k) == 1)
  214. {
  215. /* For combined CPU workers */
  216. if ((k < 1) || (k > STARPU_NMAXCPUS))
  217. {
  218. fprintf(stderr, "Invalid CPU size\n");
  219. exit(-1);
  220. }
  221. display_perf_model(model, STARPU_CPU_DEFAULT + k - 1);
  222. return;
  223. }
  224. if (strcmp(arch, "cuda") == 0) {
  225. unsigned archid;
  226. for (archid = STARPU_CUDA_DEFAULT; archid < STARPU_CUDA_DEFAULT + STARPU_MAXCUDADEVS; archid++)
  227. {
  228. char archname[32];
  229. starpu_perfmodel_get_arch_name(archid, archname, 32);
  230. fprintf(stderr, "performance model for %s\n", archname);
  231. display_perf_model(model, archid);
  232. }
  233. return;
  234. }
  235. /* There must be a cleaner way ! */
  236. int gpuid;
  237. int nmatched;
  238. nmatched = sscanf(arch, "cuda_%d", &gpuid);
  239. if (nmatched == 1)
  240. {
  241. unsigned archid = STARPU_CUDA_DEFAULT+ gpuid;
  242. display_perf_model(model, archid);
  243. return;
  244. }
  245. if (strcmp(arch, "gordon") == 0) {
  246. fprintf(stderr, "performance model for gordon\n");
  247. display_perf_model(model, STARPU_GORDON_DEFAULT);
  248. return;
  249. }
  250. fprintf(stderr, "Unknown architecture requested, aborting.\n");
  251. exit(-1);
  252. }
  253. }
  254. int main(int argc, char **argv)
  255. {
  256. // assert(argc == 2);
  257. #ifdef __MINGW32__
  258. WSADATA wsadata;
  259. WSAStartup(MAKEWORD(1,0), &wsadata);
  260. #endif
  261. parse_args(argc, argv);
  262. if (list) {
  263. int ret = starpu_list_models();
  264. if (ret) {
  265. fprintf(stderr, "The performance model directory is invalid\n");
  266. return 1;
  267. }
  268. }
  269. else {
  270. int ret = starpu_load_history_debug(symbol, &model);
  271. if (ret == 1)
  272. {
  273. fprintf(stderr, "The performance model could not be loaded\n");
  274. return 1;
  275. }
  276. display_all_perf_models(&model);
  277. }
  278. return 0;
  279. }