fstarpu_mod.f90 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. subroutine fstarpu_shutdown () bind(C,name="starpu_shutdown")
  25. end subroutine fstarpu_shutdown
  26. function fstarpu_codelet_allocate () bind(C)
  27. use iso_c_binding, only: c_ptr
  28. type(c_ptr) :: fstarpu_codelet_allocate
  29. end function fstarpu_codelet_allocate
  30. subroutine fstarpu_codelet_free (cl) bind(C)
  31. use iso_c_binding, only: c_ptr
  32. type(c_ptr), value, intent(in) :: cl
  33. end subroutine fstarpu_codelet_free
  34. subroutine fstarpu_codelet_add_cpu_func (cl, f_ptr) bind(C)
  35. use iso_c_binding, only: c_ptr, c_funptr
  36. type(c_ptr), value, intent(in) :: cl
  37. type(c_funptr), value, intent(in) :: f_ptr
  38. end subroutine fstarpu_codelet_add_cpu_func
  39. subroutine fstarpu_codelet_add_cuda_func (cl, f_ptr) bind(C)
  40. use iso_c_binding, only: c_ptr, c_funptr
  41. type(c_ptr), value, intent(in) :: cl
  42. type(c_funptr), value, intent(in) :: f_ptr
  43. end subroutine fstarpu_codelet_add_cuda_func
  44. subroutine fstarpu_codelet_add_opencl_func (cl, f_ptr) bind(C)
  45. use iso_c_binding, only: c_ptr, c_funptr
  46. type(c_ptr), value, intent(in) :: cl
  47. type(c_funptr), value, intent(in) :: f_ptr
  48. end subroutine fstarpu_codelet_add_opencl_func
  49. subroutine fstarpu_codelet_add_buffer (cl, mode) bind(C)
  50. use iso_c_binding, only: c_ptr, c_int
  51. type(c_ptr), value, intent(in) :: cl
  52. integer(c_int), value, intent(in) :: mode
  53. end subroutine fstarpu_codelet_add_buffer
  54. function fstarpu_vector_data_register(vector, nx, elt_size, ram) bind(C)
  55. use iso_c_binding
  56. type(c_ptr) :: fstarpu_vector_data_register
  57. type(c_ptr), value, intent(in) :: vector
  58. integer(c_int), value, intent(in) :: nx
  59. integer(c_size_t), value, intent(in) :: elt_size
  60. integer(c_int), value, intent(in) :: ram
  61. end function fstarpu_vector_data_register
  62. function fstarpu_vector_get_ptr(buffers, i) bind(C)
  63. use iso_c_binding
  64. type(c_ptr) :: fstarpu_vector_get_ptr
  65. type(c_ptr), value, intent(in) :: buffers
  66. integer(c_int), value, intent(in) :: i
  67. end function fstarpu_vector_get_ptr
  68. function fstarpu_vector_get_nx(buffers, i) bind(C)
  69. use iso_c_binding
  70. integer(c_int) :: fstarpu_vector_get_nx
  71. type(c_ptr), value, intent(in) :: buffers
  72. integer(c_int), value, intent(in) :: i
  73. end function fstarpu_vector_get_nx
  74. function fstarpu_matrix_data_register(matrix, ldy, ny, nx, elt_size, ram) bind(C)
  75. use iso_c_binding
  76. type(c_ptr) :: fstarpu_matrix_data_register
  77. type(c_ptr), value, intent(in) :: matrix
  78. integer(c_int), value, intent(in) :: ldy
  79. integer(c_int), value, intent(in) :: ny
  80. integer(c_int), value, intent(in) :: nx
  81. integer(c_size_t), value, intent(in) :: elt_size
  82. integer(c_int), value, intent(in) :: ram
  83. end function fstarpu_matrix_data_register
  84. function fstarpu_matrix_get_ptr(buffers, i) bind(C)
  85. use iso_c_binding
  86. type(c_ptr) :: fstarpu_matrix_get_ptr
  87. type(c_ptr), value, intent(in) :: buffers
  88. integer(c_int), value, intent(in) :: i
  89. end function fstarpu_matrix_get_ptr
  90. function fstarpu_matrix_get_ld(buffers, i) bind(C)
  91. use iso_c_binding
  92. integer(c_int) :: fstarpu_matrix_get_ld
  93. type(c_ptr), value, intent(in) :: buffers
  94. integer(c_int), value, intent(in) :: i
  95. end function fstarpu_matrix_get_ld
  96. function fstarpu_matrix_get_ny(buffers, i) bind(C)
  97. use iso_c_binding
  98. integer(c_int) :: fstarpu_matrix_get_ny
  99. type(c_ptr), value, intent(in) :: buffers
  100. integer(c_int), value, intent(in) :: i
  101. end function fstarpu_matrix_get_ny
  102. function fstarpu_matrix_get_nx(buffers, i) bind(C)
  103. use iso_c_binding
  104. integer(c_int) :: fstarpu_matrix_get_nx
  105. type(c_ptr), value, intent(in) :: buffers
  106. integer(c_int), value, intent(in) :: i
  107. end function fstarpu_matrix_get_nx
  108. subroutine fstarpu_data_unregister (dh) bind(C,name="starpu_data_unregister")
  109. use iso_c_binding, only: c_ptr
  110. type(c_ptr), value, intent(in) :: dh
  111. end subroutine fstarpu_data_unregister
  112. subroutine fstarpu_insert_task(arglist) bind(C)
  113. use iso_c_binding, only: c_ptr
  114. type(c_ptr), dimension(:), intent(in) :: arglist
  115. end subroutine fstarpu_insert_task
  116. subroutine fstarpu_task_wait_for_all () bind(C,name="starpu_task_wait_for_all")
  117. end subroutine fstarpu_task_wait_for_all
  118. end interface
  119. contains
  120. subroutine fstarpu_init ()
  121. ! Note: Referencing global C constants from Fortran has
  122. ! been found unreliable on some architectures, notably
  123. ! on Darwin. The get_integer/get_pointer_constant
  124. ! scheme is a workaround to that issue.
  125. interface
  126. ! These functions are not exported to the end user
  127. function fstarpu_get_integer_constant(s) bind(C)
  128. use iso_c_binding, only: c_int,c_char
  129. integer(c_int) :: fstarpu_get_integer_constant
  130. character(kind=c_char) :: s
  131. end function fstarpu_get_integer_constant
  132. function fstarpu_get_pointer_constant(s) bind(C)
  133. use iso_c_binding, only: c_ptr,c_char
  134. type(c_ptr) :: fstarpu_get_pointer_constant
  135. character(kind=c_char) :: s
  136. end function fstarpu_get_pointer_constant
  137. subroutine fstarpu_init_internal () bind(C)
  138. end subroutine fstarpu_init_internal
  139. end interface
  140. ! Initialize Fortran integer constants from C peers
  141. FSTARPU_R = fstarpu_get_integer_constant(C_CHAR_"FSTARPU_R"//C_NULL_CHAR)
  142. FSTARPU_W = fstarpu_get_integer_constant(C_CHAR_"FSTARPU_W"//C_NULL_CHAR)
  143. FSTARPU_RW = fstarpu_get_integer_constant(C_CHAR_"FSTARPU_RW"//C_NULL_CHAR)
  144. FSTARPU_SCRATCH = fstarpu_get_integer_constant(C_CHAR_"FSTARPU_SCRATCH"//C_NULL_CHAR)
  145. FSTARPU_REDUX = fstarpu_get_integer_constant(C_CHAR_"FSTARPU_REDUX"//C_NULL_CHAR)
  146. ! Initialize Fortran 'pointer' constants from C peers
  147. FSTARPU_DATA = fstarpu_get_pointer_constant(C_CHAR_"FSTARPU_DATA"//C_NULL_CHAR)
  148. ! Initialize StarPU
  149. call fstarpu_init_internal()
  150. end subroutine fstarpu_init
  151. end module fstarpu_mod