double_parameter.c 4.8 KB

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