task_dep.jl 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. @target STARPU_CPU
  23. @codelet function codeletB(val ::Ref{Int32}) :: Nothing
  24. # println("[Task B] Value = ", val[]);
  25. val[] = val[] +1
  26. end
  27. @target STARPU_CPU
  28. @codelet function codeletC(val ::Ref{Int32}) :: Nothing
  29. # println("[Task C] Value = ", val[]);
  30. val[] = val[] *2
  31. end
  32. function main()
  33. value = Ref(Int32(12))
  34. @starpu_block let
  35. perfmodel = starpu_perfmodel(
  36. perf_type = starpu_perfmodel_type(STARPU_HISTORY_BASED),
  37. symbol = "history_perf"
  38. )
  39. clA = starpu_codelet(
  40. cpu_func = "codeletA",
  41. modes = [STARPU_RW],
  42. perfmodel = perfmodel
  43. )
  44. clB = starpu_codelet(
  45. cpu_func = "codeletB",
  46. modes = [STARPU_RW],
  47. perfmodel = perfmodel
  48. )
  49. clC = starpu_codelet(
  50. cpu_func = "codeletC",
  51. modes = [STARPU_RW],
  52. perfmodel = perfmodel
  53. )
  54. starpu_data_set_default_sequential_consistency_flag(0)
  55. handle = starpu_data_register(value)
  56. taskA = starpu_task(cl = clA, handles = [handle])
  57. taskB = starpu_task(cl = clB, handles = [handle])
  58. taskC = starpu_task(cl = clC, handles = [handle])
  59. starpu_task_declare_deps(taskA, taskB)
  60. starpu_task_declare_deps(taskC, taskA, taskB)
  61. starpu_task_submit(taskA)
  62. starpu_task_submit(taskB)
  63. starpu_task_submit(taskC)
  64. starpu_task_wait_for_all()
  65. end
  66. if value[] != 52
  67. error("Incorrect value $(value[]) (expected 52)")
  68. end
  69. println("Value = ", value[])
  70. end
  71. starpu_init()
  72. main()
  73. starpu_shutdown()