utils.jl 3.2 KB

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