utils.jl 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. function fstarpu_task_library_name()
  17. x=get(ENV, "STARPU_JULIA_LIB", C_NULL)
  18. if (x == C_NULL)
  19. error("Environment variable STARPU_JULIA_LIB must be defined")
  20. end
  21. return x
  22. end
  23. function fstarpu_include_dir()
  24. x=get(ENV, "STARPU_INCLUDE_DIR", C_NULL)
  25. if (x == C_NULL)
  26. error("Environment variable STARPU_INCLUDE_DIR must be defined")
  27. end
  28. return x
  29. end
  30. macro starpufunc(symbol)
  31. :($symbol, starpu_wrapper_library_name)
  32. end
  33. """
  34. Used to call a StarPU function compiled inside "libjlstarpu_c_wrapper.so"
  35. Works as ccall function
  36. """
  37. macro starpucall(func, ret_type, arg_types, args...)
  38. return Expr(:call, :ccall, (func, starpu_wrapper_library_name), esc(ret_type), esc(arg_types), map(esc, args)...)
  39. end
  40. function debug_print(x...)
  41. println("\x1b[32m", x..., "\x1b[0m")
  42. flush(stdout)
  43. end
  44. function Cstring_from_String(str :: String)
  45. return Cstring(pointer(str))
  46. end
  47. tuple_len(::NTuple{N, Any}) where {N} = N
  48. function starpu_find_function(name :: String, device :: String )
  49. s=ccall(:starpu_find_function,Cstring, (Cstring,Cstring),Cstring_from_String(name),Cstring_from_String(device))
  50. if s == C_NULL
  51. print("NULL STRING\n")
  52. error("dead")
  53. end
  54. return s
  55. end
  56. function load_starpu_function_pointer(func_name :: String)
  57. if (isempty(func_name))
  58. return C_NULL
  59. end
  60. #func_pointer = ccall(:dlsym,"libdl",Ptr{Cvoid});
  61. func_pointer=Libdl.dlsym(starpu_tasks_library_handle, func_name)
  62. if (func_pointer == C_NULL)
  63. error("Couldn't find function symbol $func_name into extern library file $starpu_tasks_library")
  64. end
  65. return func_pointer
  66. end
  67. function load_wrapper_function_pointer(func_name :: String)
  68. if (isempty(func_name))
  69. return C_NULL
  70. end
  71. func_pointer=Libdl.dlsym(starpu_wrapper_library_handle, func_name)
  72. if (func_pointer == C_NULL)
  73. error("Couldn't find function symbol $func_name into extern library file $starpu_tasks_library")
  74. end
  75. return func_pointer
  76. end
  77. """
  78. Declares a Julia function which is just calling the StarPU function
  79. having the same name.
  80. """
  81. macro starpu_noparam_function(func_name, ret_type)
  82. func = Symbol(func_name)
  83. quote
  84. export $func
  85. global $func() = ccall(($func_name, starpu_wrapper_library_name),
  86. $ret_type, ()) :: $ret_type
  87. end
  88. end