Simulation Core
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

259 lines
20 KiB

  1. ! BSD 2-Clause License
  2. !
  3. ! Copyright (c) 2021-2022, Hewlett Packard Enterprise
  4. ! All rights reserved.
  5. !
  6. ! Redistribution and use in source and binary forms, with or without
  7. ! modification, are permitted provided that the following conditions are met:
  8. !
  9. ! 1. Redistributions of source code must retain the above copyright notice, this
  10. ! list of conditions and the following disclaimer.
  11. !
  12. ! 2. Redistributions in binary form must reproduce the above copyright notice,
  13. ! this list of conditions and the following disclaimer in the documentation
  14. ! and/or other materials provided with the distribution.
  15. !
  16. ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. ! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. ! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. ! DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  20. ! FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. ! DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22. ! SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. ! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  24. ! OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25. ! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. interface
  27. function get_model_c( c_client, key, key_length, model, model_length, model_data) bind(c,name="get_model")
  28. use iso_c_binding, only : c_ptr, c_char, c_size_t
  29. import :: enum_kind
  30. integer(kind=enum_kind) :: get_model_c
  31. type(c_ptr), value, intent(in) :: c_client !< Initialized SmartRedis client
  32. character(kind=c_char), intent(in) :: key(*) !< The key to use to place the model
  33. integer(kind=c_size_t), value, intent(in) :: key_length !< The length of the key c-string, excluding null
  34. type(c_ptr), intent(inout) :: model !< The model as a continuous buffer
  35. integer(kind=c_size_t), intent( out) :: model_length !< Length of the model buffer c-string
  36. type(c_ptr), intent( out) :: model_data !< Reeives model information
  37. end function get_model_c
  38. end interface
  39. interface
  40. function set_model_from_file_c( c_client, key, key_length, model_file, model_file_length, &
  41. backend, backend_length, device, device_length, batch_size, min_batch_size, tag, tag_length, &
  42. inputs, input_lengths, n_inputs, outputs, output_lengths, n_outputs ) bind(c, name="set_model_from_file")
  43. use iso_c_binding, only : c_ptr, c_size_t, c_int, c_char
  44. import :: enum_kind
  45. integer(kind=enum_kind) :: set_model_from_file_c
  46. type(c_ptr), value, intent(in) :: c_client !< Initialized SmartRedis client
  47. character(kind=c_char), intent(in) :: key(*) !< The key to use to place the model
  48. integer(kind=c_size_t), value, intent(in) :: key_length !< The length of the key c-string, excluding null
  49. character(kind=c_char), intent(in) :: model_file(*) !< The file storing the model
  50. integer(kind=c_size_t), value, intent(in) :: model_file_length !< The length of the file name c-string, excluding
  51. !! null terminating character
  52. character(kind=c_char), intent(in) :: backend(*) !< The name of the backend (TF, TFLITE, TORCH, ONNX)
  53. integer(kind=c_size_t), value, intent(in) :: backend_length !< The length of the backend name c-string,
  54. !! excluding null terminating character
  55. character(kind=c_char), intent(in) :: device(*) !< The name of the device (CPU, GPU, GPU:0, GPU:1...)
  56. integer(kind=c_size_t), value, intent(in) :: device_length !< The length of the device name c-string, excluding
  57. !! null terminating character
  58. integer(kind=c_int), value, intent(in) :: batch_size !< The batch size for model execution
  59. integer(kind=c_int), value, intent(in) :: min_batch_size !< The minimum batch size for model execution
  60. character(kind=c_char), intent(in) :: tag(*) !< A tag to attach to the model for information
  61. !! purposes
  62. integer(kind=c_size_t), value, intent(in) :: tag_length !< The length of the tag c-string, excluding null
  63. !! terminating character
  64. type(c_ptr), value, intent(in) :: inputs !< One or more names of model input nodes (TF models)
  65. type(c_ptr), value, intent(in) :: input_lengths !< The length of each input name c-string, excluding
  66. !! null terminating character
  67. integer(kind=c_size_t), value, intent(in) :: n_inputs !< The number of inputs
  68. type(c_ptr), value, intent(in) :: outputs !< One or more names of model output nodes
  69. !! (TF models)
  70. type(c_ptr), value, intent(in) :: output_lengths !< The length of each output name c-string,
  71. !! excluding null terminating character
  72. integer(kind=c_size_t), value, intent(in) :: n_outputs !< The number of outputs
  73. end function set_model_from_file_c
  74. end interface
  75. interface
  76. function set_model_from_file_multigpu_c( c_client, key, key_length, model_file, model_file_length, &
  77. backend, backend_length, first_gpu, num_gpus, batch_size, min_batch_size, tag, tag_length, &
  78. inputs, input_lengths, n_inputs, outputs, output_lengths, n_outputs ) bind(c, name="set_model_from_file_multigpu")
  79. use iso_c_binding, only : c_ptr, c_size_t, c_int, c_char
  80. import :: enum_kind
  81. integer(kind=enum_kind) :: set_model_from_file_multigpu_c
  82. type(c_ptr), value, intent(in) :: c_client !< Initialized SmartRedis client
  83. character(kind=c_char), intent(in) :: key(*) !< The key to use to place the model
  84. integer(kind=c_size_t), value, intent(in) :: key_length !< The length of the key c-string, excluding null
  85. character(kind=c_char), intent(in) :: model_file(*) !< The file storing the model
  86. integer(kind=c_size_t), value, intent(in) :: model_file_length !< The length of the file name c-string, excluding
  87. !! null terminating character
  88. character(kind=c_char), intent(in) :: backend(*) !< The name of the backend (TF, TFLITE, TORCH, ONNX)
  89. integer(kind=c_size_t), value, intent(in) :: backend_length !< The length of the backend name c-string,
  90. !! excluding null terminating character
  91. integer(kind=c_int), value, intent(in) :: first_gpu !< ID of the first GPU to set the model on
  92. integer(kind=c_int), value, intent(in) :: num_gpus !< How many GPUs to use in the orchestrator
  93. !! null terminating character
  94. integer(kind=c_int), value, intent(in) :: batch_size !< The batch size for model execution
  95. integer(kind=c_int), value, intent(in) :: min_batch_size !< The minimum batch size for model execution
  96. character(kind=c_char), intent(in) :: tag(*) !< A tag to attach to the model for information
  97. !! purposes
  98. integer(kind=c_size_t), value, intent(in) :: tag_length !< The length of the tag c-string, excluding null
  99. !! terminating character
  100. type(c_ptr), value, intent(in) :: inputs !< One or more names of model input nodes (TF models)
  101. type(c_ptr), value, intent(in) :: input_lengths !< The length of each input name c-string, excluding
  102. !! null terminating character
  103. integer(kind=c_size_t), value, intent(in) :: n_inputs !< The number of inputs
  104. type(c_ptr), value, intent(in) :: outputs !< One or more names of model output nodes
  105. !! (TF models)
  106. type(c_ptr), value, intent(in) :: output_lengths !< The length of each output name c-string,
  107. !! excluding null terminating character
  108. integer(kind=c_size_t), value, intent(in) :: n_outputs !< The number of outputs
  109. end function set_model_from_file_multigpu_c
  110. end interface
  111. interface
  112. function set_model_c( c_client, key, key_length, model, model_length, &
  113. backend, backend_length, device, device_length, batch_size, min_batch_size, tag, tag_length, &
  114. inputs, input_lengths, n_inputs, outputs, output_lengths, n_outputs ) bind(c, name="set_model")
  115. use iso_c_binding, only : c_ptr, c_size_t, c_int, c_char
  116. import :: enum_kind
  117. integer(kind=enum_kind) :: set_model_c
  118. type(c_ptr), value, intent(in) :: c_client !< Initialized SmartRedis client
  119. character(kind=c_char), intent(in) :: key(*) !< The key to use to place the model
  120. integer(kind=c_size_t), value, intent(in) :: key_length !< The length of the key c-string, excluding null
  121. character(kind=c_char), intent(in) :: model(*) !< The file storing the model
  122. integer(kind=c_size_t), value, intent(in) :: model_length !< The length of the file name c-string, excluding
  123. !! null terminating character
  124. character(kind=c_char), intent(in) :: backend(*) !< The name of the backend (TF, TFLITE, TORCH, ONNX)
  125. integer(kind=c_size_t), value, intent(in) :: backend_length !< The length of the backend name c-string,
  126. !! excluding null terminating character
  127. character(kind=c_char), intent(in) :: device(*) !< The name of the device (CPU, GPU, GPU:0, GPU:1...)
  128. integer(kind=c_size_t), value, intent(in) :: device_length !< The length of the device name c-string, excluding
  129. !! null terminating character
  130. integer(kind=c_int), value, intent(in) :: batch_size !< The batch size for model execution
  131. integer(kind=c_int), value, intent(in) :: min_batch_size !< The minimum batch size for model execution
  132. character(kind=c_char), intent(in) :: tag(*) !< A tag to attach to the model for information
  133. !! purposes
  134. integer(kind=c_size_t), value, intent(in) :: tag_length !< The length of the tag c-string, excluding null
  135. !! terminating character
  136. type(c_ptr), value, intent(in) :: inputs !< One or more names of model input nodes (TF models)
  137. type(c_ptr), value, intent(in) :: input_lengths !< The length of each input name c-string, excluding
  138. !! null terminating character
  139. integer(kind=c_size_t), value, intent(in) :: n_inputs !< The number of inputs
  140. type(c_ptr), value, intent(in) :: outputs !< One or more names of model output nodes
  141. !! (TF models)
  142. type(c_ptr), value, intent(in) :: output_lengths !< The length of each output name c-string,
  143. !! excluding null terminating character
  144. integer(kind=c_size_t), value, intent(in) :: n_outputs !< The number of outputs
  145. end function set_model_c
  146. end interface
  147. interface
  148. function set_model_multigpu_c( c_client, key, key_length, model, model_length, &
  149. backend, backend_length, first_gpu, num_gpus, batch_size, min_batch_size, tag, tag_length, &
  150. inputs, input_lengths, n_inputs, outputs, output_lengths, n_outputs ) bind(c, name="set_model_multigpu")
  151. use iso_c_binding, only : c_ptr, c_size_t, c_int, c_char
  152. import :: enum_kind
  153. integer(kind=enum_kind) :: set_model_multigpu_c
  154. type(c_ptr), value, intent(in) :: c_client !< Initialized SmartRedis client
  155. character(kind=c_char), intent(in) :: key(*) !< The key to use to place the model
  156. integer(kind=c_size_t), value, intent(in) :: key_length !< The length of the key c-string, excluding null
  157. character(kind=c_char), intent(in) :: model(*) !< The file storing the model
  158. integer(kind=c_size_t), value, intent(in) :: model_length !< The length of the file name c-string, excluding
  159. !! null terminating character
  160. character(kind=c_char), intent(in) :: backend(*) !< The name of the backend (TF, TFLITE, TORCH, ONNX)
  161. integer(kind=c_size_t), value, intent(in) :: backend_length !< The length of the backend name c-string,
  162. !! excluding null terminating character
  163. integer(kind=c_int), value, intent(in) :: first_gpu !< ID of the first GPU to set the model on
  164. integer(kind=c_int), value, intent(in) :: num_gpus !< How many GPUs to use in the orchestrator
  165. !! null terminating character
  166. integer(kind=c_int), value, intent(in) :: batch_size !< The batch size for model execution
  167. integer(kind=c_int), value, intent(in) :: min_batch_size !< The minimum batch size for model execution
  168. character(kind=c_char), intent(in) :: tag(*) !< A tag to attach to the model for information
  169. !! purposes
  170. integer(kind=c_size_t), value, intent(in) :: tag_length !< The length of the tag c-string, excluding null
  171. !! terminating character
  172. type(c_ptr), value, intent(in) :: inputs !< One or more names of model input nodes (TF models)
  173. type(c_ptr), value, intent(in) :: input_lengths !< The length of each input name c-string, excluding
  174. !! null terminating character
  175. integer(kind=c_size_t), value, intent(in) :: n_inputs !< The number of inputs
  176. type(c_ptr), value, intent(in) :: outputs !< One or more names of model output nodes
  177. !! (TF models)
  178. type(c_ptr), value, intent(in) :: output_lengths !< The length of each output name c-string,
  179. !! excluding null terminating character
  180. integer(kind=c_size_t), value, intent(in) :: n_outputs !< The number of outputs
  181. end function set_model_multigpu_c
  182. end interface
  183. interface
  184. function run_model_c(c_client, key, key_length, inputs, input_lengths, n_inputs, &
  185. outputs, output_lengths, n_outputs) bind(c, name="run_model")
  186. use iso_c_binding, only : c_ptr, c_size_t, c_char
  187. import :: enum_kind
  188. integer(kind=enum_kind) :: run_model_c
  189. type(c_ptr), value, intent(in) :: c_client !< Initialized SmartRedis client
  190. character(kind=c_char), intent(in) :: key(*) !< The key to use to place the model
  191. integer(kind=c_size_t), value, intent(in) :: key_length !< The length of the key c-string, excluding null
  192. type(c_ptr), value, intent(in) :: inputs !< One or more names of model input nodes (TF models)
  193. type(c_ptr), value, intent(in) :: input_lengths !< The length of each input name c-string, excluding
  194. !! null terminating character
  195. integer(kind=c_size_t), value, intent(in) :: n_inputs !< The number of inputs
  196. type(c_ptr), value, intent(in) :: outputs !< One or more names of model output nodes
  197. !! (TF models)
  198. type(c_ptr), value, intent(in) :: output_lengths !< The length of each output name c-string,
  199. !! excluding null terminating character
  200. integer(kind=c_size_t), value, intent(in) :: n_outputs !< The number of outputs
  201. end function run_model_c
  202. end interface
  203. interface
  204. function run_model_multigpu_c(c_client, key, key_length, inputs, input_lengths, n_inputs, &
  205. outputs, output_lengths, n_outputs, offset, first_gpu, num_gpus) &
  206. bind(c, name="run_model_multigpu")
  207. use iso_c_binding, only : c_ptr, c_size_t, c_char, c_int
  208. import :: enum_kind
  209. integer(kind=enum_kind) :: run_model_multigpu_c
  210. type(c_ptr), value, intent(in) :: c_client !< Initialized SmartRedis client
  211. character(kind=c_char), intent(in) :: key(*) !< The key to use to place the model
  212. integer(kind=c_size_t), value, intent(in) :: key_length !< The length of the key c-string, excluding null
  213. type(c_ptr), value, intent(in) :: inputs !< One or more names of model input nodes (TF models)
  214. type(c_ptr), value, intent(in) :: input_lengths !< The length of each input name c-string, excluding
  215. !! null terminating character
  216. integer(kind=c_size_t), value, intent(in) :: n_inputs !< The number of inputs
  217. type(c_ptr), value, intent(in) :: outputs !< One or more names of model output nodes
  218. !! (TF models)
  219. type(c_ptr), value, intent(in) :: output_lengths !< The length of each output name c-string,
  220. !! excluding null terminating character
  221. integer(kind=c_size_t), value, intent(in) :: n_outputs !< The number of outputs
  222. integer(kind=c_int), value, intent(in) :: offset !< Index of the current image, such as a processor
  223. !! ID or MPI rank
  224. integer(kind=c_int), value, intent(in) :: first_gpu !< ID of the first GPU to use the model on
  225. integer(kind=c_int), value, intent(in) :: num_gpus !< How many GPUs to use in the orchestrator
  226. end function run_model_multigpu_c
  227. end interface
  228. interface
  229. function delete_model_c(c_client, key, key_length) bind(c, name="delete_model")
  230. use iso_c_binding, only : c_ptr, c_size_t, c_char
  231. import :: enum_kind
  232. integer(kind=enum_kind) :: delete_model_c
  233. type(c_ptr), value, intent(in) :: c_client !< Initialized SmartRedis client
  234. character(kind=c_char), intent(in) :: key(*) !< The key to use to delete the model
  235. integer(kind=c_size_t), value, intent(in) :: key_length !< The length of the key c-string, excluding null
  236. end function delete_model_c
  237. end interface
  238. interface
  239. function delete_model_multigpu_c(c_client, key, key_length, first_gpu, num_gpus) bind(c, name="delete_model_multigpu")
  240. use iso_c_binding, only : c_ptr, c_size_t, c_char, c_int
  241. import :: enum_kind
  242. integer(kind=enum_kind) :: delete_model_multigpu_c
  243. type(c_ptr), value, intent(in) :: c_client !< Initialized SmartRedis client
  244. character(kind=c_char), intent(in) :: key(*) !< The key to use to delete the model
  245. integer(kind=c_size_t), value, intent(in) :: key_length !< The length of the key c-string, excluding null
  246. integer(kind=c_int), value, intent(in) :: first_gpu !< ID of the first GPU to use the model on
  247. integer(kind=c_int), value, intent(in) :: num_gpus !< How many GPUs to use in the orchestrator
  248. end function delete_model_multigpu_c
  249. end interface