double_parameter.c 4.7 KB

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