double_parameter.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 Université de Bordeaux 1
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <starpu.h>
  17. #include "../helper.h"
  18. static void dummy_func(void *descr[] __attribute__ ((unused)), void *arg __attribute__ ((unused)))
  19. {
  20. }
  21. static struct starpu_codelet codelet_R_R =
  22. {
  23. .where = STARPU_CPU,
  24. .cpu_funcs = { dummy_func, NULL },
  25. .model = NULL,
  26. .nbuffers = 2
  27. };
  28. static struct starpu_codelet codelet_R_W =
  29. {
  30. .where = STARPU_CPU,
  31. .cpu_funcs = { dummy_func, NULL },
  32. .model = NULL,
  33. .nbuffers = 2
  34. };
  35. static struct starpu_codelet codelet_R_RW =
  36. {
  37. .where = STARPU_CPU,
  38. .cpu_funcs = { dummy_func, NULL },
  39. .model = NULL,
  40. .nbuffers = 2
  41. };
  42. static struct starpu_codelet codelet_W_R =
  43. {
  44. .where = STARPU_CPU,
  45. .cpu_funcs = { dummy_func, NULL },
  46. .model = NULL,
  47. .nbuffers = 2
  48. };
  49. static struct starpu_codelet codelet_W_W =
  50. {
  51. .where = STARPU_CPU,
  52. .cpu_funcs = { dummy_func, NULL },
  53. .model = NULL,
  54. .nbuffers = 2
  55. };
  56. static struct starpu_codelet codelet_W_RW =
  57. {
  58. .where = STARPU_CPU,
  59. .cpu_funcs = { dummy_func, NULL },
  60. .model = NULL,
  61. .nbuffers = 2
  62. };
  63. static struct starpu_codelet codelet_RW_R =
  64. {
  65. .where = STARPU_CPU,
  66. .cpu_funcs = { dummy_func, NULL },
  67. .model = NULL,
  68. .nbuffers = 2
  69. };
  70. static struct starpu_codelet codelet_RW_W =
  71. {
  72. .where = STARPU_CPU,
  73. .cpu_funcs = { dummy_func, NULL },
  74. .model = NULL,
  75. .nbuffers = 2
  76. };
  77. static struct starpu_codelet codelet_RW_RW =
  78. {
  79. .where = STARPU_CPU,
  80. .cpu_funcs = { dummy_func, NULL },
  81. .model = NULL,
  82. .nbuffers = 2
  83. };
  84. int main(int argc, char **argv)
  85. {
  86. float foo = 0.0f;
  87. starpu_data_handle_t handle;
  88. int ret;
  89. struct starpu_task *task;
  90. ret = starpu_init(NULL);
  91. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  92. starpu_variable_data_register(&handle, 0, (uintptr_t)&foo, sizeof(foo));
  93. #define SUBMIT(mode1, mode2) \
  94. task = starpu_task_create(); \
  95. \
  96. task->buffers[0].handle = handle; \
  97. task->buffers[0].mode = STARPU_##mode1; \
  98. task->buffers[1].handle = handle; \
  99. task->buffers[1].mode = STARPU_##mode2; \
  100. if (task->buffers[0].mode == STARPU_R && task->buffers[1].mode == STARPU_R) \
  101. task->cl = &codelet_R_R; \
  102. else if (task->buffers[0].mode == STARPU_R && task->buffers[1].mode == STARPU_W) \
  103. task->cl = &codelet_R_W; \
  104. else if (task->buffers[0].mode == STARPU_R && task->buffers[1].mode == STARPU_RW) \
  105. task->cl = &codelet_R_RW; \
  106. else if (task->buffers[0].mode == STARPU_W && task->buffers[1].mode == STARPU_R) \
  107. task->cl = &codelet_W_R; \
  108. else if (task->buffers[0].mode == STARPU_W && task->buffers[1].mode == STARPU_W) \
  109. task->cl = &codelet_W_W; \
  110. else if (task->buffers[0].mode == STARPU_W && task->buffers[1].mode == STARPU_RW) \
  111. task->cl = &codelet_W_RW; \
  112. else if (task->buffers[0].mode == STARPU_RW && task->buffers[1].mode == STARPU_R) \
  113. task->cl = &codelet_RW_R; \
  114. else if (task->buffers[0].mode == STARPU_RW && task->buffers[1].mode == STARPU_W) \
  115. task->cl = &codelet_RW_W; \
  116. else if (task->buffers[0].mode == STARPU_RW && task->buffers[1].mode == STARPU_RW) \
  117. task->cl = &codelet_RW_RW; \
  118. \
  119. ret = starpu_task_submit(task); \
  120. if (ret == -ENODEV) goto enodev; \
  121. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  122. SUBMIT(R,R);
  123. SUBMIT(R,W);
  124. SUBMIT(R,RW);
  125. SUBMIT(W,R);
  126. SUBMIT(W,W);
  127. SUBMIT(W,RW);
  128. SUBMIT(RW,R);
  129. SUBMIT(RW,W);
  130. SUBMIT(RW,RW);
  131. ret = starpu_task_wait_for_all();
  132. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  133. starpu_data_unregister(handle);
  134. starpu_shutdown();
  135. return EXIT_SUCCESS;
  136. enodev:
  137. starpu_data_unregister(handle);
  138. fprintf(stderr, "WARNING: No one can execute this task\n");
  139. /* yes, we do not perform the computation but we did detect that no one
  140. * could perform the kernel, so this is not an error from StarPU */
  141. starpu_shutdown();
  142. return STARPU_TEST_SKIPPED;
  143. }