fstarpu_mod.f90 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. ! StarPU --- Runtime system for heterogeneous multicore architectures.
  2. !
  3. ! Copyright (C) 2016 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. module fstarpu_mod
  16. use iso_c_binding
  17. implicit none
  18. ! Note: Constants truly are intptr_t, but are declared as c_ptr to be
  19. ! readily usable in c_ptr arrays to mimic variadic functions.
  20. ! A side effect, though, is that such constants cannot be logically
  21. ! 'or'-ed.
  22. type(c_ptr), bind(C) :: FSTARPU_R
  23. type(c_ptr), bind(C) :: FSTARPU_W
  24. type(c_ptr), bind(C) :: FSTARPU_RW
  25. type(c_ptr), bind(C) :: FSTARPU_SCRATCH
  26. type(c_ptr), bind(C) :: FSTARPU_REDUX
  27. type(c_ptr), bind(C) :: FSTARPU_DATA
  28. type(c_ptr), bind(C) :: FSTARPU_VALUE
  29. type(c_ptr), bind(C) :: FSTARPU_SZ_INT4
  30. type(c_ptr), bind(C) :: FSTARPU_SZ_INT8
  31. type(c_ptr), bind(C) :: FSTARPU_SZ_REAL4
  32. type(c_ptr), bind(C) :: FSTARPU_SZ_REAL8
  33. interface
  34. ! == starpu.h ==
  35. subroutine fstarpu_conf_init(conf) bind(C,name="starpu_conf_init")
  36. use iso_c_binding, only: c_ptr
  37. type(c_ptr), value, intent(in) :: conf
  38. end subroutine fstarpu_conf_init
  39. ! starpu_init: see fstarpu_init
  40. ! starpu_initialize: see fstarpu_init
  41. subroutine fstarpu_pause() bind(C,name="starpu_pause")
  42. end subroutine fstarpu_pause
  43. subroutine fstarpu_resume() bind(C,name="starpu_resume")
  44. end subroutine fstarpu_resume
  45. subroutine fstarpu_shutdown () bind(C,name="starpu_shutdown")
  46. end subroutine fstarpu_shutdown
  47. ! starpu_topology_print
  48. subroutine fstarpu_asynchronous_copy_disabled() bind(C,name="starpu_asynchronous_copy_disabled")
  49. end subroutine fstarpu_asynchronous_copy_disabled
  50. subroutine fstarpu_asynchronous_cuda_copy_disabled() bind(C,name="starpu_asynchronous_cuda_copy_disabled")
  51. end subroutine fstarpu_asynchronous_cuda_copy_disabled
  52. subroutine fstarpu_asynchronous_opencl_copy_disabled() bind(C,name="starpu_asynchronous_opencl_copy_disabled")
  53. end subroutine fstarpu_asynchronous_opencl_copy_disabled
  54. subroutine fstarpu_asynchronous_mic_copy_disabled() bind(C,name="starpu_asynchronous_mic_copy_disabled")
  55. end subroutine fstarpu_asynchronous_mic_copy_disabled
  56. subroutine fstarpu_display_stats() bind(C,name="starpu_display_stats")
  57. end subroutine fstarpu_display_stats
  58. subroutine fstarpu_get_version(major,minor,release) bind(C,name="starpu_get_version")
  59. use iso_c_binding, only: c_int
  60. integer(c_int), intent(out) :: major,minor,release
  61. end subroutine fstarpu_get_version
  62. function fstarpu_cpu_worker_get_count() bind(C,name="starpu_cpu_worker_get_count")
  63. use iso_c_binding, only: c_int
  64. integer(c_int) :: fstarpu_cpu_worker_get_count
  65. end function fstarpu_cpu_worker_get_count
  66. ! == starpu_task.h ==
  67. ! starpu_tag_declare_deps
  68. ! starpu_tag_declare_deps_array
  69. ! starpu_task_declare_deps_array
  70. ! starpu_tag_wait
  71. ! starpu_tag_wait_array
  72. ! starpu_tag_notify_from_apps
  73. ! starpu_tag_restart
  74. ! starpu_tag_remove
  75. ! starpu_task_init
  76. ! starpu_task_clean
  77. ! starpu_task_create
  78. ! starpu_task_destroy
  79. ! starpu_task_submit
  80. ! starpu_task_submit_to_ctx
  81. ! starpu_task_finished
  82. ! starpu_task_wait
  83. subroutine fstarpu_task_wait_for_all () bind(C,name="starpu_task_wait_for_all")
  84. end subroutine fstarpu_task_wait_for_all
  85. ! starpu_task_wait_for_n_submitted
  86. ! starpu_task_wait_for_all_in_ctx
  87. ! starpu_task_wait_for_n_submitted_in_ctx
  88. ! starpu_task_wait_for_no_ready
  89. ! starpu_task_nready
  90. ! starpu_task_nsubmitted
  91. ! starpu_codelet_init
  92. ! starpu_codelet_display_stats
  93. ! starpu_task_get_current
  94. ! starpu_parallel_task_barrier_init
  95. ! starpu_parallel_task_barrier_init_n
  96. ! starpu_task_dup
  97. ! starpu_task_set_implementation
  98. ! starpu_task_get_implementation
  99. ! --
  100. function fstarpu_codelet_allocate () bind(C)
  101. use iso_c_binding, only: c_ptr
  102. type(c_ptr) :: fstarpu_codelet_allocate
  103. end function fstarpu_codelet_allocate
  104. subroutine fstarpu_codelet_free (cl) bind(C)
  105. use iso_c_binding, only: c_ptr
  106. type(c_ptr), value, intent(in) :: cl
  107. end subroutine fstarpu_codelet_free
  108. subroutine fstarpu_codelet_add_cpu_func (cl, f_ptr) bind(C)
  109. use iso_c_binding, only: c_ptr, c_funptr
  110. type(c_ptr), value, intent(in) :: cl
  111. type(c_funptr), value, intent(in) :: f_ptr
  112. end subroutine fstarpu_codelet_add_cpu_func
  113. subroutine fstarpu_codelet_add_cuda_func (cl, f_ptr) bind(C)
  114. use iso_c_binding, only: c_ptr, c_funptr
  115. type(c_ptr), value, intent(in) :: cl
  116. type(c_funptr), value, intent(in) :: f_ptr
  117. end subroutine fstarpu_codelet_add_cuda_func
  118. subroutine fstarpu_codelet_add_opencl_func (cl, f_ptr) bind(C)
  119. use iso_c_binding, only: c_ptr, c_funptr
  120. type(c_ptr), value, intent(in) :: cl
  121. type(c_funptr), value, intent(in) :: f_ptr
  122. end subroutine fstarpu_codelet_add_opencl_func
  123. subroutine fstarpu_codelet_add_buffer (cl, mode) bind(C)
  124. use iso_c_binding, only: c_ptr, c_ptr
  125. type(c_ptr), value, intent(in) :: cl
  126. type(c_ptr), value, intent(in) :: mode ! C function expects an intptr_t
  127. end subroutine fstarpu_codelet_add_buffer
  128. function fstarpu_vector_data_register(vector, nx, elt_size, ram) bind(C)
  129. use iso_c_binding, only: c_ptr, c_int, c_size_t
  130. type(c_ptr) :: fstarpu_vector_data_register
  131. type(c_ptr), value, intent(in) :: vector
  132. integer(c_int), value, intent(in) :: nx
  133. integer(c_size_t), value, intent(in) :: elt_size
  134. integer(c_int), value, intent(in) :: ram
  135. end function fstarpu_vector_data_register
  136. function fstarpu_vector_get_ptr(buffers, i) bind(C)
  137. use iso_c_binding, only: c_ptr, c_int
  138. type(c_ptr) :: fstarpu_vector_get_ptr
  139. type(c_ptr), value, intent(in) :: buffers
  140. integer(c_int), value, intent(in) :: i
  141. end function fstarpu_vector_get_ptr
  142. function fstarpu_vector_get_nx(buffers, i) bind(C)
  143. use iso_c_binding, only: c_ptr, c_int
  144. integer(c_int) :: fstarpu_vector_get_nx
  145. type(c_ptr), value, intent(in) :: buffers
  146. integer(c_int), value, intent(in) :: i
  147. end function fstarpu_vector_get_nx
  148. function fstarpu_matrix_data_register(matrix, ldy, ny, nx, elt_size, ram) bind(C)
  149. use iso_c_binding, only: c_ptr, c_int, c_size_t
  150. type(c_ptr) :: fstarpu_matrix_data_register
  151. type(c_ptr), value, intent(in) :: matrix
  152. integer(c_int), value, intent(in) :: ldy
  153. integer(c_int), value, intent(in) :: ny
  154. integer(c_int), value, intent(in) :: nx
  155. integer(c_size_t), value, intent(in) :: elt_size
  156. integer(c_int), value, intent(in) :: ram
  157. end function fstarpu_matrix_data_register
  158. function fstarpu_matrix_get_ptr(buffers, i) bind(C)
  159. use iso_c_binding, only: c_ptr, c_int
  160. type(c_ptr) :: fstarpu_matrix_get_ptr
  161. type(c_ptr), value, intent(in) :: buffers
  162. integer(c_int), value, intent(in) :: i
  163. end function fstarpu_matrix_get_ptr
  164. function fstarpu_matrix_get_ld(buffers, i) bind(C)
  165. use iso_c_binding, only: c_ptr, c_int
  166. integer(c_int) :: fstarpu_matrix_get_ld
  167. type(c_ptr), value, intent(in) :: buffers
  168. integer(c_int), value, intent(in) :: i
  169. end function fstarpu_matrix_get_ld
  170. function fstarpu_matrix_get_ny(buffers, i) bind(C)
  171. use iso_c_binding, only: c_ptr, c_int
  172. integer(c_int) :: fstarpu_matrix_get_ny
  173. type(c_ptr), value, intent(in) :: buffers
  174. integer(c_int), value, intent(in) :: i
  175. end function fstarpu_matrix_get_ny
  176. function fstarpu_matrix_get_nx(buffers, i) bind(C)
  177. use iso_c_binding, only: c_ptr, c_int
  178. integer(c_int) :: fstarpu_matrix_get_nx
  179. type(c_ptr), value, intent(in) :: buffers
  180. integer(c_int), value, intent(in) :: i
  181. end function fstarpu_matrix_get_nx
  182. subroutine fstarpu_data_unregister (dh) bind(C,name="starpu_data_unregister")
  183. use iso_c_binding, only: c_ptr
  184. type(c_ptr), value, intent(in) :: dh
  185. end subroutine fstarpu_data_unregister
  186. subroutine fstarpu_insert_task(arglist) bind(C)
  187. use iso_c_binding, only: c_ptr
  188. type(c_ptr), dimension(:), intent(in) :: arglist
  189. end subroutine fstarpu_insert_task
  190. subroutine fstarpu_unpack_arg(cl_arg,bufferlist) bind(C)
  191. use iso_c_binding, only: c_ptr
  192. type(c_ptr), value, intent(in) :: cl_arg
  193. type(c_ptr), dimension(:), intent(in) :: bufferlist
  194. end subroutine fstarpu_unpack_arg
  195. end interface
  196. contains
  197. function ip_to_p(i) bind(C)
  198. use iso_c_binding, only: c_ptr,c_intptr_t,C_NULL_PTR
  199. type(c_ptr) :: ip_to_p
  200. integer(c_intptr_t), value, intent(in) :: i
  201. ip_to_p = transfer(i,C_NULL_PTR)
  202. end function ip_to_p
  203. function sz_to_p(sz) bind(C)
  204. use iso_c_binding, only: c_ptr,c_size_t,c_intptr_t
  205. type(c_ptr) :: sz_to_p
  206. integer(c_size_t), value, intent(in) :: sz
  207. sz_to_p = ip_to_p(int(sz,kind=c_intptr_t))
  208. end function sz_to_p
  209. function fstarpu_init (conf) bind(C)
  210. use iso_c_binding
  211. integer(c_int) :: fstarpu_init
  212. type(c_ptr), value, intent(in) :: conf
  213. integer(4) :: FSTARPU_SZ_INT4_dummy
  214. integer(8) :: FSTARPU_SZ_INT8_dummy
  215. real(4) :: FSTARPU_SZ_REAL4_dummy
  216. real(8) :: FSTARPU_SZ_REAL8_dummy
  217. ! Note: Referencing global C constants from Fortran has
  218. ! been found unreliable on some architectures, notably
  219. ! on Darwin. The get_integer/get_pointer_constant
  220. ! scheme is a workaround to that issue.
  221. interface
  222. ! These functions are not exported to the end user
  223. function fstarpu_get_constant(s) bind(C)
  224. use iso_c_binding, only: c_ptr,c_char
  225. type(c_ptr) :: fstarpu_get_constant ! C function returns an intptr_t
  226. character(kind=c_char) :: s
  227. end function fstarpu_get_constant
  228. function fstarpu_init_internal (conf) bind(C,name="starpu_init")
  229. use iso_c_binding, only: c_ptr,c_int
  230. integer(c_int) :: fstarpu_init_internal
  231. type(c_ptr), value :: conf
  232. end function fstarpu_init_internal
  233. end interface
  234. ! Initialize Fortran constants from C peers
  235. FSTARPU_R = fstarpu_get_constant(C_CHAR_"FSTARPU_R"//C_NULL_CHAR)
  236. FSTARPU_W = fstarpu_get_constant(C_CHAR_"FSTARPU_W"//C_NULL_CHAR)
  237. FSTARPU_RW = fstarpu_get_constant(C_CHAR_"FSTARPU_RW"//C_NULL_CHAR)
  238. FSTARPU_SCRATCH = fstarpu_get_constant(C_CHAR_"FSTARPU_SCRATCH"//C_NULL_CHAR)
  239. FSTARPU_REDUX = fstarpu_get_constant(C_CHAR_"FSTARPU_REDUX"//C_NULL_CHAR)
  240. FSTARPU_DATA = fstarpu_get_constant(C_CHAR_"FSTARPU_DATA"//C_NULL_CHAR)
  241. FSTARPU_VALUE = fstarpu_get_constant(C_CHAR_"FSTARPU_VALUE"//C_NULL_CHAR)
  242. ! Initialize size constants as 'c_ptr'
  243. FSTARPU_SZ_INT4 = sz_to_p(c_sizeof(FSTARPU_SZ_INT4_dummy))
  244. FSTARPU_SZ_INT8 = sz_to_p(c_sizeof(FSTARPU_SZ_INT8_dummy))
  245. FSTARPU_SZ_REAL4 = sz_to_p(c_sizeof(FSTARPU_SZ_REAL4_dummy))
  246. FSTARPU_SZ_REAL8 = sz_to_p(c_sizeof(FSTARPU_SZ_REAL8_dummy))
  247. ! Initialize StarPU
  248. if (c_associated(conf)) then
  249. fstarpu_init = fstarpu_init_internal(conf)
  250. else
  251. fstarpu_init = fstarpu_init_internal(C_NULL_PTR)
  252. end if
  253. end function fstarpu_init
  254. function fstarpu_csizet_to_cptr(i) bind(C)
  255. use iso_c_binding
  256. type(c_ptr) :: fstarpu_csizet_to_cptr
  257. integer(c_size_t) :: i
  258. fstarpu_csizet_to_cptr = transfer(int(i,kind=c_intptr_t),C_NULL_PTR)
  259. end function fstarpu_csizet_to_cptr
  260. function fstarpu_int_to_cptr(i) bind(C)
  261. use iso_c_binding
  262. type(c_ptr) :: fstarpu_int_to_cptr
  263. integer :: i
  264. fstarpu_int_to_cptr = transfer(int(i,kind=c_intptr_t),C_NULL_PTR)
  265. end function fstarpu_int_to_cptr
  266. end module fstarpu_mod