deprecated_buffer.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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[], __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. .where = STARPU_CPU,
  30. .cpu_funcs = {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. .where = STARPU_CPU,
  38. .cpu_funcs = {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=42, y=14;
  91. starpu_data_handle_t handles[2];
  92. int ret;
  93. starpu_variable_data_register(&handles[0], 0, (uintptr_t)&x, sizeof(x));
  94. starpu_variable_data_register(&handles[1], 0, (uintptr_t)&y, sizeof(y));
  95. ret = func.func(cl, handles[0], handles[1]);
  96. starpu_data_unregister(handles[0]);
  97. starpu_data_unregister(handles[1]);
  98. if (ret == -ENODEV) return ret;
  99. FPRINTF(stderr, "%s when executing codelet <%s> with func <%s>\n", x==y?"success":"error", cl.name, func.name);
  100. return (x != y);
  101. }
  102. int main(int argc, char **argv)
  103. {
  104. int ret;
  105. struct submit_task_func insert_task = { .func = submit_codelet_insert_task, .name = "insert_task" };
  106. struct submit_task_func with_buffers = { .func = submit_codelet_with_buffers, .name = "with_buffers" };
  107. struct submit_task_func with_handles = { .func = submit_codelet_with_handles, .name = "with_handles" };
  108. ret = starpu_init(NULL);
  109. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  110. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  111. ret = submit_codelet(cl_with_mode, insert_task);
  112. if (ret == -ENODEV)
  113. {
  114. starpu_shutdown();
  115. fprintf(stderr, "WARNING: No one can execute this task\n");
  116. return STARPU_TEST_SKIPPED;
  117. }
  118. if (!ret)
  119. {
  120. ret = submit_codelet(cl_with_mode, with_buffers);
  121. }
  122. if (!ret)
  123. {
  124. ret = submit_codelet(cl_with_mode, with_handles);
  125. }
  126. if (!ret)
  127. {
  128. ret = submit_codelet(cl_without_mode, insert_task);
  129. }
  130. if (!ret)
  131. {
  132. ret = submit_codelet(cl_without_mode, with_buffers);
  133. }
  134. // We do not test the combination cl_without_mode with_handles as it is not expected to work
  135. starpu_shutdown();
  136. return ret;
  137. }