data_implicit_deps.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011 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 <stdio.h>
  18. #include <unistd.h>
  19. #include <errno.h>
  20. #include <starpu.h>
  21. #include <stdlib.h>
  22. #include "../helper.h"
  23. #define VECTORSIZE 1024
  24. static unsigned *A, *B, *C, *D;
  25. starpu_data_handle_t A_handle, B_handle, C_handle, D_handle;
  26. static unsigned var = 0;
  27. static void f(void *descr[], __attribute__ ((unused)) void *_args)
  28. {
  29. usleep(200000);
  30. }
  31. static struct starpu_codelet cl_f =
  32. {
  33. .modes[1] = STARPU_RW,
  34. .modes[0] = STARPU_R,
  35. .where = STARPU_CPU|STARPU_CUDA,
  36. .cpu_funcs = {f, NULL},
  37. .cuda_funcs = {f, NULL},
  38. .nbuffers = 2
  39. };
  40. static void g(void *descr[], __attribute__ ((unused)) void *_args)
  41. {
  42. usleep(100000);
  43. var = 42;
  44. }
  45. static struct starpu_codelet cl_g =
  46. {
  47. .modes[1] = STARPU_RW,
  48. .modes[0] = STARPU_R,
  49. .where = STARPU_CPU|STARPU_CUDA,
  50. .cpu_funcs = {g, NULL},
  51. .cuda_funcs = {g, NULL},
  52. .nbuffers = 2
  53. };
  54. static void h(void *descr[], __attribute__ ((unused)) void *_args)
  55. {
  56. FPRINTF(stderr, "VAR %u (should be 42)\n", var);
  57. STARPU_ASSERT(var == 42);
  58. }
  59. static struct starpu_codelet cl_h =
  60. {
  61. .modes[1] = STARPU_RW,
  62. .modes[0] = STARPU_R,
  63. .where = STARPU_CPU|STARPU_CUDA,
  64. .cpu_funcs = {h, NULL},
  65. .cuda_funcs = {h, NULL},
  66. .nbuffers = 2
  67. };
  68. int main(int argc, char **argv)
  69. {
  70. int ret;
  71. ret = starpu_init(NULL);
  72. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  73. A = (unsigned *) malloc(VECTORSIZE*sizeof(unsigned));
  74. B = (unsigned *) malloc(VECTORSIZE*sizeof(unsigned));
  75. C = (unsigned *) malloc(VECTORSIZE*sizeof(unsigned));
  76. D = (unsigned *) malloc(VECTORSIZE*sizeof(unsigned));
  77. starpu_vector_data_register(&A_handle, 0, (uintptr_t)A, VECTORSIZE, sizeof(unsigned));
  78. starpu_vector_data_register(&B_handle, 0, (uintptr_t)B, VECTORSIZE, sizeof(unsigned));
  79. starpu_vector_data_register(&C_handle, 0, (uintptr_t)C, VECTORSIZE, sizeof(unsigned));
  80. starpu_vector_data_register(&D_handle, 0, (uintptr_t)D, VECTORSIZE, sizeof(unsigned));
  81. #if 0
  82. starpu_data_set_sequential_consistency_flag(A_handle, 0);
  83. starpu_data_set_sequential_consistency_flag(B_handle, 0);
  84. starpu_data_set_sequential_consistency_flag(C_handle, 0);
  85. starpu_data_set_sequential_consistency_flag(D_handle, 0);
  86. #endif
  87. /* f(Ar, Brw): sleep
  88. * g(Br; Crw); sleep, var = 42
  89. * h(Cr; Drw); check that var == 42
  90. */
  91. struct starpu_task *task_f = starpu_task_create();
  92. task_f->cl = &cl_f;
  93. task_f->handles[0] = A_handle;
  94. task_f->handles[1] = B_handle;
  95. ret = starpu_task_submit(task_f);
  96. if (ret == -ENODEV) goto enodev;
  97. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  98. struct starpu_task *task_g = starpu_task_create();
  99. task_g->cl = &cl_g;
  100. task_g->handles[0] = B_handle;
  101. task_g->handles[1] = C_handle;
  102. ret = starpu_task_submit(task_g);
  103. if (ret == -ENODEV) goto enodev;
  104. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  105. struct starpu_task *task_h = starpu_task_create();
  106. task_h->cl = &cl_h;
  107. task_h->handles[0] = C_handle;
  108. task_h->handles[1] = D_handle;
  109. ret = starpu_task_submit(task_h);
  110. if (ret == -ENODEV) goto enodev;
  111. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  112. ret = starpu_task_wait_for_all();
  113. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  114. starpu_data_unregister(A_handle);
  115. starpu_data_unregister(B_handle);
  116. starpu_data_unregister(C_handle);
  117. starpu_data_unregister(D_handle);
  118. free(A);
  119. free(B);
  120. free(C);
  121. free(D);
  122. starpu_shutdown();
  123. return EXIT_SUCCESS;
  124. enodev:
  125. free(A);
  126. free(B);
  127. free(C);
  128. free(D);
  129. fprintf(stderr, "WARNING: No one can execute this task\n");
  130. /* yes, we do not perform the computation but we did detect that no one
  131. * could perform the kernel, so this is not an error from StarPU */
  132. starpu_shutdown();
  133. return STARPU_TEST_SKIPPED;
  134. }