database_client_interface.F90
1! This file is part of MOM6, the Modular Ocean Model version 6.
2! See the LICENSE file for licensing information.
3! SPDX-License-Identifier: Apache-2.0
4
5module database_client_interface
6
7 use iso_fortran_env, only : int8, int16, int32, int64, real32, real64
8
9 implicit none ; private
10
11 !> Dummy type for dataset
12 type, public :: dataset_type
13 private
14 end type dataset_type
15
16 !> Stores all data and methods associated with the communication client that is used to communicate with the database
17 type, public :: dbclient_type
18 private
19
20 contains
21
22 ! Public procedures
23 !> Puts a tensor into the database for a variety of datatypes
24 generic :: put_tensor => put_tensor_float_1d, put_tensor_float_2d, put_tensor_float_3d, put_tensor_float_4d, &
27 !> Retrieve the tensor in the database into already allocated memory for a variety of datatypesm
28 generic :: unpack_tensor => unpack_tensor_float_1d, unpack_tensor_float_2d, &
34
35 !> Decode a response code from an API function
36 procedure :: sr_error_parser
37 !> Initializes a new instance of the communication client
38 procedure :: initialize => initialize_client
39 !> Check if a communication client has been initialized
40 procedure :: isinitialized
41 !> Destructs a new instance of the communication client
42 procedure :: destructor
43 !> Rename a tensor within the database
44 procedure :: rename_tensor
45 !> Delete a tensor from the database
46 procedure :: delete_tensor
47 !> Copy a tensor within the database to a new name
48 procedure :: copy_tensor
49 !> Set a model from a file
50 procedure :: set_model_from_file
51 !> Set a model from a file on a system with multiple GPUs
52 procedure :: set_model_from_file_multigpu
53 !> Set a model from a byte string that has been loaded within the application
54 procedure :: set_model
55 !> Set a model from a byte string that has been loaded within the application on a system with multiple GPUs
56 procedure :: set_model_multigpu
57 !> Retrieve the model as a byte string
58 procedure :: get_model
59 !> Set a script from a specified file
60 procedure :: set_script_from_file
61 !> Set a script from a specified file on a system with multiple GPUS
62 procedure :: set_script_from_file_multigpu
63 !> Set a script as a byte or text string
64 procedure :: set_script
65 !> Set a script as a byte or text string on a system with multiple GPUs
66 procedure :: set_script_multigpu
67 !> Retrieve the script from the database
68 procedure :: get_script
69 !> Run a script that has already been stored in the database
70 procedure :: run_script
71 !> Run a script that has already been stored in the database with multiple GPUs
72 procedure :: run_script_multigpu
73 !> Run a model that has already been stored in the database
74 procedure :: run_model
75 !> Run a model that has already been stored in the database with multiple GPUs
76 procedure :: run_model_multigpu
77 !> Remove a script from the database
78 procedure :: delete_script
79 !> Remove a script from the database with multiple GPUs
80 procedure :: delete_script_multigpu
81 !> Remove a model from the database
82 procedure :: delete_model
83 !> Remove a model from the database with multiple GPUs
84 procedure :: delete_model_multigpu
85 !> Put a communication dataset into the database
86 procedure :: put_dataset
87 !> Retrieve a communication dataset from the database
88 procedure :: get_dataset
89 !> Rename the dataset within the database
90 procedure :: rename_dataset
91 !> Copy a dataset stored in the database into another name
92 procedure :: copy_dataset
93 !> Delete the dataset from the database
94 procedure :: delete_dataset
95
96 ! Private procedures
97 !> Put a 1d, 32-bit real tensor into database
98 procedure, private :: put_tensor_float_1d
99 !> Put a 2d, 32-bit real tensor into database
100 procedure, private :: put_tensor_float_2d
101 !> Put a 3d, 32-bit real tensor into database
102 procedure, private :: put_tensor_float_3d
103 !> Put a 4d, 32-bit real tensor into database
104 procedure, private :: put_tensor_float_4d
105 !> Put a 1d, 64-bit real tensor into database
106 procedure, private :: put_tensor_double_1d
107 !> Put a 2d, 64-bit real tensor into database
108 procedure, private :: put_tensor_double_2d
109 !> Put a 3d, 64-bit real tensor into database
110 procedure, private :: put_tensor_double_3d
111 !> Put a 4d, 64-bit real tensor into database
112 procedure, private :: put_tensor_double_4d
113 !> Put a 1d, 32-bit integer tensor into database
114 procedure, private :: put_tensor_int32_1d
115 !> Put a 2d, 32-bit integer tensor into database
116 procedure, private :: put_tensor_int32_2d
117 !> Put a 3d, 32-bit integer tensor into database
118 procedure, private :: put_tensor_int32_3d
119 !> Put a 4d, 32-bit integer tensor into database
120 procedure, private :: put_tensor_int32_4d
121 !> Unpack a 1d, 32-bit real tensor from the database
122 procedure, private :: unpack_tensor_float_1d
123 !> Unpack a 2d, 32-bit real tensor from the database
124 procedure, private :: unpack_tensor_float_2d
125 !> Unpack a 3d, 32-bit real tensor from the database
126 procedure, private :: unpack_tensor_float_3d
127 !> Unpack a 4d, 32-bit real tensor from the database
128 procedure, private :: unpack_tensor_float_4d
129 !> Unpack a 1d, 64-bit real tensor from the database
130 procedure, private :: unpack_tensor_double_1d
131 !> Unpack a 2d, 64-bit real tensor from the database
132 procedure, private :: unpack_tensor_double_2d
133 !> Unpack a 3d, 64-bit real tensor from the database
134 procedure, private :: unpack_tensor_double_3d
135 !> Unpack a 4d, 64-bit real tensor from the database
136 procedure, private :: unpack_tensor_double_4d
137 !> Unpack a 1d, 32-bit integer tensor from the database
138 procedure, private :: unpack_tensor_int32_1d
139 !> Unpack a 2d, 32-bit integer tensor from the database
140 procedure, private :: unpack_tensor_int32_2d
141 !> Unpack a 3d, 32-bit integer tensor from the database
142 procedure, private :: unpack_tensor_int32_3d
143 !> Unpack a 4d, 32-bit integer tensor from the database
144 procedure, private :: unpack_tensor_int32_4d
145
146 end type dbclient_type
147
148 contains
149
150 !> Decode a response code from an API function
151 function sr_error_parser(self, response_code) result(is_error)
152 class(dbclient_type), intent(in) :: self !< Receives the initialized client
153 integer, intent(in) :: response_code !< The response code to decode
154 logical :: is_error !< Indicates whether this is an error response
155
156 is_error = .true.
157 end function sr_error_parser
158
159 !> Initializes a new instance of a communication client
160 function initialize_client(self, cluster)
161 integer :: initialize_client
162 class(dbclient_type), intent(inout) :: self !< Receives the initialized client
163 logical, optional, intent(in ) :: cluster !< If true, client uses a database cluster (Default: .false.)
164
165 initialize_client = -1
166 end function initialize_client
167
168 !> Check whether the client has been initialized
169 logical function isinitialized(this)
170 class(dbclient_type) :: this
171 isinitialized = .false.
172 end function isinitialized
173
174 !> A destructor for the communication client
175 function destructor(self)
176 integer :: destructor
177 class(dbclient_type), intent(inout) :: self
178
179 destructor = -1
180 end function destructor
181
182 !> Put a 32-bit real 1d tensor into the database
183 function put_tensor_float_1d(self, name, data, dims) result(code)
184 real(kind=real32), dimension(:), intent(in) :: data !< Data to be sent
185 class(dbclient_type), intent(in) :: self !< Fortran communication client
186 character(len=*), intent(in) :: name !< The unique name used to store in the database
187 integer, dimension(:), intent(in) :: dims !< The length of each dimension
188 integer :: code
189
190 code = -1
191 end function put_tensor_float_1d
192
193 !> Put a 32-bit real 2d tensor into the database
194 function put_tensor_float_2d(self, name, data, dims) result(code)
195 real(kind=real32), dimension(:,:), intent(in) :: data !< Data to be sent
196 class(dbclient_type), intent(in) :: self !< Fortran communication client
197 character(len=*), intent(in) :: name !< The unique name used to store in the database
198 integer, dimension(:), intent(in) :: dims !< The length of each dimension
199 integer :: code
200
201 code = -1
202 end function put_tensor_float_2d
203
204 !> Put a 32-bit real 3d tensor into the database
205 function put_tensor_float_3d(self, name, data, dims) result(code)
206 real(kind=real32), dimension(:,:,:), intent(in) :: data !< Data to be sent
207 class(dbclient_type), intent(in) :: self !< Fortran communication client
208 character(len=*), intent(in) :: name !< The unique name used to store in the database
209 integer, dimension(:), intent(in) :: dims !< The length of each dimension
210 integer :: code
211
212 code = -1
213 end function put_tensor_float_3d
214
215 !> Put a 32-bit real 4d tensor into the database
216 function put_tensor_float_4d(self, name, data, dims) result(code)
217 real(kind=real32), dimension(:,:,:,:), intent(in) :: data !< Data to be sent
218 class(dbclient_type), intent(in) :: self !< Fortran communication client
219 character(len=*), intent(in) :: name !< The unique name used to store in the database
220 integer, dimension(:), intent(in) :: dims !< The length of each dimension
221 integer :: code
222
223 code = -1
224 end function put_tensor_float_4d
225
226 !> Put a 64-bit real 1d tensor into the database
227 function put_tensor_double_1d(self, name, data, dims) result(code)
228 real(kind=real64), dimension(:), intent(in) :: data !< Data to be sent
229 class(dbclient_type), intent(in) :: self !< Fortran communication client
230 character(len=*), intent(in) :: name !< The unique name used to store in the database
231 integer, dimension(:), intent(in) :: dims !< The length of each dimension
232 integer :: code
233
234 code = -1
235 end function put_tensor_double_1d
236
237 !> Put a 64-bit real 2d tensor into the database
238 function put_tensor_double_2d(self, name, data, dims) result(code)
239 real(kind=real64), dimension(:,:), intent(in) :: data !< Data to be sent
240 class(dbclient_type), intent(in) :: self !< Fortran communication client
241 character(len=*), intent(in) :: name !< The unique name used to store in the database
242 integer, dimension(:), intent(in) :: dims !< The length of each dimension
243 integer :: code
244
245 code = -1
246 end function put_tensor_double_2d
247
248 !> Put a 64-bit real 3d tensor into the database
249 function put_tensor_double_3d(self, name, data, dims) result(code)
250 real(kind=real64), dimension(:,:,:), intent(in) :: data !< Data to be sent
251 class(dbclient_type), intent(in) :: self !< Fortran communication client
252 character(len=*), intent(in) :: name !< The unique name used to store in the database
253 integer, dimension(:), intent(in) :: dims !< The length of each dimension
254 integer :: code
255
256 code = -1
257 end function put_tensor_double_3d
258
259 !> Put a 64-bit real 4d tensor into the database
260 function put_tensor_double_4d(self, name, data, dims) result(code)
261 real(kind=real64), dimension(:,:,:,:), intent(in) :: data !< Data to be sent
262 class(dbclient_type), intent(in) :: self !< Fortran communication client
263 character(len=*), intent(in) :: name !< The unique name used to store in the database
264 integer, dimension(:), intent(in) :: dims !< The length of each dimension
265 integer :: code
266
267 code = -1
268 end function put_tensor_double_4d
269
270 !> Put a 32-bit integer 1d tensor into the database
271 function put_tensor_int32_1d(self, name, data, dims) result(code)
272 integer(kind=int32), dimension(:), intent(in) :: data !< Data to be sent
273 class(dbclient_type), intent(in) :: self !< Fortran communication client
274 character(len=*), intent(in) :: name !< The unique name used to store in the database
275 integer, dimension(:), intent(in) :: dims !< The length of each dimension
276 integer :: code
277
278 code = -1
279 end function put_tensor_int32_1d
280
281 !> Put a 32-bit integer 2d tensor into the database
282 function put_tensor_int32_2d(self, name, data, dims) result(code)
283 integer(kind=int32), dimension(:,:), intent(in) :: data !< Data to be sent
284 class(dbclient_type), intent(in) :: self !< Fortran communication client
285 character(len=*), intent(in) :: name !< The unique name used to store in the database
286 integer, dimension(:), intent(in) :: dims !< The length of each dimension
287 integer :: code
288
289 code = -1
290 end function put_tensor_int32_2d
291
292 !> Put a 32-bit integer 3d tensor into the database
293 function put_tensor_int32_3d(self, name, data, dims) result(code)
294 integer(kind=int32), dimension(:,:,:), intent(in) :: data !< Data to be sent
295 class(dbclient_type), intent(in) :: self !< Fortran communication client
296 character(len=*), intent(in) :: name !< The unique name used to store in the database
297 integer, dimension(:), intent(in) :: dims !< The length of each dimension
298 integer :: code
299
300 code = -1
301 end function put_tensor_int32_3d
302
303 !> Put a 32-bit integer 4d tensor into the database
304 function put_tensor_int32_4d(self, name, data, dims) result(code)
305 integer(kind=int32), dimension(:,:,:,:), intent(in) :: data !< Data to be sent
306 class(dbclient_type), intent(in) :: self !< Fortran communication client
307 character(len=*), intent(in) :: name !< The unique name used to store in the database
308 integer, dimension(:), intent(in) :: dims !< The length of each dimension
309 integer :: code
310
311 code = -1
312 end function put_tensor_int32_4d
313
314 !> Unpack a 32-bit real 1d tensor from the database
315 function unpack_tensor_float_1d(self, name, data, dims) result(code)
316 real(kind=real32), dimension(:), intent( out) :: data !< Data to be received
317 class(dbclient_type), intent(in) :: self !< Fortran communication client
318 character(len=*), intent(in) :: name !< The unique name used to store in the database
319 integer, dimension(:), intent(in) :: dims !< The length of each dimension
320 integer :: code
321
322 code = -1
323 data(:) = -1.
324 end function unpack_tensor_float_1d
325
326 !> Unpack a 32-bit real 2d tensor from the database
327 function unpack_tensor_float_2d(self, name, data, dims) result(code)
328 real(kind=real32), dimension(:,:), intent( out) :: data !< Data to be received
329 class(dbclient_type), intent(in) :: self !< Fortran communication client
330 character(len=*), intent(in) :: name !< The unique name used to store in the database
331 integer, dimension(:), intent(in) :: dims !< The length of each dimension
332 integer :: code
333
334 code = -1
335 data(:,:) = -1.
336 end function unpack_tensor_float_2d
337
338 !> Unpack a 32-bit real 3d tensor from the database
339 function unpack_tensor_float_3d(self, name, data, dims) result(code)
340 real(kind=real32), dimension(:,:,:), intent( out) :: data !< Data to be received
341 class(dbclient_type), intent(in) :: self !< Fortran communication client
342 character(len=*), intent(in) :: name !< The unique name used to store in the database
343 integer, dimension(:), intent(in) :: dims !< The length of each dimension
344 integer :: code
345
346 code = -1
347 data(:,:,:) = -1.
348 end function unpack_tensor_float_3d
349
350 !> Unpack a 32-bit real 4d tensor from the database
351 function unpack_tensor_float_4d(self, name, data, dims) result(code)
352 real(kind=real32), dimension(:,:,:,:), intent( out) :: data !< Data to be received
353 class(dbclient_type), intent(in) :: self !< Fortran communication client
354 character(len=*), intent(in) :: name !< The unique name used to store in the database
355 integer, dimension(:), intent(in) :: dims !< The length of each dimension
356 integer :: code
357
358 code = -1
359 data(:,:,:,:) = -1.
360 end function unpack_tensor_float_4d
361
362 !> Unpack a 64-bit real 1d tensor from the database
363 function unpack_tensor_double_1d(self, name, data, dims) result(code)
364 real(kind=real64), dimension(:), intent( out) :: data !< Data to be received
365 class(dbclient_type), intent(in) :: self !< Fortran communication client
366 character(len=*), intent(in) :: name !< The unique name used to store in the database
367 integer, dimension(:), intent(in) :: dims !< The length of each dimension
368 integer :: code
369
370 code = -1
371 data(:) = -1.
372 end function unpack_tensor_double_1d
373
374 !> Unpack a 64-bit real 2d tensor from the database
375 function unpack_tensor_double_2d(self, name, data, dims) result(code)
376 real(kind=real64), dimension(:,:), intent( out) :: data !< Data to be received
377 class(dbclient_type), intent(in) :: self !< Fortran communication client
378 character(len=*), intent(in) :: name !< The unique name used to store in the database
379 integer, dimension(:), intent(in) :: dims !< The length of each dimension
380 integer :: code
381
382 code = -1
383 data(:,:) = -1.
384 end function unpack_tensor_double_2d
385
386 !> Unpack a 64-bit real 3d tensor from the database
387 function unpack_tensor_double_3d(self, name, data, dims) result(code)
388 real(kind=real64), dimension(:,:,:), intent( out) :: data !< Data to be received
389 class(dbclient_type), intent(in) :: self !< Fortran communication client
390 character(len=*), intent(in) :: name !< The unique name used to store in the database
391 integer, dimension(:), intent(in) :: dims !< The length of each dimension
392 integer :: code
393
394 code = -1
395 data(:,:,:) = -1.
396 end function unpack_tensor_double_3d
397
398 !> Unpack a 64-bit real 4d tensor from the database
399 function unpack_tensor_double_4d(self, name, data, dims) result(code)
400 real(kind=real64), dimension(:,:,:,:), intent( out) :: data !< Data to be received
401 class(dbclient_type), intent(in) :: self !< Fortran communication client
402 character(len=*), intent(in) :: name !< The unique name used to store in the database
403 integer, dimension(:), intent(in) :: dims !< The length of each dimension
404 integer :: code
405
406 code = -1
407 data(:,:,:,:) = -1.
408 end function unpack_tensor_double_4d
409
410 !> Unpack a 32-bit integer 1d tensor from the database
411 function unpack_tensor_int32_1d(self, name, data, dims) result(code)
412 integer(kind=int32), dimension(:), intent( out) :: data !< Data to be received
413 class(dbclient_type), intent(in) :: self !< Fortran communication client
414 character(len=*), intent(in) :: name !< The unique name used to store in the database
415 integer, dimension(:), intent(in) :: dims !< The length of each dimension
416 integer :: code
417
418 code = -1
419 data(:) = -1_int32
420 end function unpack_tensor_int32_1d
421
422 !> Unpack a 32-bit integer 2d tensor from the database
423 function unpack_tensor_int32_2d(self, name, data, dims) result(code)
424 integer(kind=int32), dimension(:,:), intent( out) :: data !< Data to be received
425 class(dbclient_type), intent(in) :: self !< Fortran communication client
426 character(len=*), intent(in) :: name !< The unique name used to store in the database
427 integer, dimension(:), intent(in) :: dims !< The length of each dimension
428 integer :: code
429
430 code = -1
431 data(:,:) = -1_int32
432 end function unpack_tensor_int32_2d
433
434 !> Unpack a 32-bit integer 3d tensor from the database
435 function unpack_tensor_int32_3d(self, name, data, dims) result(code)
436 integer(kind=int32), dimension(:,:,:), intent( out) :: data !< Data to be received
437 class(dbclient_type), intent(in) :: self !< Fortran communication client
438 character(len=*), intent(in) :: name !< The unique name used to store in the database
439 integer, dimension(:), intent(in) :: dims !< The length of each dimension
440 integer :: code
441
442 code = -1
443 data(:,:,:) = -1_int32
444 end function unpack_tensor_int32_3d
445
446 !> Unpack a 32-bit integer 4d tensor from the database
447 function unpack_tensor_int32_4d(self, name, data, dims) result(code)
448 integer(kind=int32), dimension(:,:,:,:), intent( out) :: data !< Data to be received
449 class(dbclient_type), intent(in) :: self !< Fortran communication client
450 character(len=*), intent(in) :: name !< The unique name used to store in the database
451 integer, dimension(:), intent(in) :: dims !< The length of each dimension
452 integer :: code
453
454 code = -1
455 data(:,:,:,:) = -1_int32
456 end function unpack_tensor_int32_4d
457
458 !> Move a tensor to a new name
459 function rename_tensor(self, old_name, new_name) result(code)
460 class(dbclient_type), intent(in) :: self !< The initialized Fortran communication client
461 character(len=*), intent(in) :: old_name !< The current name for the tensor
462 !! excluding null terminating character
463 character(len=*), intent(in) :: new_name !< The new tensor name
464 integer :: code
465
466 code = -1
467 end function rename_tensor
468
469 !> Delete a tensor
470 function delete_tensor(self, name) result(code)
471 class(dbclient_type), intent(in) :: self !< The initialized Fortran communication client
472 character(len=*), intent(in) :: name !< The name associated with the tensor
473 integer :: code
474
475 code = -1
476 end function delete_tensor
477
478 !> Copy a tensor to the destination name
479 function copy_tensor(self, src_name, dest_name) result(code)
480 class(dbclient_type), intent(in) :: self !< The initialized Fortran communication client
481 character(len=*), intent(in) :: src_name !< The name associated with the tensor
482 !! excluding null terminating character
483 character(len=*), intent(in) :: dest_name !< The new tensor name
484 integer :: code
485
486 code = -1
487 end function copy_tensor
488
489 !> Retrieve the model from the database
490 function get_model(self, name, model) result(code)
491 class(dbclient_type), intent(in ) :: self !< An initialized communication client
492 character(len=*), intent(in ) :: name !< The name associated with the model
493 character(len=*), intent( out) :: model !< The model as a continuous buffer
494 integer :: code
495
496 code = -1
497 model = ""
498 end function get_model
499
500 !> Load the machine learning model from a file and set the configuration
501 function set_model_from_file(self, name, model_file, backend, device, batch_size, min_batch_size, tag, &
502 inputs, outputs) result(code)
503 class(dbclient_type), intent(in) :: self !< An initialized communication client
504 character(len=*), intent(in) :: name !< The name to use to place the model
505 character(len=*), intent(in) :: model_file !< The file storing the model
506 character(len=*), intent(in) :: backend !< The name of the backend
507 !! (TF, TFLITE, TORCH, ONNX)
508 character(len=*), intent(in) :: device !< The name of the device
509 !! (CPU, GPU, GPU:0, GPU:1...)
510 integer, optional, intent(in) :: batch_size !< The batch size for model execution
511 integer, optional, intent(in) :: min_batch_size !< The minimum batch size for model execution
512 character(len=*), optional, intent(in) :: tag !< A tag to attach to the model for
513 !! information purposes
514 character(len=*), dimension(:), optional, intent(in) :: inputs !< One or more names of model
515 !! input nodes (TF models)
516 character(len=*), dimension(:), optional, intent(in) :: outputs !< One or more names of model
517 !! output nodes (TF models)
518 integer :: code
519
520 code = -1
521 end function set_model_from_file
522
523 !> Load the machine learning model from a file and set the configuration for use in multi-GPU systems
524 function set_model_from_file_multigpu(self, name, model_file, backend, first_gpu, num_gpus, batch_size, &
525 min_batch_size, tag, inputs, outputs) result(code)
526 class(dbclient_type), intent(in) :: self !< An initialized communication client
527 character(len=*), intent(in) :: name !< The name to use to place the model
528 character(len=*), intent(in) :: model_file !< The file storing the model
529 character(len=*), intent(in) :: backend !< The name of the backend
530 !! (TF, TFLITE, TORCH, ONNX)
531 integer, intent(in) :: first_gpu !< The first GPU (zero-based)
532 !! to use with the model
533 integer, intent(in) :: num_gpus !< The number of GPUs to use with the model
534 integer, optional, intent(in) :: batch_size !< The batch size for model execution
535 integer, optional, intent(in) :: min_batch_size !< The minimum batch size for model execution
536 character(len=*), optional, intent(in) :: tag !< A tag to attach to the model for
537 !! information purposes
538 character(len=*), dimension(:), optional, intent(in) :: inputs !< One or more names of model
539 !! input nodes (TF models)
540 character(len=*), dimension(:), optional, intent(in) :: outputs !< One or more names of model
541 !! output nodes (TF models)
542 integer :: code
543
544 code = -1
545 end function set_model_from_file_multigpu
546
547 !> Establish a model to run
548 function set_model(self, name, model, backend, device, batch_size, min_batch_size, tag, &
549 inputs, outputs) result(code)
550 class(dbclient_type), intent(in) :: self !< An initialized communication client
551 character(len=*), intent(in) :: name !< The name to use to place the model
552 character(len=*), intent(in) :: model !< The binary representation of the model
553 character(len=*), intent(in) :: backend !< The name of the backend (TF, TFLITE, TORCH, ONNX)
554 character(len=*), intent(in) :: device !< The name of the device (CPU, GPU, GPU:0, GPU:1...)
555 integer, intent(in) :: batch_size !< The batch size for model execution
556 integer, intent(in) :: min_batch_size !< The minimum batch size for model execution
557 character(len=*), intent(in) :: tag !< A tag to attach to the model for
558 !! information purposes
559 character(len=*), dimension(:), intent(in) :: inputs !< One or more names of model input nodes (TF models)
560 character(len=*), dimension(:), intent(in) :: outputs !< One or more names of model output nodes (TF models)
561 integer :: code
562
563 code = -1
564 end function set_model
565
566 !> Set a model from a byte string to run on a system with multiple GPUs
567 function set_model_multigpu(self, name, model, backend, first_gpu, num_gpus, batch_size, min_batch_size, tag, &
568 inputs, outputs) result(code)
569 class(dbclient_type), intent(in) :: self !< An initialized communication client
570 character(len=*), intent(in) :: name !< The name to use to place the model
571 character(len=*), intent(in) :: model !< The binary representation of the model
572 character(len=*), intent(in) :: backend !< The name of the backend (TF, TFLITE, TORCH, ONNX)
573 integer, intent(in) :: first_gpu !< The first GPU (zero-based) to use with the model
574 integer, intent(in) :: num_gpus !< The number of GPUs to use with the model
575 integer, intent(in) :: batch_size !< The batch size for model execution
576 integer, intent(in) :: min_batch_size !< The minimum batch size for model execution
577 character(len=*), intent(in) :: tag !< A tag to attach to the model for
578 !! information purposes
579 character(len=*), dimension(:), intent(in) :: inputs !< One or more names of model input nodes (TF models)
580 character(len=*), dimension(:), intent(in) :: outputs !< One or more names of model output nodes (TF models)
581 integer :: code
582
583 code = -1
584 end function set_model_multigpu
585
586 !> Run a model in the database using the specified input and output tensors
587 function run_model(self, name, inputs, outputs) result(code)
588 class(dbclient_type), intent(in) :: self !< An initialized communication client
589 character(len=*), intent(in) :: name !< The name to use to place the model
590 character(len=*), dimension(:), intent(in) :: inputs !< One or more names of model input nodes (TF models)
591 character(len=*), dimension(:), intent(in) :: outputs !< One or more names of model output nodes (TF models)
592 integer :: code
593
594 code = -1
595 end function run_model
596
597 !> Run a model in the database using the specified input and output tensors in a multi-GPU system
598 function run_model_multigpu(self, name, inputs, outputs, offset, first_gpu, num_gpus) result(code)
599 class(dbclient_type), intent(in) :: self !< An initialized communication client
600 character(len=*), intent(in) :: name !< The name to use to place the model
601 character(len=*), dimension(:), intent(in) :: inputs !< One or more names of model input nodes (TF models)
602 character(len=*), dimension(:), intent(in) :: outputs !< One or more names of model output nodes (TF models)
603 integer, intent(in) :: offset !< Index of the current image, such as a processor ID
604 !! or MPI rank
605 integer, intent(in) :: first_gpu !< The first GPU (zero-based) to use with the model
606 integer, intent(in) :: num_gpus !< The number of GPUs to use with the model
607 integer :: code
608
609 code = -1
610 end function run_model_multigpu
611
612 !> Remove a model from the database
613 function delete_model(self, name) result(code)
614 class(dbclient_type), intent(in) :: self !< An initialized communication client
615 character(len=*), intent(in) :: name !< The name to use to remove the model
616 integer :: code
617
618 code = -1
619 end function delete_model
620
621 !> Remove a model from the database
622 function delete_model_multigpu(self, name, first_gpu, num_gpus) result(code)
623 class(dbclient_type), intent(in) :: self !< An initialized communication client
624 character(len=*), intent(in) :: name !< The name to use to remove the model
625 integer, intent(in) :: first_gpu !< The first GPU (zero-based) to use with the model
626 integer, intent(in) :: num_gpus !< The number of GPUs to use with the model
627 integer :: code
628
629 code = -1
630 end function delete_model_multigpu
631
632 !> Retrieve the script from the database
633 function get_script(self, name, script) result(code)
634 class(dbclient_type), intent(in ) :: self !< An initialized communication client
635 character(len=*), intent(in ) :: name !< The name to use to place the script
636 character(len=*), intent( out) :: script !< The script as a continuous buffer
637 integer :: code
638
639 code = -1
640 script = ""
641 end function get_script
642
643 !> Set a script (from file) in the database for future execution
644 function set_script_from_file(self, name, device, script_file) result(code)
645 class(dbclient_type), intent(in) :: self !< An initialized communication client
646 character(len=*), intent(in) :: name !< The name to use to place the script
647 character(len=*), intent(in) :: device !< The name of the device (CPU, GPU, GPU:0, GPU:1...)
648 character(len=*), intent(in) :: script_file !< The file storing the script
649 integer :: code
650
651 code = -1
652 end function set_script_from_file
653
654 !> Set a script (from file) in the database for future execution in a multi-GPU system
655 function set_script_from_file_multigpu(self, name, script_file, first_gpu, num_gpus) result(code)
656 class(dbclient_type), intent(in) :: self !< An initialized communication client
657 character(len=*), intent(in) :: name !< The name to use to place the script
658 character(len=*), intent(in) :: script_file !< The file storing the script
659 integer, intent(in) :: first_gpu !< The first GPU (zero-based) to use with the model
660 integer, intent(in) :: num_gpus !< The number of GPUs to use with the model
661 integer :: code
662
663 code = -1
664 end function set_script_from_file_multigpu
665
666 !> Set a script (from buffer) in the database for future execution
667 function set_script(self, name, device, script) result(code)
668 class(dbclient_type), intent(in) :: self !< An initialized communication client
669 character(len=*), intent(in) :: name !< The name to use to place the script
670 character(len=*), intent(in) :: device !< The name of the device (CPU, GPU, GPU:0, GPU:1...)
671 character(len=*), intent(in) :: script !< The file storing the script
672 integer :: code
673
674 code = -1
675 end function set_script
676
677 !> Set a script (from buffer) in the database for future execution in a multi-GPU system
678 function set_script_multigpu(self, name, script, first_gpu, num_gpus) result(code)
679 class(dbclient_type), intent(in) :: self !< An initialized communication client
680 character(len=*), intent(in) :: name !< The name to use to place the script
681 character(len=*), intent(in) :: script !< The file storing the script
682 integer, intent(in) :: first_gpu !< The first GPU (zero-based) to use with the model
683 integer, intent(in) :: num_gpus !< The number of GPUs to use with the model
684 integer :: code
685
686 code = -1
687 end function set_script_multigpu
688
689 function run_script(self, name, func, inputs, outputs) result(code)
690 class(dbclient_type), intent(in) :: self !< An initialized communication client
691 character(len=*), intent(in) :: name !< The name to use to place the script
692 character(len=*), intent(in) :: func !< The name of the function in the script to call
693 character(len=*), dimension(:), intent(in) :: inputs !< One or more names of script
694 !! input nodes (TF scripts)
695 character(len=*), dimension(:), intent(in) :: outputs !< One or more names of script
696 !! output nodes (TF scripts)
697 integer :: code
698
699 code = -1
700 end function run_script
701
702 function run_script_multigpu(self, name, func, inputs, outputs, offset, first_gpu, num_gpus) result(code)
703 class(dbclient_type), intent(in) :: self !< An initialized communication client
704 character(len=*), intent(in) :: name !< The name to use to place the script
705 character(len=*), intent(in) :: func !< The name of the function in the script to call
706 character(len=*), dimension(:), intent(in) :: inputs !< One or more names of script
707 !! input nodes (TF scripts)
708 character(len=*), dimension(:), intent(in) :: outputs !< One or more names of script
709 !! output nodes (TF scripts)
710 integer, intent(in) :: offset !< Index of the current image, such as a processor ID
711 !! or MPI rank
712 integer, intent(in) :: first_gpu !< The first GPU (zero-based) to use with the model
713 integer, intent(in) :: num_gpus !< The number of GPUs to use with the model
714 integer :: code
715
716 code = -1
717 end function run_script_multigpu
718
719 !> Remove a script from the database
720 function delete_script(self, name) result(code)
721 class(dbclient_type), intent(in) :: self !< An initialized communication client
722 character(len=*), intent(in) :: name !< The name to use to delete the script
723 integer :: code
724
725 code = -1
726 end function delete_script
727
728 !> Remove a script_multigpu from the database
729 function delete_script_multigpu(self, name, first_gpu, num_gpus) result(code)
730 class(dbclient_type), intent(in) :: self !< An initialized communication client
731 character(len=*), intent(in) :: name !< The name to use to delete the script_multigpu
732 integer, intent(in) :: first_gpu !< The first GPU (zero-based) to use with the model
733 integer, intent(in) :: num_gpus !< The number of GPUs to use with the model
734 integer :: code
735
736 code = -1
737 end function delete_script_multigpu
738
739 !> Store a dataset in the database
740 function put_dataset(self, dataset) result(code)
741 class(dbclient_type), intent(in) :: self !< An initialized communication client
742 type(dataset_type), intent(in) :: dataset !< Dataset to store in the dataset
743 integer :: code
744
745 code = -1
746 end function put_dataset
747
748 !> Retrieve a dataset from the database
749 function get_dataset(self, name, dataset) result(code)
750 class(dbclient_type), intent(in ) :: self !< An initialized communication client
751 character(len=*), intent(in ) :: name !< Name of the dataset to get
752 type(dataset_type), intent( out) :: dataset !< receives the dataset
753 integer :: code
754
755 type(dataset_type) :: dataset_out
756 ! Placeholder dataset to prevent compiler warnings
757 ! Since dataset_type contains no data, any declared instance should work.
758
759 code = -1
760 dataset = dataset_out
761 end function get_dataset
762
763 !> Rename a dataset stored in the database
764 function rename_dataset(self, name, new_name) result(code)
765 class(dbclient_type), intent(in) :: self !< An initialized communication client
766 character(len=*), intent(in) :: name !< Original name of the dataset
767 character(len=*), intent(in) :: new_name !< New name of the dataset
768 integer :: code
769
770 code = -1
771 end function rename_dataset
772
773 !> Copy a dataset within the database to a new name
774 function copy_dataset(self, name, new_name) result(code)
775 class(dbclient_type), intent(in) :: self !< An initialized communication client
776 character(len=*), intent(in) :: name !< Source name of the dataset
777 character(len=*), intent(in) :: new_name !< Name of the new dataset
778 integer :: code
779
780 code = -1
781 end function copy_dataset
782
783 !> Delete a dataset stored within a database
784 function delete_dataset(self, name) result(code)
785 class(dbclient_type), intent(in) :: self !< An initialized communication client
786 character(len=*), intent(in) :: name !< Name of the dataset to delete
787 integer :: code
788
789 code = -1
790 end function delete_dataset
791
792 !> Appends a dataset to the aggregation list When appending a dataset to an aggregation list, the list will
793 !! automatically be created if it does not exist (i.e. this is the first entry in the list). Aggregation
794 !! lists work by referencing the dataset by storing its key, so appending a dataset to an aggregation list
795 !! does not create a copy of the dataset. Also, for this reason, the dataset must have been previously
796 !! placed into the database with a separate call to put_dataset().
797 function append_to_list(self, list_name, dataset) result(code)
798 class(dbclient_type), intent(in) :: self !< An initialized communication client
799 character(len=*), intent(in) :: list_name !< Name of the dataset to get
800 type(dataset_type), intent(in) :: dataset !< Dataset to append to the list
801 integer :: code
802
803 code = -1
804 end function append_to_list
805
806 !> Delete an aggregation list
807 function delete_list(self, list_name) result(code)
808 class(dbclient_type), intent(in) :: self !< An initialized communication client
809 character(len=*), intent(in) :: list_name !< Name of the aggregated dataset list to delete
810 integer :: code
811
812 code = -1
813 end function delete_list
814
815 !> Copy an aggregation list
816 function copy_list(self, src_name, dest_name) result(code)
817 class(dbclient_type), intent(in) :: self !< An initialized communication client
818 character(len=*), intent(in) :: src_name !< Name of the dataset to copy
819 character(len=*), intent(in) :: dest_name !< The new list name
820 integer :: code
821
822 code = -1
823 end function copy_list
824
825 !> Rename an aggregation list
826 function rename_list(self, src_name, dest_name) result(code)
827 class(dbclient_type), intent(in) :: self !< An initialized communication client
828 character(len=*), intent(in) :: src_name !< Name of the dataset to rename
829 character(len=*), intent(in) :: dest_name !< The new list name
830 integer :: code
831
832 code = -1
833 end function rename_list
834
835 end module database_client_interface
836