double_parameter.c 4.8 KB

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