perfmodel-display.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (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. /* what kernel ? */
  23. static char *symbol = NULL;
  24. /* what parameter should be displayed ? (NULL = all) */
  25. static char *parameter = NULL;
  26. /* which architecture ? (NULL = all)*/
  27. static char *arch = NULL;
  28. static void usage(char **argv)
  29. {
  30. /* TODO */
  31. fprintf(stderr, "Usage: %s [ options ]\n", argv[0]);
  32. fprintf(stderr, "\n");
  33. fprintf(stderr, "Options:\n");
  34. fprintf(stderr, " -s <symbol> specify the symbol\n");
  35. fprintf(stderr, " -p <parameter> specify the parameter (e.g. a, b, c)\n");
  36. fprintf(stderr, " -a <arch> specify the architecture (e.g. core, cuda, gordon)\n");
  37. fprintf(stderr, "\n");
  38. exit(-1);
  39. }
  40. static void parse_args(int argc, char **argv)
  41. {
  42. int c;
  43. while ((c = getopt(argc, argv, "s:p:a:h")) != -1) {
  44. switch (c) {
  45. case 's':
  46. /* symbol */
  47. symbol = optarg;
  48. break;
  49. case 'p':
  50. /* parameter (eg. a, b, c .. ) */
  51. parameter = optarg;
  52. break;
  53. case 'a':
  54. /* architecture (core, cuda, gordon) */
  55. arch = optarg;
  56. break;
  57. case 'h':
  58. usage(argv);
  59. break;
  60. case '?':
  61. default:
  62. fprintf(stderr, "Unrecognized option: -%c\n", optopt);
  63. }
  64. }
  65. if (!symbol)
  66. {
  67. fprintf(stderr, "No symbol name was given, aborting\n");
  68. exit(-1);
  69. }
  70. }
  71. static void display_perf_model(struct starpu_perfmodel_t *model, enum starpu_perf_archtype arch)
  72. {
  73. struct starpu_per_arch_perfmodel_t *arch_model = &model->per_arch[arch];
  74. if (parameter == NULL)
  75. {
  76. /* no specific parameter was requested, so we display everything */
  77. fprintf(stderr, "\tRegression : #sample = %d (%s)\n",
  78. arch_model->regression.nsample,
  79. arch_model->regression.valid?"VALID":"INVALID");
  80. /* Only display the regression model if we could actually build a model */
  81. if (arch_model->regression.valid)
  82. {
  83. fprintf(stderr, "\tLinear: y = alpha size ^ beta\n");
  84. fprintf(stderr, "\t\talpha = %le\n", arch_model->regression.alpha);
  85. fprintf(stderr, "\t\tbeta = %le\n", arch_model->regression.beta);
  86. fprintf(stderr, "\tNon-Linear: y = a size ^b + c\n");
  87. fprintf(stderr, "\t\ta = %le\n", arch_model->regression.a);
  88. fprintf(stderr, "\t\tb = %le\n", arch_model->regression.b);
  89. fprintf(stderr, "\t\tc = %le\n", arch_model->regression.c);
  90. }
  91. char debugname[1024];
  92. starpu_perfmodel_debugfilepath(model, arch, debugname, 1024);
  93. printf("\t debug file path : %s\n", debugname);
  94. }
  95. else {
  96. /* only display the parameter that was specifically requested */
  97. if (strcmp(parameter, "a") == 0) {
  98. printf("%le\n", arch_model->regression.a);
  99. return;
  100. }
  101. if (strcmp(parameter, "b") == 0) {
  102. printf("%le\n", arch_model->regression.b);
  103. return;
  104. }
  105. if (strcmp(parameter, "c") == 0) {
  106. printf("%le\n", arch_model->regression.c);
  107. return;
  108. }
  109. if (strcmp(parameter, "alpha") == 0) {
  110. printf("%le\n", arch_model->regression.alpha);
  111. return;
  112. }
  113. if (strcmp(parameter, "beta") == 0) {
  114. printf("%le\n", arch_model->regression.beta);
  115. return;
  116. }
  117. if (strcmp(parameter, "path-file-debug") == 0) {
  118. char debugname[256];
  119. starpu_perfmodel_debugfilepath(model, arch, debugname, 1024);
  120. printf("%s\n", debugname);
  121. return;
  122. }
  123. /* TODO display if it's valid ? */
  124. fprintf(stderr, "Unknown parameter requested, aborting.\n");
  125. exit(-1);
  126. }
  127. }
  128. static void display_all_perf_models(struct starpu_perfmodel_t *model)
  129. {
  130. if (arch == NULL)
  131. {
  132. /* display all architectures */
  133. unsigned archid;
  134. for (archid = 0; archid < NARCH_VARIATIONS; archid++)
  135. {
  136. char archname[32];
  137. starpu_perfmodel_get_arch_name(archid, archname, 32);
  138. fprintf(stderr, "performance model for %s\n", archname);
  139. display_perf_model(model, archid);
  140. }
  141. }
  142. else {
  143. if (strcmp(arch, "core") == 0) {
  144. display_perf_model(model, STARPU_CORE_DEFAULT);
  145. return;
  146. }
  147. if (strcmp(arch, "cuda") == 0) {
  148. unsigned archid;
  149. for (archid = STARPU_CUDA_DEFAULT; archid < STARPU_CUDA_DEFAULT + MAXCUDADEVS; archid++)
  150. {
  151. char archname[32];
  152. starpu_perfmodel_get_arch_name(archid, archname, 32);
  153. fprintf(stderr, "performance model for %s\n", archname);
  154. display_perf_model(model, archid);
  155. }
  156. return;
  157. }
  158. if (strcmp(arch, "gordon") == 0) {
  159. fprintf(stderr, "performance model for gordon\n");
  160. display_perf_model(model, STARPU_GORDON_DEFAULT);
  161. return;
  162. }
  163. fprintf(stderr, "Unknown architecture requested, aborting.\n");
  164. exit(-1);
  165. }
  166. }
  167. int main(int argc, char **argv)
  168. {
  169. // assert(argc == 2);
  170. parse_args(argc, argv);
  171. int ret = starpu_load_history_debug(symbol, &model);
  172. if (ret == 1)
  173. {
  174. fprintf(stderr, "The performance model could not be loaded\n");
  175. return 1;
  176. }
  177. display_all_perf_models(&model);
  178. return 0;
  179. }