double_parameter.c 4.7 KB

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