perfmodel-display.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 = malloc(1024);
  86. starpu_perfmodel_debugfilepath(model, arch, &debugname, 1024);
  87. free(debugname);
  88. printf("\t debug file path : %s\n", debugname);
  89. }
  90. else {
  91. /* only display the parameter that was specifically requested */
  92. if (strcmp(parameter, "a") == 0) {
  93. printf("%le\n", arch_model->regression.a);
  94. return;
  95. }
  96. if (strcmp(parameter, "b") == 0) {
  97. printf("%le\n", arch_model->regression.b);
  98. return;
  99. }
  100. if (strcmp(parameter, "c") == 0) {
  101. printf("%le\n", arch_model->regression.c);
  102. return;
  103. }
  104. if (strcmp(parameter, "alpha") == 0) {
  105. printf("%le\n", arch_model->regression.alpha);
  106. return;
  107. }
  108. if (strcmp(parameter, "beta") == 0) {
  109. printf("%le\n", arch_model->regression.beta);
  110. return;
  111. }
  112. if (strcmp(parameter, "path-file-debug") == 0) {
  113. char *debugname = malloc(1024);
  114. starpu_perfmodel_debugfilepath(model, arch, &debugname, 1024);
  115. printf("%s\n", debugname);
  116. free(debugname);
  117. return;
  118. }
  119. /* TODO display if it's valid ? */
  120. fprintf(stderr, "Unknown parameter requested, aborting.\n");
  121. exit(-1);
  122. }
  123. }
  124. static void display_all_perf_models(struct starpu_perfmodel_t *model)
  125. {
  126. if (arch == NULL)
  127. {
  128. /* display all architectures */
  129. /* yet, we assume there is a single performance model per
  130. * architecture */
  131. fprintf(stderr, "performance model for CPUs :\n");
  132. display_perf_model(model, STARPU_CORE_DEFAULT);
  133. fprintf(stderr, "performance model for CUDA :\n");
  134. display_perf_model(model, STARPU_CUDA_DEFAULT);
  135. fprintf(stderr, "performance model for CUDA (2):\n");
  136. display_perf_model(model, STARPU_CUDA_2);
  137. fprintf(stderr, "performance model for CUDA (3):\n");
  138. display_perf_model(model, STARPU_CUDA_3);
  139. fprintf(stderr, "performance model for CUDA (4):\n");
  140. display_perf_model(model, STARPU_CUDA_4);
  141. fprintf(stderr, "performance model for GORDON :\n");
  142. display_perf_model(model, STARPU_GORDON_DEFAULT);
  143. }
  144. else {
  145. if (strcmp(arch, "core") == 0) {
  146. display_perf_model(model, STARPU_CORE_DEFAULT);
  147. return;
  148. }
  149. if (strcmp(arch, "cuda") == 0) {
  150. display_perf_model(model, STARPU_CUDA_DEFAULT);
  151. display_perf_model(model, STARPU_CUDA_2);
  152. display_perf_model(model, STARPU_CUDA_3);
  153. display_perf_model(model, STARPU_CUDA_4);
  154. return;
  155. }
  156. if (strcmp(arch, "gordon") == 0) {
  157. display_perf_model(model, STARPU_GORDON_DEFAULT);
  158. return;
  159. }
  160. fprintf(stderr, "Unknown architecture requested, aborting.\n");
  161. exit(-1);
  162. }
  163. }
  164. int main(int argc, char **argv)
  165. {
  166. // assert(argc == 2);
  167. parse_args(argc, argv);
  168. int ret = starpu_load_history_debug(symbol, &model);
  169. if (ret == 1)
  170. {
  171. fprintf(stderr, "The performance model could not be loaded\n");
  172. return 1;
  173. }
  174. display_all_perf_models(&model);
  175. return 0;
  176. }