burst_gemm.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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, mpi_init, worldsize, mpi_rank;
  89. parse_args(argc, argv);
  90. MPI_INIT_THREAD(&argc, &argv, MPI_THREAD_SERIALIZED, &mpi_init);
  91. ret = starpu_mpi_init_conf(&argc, &argv, mpi_init, MPI_COMM_WORLD, NULL);
  92. if (ret == -ENODEV)
  93. return 77;
  94. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init_conf");
  95. starpu_mpi_comm_rank(MPI_COMM_WORLD, &mpi_rank);
  96. starpu_mpi_comm_size(MPI_COMM_WORLD, &worldsize);
  97. if (worldsize < 2)
  98. {
  99. if (mpi_rank == 0)
  100. FPRINTF(stderr, "We need 2 processes.\n");
  101. starpu_mpi_shutdown();
  102. if (!mpi_init)
  103. MPI_Finalize();
  104. return STARPU_TEST_SKIPPED;
  105. }
  106. gemm_alloc_data();
  107. if (gemm_init_data() == -ENODEV)
  108. goto enodev;
  109. /* GEMM warmup, to really load the BLAS library */
  110. if (gemm_warmup)
  111. {
  112. if (gemm_warmup_wait)
  113. {
  114. starpu_task_wait_for_all();
  115. starpu_pause();
  116. }
  117. if(gemm_submit_tasks() == -ENODEV)
  118. goto enodev;
  119. if (gemm_warmup_wait)
  120. {
  121. starpu_resume();
  122. }
  123. }
  124. burst_init_data(mpi_rank);
  125. /* Wait for everything and everybody: */
  126. starpu_task_wait_for_all();
  127. starpu_mpi_barrier(MPI_COMM_WORLD);
  128. FPRINTF(stderr, "** Burst warmup **\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, but workers are polling **\n");
  132. burst_all(mpi_rank);
  133. starpu_sleep(0.3); // sleep to easily distinguish different bursts in traces
  134. FPRINTF(stderr, "** Burst while there is no task available, workers are paused **\n");
  135. starpu_pause();
  136. burst_all(mpi_rank);
  137. starpu_sleep(0.3); // sleep to easily distinguish different bursts in traces
  138. FPRINTF(stderr, "** Burst while workers are really working **\n");
  139. if(gemm_submit_tasks() == -ENODEV)
  140. goto enodev;
  141. starpu_resume();
  142. burst_all(mpi_rank);
  143. FPRINTF(stderr, "Burst done, now waiting for computing tasks to finish\n");
  144. /* Wait for everything and everybody: */
  145. starpu_task_wait_for_all();
  146. starpu_mpi_barrier(MPI_COMM_WORLD);
  147. starpu_sleep(0.3); // sleep to easily distinguish different parts in traces
  148. FPRINTF(stderr, "** Workers are computing, without communications **\n");
  149. starpu_pause();
  150. if(gemm_submit_tasks() == -ENODEV)
  151. goto enodev;
  152. starpu_resume();
  153. /* Wait for everything and everybody: */
  154. starpu_task_wait_for_all();
  155. starpu_mpi_barrier(MPI_COMM_WORLD);
  156. starpu_sleep(0.3); // sleep to easily distinguish different parts in traces
  157. FPRINTF(stderr, "** Burst while workers are computing, but polling a moment between each task **\n");
  158. starpu_pause();
  159. gemm_add_polling_dependencies();
  160. if(gemm_submit_tasks_with_tags(/* enable task tags */ 1) == -ENODEV)
  161. goto enodev;
  162. starpu_resume();
  163. burst_all(mpi_rank);
  164. /* Wait for everything and everybody: */
  165. starpu_task_wait_for_all();
  166. starpu_mpi_barrier(MPI_COMM_WORLD);
  167. enodev:
  168. gemm_release();
  169. burst_free_data(mpi_rank);
  170. starpu_mpi_shutdown();
  171. if (!mpi_init)
  172. MPI_Finalize();
  173. return ret;
  174. }