sequential_consistency.jl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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(val ::Ref{Int32}) :: Nothing
  19. # print("[Task A] Value = ", val[]);
  20. val[] = val[] * 2
  21. end
  22. function callbackA(arg)
  23. clB = arg[1]
  24. handle = arg[2]
  25. tagHoldC = arg[3]
  26. taskB = starpu_task(cl = clB, handles = [handle],
  27. callback = starpu_tag_notify_from_apps,
  28. callback_arg = tagHoldC,
  29. sequential_consistency=false)
  30. starpu_task_submit(taskB)
  31. end
  32. @target STARPU_CPU
  33. @codelet function codeletB(val ::Ref{Int32}) :: Nothing
  34. # println("[Task B] Value = ", val[]);
  35. val[] = val[] +1
  36. end
  37. @target STARPU_CPU
  38. @codelet function codeletC(val ::Ref{Int32}) :: Nothing
  39. # println("[Task C] Value = ", val[]);
  40. val[] = val[] *2
  41. end
  42. # Submit taskA and hold it
  43. # Submit taskC and hold it
  44. # Release taskA
  45. # Execute taskA --> callback: submit taskB
  46. # Execute taskB --> callback: release taskC
  47. #
  48. # All three tasks use the same data in RW, taskB is submitted after
  49. # taskC, so taskB should normally only execute after taskC but as the
  50. # sequential consistency for (taskB, data) is unset, taskB can
  51. # execute straightaway
  52. function main()
  53. value = Ref(Int32(12))
  54. @starpu_block let
  55. tagHoldA :: starpu_tag_t = 32
  56. tagHoldC :: starpu_tag_t = 84
  57. tagA :: starpu_tag_t = 421
  58. tagC :: starpu_tag_t = 842
  59. starpu_tag_declare_deps(tagA, tagHoldA)
  60. starpu_tag_declare_deps(tagC, tagHoldC)
  61. perfmodel = starpu_perfmodel(
  62. perf_type = starpu_perfmodel_type(STARPU_HISTORY_BASED),
  63. symbol = "history_perf"
  64. )
  65. clA = starpu_codelet(
  66. cpu_func = CPU_CODELETS["codeletA"],
  67. modes = [STARPU_RW],
  68. perfmodel = perfmodel
  69. )
  70. clB = starpu_codelet(
  71. cpu_func = CPU_CODELETS["codeletB"],
  72. modes = [STARPU_RW],
  73. perfmodel = perfmodel
  74. )
  75. clC = starpu_codelet(
  76. cpu_func = CPU_CODELETS["codeletC"],
  77. modes = [STARPU_RW],
  78. perfmodel = perfmodel
  79. )
  80. handle = starpu_data_register(value)
  81. taskA = starpu_task(cl = clA, handles = [handle], tag = tagA,
  82. callback = callbackA,
  83. callback_arg=(clB, handle, tagHoldC))
  84. starpu_task_submit(taskA)
  85. taskC = starpu_task(cl = clC, handles = [handle], tag = tagC)
  86. starpu_task_submit(taskC)
  87. # Release taskA (we want to make sure it will execute after taskC has been submitted)
  88. starpu_tag_notify_from_apps(tagHoldA)
  89. starpu_task_wait_for_all()
  90. end
  91. if value[] != 50
  92. error("Incorrect value $(value[]) (expected 50)")
  93. end
  94. println("Value = ", value[])
  95. end
  96. starpu_init()
  97. main()
  98. starpu_shutdown()