starpu_tasks_rec_complete.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-2015,2017 CNRS
  4. * Copyright (C) 2011-2014,2016 Université de Bordeaux
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <stdint.h>
  20. #include <errno.h>
  21. #include <string.h>
  22. #include <common/config.h>
  23. #include <common/uthash.h>
  24. #include <common/utils.h>
  25. #include <starpu.h>
  26. #define PROGNAME "starpu_tasks_rec_complete"
  27. /*
  28. * This program takes a tasks.rec file, and emits a tasks.rec file with
  29. * additional information, notably estimated termination times.
  30. */
  31. static struct model
  32. {
  33. UT_hash_handle hh;
  34. char *name;
  35. struct starpu_perfmodel model;
  36. } *models;
  37. int main(int argc, char *argv[])
  38. {
  39. FILE *input;
  40. FILE *output;
  41. char s[1024], *c;
  42. uint32_t footprint = 0;
  43. int already_there = 0;
  44. char *model_name = NULL;
  45. struct model *model, *tmp;
  46. int ret;
  47. if (argc >= 2)
  48. {
  49. if (!strcmp(argv[1], "-h") ||
  50. !strcmp(argv[1], "--help"))
  51. {
  52. fprintf(stderr, "Complete a tasks.rec file with additional information, notably estimated termination times.\n");
  53. fprintf(stderr, "\n");
  54. fprintf(stderr, "Usage: %s [input-file [output-file]]\n", PROGNAME);
  55. fprintf(stderr, "\n");
  56. fprintf(stderr, "If input or output file names are not given, stdin and stdout are used.");
  57. fprintf(stderr, "\n");
  58. fprintf(stderr, "Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
  59. exit(EXIT_SUCCESS);
  60. }
  61. }
  62. #ifdef STARPU_HAVE_SETENV
  63. setenv("STARPU_FXT_TRACE", "0", 1);
  64. #endif
  65. if (starpu_init(NULL) != 0)
  66. {
  67. fprintf(stderr, "StarPU initialization failure\n");
  68. exit(EXIT_FAILURE);
  69. }
  70. starpu_pause();
  71. if (argc >= 2)
  72. {
  73. input = fopen(argv[1], "r");
  74. if (!input)
  75. {
  76. fprintf(stderr, "couldn't open %s for read: %s\n", argv[1], strerror(errno));
  77. exit(EXIT_FAILURE);
  78. }
  79. }
  80. else
  81. input = stdin;
  82. if (argc >= 3)
  83. {
  84. output = fopen(argv[2], "w+");
  85. if (!output)
  86. {
  87. fprintf(stderr, "couldn't open %s for write: %s\n", argv[1], strerror(errno));
  88. exit(EXIT_FAILURE);
  89. }
  90. }
  91. else
  92. output = stdout;
  93. while (fgets(s, sizeof(s), input))
  94. {
  95. if (strlen(s) == sizeof(s) - 1)
  96. {
  97. fprintf(stderr, "oops, very long line '%s', it's odd\n", s);
  98. exit(EXIT_FAILURE);
  99. }
  100. if (s[0] == '\n')
  101. {
  102. /* empty line, end of task */
  103. if (model_name)
  104. {
  105. if (already_there)
  106. {
  107. free(model_name);
  108. }
  109. else
  110. {
  111. /* Try to get already-loaded model */
  112. HASH_FIND_STR(models, model_name, model);
  113. if (model == NULL)
  114. {
  115. _STARPU_MALLOC(model, sizeof(*model));
  116. model->name = model_name;
  117. memset(&model->model, 0, sizeof(model->model));
  118. model->model.type = STARPU_PERFMODEL_INVALID;
  119. ret = starpu_perfmodel_load_symbol(model_name, &model->model);
  120. if (ret == 1)
  121. {
  122. fprintf(stderr, "The performance model for the symbol <%s> could not be loaded\n", model_name);
  123. exit(EXIT_FAILURE);
  124. }
  125. HASH_ADD_STR(models, name, model);
  126. }
  127. else
  128. free(model_name);
  129. fprintf(output, "EstimatedTime: ");
  130. starpu_perfmodel_print_estimations(&model->model, footprint, output);
  131. fprintf(output, "\n");
  132. }
  133. model_name = NULL;
  134. }
  135. already_there = 0;
  136. fprintf(output, "\n");
  137. continue;
  138. }
  139. /* Get rec field name */
  140. c = strchr(s, ':');
  141. if (!c)
  142. {
  143. fprintf(stderr, "odd line '%s'\n", s);
  144. exit(EXIT_FAILURE);
  145. }
  146. #define STRHEADCMP(s, head) strncmp(s, head, strlen(head))
  147. if (!STRHEADCMP(s, "Footprint: "))
  148. {
  149. footprint = strtoul(s + strlen("Footprint: "), NULL, 16);
  150. }
  151. else if (!STRHEADCMP(s, "Model: "))
  152. {
  153. model_name = strdup(s + strlen("Model: "));
  154. model_name[strlen(model_name) - 1] = '\0'; /* Drop '\n' */
  155. }
  156. else if (!STRHEADCMP(s, "EstimatedTime: "))
  157. {
  158. already_there = 1;
  159. }
  160. fprintf(output, "%s", s);
  161. }
  162. if (fclose(input))
  163. {
  164. fprintf(stderr, "couldn't close input: %s\n", strerror(errno));
  165. exit(EXIT_FAILURE);
  166. }
  167. if (fclose(output))
  168. {
  169. fprintf(stderr, "couldn't close output: %s\n", strerror(errno));
  170. exit(EXIT_FAILURE);
  171. }
  172. starpu_resume();
  173. starpu_shutdown();
  174. HASH_ITER(hh, models, model, tmp)
  175. {
  176. free(model->name);
  177. HASH_DEL(models, model);
  178. }
  179. return 0;
  180. }