double_parameter.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  102. starpu_variable_data_register(&handle, 0, (uintptr_t)&foo, sizeof(foo));
  103. #define SUBMIT(mode0, mode1) \
  104. { \
  105. task = starpu_task_create(); \
  106. task->handles[0] = handle; \
  107. task->handles[1] = handle; \
  108. enum starpu_access_mode smode0 = STARPU_##mode0; \
  109. enum starpu_access_mode smode1 = STARPU_##mode0; \
  110. if (smode0 == STARPU_R && smode1 == STARPU_R) \
  111. task->cl = &codelet_R_R; \
  112. else if (smode0 == STARPU_R && smode1 == STARPU_W) \
  113. task->cl = &codelet_R_W; \
  114. else if (smode0 == STARPU_R && smode1 == STARPU_RW) \
  115. task->cl = &codelet_R_RW; \
  116. else if (smode0 == STARPU_W && smode1 == STARPU_R) \
  117. task->cl = &codelet_W_R; \
  118. else if (smode0 == STARPU_W && smode1 == STARPU_W) \
  119. task->cl = &codelet_W_W; \
  120. else if (smode0 == STARPU_W && smode1 == STARPU_RW) \
  121. task->cl = &codelet_W_RW; \
  122. else if (smode0 == STARPU_RW && smode1 == STARPU_R) \
  123. task->cl = &codelet_RW_R; \
  124. else if (smode0 == STARPU_RW && smode1 == STARPU_W) \
  125. task->cl = &codelet_RW_W; \
  126. else if (smode0 == STARPU_RW && smode1 == STARPU_RW) \
  127. task->cl = &codelet_RW_RW; \
  128. \
  129. ret = starpu_task_submit(task); \
  130. if (ret == -ENODEV) goto enodev; \
  131. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit"); \
  132. }
  133. SUBMIT(R,R);
  134. SUBMIT(R,W);
  135. SUBMIT(R,RW);
  136. SUBMIT(W,R);
  137. SUBMIT(W,W);
  138. SUBMIT(W,RW);
  139. SUBMIT(RW,R);
  140. SUBMIT(RW,W);
  141. SUBMIT(RW,RW);
  142. ret = starpu_task_wait_for_all();
  143. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  144. starpu_data_unregister(handle);
  145. starpu_shutdown();
  146. return EXIT_SUCCESS;
  147. enodev:
  148. starpu_data_unregister(handle);
  149. fprintf(stderr, "WARNING: No one can execute this task\n");
  150. /* yes, we do not perform the computation but we did detect that no one
  151. * could perform the kernel, so this is not an error from StarPU */
  152. starpu_shutdown();
  153. return STARPU_TEST_SKIPPED;
  154. }