perfmodel-display.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2010 (see AUTHORS file)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <assert.h>
  17. #include <unistd.h>
  18. #include <stdio.h>
  19. #include <starpu.h>
  20. #include <starpu-perfmodel.h>
  21. static struct starpu_perfmodel_t model;
  22. /* display all available models */
  23. static int list = 0;
  24. /* what kernel ? */
  25. static char *symbol = NULL;
  26. /* what parameter should be displayed ? (NULL = all) */
  27. static char *parameter = NULL;
  28. /* which architecture ? (NULL = all)*/
  29. static char *arch = NULL;
  30. static void usage(char **argv)
  31. {
  32. /* TODO */
  33. fprintf(stderr, "Usage: %s [ options ]\n", argv[0]);
  34. fprintf(stderr, "\n");
  35. fprintf(stderr, "One must specify either -l or -s\n");
  36. fprintf(stderr, "Options:\n");
  37. fprintf(stderr, " -l display all available models\n");
  38. fprintf(stderr, " -s <symbol> specify the symbol\n");
  39. fprintf(stderr, " -p <parameter> specify the parameter (e.g. a, b, c)\n");
  40. fprintf(stderr, " -a <arch> specify the architecture (e.g. cpu, cuda, gordon)\n");
  41. fprintf(stderr, "\n");
  42. exit(-1);
  43. }
  44. static void parse_args(int argc, char **argv)
  45. {
  46. int c;
  47. while ((c = getopt(argc, argv, "ls:p:a:h")) != -1) {
  48. switch (c) {
  49. case 'l':
  50. /* list all models */
  51. list = 1;
  52. break;
  53. case 's':
  54. /* symbol */
  55. symbol = optarg;
  56. break;
  57. case 'p':
  58. /* parameter (eg. a, b, c .. ) */
  59. parameter = optarg;
  60. break;
  61. case 'a':
  62. /* architecture (cpu, cuda, gordon) */
  63. arch = optarg;
  64. break;
  65. case 'h':
  66. usage(argv);
  67. break;
  68. case '?':
  69. default:
  70. fprintf(stderr, "Unrecognized option: -%c\n", optopt);
  71. }
  72. }
  73. if (!symbol && !list)
  74. {
  75. fprintf(stderr, "Incorrect usage, aborting\n");
  76. usage(argv);
  77. exit(-1);
  78. }
  79. }
  80. static void display_perf_model(struct starpu_perfmodel_t *model, enum starpu_perf_archtype arch)
  81. {
  82. struct starpu_per_arch_perfmodel_t *arch_model = &model->per_arch[arch];
  83. if (parameter == NULL)
  84. {
  85. /* no specific parameter was requested, so we display everything */
  86. fprintf(stderr, "\tRegression : #sample = %d (%s)\n",
  87. arch_model->regression.nsample,
  88. arch_model->regression.valid?"VALID":"INVALID");
  89. /* Only display the regression model if we could actually build a model */
  90. if (arch_model->regression.valid)
  91. {
  92. fprintf(stderr, "\tLinear: y = alpha size ^ beta\n");
  93. fprintf(stderr, "\t\talpha = %le\n", arch_model->regression.alpha);
  94. fprintf(stderr, "\t\tbeta = %le\n", arch_model->regression.beta);
  95. fprintf(stderr, "\tNon-Linear: y = a size ^b + c\n");
  96. fprintf(stderr, "\t\ta = %le\n", arch_model->regression.a);
  97. fprintf(stderr, "\t\tb = %le\n", arch_model->regression.b);
  98. fprintf(stderr, "\t\tc = %le\n", arch_model->regression.c);
  99. }
  100. char debugname[1024];
  101. starpu_perfmodel_debugfilepath(model, arch, debugname, 1024);
  102. printf("\t debug file path : %s\n", debugname);
  103. }
  104. else {
  105. /* only display the parameter that was specifically requested */
  106. if (strcmp(parameter, "a") == 0) {
  107. printf("%le\n", arch_model->regression.a);
  108. return;
  109. }
  110. if (strcmp(parameter, "b") == 0) {
  111. printf("%le\n", arch_model->regression.b);
  112. return;
  113. }
  114. if (strcmp(parameter, "c") == 0) {
  115. printf("%le\n", arch_model->regression.c);
  116. return;
  117. }
  118. if (strcmp(parameter, "alpha") == 0) {
  119. printf("%le\n", arch_model->regression.alpha);
  120. return;
  121. }
  122. if (strcmp(parameter, "beta") == 0) {
  123. printf("%le\n", arch_model->regression.beta);
  124. return;
  125. }
  126. if (strcmp(parameter, "path-file-debug") == 0) {
  127. char debugname[256];
  128. starpu_perfmodel_debugfilepath(model, arch, debugname, 1024);
  129. printf("%s\n", debugname);
  130. return;
  131. }
  132. /* TODO display if it's valid ? */
  133. fprintf(stderr, "Unknown parameter requested, aborting.\n");
  134. exit(-1);
  135. }
  136. }
  137. static void display_all_perf_models(struct starpu_perfmodel_t *model)
  138. {
  139. if (arch == NULL)
  140. {
  141. /* display all architectures */
  142. unsigned archid;
  143. for (archid = 0; archid < STARPU_NARCH_VARIATIONS; archid++)
  144. {
  145. char archname[32];
  146. starpu_perfmodel_get_arch_name(archid, archname, 32);
  147. fprintf(stderr, "performance model for %s\n", archname);
  148. display_perf_model(model, archid);
  149. }
  150. }
  151. else {
  152. if (strcmp(arch, "cpu") == 0) {
  153. display_perf_model(model, STARPU_CPU_DEFAULT);
  154. return;
  155. }
  156. if (strcmp(arch, "cuda") == 0) {
  157. unsigned archid;
  158. for (archid = STARPU_CUDA_DEFAULT; archid < STARPU_CUDA_DEFAULT + STARPU_MAXCUDADEVS; archid++)
  159. {
  160. char archname[32];
  161. starpu_perfmodel_get_arch_name(archid, archname, 32);
  162. fprintf(stderr, "performance model for %s\n", archname);
  163. display_perf_model(model, archid);
  164. }
  165. return;
  166. }
  167. if (strcmp(arch, "gordon") == 0) {
  168. fprintf(stderr, "performance model for gordon\n");
  169. display_perf_model(model, STARPU_GORDON_DEFAULT);
  170. return;
  171. }
  172. fprintf(stderr, "Unknown architecture requested, aborting.\n");
  173. exit(-1);
  174. }
  175. }
  176. int main(int argc, char **argv)
  177. {
  178. // assert(argc == 2);
  179. parse_args(argc, argv);
  180. if (list) {
  181. int ret = starpu_list_models();
  182. if (ret) {
  183. fprintf(stderr, "The performance model directory is invalid\n");
  184. return 1;
  185. }
  186. }
  187. else {
  188. int ret = starpu_load_history_debug(symbol, &model);
  189. if (ret == 1)
  190. {
  191. fprintf(stderr, "The performance model could not be loaded\n");
  192. return 1;
  193. }
  194. display_all_perf_models(&model);
  195. }
  196. return 0;
  197. }