perfmodel_print.c 7.4 KB

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