data_implicit_deps.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. #define VECTORSIZE 1024
  23. #define FPRINTF(ofile, fmt, args ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ##args); }} while(0)
  24. static unsigned *A, *B, *C, *D;
  25. starpu_data_handle 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 starpu_codelet cl_f = {
  32. .where = STARPU_CPU|STARPU_CUDA,
  33. .cpu_func = f,
  34. .cuda_func = f,
  35. .nbuffers = 2
  36. };
  37. static void g(void *descr[], __attribute__ ((unused)) void *_args)
  38. {
  39. usleep(100000);
  40. var = 42;
  41. }
  42. static starpu_codelet cl_g = {
  43. .where = STARPU_CPU|STARPU_CUDA,
  44. .cpu_func = g,
  45. .cuda_func = g,
  46. .nbuffers = 2
  47. };
  48. static void h(void *descr[], __attribute__ ((unused)) void *_args)
  49. {
  50. FPRINTF(stderr, "VAR %u (should be 42)\n", var);
  51. STARPU_ASSERT(var == 42);
  52. }
  53. static starpu_codelet cl_h = {
  54. .where = STARPU_CPU|STARPU_CUDA,
  55. .cpu_func = h,
  56. .cuda_func = h,
  57. .nbuffers = 2
  58. };
  59. int main(int argc, char **argv)
  60. {
  61. starpu_init(NULL);
  62. A = malloc(VECTORSIZE*sizeof(unsigned));
  63. B = malloc(VECTORSIZE*sizeof(unsigned));
  64. C = malloc(VECTORSIZE*sizeof(unsigned));
  65. D = malloc(VECTORSIZE*sizeof(unsigned));
  66. starpu_vector_data_register(&A_handle, 0, (uintptr_t)A, VECTORSIZE, sizeof(unsigned));
  67. starpu_vector_data_register(&B_handle, 0, (uintptr_t)B, VECTORSIZE, sizeof(unsigned));
  68. starpu_vector_data_register(&C_handle, 0, (uintptr_t)C, VECTORSIZE, sizeof(unsigned));
  69. starpu_vector_data_register(&D_handle, 0, (uintptr_t)D, VECTORSIZE, sizeof(unsigned));
  70. #if 0
  71. starpu_data_set_sequential_consistency_flag(A_handle, 0);
  72. starpu_data_set_sequential_consistency_flag(B_handle, 0);
  73. starpu_data_set_sequential_consistency_flag(C_handle, 0);
  74. starpu_data_set_sequential_consistency_flag(D_handle, 0);
  75. #endif
  76. /* f(Ar, Brw): sleep
  77. * g(Br; Crw); sleep, var = 42
  78. * h(Cr; Drw); check that var == 42
  79. */
  80. struct starpu_task *task_f = starpu_task_create();
  81. task_f->cl = &cl_f;
  82. task_f->buffers[0].handle = A_handle;
  83. task_f->buffers[0].mode = STARPU_R;
  84. task_f->buffers[1].handle = B_handle;
  85. task_f->buffers[1].mode = STARPU_RW;
  86. starpu_task_submit(task_f);
  87. struct starpu_task *task_g = starpu_task_create();
  88. task_g->cl = &cl_g;
  89. task_g->buffers[0].handle = B_handle;
  90. task_g->buffers[0].mode = STARPU_R;
  91. task_g->buffers[1].handle = C_handle;
  92. task_g->buffers[1].mode = STARPU_RW;
  93. starpu_task_submit(task_g);
  94. struct starpu_task *task_h = starpu_task_create();
  95. task_h->cl = &cl_h;
  96. task_h->buffers[0].handle = C_handle;
  97. task_h->buffers[0].mode = STARPU_R;
  98. task_h->buffers[1].handle = D_handle;
  99. task_h->buffers[1].mode = STARPU_RW;
  100. starpu_task_submit(task_h);
  101. starpu_task_wait_for_all();
  102. free(A);
  103. free(B);
  104. free(C);
  105. free(D);
  106. starpu_shutdown();
  107. return 0;
  108. }