burst_gemm.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU 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. * StarPU 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. /*
  17. * Program to be executed with trace recording to watch the impact of
  18. * computations (or task polling) on communications.
  19. */
  20. #include <limits.h>
  21. #include <string.h>
  22. #include <unistd.h>
  23. #include <sys/types.h>
  24. #include <starpu_mpi.h>
  25. #include <starpu_fxt.h>
  26. #include "helper.h"
  27. #include "gemm_helper.h"
  28. #include "burst_helper.h"
  29. static int gemm_warmup = 1;
  30. static int gemm_warmup_wait = 0;
  31. void parse_args(int argc, char **argv)
  32. {
  33. int i;
  34. for (i = 1; i < argc; i++)
  35. {
  36. if (strcmp(argv[i], "-nblocks") == 0)
  37. {
  38. char *argptr;
  39. nslices = strtol(argv[++i], &argptr, 10);
  40. matrix_dim = 320 * nslices;
  41. }
  42. else if (strcmp(argv[i], "-size") == 0)
  43. {
  44. char *argptr;
  45. unsigned matrix_dim_tmp = strtol(argv[++i], &argptr, 10);
  46. if (matrix_dim_tmp % 320 != 0)
  47. {
  48. fprintf(stderr, "Matrix size has to be a multiple of 320\n");
  49. }
  50. else
  51. {
  52. matrix_dim = matrix_dim_tmp;
  53. nslices = matrix_dim / 320;
  54. }
  55. }
  56. else if (strcmp(argv[i], "-check") == 0)
  57. {
  58. check = 1;
  59. }
  60. else if (strcmp(argv[i], "-nreqs") == 0)
  61. {
  62. burst_nb_requests = atoi(argv[++i]);
  63. }
  64. else if (strcmp(argv[i], "-no-gemm-warmup") == 0)
  65. {
  66. gemm_warmup = 0;
  67. }
  68. else if (strcmp(argv[i], "-gemm-warmup-wait") == 0)
  69. {
  70. /* All warmup GEMMs will start at the same moment */
  71. gemm_warmup_wait = 1;
  72. }
  73. else if (strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0)
  74. {
  75. fprintf(stderr,"Usage: %s [-nblocks n] [-size size] [-check] [-nreqs nreqs] [-no-gemm-warmup] [-gemm-warmup-wait]\n", argv[0]);
  76. fprintf(stderr,"Currently selected: matrix size: %u - %u blocks - %d requests in each burst - gemm warmup: %d -gemm-warmup-wait: %d\n", matrix_dim, nslices, burst_nb_requests, gemm_warmup, gemm_warmup_wait);
  77. exit(EXIT_SUCCESS);
  78. }
  79. else
  80. {
  81. fprintf(stderr,"Unrecognized option %s\n", argv[i]);
  82. exit(EXIT_FAILURE);
  83. }
  84. }
  85. }
  86. int main(int argc, char **argv)
  87. {
  88. int ret, worldsize, mpi_rank;
  89. parse_args(argc, argv);
  90. ret = starpu_mpi_init_conf(&argc, &argv, 1, MPI_COMM_WORLD, NULL);
  91. if (ret == -ENODEV)
  92. return 77;
  93. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init_conf");
  94. starpu_mpi_comm_rank(MPI_COMM_WORLD, &mpi_rank);
  95. starpu_mpi_comm_size(MPI_COMM_WORLD, &worldsize);
  96. if (worldsize < 2)
  97. {
  98. if (mpi_rank == 0)
  99. FPRINTF(stderr, "We need 2 processes.\n");
  100. starpu_mpi_shutdown();
  101. return STARPU_TEST_SKIPPED;
  102. }
  103. gemm_alloc_data();
  104. if (gemm_init_data() == -ENODEV)
  105. goto enodev;
  106. /* GEMM warmup, to really load the BLAS library */
  107. if (gemm_warmup)
  108. {
  109. if (gemm_warmup_wait)
  110. {
  111. starpu_task_wait_for_all();
  112. starpu_pause();
  113. }
  114. if(gemm_submit_tasks() == -ENODEV)
  115. goto enodev;
  116. if (gemm_warmup_wait)
  117. {
  118. starpu_resume();
  119. }
  120. }
  121. burst_init_data(mpi_rank);
  122. /* Wait for everything and everybody: */
  123. starpu_task_wait_for_all();
  124. starpu_mpi_barrier(MPI_COMM_WORLD);
  125. FPRINTF(stderr, "** Burst warmup **\n");
  126. burst_all(mpi_rank);
  127. starpu_sleep(0.3); // sleep to easily distinguish different bursts in traces
  128. FPRINTF(stderr, "** Burst while there is no task available, but workers are polling **\n");
  129. burst_all(mpi_rank);
  130. starpu_sleep(0.3); // sleep to easily distinguish different bursts in traces
  131. FPRINTF(stderr, "** Burst while there is no task available, workers are paused **\n");
  132. starpu_pause();
  133. burst_all(mpi_rank);
  134. starpu_sleep(0.3); // sleep to easily distinguish different bursts in traces
  135. FPRINTF(stderr, "** Burst while workers are really working **\n");
  136. if(gemm_submit_tasks() == -ENODEV)
  137. goto enodev;
  138. starpu_resume();
  139. burst_all(mpi_rank);
  140. FPRINTF(stderr, "Burst done, now waiting for computing tasks to finish\n");
  141. /* Wait for everything and everybody: */
  142. starpu_task_wait_for_all();
  143. starpu_mpi_barrier(MPI_COMM_WORLD);
  144. starpu_sleep(0.3); // sleep to easily distinguish different parts in traces
  145. FPRINTF(stderr, "** Workers are computing, without communications **\n");
  146. starpu_pause();
  147. if(gemm_submit_tasks() == -ENODEV)
  148. goto enodev;
  149. starpu_resume();
  150. /* Wait for everything and everybody: */
  151. starpu_task_wait_for_all();
  152. starpu_mpi_barrier(MPI_COMM_WORLD);
  153. starpu_sleep(0.3); // sleep to easily distinguish different parts in traces
  154. FPRINTF(stderr, "** Burst while workers are computing, but polling a moment between each task **\n");
  155. starpu_pause();
  156. gemm_add_polling_dependencies();
  157. if(gemm_submit_tasks_with_tags(/* enable task tags */ 1) == -ENODEV)
  158. goto enodev;
  159. starpu_resume();
  160. burst_all(mpi_rank);
  161. /* Wait for everything and everybody: */
  162. starpu_task_wait_for_all();
  163. starpu_mpi_barrier(MPI_COMM_WORLD);
  164. enodev:
  165. gemm_release();
  166. burst_free_data(mpi_rank);
  167. starpu_mpi_shutdown();
  168. return ret;
  169. }