double_parameter.c 4.4 KB

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