callback.jl 1.8 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. starpu_init()
  23. function callback(args)
  24. cl = args[1]
  25. handles = args[2]
  26. task = starpu_task(cl = cl, handles=handles)
  27. starpu_task_submit(task)
  28. end
  29. function variable_with_starpu(val ::Ref{Int32})
  30. perfmodel = starpu_perfmodel(
  31. perf_type = starpu_perfmodel_type(STARPU_HISTORY_BASED),
  32. symbol = "history_perf"
  33. )
  34. cl = starpu_codelet(
  35. cpu_func = CPU_CODELETS["variable"],
  36. # cuda_func = CUDA_CODELETS["matrix_mult"],
  37. #opencl_func="ocl_matrix_mult",
  38. modes = [STARPU_RW],
  39. perfmodel = perfmodel
  40. )
  41. @starpu_block let
  42. hVal = starpu_data_register(val)
  43. task = starpu_task(cl = cl, handles = [hVal], callback=callback, callback_arg=(cl, [hVal]))
  44. starpu_task_submit(task)
  45. starpu_task_wait_for_all()
  46. end
  47. end
  48. function display()
  49. v = Ref(Int32(40))
  50. variable_with_starpu(v)
  51. println("variable -> ", v[])
  52. if v[] == 42
  53. println("result is correct")
  54. else
  55. println("result is incorret")
  56. end
  57. end
  58. display()
  59. starpu_shutdown()