double_parameter.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-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. #include <starpu.h>
  17. #include "../helper.h"
  18. /*
  19. * Try passing the same parameter twice, with various access modes
  20. */
  21. void dummy_func(void *descr[], void *arg)
  22. {
  23. (void)descr;
  24. (void)arg;
  25. }
  26. static struct starpu_codelet codelet_R_R =
  27. {
  28. .cpu_funcs = { dummy_func },
  29. .cpu_funcs_name = {"dummy_func"},
  30. .model = NULL,
  31. .nbuffers = 2,
  32. .modes = {STARPU_R, STARPU_R}
  33. };
  34. static struct starpu_codelet codelet_R_W =
  35. {
  36. .cpu_funcs = { dummy_func },
  37. .cpu_funcs_name = {"dummy_func"},
  38. .model = NULL,
  39. .nbuffers = 2,
  40. .modes = {STARPU_R, STARPU_W}
  41. };
  42. static struct starpu_codelet codelet_R_RW =
  43. {
  44. .cpu_funcs = { dummy_func },
  45. .cpu_funcs_name = {"dummy_func"},
  46. .model = NULL,
  47. .nbuffers = 2,
  48. .modes = {STARPU_R, STARPU_RW}
  49. };
  50. static struct starpu_codelet codelet_W_R =
  51. {
  52. .cpu_funcs = { dummy_func },
  53. .cpu_funcs_name = {"dummy_func"},
  54. .model = NULL,
  55. .nbuffers = 2,
  56. .modes = {STARPU_W, STARPU_R}
  57. };
  58. static struct starpu_codelet codelet_W_W =
  59. {
  60. .cpu_funcs = { dummy_func },
  61. .cpu_funcs_name = {"dummy_func"},
  62. .model = NULL,
  63. .nbuffers = 2,
  64. .modes = {STARPU_W, STARPU_W}
  65. };
  66. static struct starpu_codelet codelet_W_RW =
  67. {
  68. .cpu_funcs = { dummy_func },
  69. .cpu_funcs_name = {"dummy_func"},
  70. .model = NULL,
  71. .nbuffers = 2,
  72. .modes = {STARPU_W, STARPU_RW}
  73. };
  74. static struct starpu_codelet codelet_RW_R =
  75. {
  76. .cpu_funcs = { dummy_func },
  77. .cpu_funcs_name = {"dummy_func"},
  78. .model = NULL,
  79. .nbuffers = 2,
  80. .modes = {STARPU_RW, STARPU_R}
  81. };
  82. static struct starpu_codelet codelet_RW_W =
  83. {
  84. .cpu_funcs = { dummy_func },
  85. .cpu_funcs_name = {"dummy_func"},
  86. .model = NULL,
  87. .nbuffers = 2,
  88. .modes = {STARPU_RW, STARPU_W}
  89. };
  90. static struct starpu_codelet codelet_RW_RW =
  91. {
  92. .cpu_funcs = { dummy_func },
  93. .cpu_funcs_name = {"dummy_func"},
  94. .model = NULL,
  95. .nbuffers = 2,
  96. .modes = {STARPU_RW, STARPU_RW}
  97. };
  98. int main(int argc, char **argv)
  99. {
  100. float foo = 0.0f;
  101. starpu_data_handle_t handle;
  102. int ret;
  103. struct starpu_task *task;
  104. ret = starpu_initialize(NULL, &argc, &argv);
  105. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  106. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  107. starpu_variable_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)&foo, sizeof(foo));
  108. #define SUBMIT(mode0, mode1) \
  109. { \
  110. task = starpu_task_create(); \
  111. task->handles[0] = handle; \
  112. task->handles[1] = handle; \
  113. enum starpu_data_access_mode smode0 = STARPU_##mode0; \
  114. enum starpu_data_access_mode smode1 = STARPU_##mode0; \
  115. if (smode0 == STARPU_R && smode1 == STARPU_R) \
  116. task->cl = &codelet_R_R; \
  117. else if (smode0 == STARPU_R && smode1 == STARPU_W) \
  118. task->cl = &codelet_R_W; \
  119. else if (smode0 == STARPU_R && smode1 == STARPU_RW) \
  120. task->cl = &codelet_R_RW; \
  121. else if (smode0 == STARPU_W && smode1 == STARPU_R) \
  122. task->cl = &codelet_W_R; \
  123. else if (smode0 == STARPU_W && smode1 == STARPU_W) \
  124. task->cl = &codelet_W_W; \
  125. else if (smode0 == STARPU_W && smode1 == STARPU_RW) \
  126. task->cl = &codelet_W_RW; \
  127. else if (smode0 == STARPU_RW && smode1 == STARPU_R) \
  128. task->cl = &codelet_RW_R; \
  129. else if (smode0 == STARPU_RW && smode1 == STARPU_W) \
  130. task->cl = &codelet_RW_W; \
  131. else if (smode0 == STARPU_RW && smode1 == STARPU_RW) \
  132. task->cl = &codelet_RW_RW; \
  133. \
  134. ret = starpu_task_submit(task); \
  135. if (ret == -ENODEV) goto enodev; \
  136. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit"); \
  137. }
  138. SUBMIT(R,R);
  139. SUBMIT(R,W);
  140. SUBMIT(R,RW);
  141. SUBMIT(W,R);
  142. SUBMIT(W,W);
  143. SUBMIT(W,RW);
  144. SUBMIT(RW,R);
  145. SUBMIT(RW,W);
  146. SUBMIT(RW,RW);
  147. ret = starpu_task_wait_for_all();
  148. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  149. starpu_data_unregister(handle);
  150. starpu_shutdown();
  151. return EXIT_SUCCESS;
  152. enodev:
  153. starpu_data_unregister(handle);
  154. fprintf(stderr, "WARNING: No one can execute this task\n");
  155. /* yes, we do not perform the computation but we did detect that no one
  156. * could perform the kernel, so this is not an error from StarPU */
  157. starpu_shutdown();
  158. return STARPU_TEST_SKIPPED;
  159. }