fstarpu_mod.f90 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. integer(c_int), bind(C) :: FSTARPU_R
  18. integer(c_int), bind(C) :: FSTARPU_W
  19. integer(c_int), bind(C) :: FSTARPU_RW
  20. integer(c_int), bind(C) :: FSTARPU_SCRATCH
  21. integer(c_int), bind(C) :: FSTARPU_REDUX
  22. type(c_ptr), bind(C) :: FSTARPU_DATA
  23. interface
  24. ! == starpu.h ==
  25. subroutine fstarpu_conf_init(conf) bind(C,name="starpu_conf_init")
  26. use iso_c_binding, only: c_ptr
  27. type(c_ptr), value, intent(in) :: conf
  28. end subroutine fstarpu_conf_init
  29. ! starpu_init: see fstarpu_init
  30. ! starpu_initialize: see fstarpu_init
  31. subroutine fstarpu_pause() bind(C,name="starpu_pause")
  32. end subroutine fstarpu_pause
  33. subroutine fstarpu_resume() bind(C,name="starpu_resume")
  34. end subroutine fstarpu_resume
  35. subroutine fstarpu_shutdown () bind(C,name="starpu_shutdown")
  36. end subroutine fstarpu_shutdown
  37. ! starpu_topology_print
  38. subroutine fstarpu_asynchronous_copy_disabled() bind(C,name="starpu_asynchronous_copy_disabled")
  39. end subroutine fstarpu_asynchronous_copy_disabled
  40. subroutine fstarpu_asynchronous_cuda_copy_disabled() bind(C,name="starpu_asynchronous_cuda_copy_disabled")
  41. end subroutine fstarpu_asynchronous_cuda_copy_disabled
  42. subroutine fstarpu_asynchronous_opencl_copy_disabled() bind(C,name="starpu_asynchronous_opencl_copy_disabled")
  43. end subroutine fstarpu_asynchronous_opencl_copy_disabled
  44. subroutine fstarpu_asynchronous_mic_copy_disabled() bind(C,name="starpu_asynchronous_mic_copy_disabled")
  45. end subroutine fstarpu_asynchronous_mic_copy_disabled
  46. subroutine fstarpu_display_stats() bind(C,name="starpu_display_stats")
  47. end subroutine fstarpu_display_stats
  48. subroutine fstarpu_get_version(major,minor,release) bind(C,name="starpu_get_version")
  49. use iso_c_binding, only: c_int
  50. integer(c_int), intent(out) :: major,minor,release
  51. end subroutine fstarpu_get_version
  52. function fstarpu_cpu_worker_get_count() bind(C,name="starpu_cpu_worker_get_count")
  53. use iso_c_binding, only: c_int
  54. integer(c_int) :: fstarpu_cpu_worker_get_count
  55. end function fstarpu_cpu_worker_get_count
  56. ! == starpu_task.h ==
  57. ! starpu_tag_declare_deps
  58. ! starpu_tag_declare_deps_array
  59. ! starpu_task_declare_deps_array
  60. ! starpu_tag_wait
  61. ! starpu_tag_wait_array
  62. ! starpu_tag_notify_from_apps
  63. ! starpu_tag_restart
  64. ! starpu_tag_remove
  65. ! starpu_task_init
  66. ! starpu_task_clean
  67. ! starpu_task_create
  68. ! starpu_task_destroy
  69. ! starpu_task_submit
  70. ! starpu_task_submit_to_ctx
  71. ! starpu_task_finished
  72. ! starpu_task_wait
  73. subroutine fstarpu_task_wait_for_all () bind(C,name="starpu_task_wait_for_all")
  74. end subroutine fstarpu_task_wait_for_all
  75. ! starpu_task_wait_for_n_submitted
  76. ! starpu_task_wait_for_all_in_ctx
  77. ! starpu_task_wait_for_n_submitted_in_ctx
  78. ! starpu_task_wait_for_no_ready
  79. ! starpu_task_nready
  80. ! starpu_task_nsubmitted
  81. ! starpu_codelet_init
  82. ! starpu_codelet_display_stats
  83. ! starpu_task_get_current
  84. ! starpu_parallel_task_barrier_init
  85. ! starpu_parallel_task_barrier_init_n
  86. ! starpu_task_dup
  87. ! starpu_task_set_implementation
  88. ! starpu_task_get_implementation
  89. ! --
  90. function fstarpu_codelet_allocate () bind(C)
  91. use iso_c_binding, only: c_ptr
  92. type(c_ptr) :: fstarpu_codelet_allocate
  93. end function fstarpu_codelet_allocate
  94. subroutine fstarpu_codelet_free (cl) bind(C)
  95. use iso_c_binding, only: c_ptr
  96. type(c_ptr), value, intent(in) :: cl
  97. end subroutine fstarpu_codelet_free
  98. subroutine fstarpu_codelet_add_cpu_func (cl, f_ptr) bind(C)
  99. use iso_c_binding, only: c_ptr, c_funptr
  100. type(c_ptr), value, intent(in) :: cl
  101. type(c_funptr), value, intent(in) :: f_ptr
  102. end subroutine fstarpu_codelet_add_cpu_func
  103. subroutine fstarpu_codelet_add_cuda_func (cl, f_ptr) bind(C)
  104. use iso_c_binding, only: c_ptr, c_funptr
  105. type(c_ptr), value, intent(in) :: cl
  106. type(c_funptr), value, intent(in) :: f_ptr
  107. end subroutine fstarpu_codelet_add_cuda_func
  108. subroutine fstarpu_codelet_add_opencl_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_opencl_func
  113. subroutine fstarpu_codelet_add_buffer (cl, mode) bind(C)
  114. use iso_c_binding, only: c_ptr, c_int
  115. type(c_ptr), value, intent(in) :: cl
  116. integer(c_int), value, intent(in) :: mode
  117. end subroutine fstarpu_codelet_add_buffer
  118. function fstarpu_vector_data_register(vector, nx, elt_size, ram) bind(C)
  119. use iso_c_binding, only: c_ptr, c_int, c_size_t
  120. type(c_ptr) :: fstarpu_vector_data_register
  121. type(c_ptr), value, intent(in) :: vector
  122. integer(c_int), value, intent(in) :: nx
  123. integer(c_size_t), value, intent(in) :: elt_size
  124. integer(c_int), value, intent(in) :: ram
  125. end function fstarpu_vector_data_register
  126. function fstarpu_vector_get_ptr(buffers, i) bind(C)
  127. use iso_c_binding, only: c_ptr, c_int
  128. type(c_ptr) :: fstarpu_vector_get_ptr
  129. type(c_ptr), value, intent(in) :: buffers
  130. integer(c_int), value, intent(in) :: i
  131. end function fstarpu_vector_get_ptr
  132. function fstarpu_vector_get_nx(buffers, i) bind(C)
  133. use iso_c_binding, only: c_ptr, c_int
  134. integer(c_int) :: fstarpu_vector_get_nx
  135. type(c_ptr), value, intent(in) :: buffers
  136. integer(c_int), value, intent(in) :: i
  137. end function fstarpu_vector_get_nx
  138. function fstarpu_matrix_data_register(matrix, ldy, ny, nx, elt_size, ram) bind(C)
  139. use iso_c_binding, only: c_ptr, c_int, c_size_t
  140. type(c_ptr) :: fstarpu_matrix_data_register
  141. type(c_ptr), value, intent(in) :: matrix
  142. integer(c_int), value, intent(in) :: ldy
  143. integer(c_int), value, intent(in) :: ny
  144. integer(c_int), value, intent(in) :: nx
  145. integer(c_size_t), value, intent(in) :: elt_size
  146. integer(c_int), value, intent(in) :: ram
  147. end function fstarpu_matrix_data_register
  148. function fstarpu_matrix_get_ptr(buffers, i) bind(C)
  149. use iso_c_binding, only: c_ptr, c_int
  150. type(c_ptr) :: fstarpu_matrix_get_ptr
  151. type(c_ptr), value, intent(in) :: buffers
  152. integer(c_int), value, intent(in) :: i
  153. end function fstarpu_matrix_get_ptr
  154. function fstarpu_matrix_get_ld(buffers, i) bind(C)
  155. use iso_c_binding, only: c_ptr, c_int
  156. integer(c_int) :: fstarpu_matrix_get_ld
  157. type(c_ptr), value, intent(in) :: buffers
  158. integer(c_int), value, intent(in) :: i
  159. end function fstarpu_matrix_get_ld
  160. function fstarpu_matrix_get_ny(buffers, i) bind(C)
  161. use iso_c_binding, only: c_ptr, c_int
  162. integer(c_int) :: fstarpu_matrix_get_ny
  163. type(c_ptr), value, intent(in) :: buffers
  164. integer(c_int), value, intent(in) :: i
  165. end function fstarpu_matrix_get_ny
  166. function fstarpu_matrix_get_nx(buffers, i) bind(C)
  167. use iso_c_binding, only: c_ptr, c_int
  168. integer(c_int) :: fstarpu_matrix_get_nx
  169. type(c_ptr), value, intent(in) :: buffers
  170. integer(c_int), value, intent(in) :: i
  171. end function fstarpu_matrix_get_nx
  172. subroutine fstarpu_data_unregister (dh) bind(C,name="starpu_data_unregister")
  173. use iso_c_binding, only: c_ptr
  174. type(c_ptr), value, intent(in) :: dh
  175. end subroutine fstarpu_data_unregister
  176. subroutine fstarpu_insert_task(arglist) bind(C)
  177. use iso_c_binding, only: c_ptr
  178. type(c_ptr), dimension(:), intent(in) :: arglist
  179. end subroutine fstarpu_insert_task
  180. end interface
  181. contains
  182. function fstarpu_init (conf) bind(C)
  183. use iso_c_binding
  184. integer(c_int) :: fstarpu_init
  185. type(c_ptr), value, intent(in) :: conf
  186. ! Note: Referencing global C constants from Fortran has
  187. ! been found unreliable on some architectures, notably
  188. ! on Darwin. The get_integer/get_pointer_constant
  189. ! scheme is a workaround to that issue.
  190. interface
  191. ! These functions are not exported to the end user
  192. function fstarpu_get_integer_constant(s) bind(C)
  193. use iso_c_binding, only: c_int,c_char
  194. integer(c_int) :: fstarpu_get_integer_constant
  195. character(kind=c_char) :: s
  196. end function fstarpu_get_integer_constant
  197. function fstarpu_get_pointer_constant(s) bind(C)
  198. use iso_c_binding, only: c_ptr,c_char
  199. type(c_ptr) :: fstarpu_get_pointer_constant
  200. character(kind=c_char) :: s
  201. end function fstarpu_get_pointer_constant
  202. function fstarpu_init_internal (conf) bind(C,name="starpu_init")
  203. use iso_c_binding, only: c_ptr,c_int
  204. integer(c_int) :: fstarpu_init_internal
  205. type(c_ptr), value :: conf
  206. end function fstarpu_init_internal
  207. end interface
  208. ! Initialize Fortran integer constants from C peers
  209. FSTARPU_R = fstarpu_get_integer_constant(C_CHAR_"FSTARPU_R"//C_NULL_CHAR)
  210. FSTARPU_W = fstarpu_get_integer_constant(C_CHAR_"FSTARPU_W"//C_NULL_CHAR)
  211. FSTARPU_RW = fstarpu_get_integer_constant(C_CHAR_"FSTARPU_RW"//C_NULL_CHAR)
  212. FSTARPU_SCRATCH = fstarpu_get_integer_constant(C_CHAR_"FSTARPU_SCRATCH"//C_NULL_CHAR)
  213. FSTARPU_REDUX = fstarpu_get_integer_constant(C_CHAR_"FSTARPU_REDUX"//C_NULL_CHAR)
  214. ! Initialize Fortran 'pointer' constants from C peers
  215. FSTARPU_DATA = fstarpu_get_pointer_constant(C_CHAR_"FSTARPU_DATA"//C_NULL_CHAR)
  216. ! Initialize StarPU
  217. if (c_associated(conf)) then
  218. fstarpu_init = fstarpu_init_internal(conf)
  219. else
  220. fstarpu_init = fstarpu_init_internal(C_NULL_PTR)
  221. end if
  222. end function fstarpu_init
  223. end module fstarpu_mod