perfmodel_print.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2013-2016 Université de Bordeaux
  4. * Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017 CNRS
  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 <starpu.h>
  19. #include <starpu_perfmodel.h>
  20. #include <common/config.h>
  21. #include "perfmodel.h"
  22. static
  23. void _starpu_perfmodel_print_history_based(struct starpu_perfmodel_per_arch *per_arch_model, char *parameter, uint32_t *footprint, FILE *output)
  24. {
  25. struct starpu_perfmodel_history_list *ptr;
  26. ptr = per_arch_model->list;
  27. if (!parameter && ptr)
  28. fprintf(output, "# hash\t\tsize\t\tflops\t\tmean (us)\tstddev (us)\t\tn\n");
  29. while (ptr)
  30. {
  31. struct starpu_perfmodel_history_entry *entry = ptr->entry;
  32. if (!footprint || entry->footprint == *footprint)
  33. {
  34. if (!parameter)
  35. {
  36. /* There isn't a parameter that is explicitely requested, so we display all parameters */
  37. fprintf(output, "%08x\t%-15lu\t%-15e\t%-15e\t%-15e\t%u\n", entry->footprint,
  38. (unsigned long) entry->size, entry->flops, entry->mean, entry->deviation, entry->nsample);
  39. }
  40. else
  41. {
  42. /* only display the parameter that was specifically requested */
  43. if (strcmp(parameter, "mean") == 0)
  44. {
  45. fprintf(output, "%-15e\n", entry->mean);
  46. }
  47. if (strcmp(parameter, "stddev") == 0)
  48. {
  49. fprintf(output, "%-15e\n", entry->deviation);
  50. return;
  51. }
  52. }
  53. }
  54. ptr = ptr->next;
  55. }
  56. }
  57. void starpu_perfmodel_print(struct starpu_perfmodel *model, struct starpu_perfmodel_arch* arch, unsigned nimpl, char *parameter, uint32_t *footprint, FILE *output)
  58. {
  59. int comb = starpu_perfmodel_arch_comb_get(arch->ndevices, arch->devices);
  60. STARPU_ASSERT(comb != -1);
  61. struct starpu_perfmodel_per_arch *arch_model = &model->state->per_arch[comb][nimpl];
  62. if (arch_model->regression.nsample || arch_model->regression.valid || arch_model->regression.nl_valid || arch_model->list)
  63. {
  64. char archname[32];
  65. starpu_perfmodel_get_arch_name(arch, archname, 32, nimpl);
  66. fprintf(output, "# performance model for %s\n", archname);
  67. }
  68. if (parameter == NULL)
  69. {
  70. /* no specific parameter was requested, so we display everything */
  71. if (arch_model->regression.nsample)
  72. {
  73. fprintf(output, "\tRegression : #sample = %u\n", arch_model->regression.nsample);
  74. }
  75. /* Only display the regression model if we could actually build a model */
  76. if (arch_model->regression.valid)
  77. {
  78. fprintf(output, "\tLinear: y = alpha size ^ beta\n");
  79. fprintf(output, "\t\talpha = %e\n", arch_model->regression.alpha);
  80. fprintf(output, "\t\tbeta = %e\n", arch_model->regression.beta);
  81. }
  82. else
  83. {
  84. //fprintf(output, "\tLinear model is INVALID\n");
  85. }
  86. if (arch_model->regression.nl_valid)
  87. {
  88. fprintf(output, "\tNon-Linear: y = a size ^b + c\n");
  89. fprintf(output, "\t\ta = %e\n", arch_model->regression.a);
  90. fprintf(output, "\t\tb = %e\n", arch_model->regression.b);
  91. fprintf(output, "\t\tc = %e\n", arch_model->regression.c);
  92. }
  93. else
  94. {
  95. //fprintf(output, "\tNon-Linear model is INVALID\n");
  96. }
  97. _starpu_perfmodel_print_history_based(arch_model, parameter, footprint, output);
  98. #if 0
  99. char debugname[1024];
  100. starpu_perfmodel_debugfilepath(model, arch, debugname, 1024, nimpl);
  101. _STARPU_MSG("\t debug file path : %s\n", debugname);
  102. #endif
  103. }
  104. else
  105. {
  106. /* only display the parameter that was specifically requested */
  107. if (strcmp(parameter, "a") == 0)
  108. {
  109. fprintf(output, "%e\n", arch_model->regression.a);
  110. return;
  111. }
  112. if (strcmp(parameter, "b") == 0)
  113. {
  114. fprintf(output, "%e\n", arch_model->regression.b);
  115. return;
  116. }
  117. if (strcmp(parameter, "c") == 0)
  118. {
  119. fprintf(output, "%e\n", arch_model->regression.c);
  120. return;
  121. }
  122. if (strcmp(parameter, "alpha") == 0)
  123. {
  124. fprintf(output, "%e\n", arch_model->regression.alpha);
  125. return;
  126. }
  127. if (strcmp(parameter, "beta") == 0)
  128. {
  129. fprintf(output, "%e\n", arch_model->regression.beta);
  130. return;
  131. }
  132. if (strcmp(parameter, "path-file-debug") == 0)
  133. {
  134. char debugname[256];
  135. starpu_perfmodel_debugfilepath(model, arch, debugname, 256, nimpl);
  136. fprintf(output, "%s\n", debugname);
  137. return;
  138. }
  139. if ((strcmp(parameter, "mean") == 0) || (strcmp(parameter, "stddev") == 0))
  140. {
  141. _starpu_perfmodel_print_history_based(arch_model, parameter, footprint, output);
  142. return;
  143. }
  144. /* TODO display if it's valid ? */
  145. _STARPU_ERROR("Unknown parameter requested, aborting.\n");
  146. }
  147. }
  148. int starpu_perfmodel_print_all(struct starpu_perfmodel *model, char *arch, char *parameter, uint32_t *footprint, FILE *output)
  149. {
  150. if (arch == NULL)
  151. {
  152. int comb, impl;
  153. for(comb = 0; comb < starpu_perfmodel_get_narch_combs(); comb++)
  154. {
  155. struct starpu_perfmodel_arch *arch_comb = _starpu_arch_comb_get(comb);
  156. int nimpls = model->state ? model->state->nimpls[comb] : 0;
  157. for(impl = 0; impl < nimpls; impl++)
  158. starpu_perfmodel_print(model, arch_comb, impl, parameter, footprint, output);
  159. }
  160. }
  161. else
  162. {
  163. if (strcmp(arch, "cpu") == 0)
  164. {
  165. int implid;
  166. struct starpu_perfmodel_arch perf_arch;
  167. perf_arch.ndevices = 1;
  168. _STARPU_MALLOC(perf_arch.devices, sizeof(struct starpu_perfmodel_device));
  169. perf_arch.devices[0].type = STARPU_CPU_WORKER;
  170. perf_arch.devices[0].devid = 0;
  171. perf_arch.devices[0].ncores = 1;
  172. int comb = starpu_perfmodel_arch_comb_get(perf_arch.ndevices, perf_arch.devices);
  173. STARPU_ASSERT(comb != -1);
  174. int nimpls = model->state->nimpls[comb];
  175. for (implid = 0; implid < nimpls; implid++)
  176. starpu_perfmodel_print(model, &perf_arch,implid, parameter, footprint, output); /* Display all codelets on cpu */
  177. free(perf_arch.devices);
  178. return 0;
  179. }
  180. int k;
  181. if (sscanf(arch, "cpu:%d", &k) == 1)
  182. {
  183. /* For combined CPU workers */
  184. if ((k < 1) || (k > STARPU_MAXCPUS))
  185. {
  186. _STARPU_ERROR("Invalid CPU size\n");
  187. }
  188. int implid;
  189. struct starpu_perfmodel_arch perf_arch;
  190. perf_arch.ndevices = 1;
  191. _STARPU_MALLOC(perf_arch.devices, sizeof(struct starpu_perfmodel_device));
  192. perf_arch.devices[0].type = STARPU_CPU_WORKER;
  193. perf_arch.devices[0].devid = 0;
  194. perf_arch.devices[0].ncores = k;
  195. int comb = starpu_perfmodel_arch_comb_get(perf_arch.ndevices, perf_arch.devices);
  196. STARPU_ASSERT(comb != -1);
  197. int nimpls = model->state->nimpls[comb];
  198. for (implid = 0; implid < nimpls; implid++)
  199. starpu_perfmodel_print(model, &perf_arch, implid, parameter, footprint, output);
  200. free(perf_arch.devices);
  201. return 0;
  202. }
  203. if (strcmp(arch, "cuda") == 0)
  204. {
  205. int implid;
  206. struct starpu_perfmodel_arch perf_arch;
  207. perf_arch.ndevices = 1;
  208. _STARPU_MALLOC(perf_arch.devices, sizeof(struct starpu_perfmodel_device));
  209. perf_arch.devices[0].type = STARPU_CUDA_WORKER;
  210. perf_arch.devices[0].ncores = 1;
  211. int comb;
  212. for(comb = 0; comb < starpu_perfmodel_get_narch_combs(); comb++)
  213. {
  214. struct starpu_perfmodel_arch *arch_comb = _starpu_arch_comb_get(comb);
  215. if(arch_comb->ndevices == 1 && arch_comb->devices[0].type == STARPU_CUDA_WORKER)
  216. {
  217. perf_arch.devices[0].devid = arch_comb->devices[0].devid;
  218. int nimpls = model->state->nimpls[comb];
  219. for (implid = 0; implid < nimpls; implid++)
  220. starpu_perfmodel_print(model, &perf_arch, implid, parameter, footprint, output);
  221. }
  222. }
  223. free(perf_arch.devices);
  224. return 0;
  225. }
  226. /* TODO: There must be a cleaner way ! */
  227. int gpuid;
  228. int nmatched;
  229. nmatched = sscanf(arch, "cuda_%d", &gpuid);
  230. if (nmatched == 0)
  231. nmatched = sscanf(arch, "cuda%d", &gpuid);
  232. if (nmatched == 1)
  233. {
  234. struct starpu_perfmodel_arch perf_arch;
  235. perf_arch.ndevices = 1;
  236. _STARPU_MALLOC(perf_arch.devices, sizeof(struct starpu_perfmodel_device));
  237. perf_arch.devices[0].type = STARPU_CUDA_WORKER;
  238. perf_arch.devices[0].devid = gpuid;
  239. perf_arch.devices[0].ncores = 1;
  240. int comb = starpu_perfmodel_arch_comb_get(perf_arch.ndevices, perf_arch.devices);
  241. STARPU_ASSERT(comb != -1);
  242. int nimpls = model->state->nimpls[comb];
  243. int implid;
  244. for (implid = 0; implid < nimpls; implid++)
  245. starpu_perfmodel_print(model, &perf_arch, implid, parameter, footprint, output);
  246. return 0;
  247. }
  248. _STARPU_MSG("Unknown architecture requested\n");
  249. return -1;
  250. }
  251. return 0;
  252. }
  253. int starpu_perfmodel_print_estimations(struct starpu_perfmodel *model, uint32_t footprint, FILE *output)
  254. {
  255. unsigned workerid;
  256. for (workerid = 0; workerid < starpu_worker_get_count(); workerid++)
  257. {
  258. struct starpu_perfmodel_arch* arch = starpu_worker_get_perf_archtype(workerid, STARPU_NMAX_SCHED_CTXS);
  259. int comb = starpu_perfmodel_arch_comb_get(arch->ndevices, arch->devices);
  260. struct starpu_perfmodel_per_arch *arch_model;
  261. struct starpu_perfmodel_history_list *ptr = NULL;
  262. if (comb >= 0 && model->state->per_arch[comb])
  263. {
  264. arch_model = &model->state->per_arch[comb][0];
  265. for (ptr = arch_model->list; ptr; ptr = ptr->next)
  266. {
  267. struct starpu_perfmodel_history_entry *entry = ptr->entry;
  268. if (entry->footprint == footprint)
  269. {
  270. fprintf(output, "%s%e", workerid?" ":"", entry->mean);
  271. break;
  272. }
  273. }
  274. }
  275. if (!ptr)
  276. {
  277. /* Didn't find any entry :/ */
  278. fprintf(output, "%sinf", workerid?" ":"");
  279. }
  280. }
  281. return 0;
  282. }