deprecated_buffer.c 4.2 KB

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