data_implicit_deps.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <config.h>
  18. #include <stdio.h>
  19. #include <unistd.h>
  20. #include <errno.h>
  21. #include <starpu.h>
  22. #include <stdlib.h>
  23. #include "../helper.h"
  24. #define VECTORSIZE 1024
  25. static unsigned *A, *B, *C, *D;
  26. starpu_data_handle_t A_handle, B_handle, C_handle, D_handle;
  27. static unsigned var = 0;
  28. starpu_data_handle_t var_handle;
  29. void f(void *descr[], __attribute__ ((unused)) void *_args)
  30. {
  31. STARPU_SKIP_IF_VALGRIND;
  32. usleep(200000);
  33. }
  34. static struct starpu_codelet cl_f =
  35. {
  36. .modes = { STARPU_RW, STARPU_R, STARPU_RW },
  37. .cpu_funcs = {f, NULL},
  38. .cuda_funcs = {f, NULL},
  39. .opencl_funcs = {f, NULL},
  40. .cpu_funcs_name = {"f", NULL},
  41. .nbuffers = 3,
  42. };
  43. void g(void *descr[], __attribute__ ((unused)) void *_args)
  44. {
  45. STARPU_SKIP_IF_VALGRIND;
  46. unsigned *val = (unsigned *) STARPU_VARIABLE_GET_PTR(descr[0]);
  47. usleep(100000);
  48. *val = 42;
  49. }
  50. static struct starpu_codelet cl_g =
  51. {
  52. .modes = { STARPU_RW, STARPU_R, STARPU_RW },
  53. .cpu_funcs = {g, NULL},
  54. .cuda_funcs = {g, NULL},
  55. .opencl_funcs = {g, NULL},
  56. .cpu_funcs_name = {"g", NULL},
  57. .nbuffers = 3,
  58. };
  59. void h(void *descr[], __attribute__ ((unused)) void *_args)
  60. {
  61. STARPU_SKIP_IF_VALGRIND;
  62. unsigned *val = (unsigned *) STARPU_VARIABLE_GET_PTR(descr[0]);
  63. FPRINTF(stderr, "VAR %u (should be 42)\n", *val);
  64. STARPU_ASSERT(*val == 42);
  65. }
  66. static struct starpu_codelet cl_h =
  67. {
  68. .modes = { STARPU_RW, STARPU_R, STARPU_RW },
  69. .cpu_funcs = {h, NULL},
  70. .cuda_funcs = {h, NULL},
  71. .opencl_funcs = {h, NULL},
  72. .cpu_funcs_name = {"h", NULL},
  73. .nbuffers = 3
  74. };
  75. int main(int argc, char **argv)
  76. {
  77. int ret;
  78. ret = starpu_initialize(NULL, &argc, &argv);
  79. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  80. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  81. A = (unsigned *) malloc(VECTORSIZE*sizeof(unsigned));
  82. B = (unsigned *) malloc(VECTORSIZE*sizeof(unsigned));
  83. C = (unsigned *) malloc(VECTORSIZE*sizeof(unsigned));
  84. D = (unsigned *) malloc(VECTORSIZE*sizeof(unsigned));
  85. starpu_vector_data_register(&A_handle, 0, (uintptr_t)A, VECTORSIZE, sizeof(unsigned));
  86. starpu_vector_data_register(&B_handle, 0, (uintptr_t)B, VECTORSIZE, sizeof(unsigned));
  87. starpu_vector_data_register(&C_handle, 0, (uintptr_t)C, VECTORSIZE, sizeof(unsigned));
  88. starpu_vector_data_register(&D_handle, 0, (uintptr_t)D, VECTORSIZE, sizeof(unsigned));
  89. starpu_variable_data_register(&var_handle, 0, (uintptr_t)(&var), sizeof(var));
  90. #if 0
  91. starpu_data_set_sequential_consistency_flag(A_handle, 0);
  92. starpu_data_set_sequential_consistency_flag(B_handle, 0);
  93. starpu_data_set_sequential_consistency_flag(C_handle, 0);
  94. starpu_data_set_sequential_consistency_flag(D_handle, 0);
  95. #endif
  96. /* f(Ar, Brw): sleep
  97. * g(Br; Crw); sleep, var = 42
  98. * h(Cr; Drw); check that var == 42
  99. */
  100. struct starpu_task *task_f = starpu_task_create();
  101. task_f->cl = &cl_f;
  102. task_f->handles[0] = var_handle;
  103. task_f->handles[1] = A_handle;
  104. task_f->handles[2] = B_handle;
  105. ret = starpu_task_submit(task_f);
  106. if (ret == -ENODEV) goto enodev;
  107. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  108. struct starpu_task *task_g = starpu_task_create();
  109. task_g->cl = &cl_g;
  110. task_g->handles[0] = var_handle;
  111. task_g->handles[1] = B_handle;
  112. task_g->handles[2] = C_handle;
  113. ret = starpu_task_submit(task_g);
  114. if (ret == -ENODEV) goto enodev;
  115. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  116. struct starpu_task *task_h = starpu_task_create();
  117. task_h->cl = &cl_h;
  118. task_h->handles[0] = var_handle;
  119. task_h->handles[1] = C_handle;
  120. task_h->handles[2] = D_handle;
  121. ret = starpu_task_submit(task_h);
  122. if (ret == -ENODEV) goto enodev;
  123. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  124. ret = starpu_task_wait_for_all();
  125. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  126. starpu_data_unregister(A_handle);
  127. starpu_data_unregister(B_handle);
  128. starpu_data_unregister(C_handle);
  129. starpu_data_unregister(D_handle);
  130. starpu_data_unregister(var_handle);
  131. free(A);
  132. free(B);
  133. free(C);
  134. free(D);
  135. starpu_shutdown();
  136. return EXIT_SUCCESS;
  137. enodev:
  138. free(A);
  139. free(B);
  140. free(C);
  141. free(D);
  142. fprintf(stderr, "WARNING: No one can execute this task\n");
  143. /* yes, we do not perform the computation but we did detect that no one
  144. * could perform the kernel, so this is not an error from StarPU */
  145. starpu_shutdown();
  146. return STARPU_TEST_SKIPPED;
  147. }