deprecated_buffer.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2011, 2012, 2013 Centre National de la Recherche Scientifique
  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 <config.h>
  17. #include <starpu.h>
  18. #include "../helper.h"
  19. void cpu_codelet(void *descr[], STARPU_ATTRIBUTE_UNUSED void *_args)
  20. {
  21. int *valin = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  22. int *valout = (int *)STARPU_VARIABLE_GET_PTR(descr[1]);
  23. *valout = *valin;
  24. }
  25. struct starpu_codelet cl_with_mode =
  26. {
  27. .name = "with_mode",
  28. .cpu_funcs = {cpu_codelet, NULL},
  29. .cpu_funcs_name = {"cpu_codelet", NULL},
  30. .nbuffers = 2,
  31. .modes = {STARPU_R, STARPU_W},
  32. };
  33. struct starpu_codelet cl_without_mode =
  34. {
  35. .name = "without_mode",
  36. .cpu_funcs = {cpu_codelet, NULL},
  37. .cpu_funcs_name = {"cpu_codelet", NULL},
  38. .nbuffers = 2
  39. };
  40. static
  41. int submit_codelet_task_insert(struct starpu_codelet cl, starpu_data_handle_t handles0, starpu_data_handle_t handles1)
  42. {
  43. int ret;
  44. ret = starpu_task_insert(&cl,
  45. STARPU_R, handles0,
  46. STARPU_W, handles1,
  47. 0);
  48. if (ret == -ENODEV) return ret;
  49. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  50. starpu_task_wait_for_all();
  51. return 0;
  52. }
  53. static
  54. int submit_codelet_with_buffers(struct starpu_codelet cl, starpu_data_handle_t handles0, starpu_data_handle_t handles1)
  55. {
  56. int ret;
  57. struct starpu_task *task;
  58. task = starpu_task_create();
  59. task->cl = &cl;
  60. task->buffers[0].handle = handles0;
  61. task->buffers[0].mode = STARPU_R;
  62. task->buffers[1].handle = handles1;
  63. task->buffers[1].mode = STARPU_W;
  64. ret = starpu_task_submit(task);
  65. if (ret == -ENODEV) return ret;
  66. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  67. starpu_task_wait_for_all();
  68. return 0;
  69. }
  70. static
  71. int submit_codelet_with_handles(struct starpu_codelet cl, starpu_data_handle_t handles0, starpu_data_handle_t handles1)
  72. {
  73. int ret;
  74. struct starpu_task *task;
  75. task = starpu_task_create();
  76. task->cl = &cl;
  77. task->handles[0] = handles0;
  78. task->handles[1] = handles1;
  79. ret = starpu_task_submit(task);
  80. if (ret == -ENODEV) return ret;
  81. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  82. starpu_task_wait_for_all();
  83. return 0;
  84. }
  85. struct submit_task_func
  86. {
  87. int (*func)(struct starpu_codelet cl, starpu_data_handle_t handles0, starpu_data_handle_t handles1);
  88. char *name;
  89. };
  90. static
  91. int submit_codelet(struct starpu_codelet cl, struct submit_task_func func)
  92. {
  93. int *x, *y;
  94. starpu_malloc((void**)&x, sizeof(*x));
  95. starpu_malloc((void**)&y, sizeof(*y));
  96. *x = 42;
  97. *y = 14;
  98. starpu_data_handle_t handles[2];
  99. int ret;
  100. starpu_variable_data_register(&handles[0], STARPU_MAIN_RAM, (uintptr_t)x, sizeof(*x));
  101. starpu_variable_data_register(&handles[1], STARPU_MAIN_RAM, (uintptr_t)y, sizeof(*y));
  102. ret = func.func(cl, handles[0], handles[1]);
  103. starpu_data_unregister(handles[0]);
  104. starpu_data_unregister(handles[1]);
  105. if (!ret)
  106. {
  107. FPRINTF(stderr, "%s when executing codelet <%s> with func <%s>\n", *x==*y?"success":"error", cl.name, func.name);
  108. ret = (*x != *y);
  109. }
  110. starpu_free(x);
  111. starpu_free(y);
  112. return ret;
  113. }
  114. int main(int argc, char **argv)
  115. {
  116. int ret;
  117. struct submit_task_func task_insert = { .func = submit_codelet_task_insert, .name = "task_insert" };
  118. struct submit_task_func with_buffers = { .func = submit_codelet_with_buffers, .name = "with_buffers" };
  119. struct submit_task_func with_handles = { .func = submit_codelet_with_handles, .name = "with_handles" };
  120. ret = starpu_initialize(NULL, &argc, &argv);
  121. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  122. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  123. ret = submit_codelet(cl_with_mode, task_insert);
  124. if (ret == -ENODEV)
  125. {
  126. starpu_shutdown();
  127. fprintf(stderr, "WARNING: No one can execute this task\n");
  128. return STARPU_TEST_SKIPPED;
  129. }
  130. if (!ret)
  131. {
  132. ret = submit_codelet(cl_with_mode, with_buffers);
  133. }
  134. if (!ret)
  135. {
  136. ret = submit_codelet(cl_with_mode, with_handles);
  137. }
  138. if (!ret)
  139. {
  140. ret = submit_codelet(cl_without_mode, task_insert);
  141. }
  142. if (!ret)
  143. {
  144. ret = submit_codelet(cl_without_mode, with_buffers);
  145. }
  146. // We do not test the combination cl_without_mode with_handles as it is not expected to work
  147. starpu_shutdown();
  148. STARPU_RETURN(ret);
  149. }