perfmodel-display.c 4.9 KB

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