testCommute.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2015 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. * for i from 0 to nbA
  18. * insert task handles[i] in STARPU_RW|STARPU_COMMUTE
  19. * for j from 0 to nbA
  20. * if i != j
  21. insert task handles[i] in STARPU_RW|STARPU_COMMUTE, and handles[j] in STARPU_RW|STARPU_COMMUTE
  22. */
  23. // @FUSE_STARPU
  24. #ifdef STARPU_QUICK_CHECK
  25. #define SLEEP_SLOW 6000
  26. #define SLEEP_FAST 1000
  27. #else
  28. #define SLEEP_SLOW 600000
  29. #define SLEEP_FAST 100000
  30. #endif
  31. #include <starpu.h>
  32. #include "../helper.h"
  33. #include <vector>
  34. #include <unistd.h>
  35. void callback(void * /*buffers*/[], void * /*cl_arg*/)
  36. {
  37. usleep(SLEEP_FAST);
  38. FPRINTF(stdout,"COMMUTE_LOG] callback\n"); fflush(stdout);
  39. }
  40. void callback_slow(void * /*buffers*/[], void * /*cl_arg*/)
  41. {
  42. usleep(SLEEP_SLOW);
  43. FPRINTF(stdout,"COMMUTE_LOG] callback_slow\n"); fflush(stdout);
  44. }
  45. int main(int /*argc*/, char** /*argv*/)
  46. {
  47. int ret;
  48. struct starpu_conf conf;
  49. ret = starpu_conf_init(&conf);
  50. STARPU_ASSERT(ret == 0);
  51. //conf.ncpus = 1;//// 4
  52. ret = starpu_init(&conf);
  53. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  54. STARPU_ASSERT(ret == 0);
  55. FPRINTF(stdout, "Max Thread %d\n", starpu_worker_get_count());
  56. //////////////////////////////////////////////////////
  57. starpu_codelet normalCodelete;
  58. {
  59. memset(&normalCodelete, 0, sizeof(normalCodelete));
  60. normalCodelete.where = STARPU_CPU;
  61. normalCodelete.cpu_funcs[0] = callback;
  62. normalCodelete.nbuffers = 2;
  63. normalCodelete.modes[0] = starpu_data_access_mode(STARPU_RW|STARPU_COMMUTE);
  64. normalCodelete.modes[1] = starpu_data_access_mode(STARPU_RW|STARPU_COMMUTE);
  65. normalCodelete.name = "normalCodelete";
  66. }
  67. starpu_codelet slowCodelete;
  68. {
  69. memset(&slowCodelete, 0, sizeof(slowCodelete));
  70. slowCodelete.where = STARPU_CPU;
  71. slowCodelete.cpu_funcs[0] = callback_slow;
  72. slowCodelete.nbuffers = 1;
  73. slowCodelete.modes[0] = starpu_data_access_mode (STARPU_RW|STARPU_COMMUTE);
  74. slowCodelete.name = "slowCodelete";
  75. }
  76. //////////////////////////////////////////////////////
  77. //////////////////////////////////////////////////////
  78. ///const int nbA = 3;
  79. const int nbA = 10;
  80. FPRINTF(stdout, "Nb A = %d\n", nbA);
  81. std::vector<starpu_data_handle_t> handleA(nbA);
  82. std::vector<int> dataA(nbA);
  83. for(int idx = 0 ; idx < nbA ; ++idx)
  84. {
  85. dataA[idx] = idx;
  86. }
  87. for(int idxHandle = 0 ; idxHandle < nbA ; ++idxHandle)
  88. {
  89. starpu_variable_data_register(&handleA[idxHandle], 0, (uintptr_t)&dataA[idxHandle], sizeof(dataA[idxHandle]));
  90. }
  91. //////////////////////////////////////////////////////
  92. //////////////////////////////////////////////////////
  93. FPRINTF(stdout,"Submit tasks\n");
  94. for(int idxHandleA1 = 0 ; idxHandleA1 < nbA ; ++idxHandleA1)
  95. {
  96. ret = starpu_task_insert(&slowCodelete,
  97. (STARPU_RW|STARPU_COMMUTE), handleA[idxHandleA1],
  98. 0);
  99. if (ret == -ENODEV) goto out;
  100. for(int idxHandleA2 = 0 ; idxHandleA2 < nbA ; ++idxHandleA2)
  101. {
  102. if(idxHandleA1 != idxHandleA2)
  103. {
  104. ret = starpu_task_insert(&normalCodelete,
  105. (STARPU_RW|STARPU_COMMUTE), handleA[idxHandleA1],
  106. (STARPU_RW|STARPU_COMMUTE), handleA[idxHandleA2],
  107. 0);
  108. if (ret == -ENODEV) goto out;
  109. }
  110. }
  111. }
  112. //////////////////////////////////////////////////////
  113. FPRINTF(stdout,"Wait task\n");
  114. out:
  115. starpu_task_wait_for_all();
  116. //////////////////////////////////////////////////////
  117. FPRINTF(stdout,"Release data\n");
  118. for(int idxHandle = 0 ; idxHandle < nbA ; ++idxHandle)
  119. {
  120. starpu_data_unregister(handleA[idxHandle]);
  121. }
  122. //////////////////////////////////////////////////////
  123. FPRINTF(stdout,"Shutdown\n");
  124. starpu_shutdown();
  125. return 0;
  126. }