end_dep.jl 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # StarPU --- Runtime system for heterogeneous multicore architectures.
  2. #
  3. # Copyright (C) 2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  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. using StarPU
  17. @target STARPU_CPU
  18. @codelet function codeletA() :: Nothing
  19. # print("[Task A] Value = ", val[]);
  20. # do nothing
  21. end
  22. @target STARPU_CPU
  23. @codelet function codeletB(val ::Ref{Int32}) :: Nothing
  24. # println("[Task B] Value = ", val[]);
  25. val[] = val[] *2
  26. end
  27. function callbackB(task)
  28. sleep(1)
  29. starpu_task_end_dep_release(task)
  30. end
  31. @target STARPU_CPU
  32. @codelet function codeletC(val ::Ref{Int32}) :: Nothing
  33. # println("[Task C] Value = ", val[]);
  34. val[] = val[] *2
  35. end
  36. function callbackC(task)
  37. starpu_task_end_dep_release(task)
  38. end
  39. function main()
  40. value = Ref(Int32(12))
  41. @starpu_block let
  42. perfmodel = starpu_perfmodel(
  43. perf_type = starpu_perfmodel_type(STARPU_HISTORY_BASED),
  44. symbol = "history_perf"
  45. )
  46. clA = starpu_codelet(
  47. cpu_func = "codeletA",
  48. perfmodel = perfmodel
  49. )
  50. clB = starpu_codelet(
  51. cpu_func = "codeletB",
  52. modes = [STARPU_RW],
  53. perfmodel = perfmodel
  54. )
  55. clC = starpu_codelet(
  56. cpu_func = "codeletC",
  57. modes = [STARPU_RW],
  58. perfmodel = perfmodel
  59. )
  60. handle = starpu_data_register(value)
  61. starpu_data_set_sequential_consistency_flag(handle, 0)
  62. taskA = starpu_task(cl = clA, detach=0)
  63. taskB = starpu_task(cl = clB, handles = [handle], callback=callbackB, callback_arg=taskA)
  64. taskC = starpu_task(cl = clC, handles = [handle], callback=callbackC, callback_arg=taskA)
  65. starpu_task_end_dep_add(taskA, 2)
  66. starpu_task_declare_deps(taskC, taskB)
  67. starpu_task_submit(taskA)
  68. starpu_task_submit(taskB)
  69. starpu_task_submit(taskC)
  70. starpu_task_wait(taskA)
  71. starpu_data_acquire_on_node(handle, STARPU_MAIN_RAM, STARPU_R);
  72. # Waiting for taskA should have also waited for taskB and taskC
  73. if value[] != 48
  74. error("Incorrect value $(value[]) (expected 48)")
  75. end
  76. starpu_data_release_on_node(handle, STARPU_MAIN_RAM);
  77. end
  78. println("Value = ", value[])
  79. end
  80. # Disable garbage collector because of random segfault/hang when using mutex.
  81. # This issue should be solved with Julia release 1.5.
  82. GC.enable(false)
  83. starpu_init()
  84. main()
  85. starpu_shutdown()
  86. GC.enable(true)