callback.jl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 variable(val ::Ref{Int32}) :: Nothing
  19. val[] = val[] + 1
  20. return
  21. end
  22. function callback(args)
  23. cl = args[1]
  24. handles = args[2]
  25. task = starpu_task(cl = cl, handles=handles)
  26. starpu_task_submit(task)
  27. end
  28. function variable_with_starpu(val ::Ref{Int32})
  29. perfmodel = starpu_perfmodel(
  30. perf_type = starpu_perfmodel_type(STARPU_HISTORY_BASED),
  31. symbol = "history_perf"
  32. )
  33. cl = starpu_codelet(
  34. cpu_func = "variable",
  35. modes = [STARPU_RW],
  36. perfmodel = perfmodel
  37. )
  38. @starpu_block let
  39. hVal = starpu_data_register(val)
  40. task = starpu_task(cl = cl, handles = [hVal], callback=callback, callback_arg=(cl, [hVal]))
  41. starpu_task_submit(task)
  42. starpu_task_wait_for_all()
  43. end
  44. end
  45. function display()
  46. v = Ref(Int32(40))
  47. variable_with_starpu(v)
  48. println("variable -> ", v[])
  49. if v[] == 42
  50. println("result is correct")
  51. else
  52. error("result is incorret")
  53. end
  54. end
  55. # Disable garbage collector because of random segfault/hang when using mutex.
  56. # This issue should be solved with Julia release 1.5.
  57. GC.enable(false)
  58. starpu_init()
  59. display()
  60. starpu_shutdown()
  61. GC.enable(true)