deprecated_buffer.c 4.5 KB

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