deprecated_buffer.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. int submit_codelet_task_insert(struct starpu_codelet cl, starpu_data_handle_t handles0, starpu_data_handle_t handles1)
  41. {
  42. int ret;
  43. ret = starpu_task_insert(&cl,
  44. STARPU_R, handles0,
  45. STARPU_W, handles1,
  46. 0);
  47. if (ret == -ENODEV) return ret;
  48. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  49. starpu_task_wait_for_all();
  50. return 0;
  51. }
  52. int submit_codelet_with_buffers(struct starpu_codelet cl, starpu_data_handle_t handles0, starpu_data_handle_t handles1)
  53. {
  54. int ret;
  55. struct starpu_task *task;
  56. task = starpu_task_create();
  57. task->cl = &cl;
  58. task->buffers[0].handle = handles0;
  59. task->buffers[0].mode = STARPU_R;
  60. task->buffers[1].handle = handles1;
  61. task->buffers[1].mode = STARPU_W;
  62. ret = starpu_task_submit(task);
  63. if (ret == -ENODEV) return ret;
  64. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  65. starpu_task_wait_for_all();
  66. return 0;
  67. }
  68. int submit_codelet_with_handles(struct starpu_codelet cl, starpu_data_handle_t handles0, starpu_data_handle_t handles1)
  69. {
  70. int ret;
  71. struct starpu_task *task;
  72. task = starpu_task_create();
  73. task->cl = &cl;
  74. task->handles[0] = handles0;
  75. task->handles[1] = handles1;
  76. ret = starpu_task_submit(task);
  77. if (ret == -ENODEV) return ret;
  78. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  79. starpu_task_wait_for_all();
  80. return 0;
  81. }
  82. struct submit_task_func
  83. {
  84. int (*func)(struct starpu_codelet cl, starpu_data_handle_t handles0, starpu_data_handle_t handles1);
  85. char *name;
  86. };
  87. int submit_codelet(struct starpu_codelet cl, struct submit_task_func func)
  88. {
  89. int *x, *y;
  90. starpu_malloc((void**)&x, sizeof(*x));
  91. starpu_malloc((void**)&y, sizeof(*y));
  92. *x = 42;
  93. *y = 14;
  94. starpu_data_handle_t handles[2];
  95. int ret;
  96. starpu_variable_data_register(&handles[0], STARPU_MAIN_RAM, (uintptr_t)x, sizeof(*x));
  97. starpu_variable_data_register(&handles[1], STARPU_MAIN_RAM, (uintptr_t)y, sizeof(*y));
  98. ret = func.func(cl, handles[0], handles[1]);
  99. starpu_data_unregister(handles[0]);
  100. starpu_data_unregister(handles[1]);
  101. if (!ret)
  102. {
  103. FPRINTF(stderr, "%s when executing codelet <%s> with func <%s>\n", *x==*y?"success":"error", cl.name, func.name);
  104. ret = (*x != *y);
  105. }
  106. starpu_free(x);
  107. starpu_free(y);
  108. return ret;
  109. }
  110. int main(int argc, char **argv)
  111. {
  112. int ret;
  113. struct submit_task_func task_insert = { .func = submit_codelet_task_insert, .name = "task_insert" };
  114. struct submit_task_func with_buffers = { .func = submit_codelet_with_buffers, .name = "with_buffers" };
  115. struct submit_task_func with_handles = { .func = submit_codelet_with_handles, .name = "with_handles" };
  116. ret = starpu_initialize(NULL, &argc, &argv);
  117. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  118. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  119. ret = submit_codelet(cl_with_mode, task_insert);
  120. if (ret == -ENODEV)
  121. {
  122. starpu_shutdown();
  123. fprintf(stderr, "WARNING: No one can execute this task\n");
  124. return STARPU_TEST_SKIPPED;
  125. }
  126. if (!ret)
  127. {
  128. ret = submit_codelet(cl_with_mode, with_buffers);
  129. }
  130. if (!ret)
  131. {
  132. ret = submit_codelet(cl_with_mode, with_handles);
  133. }
  134. if (!ret)
  135. {
  136. ret = submit_codelet(cl_without_mode, task_insert);
  137. }
  138. if (!ret)
  139. {
  140. ret = submit_codelet(cl_without_mode, with_buffers);
  141. }
  142. // We do not test the combination cl_without_mode with_handles as it is not expected to work
  143. starpu_shutdown();
  144. STARPU_RETURN(ret);
  145. }