perfmodel_print.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 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\tmean\t\tstddev\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%u\n", entry->footprint,
  37. (unsigned long) entry->size, 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, enum starpu_perf_archtype arch, unsigned nimpl, char *parameter, uint32_t *footprint, FILE *output)
  57. {
  58. struct starpu_perfmodel_per_arch *arch_model = &model->per_arch[arch][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 archid;
  152. unsigned implid;
  153. for (archid = 0; archid < STARPU_NARCH_VARIATIONS; archid++)
  154. {
  155. for (implid = 0; implid < STARPU_MAXIMPLEMENTATIONS; implid++)
  156. { /* Display all codelets on each arch */
  157. starpu_perfmodel_print(model, (enum starpu_perf_archtype) archid, implid, parameter, footprint, output);
  158. }
  159. }
  160. }
  161. else
  162. {
  163. if (strcmp(arch, "cpu") == 0)
  164. {
  165. unsigned implid;
  166. for (implid = 0; implid < STARPU_MAXIMPLEMENTATIONS; implid++)
  167. starpu_perfmodel_print(model, STARPU_CPU_DEFAULT,implid, parameter, footprint, output); /* Display all codelets on cpu */
  168. return 0;
  169. }
  170. int k;
  171. if (sscanf(arch, "cpu:%d", &k) == 1)
  172. {
  173. /* For combined CPU workers */
  174. if ((k < 1) || (k > STARPU_MAXCPUS))
  175. {
  176. fprintf(output, "Invalid CPU size\n");
  177. exit(-1);
  178. }
  179. unsigned implid;
  180. for (implid = 0; implid < STARPU_MAXIMPLEMENTATIONS; implid++)
  181. starpu_perfmodel_print(model, (enum starpu_perf_archtype) (STARPU_CPU_DEFAULT + k - 1), implid, parameter, footprint, output);
  182. return 0;
  183. }
  184. if (strcmp(arch, "cuda") == 0)
  185. {
  186. unsigned archid;
  187. unsigned implid;
  188. for (archid = STARPU_CUDA_DEFAULT; archid < STARPU_CUDA_DEFAULT + STARPU_MAXCUDADEVS; archid++)
  189. {
  190. for (implid = 0; implid <STARPU_MAXIMPLEMENTATIONS; implid ++)
  191. {
  192. char archname[32];
  193. starpu_perfmodel_get_arch_name((enum starpu_perf_archtype) archid, archname, 32, implid);
  194. fprintf(output, "performance model for %s\n", archname);
  195. starpu_perfmodel_print(model, (enum starpu_perf_archtype) archid, implid, parameter, footprint, output);
  196. }
  197. }
  198. return 0;
  199. }
  200. /* There must be a cleaner way ! */
  201. int gpuid;
  202. int nmatched;
  203. nmatched = sscanf(arch, "cuda_%d", &gpuid);
  204. if (nmatched == 1)
  205. {
  206. int archid = STARPU_CUDA_DEFAULT+ gpuid;
  207. unsigned implid;
  208. for (implid = 0; implid < STARPU_MAXIMPLEMENTATIONS; implid++)
  209. starpu_perfmodel_print(model, (enum starpu_perf_archtype) archid, implid, parameter, footprint, output);
  210. return 0;
  211. }
  212. fprintf(output, "Unknown architecture requested\n");
  213. return -1;
  214. }
  215. return 0;
  216. }