fstarpu_mod.f90 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. subroutine fstarpu_data_unregister (dh) bind(C,name="starpu_data_unregister")
  75. use iso_c_binding, only: c_ptr
  76. type(c_ptr), value, intent(in) :: dh
  77. end subroutine fstarpu_data_unregister
  78. subroutine fstarpu_insert_task(arglist) bind(C)
  79. use iso_c_binding, only: c_ptr
  80. type(c_ptr), dimension(:), intent(in) :: arglist
  81. end subroutine fstarpu_insert_task
  82. subroutine fstarpu_task_wait_for_all () bind(C,name="starpu_task_wait_for_all")
  83. end subroutine fstarpu_task_wait_for_all
  84. end interface
  85. contains
  86. subroutine fstarpu_init ()
  87. ! Note: Referencing global C constants from Fortran has
  88. ! been found unreliable on some architectures, notably
  89. ! on Darwin. The get_integer/get_pointer_constant
  90. ! scheme is a workaround to that issue.
  91. interface
  92. ! These functions are not exported to the end user
  93. function fstarpu_get_integer_constant(s) bind(C)
  94. use iso_c_binding, only: c_int,c_char
  95. integer(c_int) :: fstarpu_get_integer_constant
  96. character(kind=c_char) :: s
  97. end function fstarpu_get_integer_constant
  98. function fstarpu_get_pointer_constant(s) bind(C)
  99. use iso_c_binding, only: c_ptr,c_char
  100. type(c_ptr) :: fstarpu_get_pointer_constant
  101. character(kind=c_char) :: s
  102. end function fstarpu_get_pointer_constant
  103. subroutine fstarpu_init_internal () bind(C)
  104. end subroutine fstarpu_init_internal
  105. end interface
  106. ! Initialize Fortran integer constants from C peers
  107. FSTARPU_R = fstarpu_get_integer_constant(C_CHAR_"FSTARPU_R"//C_NULL_CHAR)
  108. FSTARPU_W = fstarpu_get_integer_constant(C_CHAR_"FSTARPU_W"//C_NULL_CHAR)
  109. FSTARPU_RW = fstarpu_get_integer_constant(C_CHAR_"FSTARPU_RW"//C_NULL_CHAR)
  110. FSTARPU_SCRATCH = fstarpu_get_integer_constant(C_CHAR_"FSTARPU_SCRATCH"//C_NULL_CHAR)
  111. FSTARPU_REDUX = fstarpu_get_integer_constant(C_CHAR_"FSTARPU_REDUX"//C_NULL_CHAR)
  112. ! Initialize Fortran 'pointer' constants from C peers
  113. FSTARPU_DATA = fstarpu_get_pointer_constant(C_CHAR_"FSTARPU_DATA"//C_NULL_CHAR)
  114. ! Initialize StarPU
  115. call fstarpu_init_internal()
  116. end subroutine fstarpu_init
  117. end module fstarpu_mod