init.jl 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. """
  17. Must be called before any other starpu function. Field extern_task_path is the
  18. shared library path which will be used to find StarpuCodelet
  19. cpu and gpu function names
  20. """
  21. function starpu_init()
  22. debug_print("starpu_init")
  23. if (get(ENV,"JULIA_TASK_LIB",0)!=0)
  24. global starpu_tasks_library_handle= Libdl.dlopen(ENV["JULIA_TASK_LIB"])
  25. debug_print("Loading external codelet library")
  26. ff = Libdl.dlsym(starpu_tasks_library_handle,:starpu_find_function)
  27. dump(ff)
  28. for k in keys(CPU_CODELETS)
  29. CPU_CODELETS[k]=unsafe_string(ccall(ff,Cstring, (Cstring,Cstring),Cstring_from_String(string(k)),Cstring_from_String("cpu")))
  30. if STARPU_USE_CUDA == 1
  31. CUDA_CODELETS[k]=unsafe_string(ccall(ff,Cstring, (Cstring,Cstring),Cstring_from_String(string(k)),Cstring_from_String("gpu")))
  32. end
  33. print(k,">>>>",CPU_CODELETS[k],"\n")
  34. end
  35. else
  36. srcdir=get(ENV,"STARPU_JULIA_BUILD",0)
  37. if (srcdir == 0)
  38. error("Must define environment variable STARPU_JULIA_BUILD")
  39. end
  40. makefile=string(srcdir, "/src/dynamic_compiler/Makefile")
  41. debug_print("generating codelet library with ")
  42. debug_print(makefile)
  43. run(`make -f $makefile generated_tasks.so`)
  44. global starpu_tasks_library_handle=Libdl.dlopen("generated_tasks.so")
  45. end
  46. global starpu_wrapper_library_handle= Libdl.dlopen(starpu_wrapper_library_name)
  47. output = starpu_init(C_NULL)
  48. global task_pool = ThreadPools.QueuePool(2)
  49. starpu_enter_new_block()
  50. return output
  51. end
  52. """
  53. Must be called at the end of the program
  54. """
  55. function starpu_shutdown()
  56. debug_print("starpu_shutdown")
  57. starpu_exit_block()
  58. @starpucall starpu_shutdown Cvoid ()
  59. lock(mutex)
  60. empty!(perfmodel_list)
  61. empty!(codelet_list)
  62. empty!(task_list)
  63. unlock(mutex)
  64. return nothing
  65. end