Octopus
cuda.F90
Go to the documentation of this file.
1!! Copyright (C) 2019 X. Andrade
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
21module cuda_oct_m
22
23 implicit none
24
25 private
26 public :: &
27 cuda_init, &
28 cuda_end, &
59 cuda_deref, &
71 cublas_end, &
73
74 integer, parameter, public :: &
75#ifdef HAVE_HIP
78#else
81#endif
82
83 integer, parameter, public :: &
84#ifdef HAVE_HIP
85 cublas_op_n = 111, &
86 cublas_op_t = 112, &
87 cublas_op_c = 113
88#else
89 cublas_op_n = 0, &
90 cublas_op_t = 1, &
91 cublas_op_c = 2
92#endif
93
94 integer, parameter, public :: &
95#ifdef HAVE_HIP
98#else
101#endif
102
103 integer, parameter, public :: &
104#ifdef HAVE_HIP
105 cublas_side_left = 141, &
107#else
108 cublas_side_left = 0, &
110#endif
111
112 interface
113
114 subroutine cuda_init(context, device, stream, device_number, rank) bind(c, name="oct_cuda_init")
115 use iso_c_binding
116 implicit none
117
118 type(c_ptr), intent(inout) :: context
119 type(c_ptr), intent(inout) :: device
120 type(c_ptr), intent(inout) :: stream
121 integer(c_int), intent(inout) :: device_number
122 integer(c_int), intent(out) :: rank
123 end subroutine cuda_init
124
125 ! -------------------------------------------------
126
127 subroutine cuda_end(context, device) bind(c, name="oct_cuda_end")
128 use iso_c_binding
129 implicit none
130
131 type(c_ptr), intent(inout) :: context
132 type(c_ptr), intent(inout) :: device
133 end subroutine cuda_end
134
135 ! -------------------------------------------------
136
137 subroutine cuda_program_map_init(program_map) bind(c, name="oct_cuda_program_map_init")
138 use iso_c_binding
139 implicit none
140
141 type(c_ptr), intent(inout) :: program_map
142 end subroutine cuda_program_map_init
143
144 ! -------------------------------------------------
145
146 subroutine cuda_program_map_end(program_map) bind(c, name="oct_cuda_program_map_end")
147 use iso_c_binding
148 implicit none
149
150 type(c_ptr), intent(inout) :: program_map
151 end subroutine cuda_program_map_end
152
153 ! -------------------------------------------------
154
155 subroutine cuda_program_register(program_map, fname, name) bind(c, name="oct_cuda_program_register")
156 use iso_c_binding
157 implicit none
158
159 type(c_ptr), intent(inout) :: program_map
160 character(kind=c_char), intent(in) :: fname(*)
161 character(kind=c_char), intent(in) :: name(*)
162 end subroutine cuda_program_register
163
164 ! -------------------------------------------------
165
166 subroutine cuda_program_build(program_map, device, fname, flags) bind(c, name="oct_cuda_program_build")
167 use iso_c_binding
168 implicit none
170 type(c_ptr), intent(inout) :: program_map
171 type(c_ptr), intent(inout) :: device
172 character(kind=c_char), intent(in) :: fname(*)
173 character(kind=c_char), intent(in) :: flags(*)
174 end subroutine cuda_program_build
175
176 ! -------------------------------------------------
177
178 subroutine cuda_program_get_kernel(kernel, program_map, fname, flags, name) &
179 bind(c, name="oct_cuda_program_get_kernel")
180 use iso_c_binding
181 implicit none
182
183 type(c_ptr), intent(inout) :: kernel
184 type(c_ptr), intent(inout) :: program_map
185 character(kind=c_char), intent(in) :: fname(*)
186 character(kind=c_char), intent(in) :: flags(*)
187 character(kind=c_char), intent(in) :: name(*)
188 end subroutine cuda_program_get_kernel
189 ! -------------------------------------------------
190
191 subroutine cuda_release_module(modul) bind(c, name="oct_cuda_release_module")
192 use iso_c_binding
193 implicit none
194
195 type(c_ptr), intent(inout) :: modul
196 end subroutine cuda_release_module
197
198 ! -------------------------------------------------
199
200 subroutine cuda_release_kernel(kernel) bind(c, name="oct_cuda_release_kernel")
201 use iso_c_binding
202 implicit none
203
204 type(c_ptr), intent(inout) :: kernel
205 end subroutine cuda_release_kernel
206
207 ! -------------------------------------------------
208
209 subroutine cuda_device_max_threads_per_block(device, max_threads) bind(c, name="oct_cuda_device_max_threads_per_block")
210 use iso_c_binding
211 implicit none
212
213 type(c_ptr), intent(inout) :: device
214 integer(c_int), intent(out) :: max_threads
216
217 ! -------------------------------------------------
218
219 subroutine cuda_kernel_max_threads_per_block(device, max_threads) bind(c, name="oct_cuda_kernel_max_threads_per_block")
220 use iso_c_binding
221 implicit none
223 type(c_ptr), intent(inout) :: device
224 integer(c_int), intent(out) :: max_threads
226
227 ! -------------------------------------------------
228
229 subroutine cuda_device_max_grid_dim_x(device, max_dim) bind(c, name="oct_cuda_device_max_grid_dim_x")
230 use iso_c_binding
231 implicit none
233 type(c_ptr), intent(inout) :: device
234 integer(c_int), intent(out) :: max_dim
235 end subroutine cuda_device_max_grid_dim_x
236
237 ! -------------------------------------------------
238
239 subroutine cuda_device_max_grid_dim_y(device, max_dim) bind(c, name="oct_cuda_device_max_grid_dim_y")
240 use iso_c_binding
241 implicit none
242
243 type(c_ptr), intent(inout) :: device
244 integer(c_int), intent(out) :: max_dim
245 end subroutine cuda_device_max_grid_dim_y
246
247 ! -------------------------------------------------
248
249 subroutine cuda_device_max_grid_dim_z(device, max_dim) bind(c, name="oct_cuda_device_max_grid_dim_z")
250 use iso_c_binding
251 implicit none
252
253 type(c_ptr), intent(inout) :: device
254 integer(c_int), intent(out) :: max_dim
255 end subroutine cuda_device_max_grid_dim_z
256
257 ! -------------------------------------------------
258
259 subroutine cuda_device_max_block_dim_x(device, max_dim) bind(c, name="oct_cuda_device_max_block_dim_x")
260 use iso_c_binding
261 implicit none
262
263 type(c_ptr), intent(inout) :: device
264 integer(c_int), intent(out) :: max_dim
265 end subroutine cuda_device_max_block_dim_x
266
267 ! -------------------------------------------------
268
269 subroutine cuda_device_max_block_dim_y(device, max_dim) bind(c, name="oct_cuda_device_max_block_dim_y")
270 use iso_c_binding
271 implicit none
272
273 type(c_ptr), intent(inout) :: device
274 integer(c_int), intent(out) :: max_dim
275 end subroutine cuda_device_max_block_dim_y
276
277 ! -------------------------------------------------
278
279 subroutine cuda_device_max_block_dim_z(device, max_dim) bind(c, name="oct_cuda_device_max_block_dim_z")
280 use iso_c_binding
281 implicit none
282
283 type(c_ptr), intent(inout) :: device
284 integer(c_int), intent(out) :: max_dim
285 end subroutine cuda_device_max_block_dim_z
287
288 ! -------------------------------------------------
289
290 subroutine cuda_device_total_memory(device, total_memory) bind(c, name="oct_cuda_device_total_memory")
291 use iso_c_binding
292 use, intrinsic :: iso_fortran_env
293 implicit none
294
295 type(c_ptr), intent(inout) :: device
296 integer(c_int64_t), intent(out) :: total_memory
297 end subroutine cuda_device_total_memory
298
299 ! -------------------------------------------------
300
301 subroutine cuda_device_shared_memory(device, shared_memory) bind(c, name="oct_cuda_device_shared_memory")
302 use iso_c_binding
303 use, intrinsic :: iso_fortran_env
304 implicit none
305
306 type(c_ptr), intent(inout) :: device
307 integer(c_int64_t), intent(out) :: shared_memory
308 end subroutine cuda_device_shared_memory
309
310 ! -------------------------------------------------
311
312 subroutine cuda_mem_alloc(cuda_ptr, size) bind(c, name="oct_cuda_mem_alloc")
313 use iso_c_binding
314 use, intrinsic :: iso_fortran_env
315 implicit none
316
317 type(c_ptr), intent(inout) :: cuda_ptr
318 integer(c_int64_t), intent(in) :: size
319 end subroutine cuda_mem_alloc
320
321 ! -------------------------------------------------
322
323 subroutine cuda_mem_free(cuda_ptr) bind(c, name="oct_cuda_mem_free")
324 use iso_c_binding
325 implicit none
326
327 type(c_ptr), intent(inout) :: cuda_ptr
328 end subroutine cuda_mem_free
329
330 ! -------------------------------------------------
331
332 subroutine cuda_alloc_arg_array(arg_array) bind(c, name="oct_cuda_alloc_arg_array")
333 use iso_c_binding
334 implicit none
335
336 type(c_ptr), intent(inout) :: arg_array
337 end subroutine cuda_alloc_arg_array
338
339 ! -------------------------------------------------
340
341 subroutine cuda_free_arg_array(arg_array) bind(c, name="oct_cuda_free_arg_array")
342 use iso_c_binding
343 implicit none
345 type(c_ptr), intent(inout) :: arg_array
346 end subroutine cuda_free_arg_array
347
348 ! -------------------------------------------------
349
350 subroutine cuda_kernel_set_arg_buffer(arg_array, cuda_ptr, arg_index) bind(c, name="oct_cuda_kernel_set_arg_buffer")
351 use iso_c_binding
352 implicit none
353
354 type(c_ptr), intent(inout) :: arg_array
355 type(c_ptr), intent(in) :: cuda_ptr
356 integer(c_int), intent(in) :: arg_index
357 end subroutine cuda_kernel_set_arg_buffer
358
359 ! -------------------------------------------------
360
361 subroutine cuda_kernel_set_arg_value(arg_array, arg, arg_index, arg_size) bind(c, name="oct_cuda_kernel_set_arg_value")
362 use iso_c_binding
363 implicit none
365 type(c_ptr), intent(inout) :: arg_array
366 type(c_ptr), intent(in) :: arg
367 integer(c_int), intent(in) :: arg_index
368 integer(c_int), intent(in) :: arg_size
369 end subroutine cuda_kernel_set_arg_value
370
371 ! -------------------------------------------------
372
373 subroutine cuda_context_synchronize() bind(c, name="oct_cuda_context_synchronize")
374 implicit none
375 end subroutine cuda_context_synchronize
376
377 ! -------------------------------------------------
378
379 subroutine cuda_synchronize_all_streams() bind(c, name="oct_cuda_synchronize_all_streams")
380 implicit none
381 end subroutine cuda_synchronize_all_streams
382
383 ! -------------------------------------------------
384
385 subroutine cuda_launch_kernel(kernel, griddim, blockdim, shared_mem, arg_array) bind(c, name="oct_cuda_launch_kernel")
386 use iso_c_binding
387 use, intrinsic :: iso_fortran_env
388 implicit none
389
390 type(c_ptr), intent(inout) :: kernel
391 integer(c_int64_t), intent(in) :: griddim
392 integer(c_int64_t), intent(in) :: blockdim
393 integer(c_int64_t), intent(in) :: shared_mem
394 type(c_ptr), intent(inout) :: arg_array
395 end subroutine cuda_launch_kernel
397 ! -------------------------------------------------
398
399 subroutine cuda_device_name(device, name) bind(c, name="oct_cuda_device_name")
400 use iso_c_binding
401 implicit none
402
403 type(c_ptr), intent(inout) :: device
404 character(kind=c_char), intent(inout) :: name(*)
405 end subroutine cuda_device_name
406
407 ! -------------------------------------------------
408
409 subroutine cuda_device_capability(device, major, minor) bind(c, name="oct_cuda_device_capability")
410 use iso_c_binding
411 implicit none
412
413 type(c_ptr), intent(inout) :: device
414 integer(c_int), intent(out) :: major
415 integer(c_int), intent(out) :: minor
416 end subroutine cuda_device_capability
417
418 ! -------------------------------------------------
419
420 subroutine cuda_driver_version(version) bind(c, name="oct_cuda_driver_version")
421 use iso_c_binding
422 implicit none
423
424 integer(c_int),intent(out) :: version
425 end subroutine cuda_driver_version
426
427 ! -------------------------------------------------
428
429 subroutine cuda_device_get_warpsize(device, warpsize) bind(c, name="oct_cuda_device_get_warpsize")
430 use iso_c_binding
431 implicit none
432
433 type(c_ptr), intent(inout) :: device
434 integer(c_int), intent(out) :: warpsize
435 end subroutine cuda_device_get_warpsize
437 subroutine cuda_deref(cuda_ptr, cuda_deref_ptr) bind(c, name="oct_cuda_deref")
438 use iso_c_binding
439 implicit none
440
441 type(c_ptr), intent(in) :: cuda_ptr
442 type(c_ptr), intent(out) :: cuda_deref_ptr
443 end subroutine cuda_deref
444
445 subroutine cuda_set_stream(stream, stream_number) bind(c, name="oct_cuda_set_stream")
446 use iso_c_binding
447 implicit none
448
449 type(c_ptr), intent(inout) :: stream
450 integer(c_int), intent(in) :: stream_number
451 end subroutine cuda_set_stream
452
453 subroutine cuda_get_stream(stream_number) bind(c, name="oct_cuda_get_stream")
454 use iso_c_binding
455 implicit none
457 integer(c_int), intent(out) :: stream_number
458 end subroutine cuda_get_stream
459
460 ! -------------------------------------------------
461
462 subroutine cuda_memcpy_htod(cuda_ptr, data, size, offset) bind(c, name="oct_cuda_memcpy_htod")
463 use iso_c_binding
464 use, intrinsic :: iso_fortran_env
465 implicit none
466
467 type(c_ptr), intent(in) :: cuda_ptr
468 type(c_ptr), intent(in) :: data
469 integer(c_int64_t), intent(in) :: size
470 integer(c_int64_t), intent(in) :: offset
471 end subroutine cuda_memcpy_htod
472
473 ! -------------------------------------------------
475 subroutine cuda_memcpy_dtoh(cuda_ptr, data, size, offset) bind(c, name="oct_cuda_memcpy_dtoh")
476 use iso_c_binding
477 use, intrinsic :: iso_fortran_env
478 implicit none
479
480 type(c_ptr), intent(in) :: cuda_ptr
481 type(c_ptr), intent(inout) :: data
482 integer(c_int64_t), intent(in) :: size
483 integer(c_int64_t), intent(in) :: offset
484 end subroutine cuda_memcpy_dtoh
485
486 ! -------------------------------------------------
487
488 subroutine cuda_memcpy_dtod(cuda_ptr_dest, cuda_ptr_src, size, offset_dest, offset_src) bind(c, name="oct_cuda_memcpy_dtod")
489 use iso_c_binding
490 use, intrinsic :: iso_fortran_env
491 implicit none
492
493 type(c_ptr), intent(inout) :: cuda_ptr_dest
494 type(c_ptr), intent(in) :: cuda_ptr_src
495 integer(c_int64_t), intent(in) :: size
496 integer(c_int64_t), intent(in) :: offset_dest
497 integer(c_int64_t), intent(in) :: offset_src
498 end subroutine cuda_memcpy_dtod
499
500 subroutine cuda_get_pointer_with_offset(buffer, offset, buffer_offset) bind(c, name="oct_cuda_get_pointer_with_offset")
501 use iso_c_binding
502 implicit none
503
504 type(c_ptr), intent(in) :: buffer
505 integer(8), intent(in) :: offset
506 type(c_ptr), intent(out) :: buffer_offset
507 end subroutine cuda_get_pointer_with_offset
508
509 subroutine cuda_clean_pointer(buffer) bind(c, name="oct_cuda_clean_pointer")
510 use iso_c_binding
511 implicit none
512
513 type(c_ptr), intent(in) :: buffer
514 end subroutine cuda_clean_pointer
516 subroutine cuda_mem_free_async(cuda_ptr) bind(c, name="oct_cuda_mem_free_async")
517 use iso_c_binding
518 implicit none
519
520 type(c_ptr), intent(inout) :: cuda_ptr
521 end subroutine cuda_mem_free_async
522
523 subroutine cuda_mem_set_async(cuda_ptr, arg, arg_size, arg_offset) bind(c, name="oct_cuda_mem_set_async")
524 use iso_c_binding
525 implicit none
526
527 type(c_ptr), intent(inout) :: cuda_ptr
528 integer(c_int8_t), intent(in) :: arg
529 integer(c_int64_t) :: arg_size
530 integer(c_int64_t) :: arg_offset
531 end subroutine cuda_mem_set_async
533 subroutine cuda_mem_alloc_async(cuda_ptr, arg_size) bind(c, name="oct_cuda_mem_alloc_async")
534 use iso_c_binding
535 implicit none
536
537 type(c_ptr), intent(inout) :: cuda_ptr
538 integer(c_int64_t) :: arg_size
539 end subroutine cuda_mem_alloc_async
541 ! -------------------------------------------------
542
543 subroutine cublas_init(stream) bind(c, name="oct_cublas_init")
544 use iso_c_binding
545 implicit none
546
547 type(c_ptr), intent(in) :: stream
548 end subroutine cublas_init
549
550 subroutine cublas_end() bind(c, name="oct_cublas_end")
551 implicit none
552 end subroutine cublas_end
553
554 subroutine cublas_set_stream(stream, stream_number) bind(c, name="oct_cublas_set_stream")
555 use iso_c_binding
556 implicit none
558 type(c_ptr), intent(in) :: stream
559 integer(c_int), intent(in) :: stream_number
560 end subroutine cublas_set_stream
561
562 end interface
563
564end module cuda_oct_m
565
566!! Local Variables:
567!! mode: f90
568!! coding: utf-8
569!! End:
integer, parameter, public cublas_side_left
Definition: cuda.F90:198
integer, parameter, public cublas_fill_mode_upper
Definition: cuda.F90:189
integer, parameter, public cublas_op_n
Definition: cuda.F90:178
integer, parameter, public cublas_op_c
Definition: cuda.F90:178
integer, parameter, public cublas_diag_non_unit
Definition: cuda.F90:169
integer, parameter, public cublas_op_t
Definition: cuda.F90:178
integer, parameter, public cublas_fill_mode_lower
Definition: cuda.F90:189
integer, parameter, public cublas_side_right
Definition: cuda.F90:198
integer, parameter, public cublas_diag_unit
Definition: cuda.F90:169