double_parameter.c 4.8 KB

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