data_implicit_deps.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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 <stdio.h>
  17. #include <unistd.h>
  18. #include <errno.h>
  19. #include <starpu.h>
  20. #include <stdlib.h>
  21. #define VECTORSIZE 1024
  22. static unsigned *A, *B, *C, *D;
  23. starpu_data_handle A_handle, B_handle, C_handle, D_handle;
  24. static unsigned var = 0;
  25. static void f(void *descr[], __attribute__ ((unused)) void *_args)
  26. {
  27. usleep(200000);
  28. }
  29. static starpu_codelet cl_f = {
  30. .where = STARPU_CPU|STARPU_CUDA,
  31. .cpu_func = f,
  32. .cuda_func = f,
  33. .nbuffers = 2
  34. };
  35. static void g(void *descr[], __attribute__ ((unused)) void *_args)
  36. {
  37. usleep(100000);
  38. var = 42;
  39. }
  40. static starpu_codelet cl_g = {
  41. .where = STARPU_CPU|STARPU_CUDA,
  42. .cpu_func = g,
  43. .cuda_func = g,
  44. .nbuffers = 2
  45. };
  46. static void h(void *descr[], __attribute__ ((unused)) void *_args)
  47. {
  48. fprintf(stderr, "VAR %d (should be 42)\n", var);
  49. STARPU_ASSERT(var == 42);
  50. }
  51. static starpu_codelet cl_h = {
  52. .where = STARPU_CPU|STARPU_CUDA,
  53. .cpu_func = h,
  54. .cuda_func = h,
  55. .nbuffers = 2
  56. };
  57. int main(int argc, char **argv)
  58. {
  59. starpu_init(NULL);
  60. A = malloc(VECTORSIZE*sizeof(unsigned));
  61. B = malloc(VECTORSIZE*sizeof(unsigned));
  62. C = malloc(VECTORSIZE*sizeof(unsigned));
  63. D = malloc(VECTORSIZE*sizeof(unsigned));
  64. starpu_register_vector_data(&A_handle, 0, (uintptr_t)A, VECTORSIZE, sizeof(unsigned));
  65. starpu_register_vector_data(&B_handle, 0, (uintptr_t)B, VECTORSIZE, sizeof(unsigned));
  66. starpu_register_vector_data(&C_handle, 0, (uintptr_t)C, VECTORSIZE, sizeof(unsigned));
  67. starpu_register_vector_data(&D_handle, 0, (uintptr_t)D, VECTORSIZE, sizeof(unsigned));
  68. #if 0
  69. starpu_data_set_sequential_consistency_flag(A_handle, 0);
  70. starpu_data_set_sequential_consistency_flag(B_handle, 0);
  71. starpu_data_set_sequential_consistency_flag(C_handle, 0);
  72. starpu_data_set_sequential_consistency_flag(D_handle, 0);
  73. #endif
  74. /* f(Ar, Brw): sleep
  75. * g(Br; Crw); sleep, var = 42
  76. * h(Cr; Drw); check that var == 42
  77. */
  78. struct starpu_task *task_f = starpu_task_create();
  79. task_f->cl = &cl_f;
  80. task_f->buffers[0].handle = A_handle;
  81. task_f->buffers[0].mode = STARPU_R;
  82. task_f->buffers[1].handle = B_handle;
  83. task_f->buffers[1].mode = STARPU_RW;
  84. starpu_submit_task(task_f);
  85. struct starpu_task *task_g = starpu_task_create();
  86. task_g->cl = &cl_g;
  87. task_g->buffers[0].handle = B_handle;
  88. task_g->buffers[0].mode = STARPU_R;
  89. task_g->buffers[1].handle = C_handle;
  90. task_g->buffers[1].mode = STARPU_RW;
  91. starpu_submit_task(task_g);
  92. struct starpu_task *task_h = starpu_task_create();
  93. task_h->cl = &cl_h;
  94. task_h->buffers[0].handle = C_handle;
  95. task_h->buffers[0].mode = STARPU_R;
  96. task_h->buffers[1].handle = D_handle;
  97. task_h->buffers[1].mode = STARPU_RW;
  98. starpu_submit_task(task_h);
  99. starpu_wait_all_tasks();
  100. starpu_shutdown();
  101. return 0;
  102. }