starpu_perfmodel_display.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. 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_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. 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);
  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 = %le\n", arch_model->regression.alpha);
  142. fprintf(stderr, "\t\tbeta = %le\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 = %le\n", arch_model->regression.a);
  151. fprintf(stderr, "\t\tb = %le\n", arch_model->regression.b);
  152. fprintf(stderr, "\t\tc = %le\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);
  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("%le\n", arch_model->regression.a);
  168. return;
  169. }
  170. if (strcmp(parameter, "b") == 0) {
  171. printf("%le\n", arch_model->regression.b);
  172. return;
  173. }
  174. if (strcmp(parameter, "c") == 0) {
  175. printf("%le\n", arch_model->regression.c);
  176. return;
  177. }
  178. if (strcmp(parameter, "alpha") == 0) {
  179. printf("%le\n", arch_model->regression.alpha);
  180. return;
  181. }
  182. if (strcmp(parameter, "beta") == 0) {
  183. printf("%le\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);
  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_t *model)
  202. {
  203. if (arch == NULL)
  204. {
  205. /* display all architectures */
  206. unsigned archid;
  207. for (archid = 0; archid < STARPU_NARCH_VARIATIONS; archid++)
  208. {
  209. display_perf_model(model, archid);
  210. }
  211. }
  212. else {
  213. if (strcmp(arch, "cpu") == 0) {
  214. display_perf_model(model, STARPU_CPU_DEFAULT);
  215. return;
  216. }
  217. int k;
  218. if (sscanf(arch, "cpu:%d", &k) == 1)
  219. {
  220. /* For combined CPU workers */
  221. if ((k < 1) || (k > STARPU_NMAXCPUS))
  222. {
  223. fprintf(stderr, "Invalid CPU size\n");
  224. exit(-1);
  225. }
  226. display_perf_model(model, STARPU_CPU_DEFAULT + k - 1);
  227. return;
  228. }
  229. if (strcmp(arch, "cuda") == 0) {
  230. unsigned archid;
  231. for (archid = STARPU_CUDA_DEFAULT; archid < STARPU_CUDA_DEFAULT + STARPU_MAXCUDADEVS; archid++)
  232. {
  233. char archname[32];
  234. starpu_perfmodel_get_arch_name(archid, archname, 32);
  235. fprintf(stderr, "performance model for %s\n", archname);
  236. display_perf_model(model, archid);
  237. }
  238. return;
  239. }
  240. /* There must be a cleaner way ! */
  241. int gpuid;
  242. int nmatched;
  243. nmatched = sscanf(arch, "cuda_%d", &gpuid);
  244. if (nmatched == 1)
  245. {
  246. unsigned archid = STARPU_CUDA_DEFAULT+ gpuid;
  247. display_perf_model(model, archid);
  248. return;
  249. }
  250. if (strcmp(arch, "gordon") == 0) {
  251. fprintf(stderr, "performance model for gordon\n");
  252. display_perf_model(model, STARPU_GORDON_DEFAULT);
  253. return;
  254. }
  255. fprintf(stderr, "Unknown architecture requested, aborting.\n");
  256. exit(-1);
  257. }
  258. }
  259. int main(int argc, char **argv)
  260. {
  261. // assert(argc == 2);
  262. #ifdef __MINGW32__
  263. WSADATA wsadata;
  264. WSAStartup(MAKEWORD(1,0), &wsadata);
  265. #endif
  266. parse_args(argc, argv);
  267. if (list) {
  268. int ret = starpu_list_models();
  269. if (ret) {
  270. fprintf(stderr, "The performance model directory is invalid\n");
  271. return 1;
  272. }
  273. }
  274. else {
  275. int ret = starpu_load_history_debug(symbol, &model);
  276. if (ret == 1)
  277. {
  278. fprintf(stderr, "The performance model could not be loaded\n");
  279. return 1;
  280. }
  281. display_all_perf_models(&model);
  282. }
  283. return 0;
  284. }