mic_lib.f90 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. !
  2. ! Copyright (c) 2014 Intel Corporation. All Rights Reserved.
  3. !
  4. ! Redistribution and use in source and binary forms, with or without
  5. ! modification, are permitted provided that the following conditions
  6. ! are met:
  7. !
  8. ! * Redistributions of source code must retain the above copyright
  9. ! notice, this list of conditions and the following disclaimer.
  10. ! * Redistributions in binary form must reproduce the above copyright
  11. ! notice, this list of conditions and the following disclaimer in the
  12. ! documentation and/or other materials provided with the distribution.
  13. ! * Neither the name of Intel Corporation nor the names of its
  14. ! contributors may be used to endorse or promote products derived
  15. ! from this software without specific prior written permission.
  16. !
  17. ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. ! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. ! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. ! A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. ! HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. ! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. ! LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. ! DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. ! THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. ! (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. ! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. !
  29. ! **********************************************************************************
  30. ! * This file is intended to support the Intel(r) Many Integrated Core Architecture.
  31. ! **********************************************************************************
  32. ! free form Fortran source - should be named .f90
  33. ! lines are longer than 72 characters
  34. module mic_lib
  35. use, intrinsic :: iso_c_binding
  36. integer, parameter:: target_mic=2
  37. integer, parameter:: default_target_type=target_mic
  38. integer, parameter:: default_target_number=0
  39. enum, bind(C)
  40. enumerator :: OFFLOAD_SUCCESS = 0
  41. enumerator :: OFFLOAD_DISABLED ! offload is disabled
  42. enumerator :: OFFLOAD_UNAVAILABLE ! card is not available
  43. enumerator :: OFFLOAD_OUT_OF_MEMORY ! not enough memory on device
  44. enumerator :: OFFLOAD_PROCESS_DIED ! target process has died
  45. enumerator :: OFFLOAD_ERROR ! unspecified error
  46. end enum
  47. type, bind (C) :: offload_status
  48. integer(kind=c_int) :: result = OFFLOAD_DISABLED
  49. integer(kind=c_int) :: device_number = -1
  50. integer(kind=c_size_t) :: data_sent = 0
  51. integer(kind=c_size_t) :: data_received = 0
  52. end type offload_status
  53. interface
  54. function offload_number_of_devices () &
  55. bind (C, name = "_Offload_number_of_devices")
  56. !dec$ attributes default :: offload_number_of_devices
  57. import :: c_int
  58. integer (kind=c_int) :: offload_number_of_devices
  59. !dec$ attributes offload:mic :: offload_number_of_devices
  60. !dir$ attributes known_intrinsic :: offload_number_of_devices
  61. end function offload_number_of_devices
  62. function offload_signaled(target_number, signal) &
  63. bind (C, name = "_Offload_signaled")
  64. !dec$ attributes default :: offload_signaled
  65. import :: c_int, c_int64_t
  66. integer (kind=c_int) :: offload_signaled
  67. integer (kind=c_int), value :: target_number
  68. integer (kind=c_int64_t), value :: signal
  69. !dec$ attributes offload:mic :: offload_signaled
  70. end function offload_signaled
  71. subroutine offload_report(val) &
  72. bind (C, name = "_Offload_report")
  73. !dec$ attributes default :: offload_report
  74. import :: c_int
  75. integer (kind=c_int), value :: val
  76. !dec$ attributes offload:mic :: offload_report
  77. end subroutine offload_report
  78. function offload_get_device_number() &
  79. bind (C, name = "_Offload_get_device_number")
  80. !dec$ attributes default :: offload_get_device_number
  81. import :: c_int
  82. integer (kind=c_int) :: offload_get_device_number
  83. !dec$ attributes offload:mic :: offload_get_device_number
  84. end function offload_get_device_number
  85. function offload_get_physical_device_number() &
  86. bind (C, name = "_Offload_get_physical_device_number")
  87. !dec$ attributes default :: offload_get_physical_device_number
  88. import :: c_int
  89. integer (kind=c_int) :: offload_get_physical_device_number
  90. !dec$ attributes offload:mic :: offload_get_physical_device_number
  91. end function offload_get_physical_device_number
  92. ! OpenMP API wrappers
  93. subroutine omp_set_num_threads_target (target_type, &
  94. target_number, &
  95. num_threads) &
  96. bind (C, name = "omp_set_num_threads_target")
  97. import :: c_int
  98. integer (kind=c_int), value :: target_type, target_number, num_threads
  99. end subroutine omp_set_num_threads_target
  100. function omp_get_max_threads_target (target_type, &
  101. target_number) &
  102. bind (C, name = "omp_get_max_threads_target")
  103. import :: c_int
  104. integer (kind=c_int) :: omp_get_max_threads_target
  105. integer (kind=c_int), value :: target_type, target_number
  106. end function omp_get_max_threads_target
  107. function omp_get_num_procs_target (target_type, &
  108. target_number) &
  109. bind (C, name = "omp_get_num_procs_target")
  110. import :: c_int
  111. integer (kind=c_int) :: omp_get_num_procs_target
  112. integer (kind=c_int), value :: target_type, target_number
  113. end function omp_get_num_procs_target
  114. subroutine omp_set_dynamic_target (target_type, &
  115. target_number, &
  116. num_threads) &
  117. bind (C, name = "omp_set_dynamic_target")
  118. import :: c_int
  119. integer (kind=c_int), value :: target_type, target_number, num_threads
  120. end subroutine omp_set_dynamic_target
  121. function omp_get_dynamic_target (target_type, &
  122. target_number) &
  123. bind (C, name = "omp_get_dynamic_target")
  124. import :: c_int
  125. integer (kind=c_int) :: omp_get_dynamic_target
  126. integer (kind=c_int), value :: target_type, target_number
  127. end function omp_get_dynamic_target
  128. subroutine omp_set_nested_target (target_type, &
  129. target_number, &
  130. nested) &
  131. bind (C, name = "omp_set_nested_target")
  132. import :: c_int
  133. integer (kind=c_int), value :: target_type, target_number, nested
  134. end subroutine omp_set_nested_target
  135. function omp_get_nested_target (target_type, &
  136. target_number) &
  137. bind (C, name = "omp_get_nested_target")
  138. import :: c_int
  139. integer (kind=c_int) :: omp_get_nested_target
  140. integer (kind=c_int), value :: target_type, target_number
  141. end function omp_get_nested_target
  142. subroutine omp_set_schedule_target (target_type, &
  143. target_number, &
  144. kind, &
  145. modifier) &
  146. bind (C, name = "omp_set_schedule_target")
  147. import :: c_int
  148. integer (kind=c_int), value :: target_type, target_number, kind, modifier
  149. end subroutine omp_set_schedule_target
  150. subroutine omp_get_schedule_target (target_type, &
  151. target_number, &
  152. kind, &
  153. modifier) &
  154. bind (C, name = "omp_get_schedule_target")
  155. import :: c_int, c_intptr_t
  156. integer (kind=c_int), value :: target_type, target_number
  157. integer (kind=c_intptr_t), value :: kind, modifier
  158. end subroutine omp_get_schedule_target
  159. ! lock API functions
  160. subroutine omp_init_lock_target (target_type, &
  161. target_number, &
  162. lock) &
  163. bind (C, name = "omp_init_lock_target")
  164. import :: c_int, c_intptr_t
  165. !dir$ attributes known_intrinsic :: omp_init_lock_target
  166. integer (kind=c_int), value :: target_type, target_number
  167. integer (kind=c_intptr_t), value :: lock
  168. end subroutine omp_init_lock_target
  169. subroutine omp_destroy_lock_target (target_type, &
  170. target_number, &
  171. lock) &
  172. bind (C, name = "omp_destroy_lock_target")
  173. import :: c_int, c_intptr_t
  174. !dir$ attributes known_intrinsic :: omp_destroy_lock_target
  175. integer (kind=c_int), value :: target_type, target_number
  176. integer (kind=c_intptr_t), value :: lock
  177. end subroutine omp_destroy_lock_target
  178. subroutine omp_set_lock_target (target_type, &
  179. target_number, &
  180. lock) &
  181. bind (C, name = "omp_set_lock_target")
  182. import :: c_int, c_intptr_t
  183. !dir$ attributes known_intrinsic :: omp_set_lock_target
  184. integer (kind=c_int), value :: target_type, target_number
  185. integer (kind=c_intptr_t), value :: lock
  186. end subroutine omp_set_lock_target
  187. subroutine omp_unset_lock_target (target_type, &
  188. target_number, &
  189. lock) &
  190. bind (C, name = "omp_unset_lock_target")
  191. import :: c_int, c_intptr_t
  192. !dir$ attributes known_intrinsic :: omp_unset_lock_target
  193. integer (kind=c_int), value :: target_type, target_number
  194. integer (kind=c_intptr_t), value :: lock
  195. end subroutine omp_unset_lock_target
  196. function omp_test_lock_target (target_type, &
  197. target_number, &
  198. lock) &
  199. bind (C, name = "omp_test_lock_target")
  200. import :: c_int, c_intptr_t
  201. integer (kind=c_int) :: omp_test_lock_target
  202. integer (kind=c_int), value :: target_type, target_number
  203. integer (kind=c_intptr_t), value :: lock
  204. end function omp_test_lock_target
  205. ! nested lock API functions
  206. subroutine omp_init_nest_lock_target (target_type, &
  207. target_number, &
  208. lock) &
  209. bind (C, name = "omp_init_nest_lock_target")
  210. import :: c_int, c_intptr_t
  211. integer (kind=c_int), value :: target_type, target_number
  212. integer (kind=c_intptr_t), value :: lock
  213. end subroutine omp_init_nest_lock_target
  214. subroutine omp_destroy_nest_lock_target (target_type, &
  215. target_number, &
  216. lock) &
  217. bind (C, name = "omp_destroy_nest_lock_target")
  218. import :: c_int, c_intptr_t
  219. integer (kind=c_int), value :: target_type, target_number
  220. integer (kind=c_intptr_t), value :: lock
  221. end subroutine omp_destroy_nest_lock_target
  222. subroutine omp_set_nest_lock_target (target_type, &
  223. target_number, &
  224. lock) &
  225. bind (C, name = "omp_set_nest_lock_target")
  226. import :: c_int, c_intptr_t
  227. integer (kind=c_int), value :: target_type, target_number
  228. integer (kind=c_intptr_t), value :: lock
  229. end subroutine omp_set_nest_lock_target
  230. subroutine omp_unset_nest_lock_target (target_type, &
  231. target_number, &
  232. lock) &
  233. bind (C, name = "omp_unset_nest_lock_target")
  234. import :: c_int, c_intptr_t
  235. integer (kind=c_int), value :: target_type, target_number
  236. integer (kind=c_intptr_t), value :: lock
  237. end subroutine omp_unset_nest_lock_target
  238. function omp_test_nest_lock_target (target_type, &
  239. target_number, &
  240. lock) &
  241. bind (C, name = "omp_test_nest_lock_target")
  242. import :: c_int, c_intptr_t
  243. integer (kind=c_int) :: omp_test_nest_lock_target
  244. integer (kind=c_int), value :: target_type, target_number
  245. integer (kind=c_intptr_t), value :: lock
  246. end function omp_test_nest_lock_target
  247. end interface
  248. end module mic_lib