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, &
70
71 integer, parameter, public :: &
72#ifdef HAVE_HIP
75#else
78#endif
79
80 integer, parameter, public :: &
81#ifdef HAVE_HIP
82 cublas_op_n = 111, &
83 cublas_op_t = 112, &
84 cublas_op_c = 113
85#else
86 cublas_op_n = 0, &
87 cublas_op_t = 1, &
88 cublas_op_c = 2
89#endif
90
91 integer, parameter, public :: &
92#ifdef HAVE_HIP
95#else
98#endif
99
100 integer, parameter, public :: &
101#ifdef HAVE_HIP
102 cublas_side_left = 141, &
104#else
105 cublas_side_left = 0, &
107#endif
108
109 interface
110
111 subroutine cuda_init(context, device, stream, device_number, rank) bind(c, name="oct_cuda_init")
112 use iso_c_binding
113 implicit none
114
115 type(c_ptr), intent(inout) :: context
116 type(c_ptr), intent(inout) :: device
117 type(c_ptr), intent(inout) :: stream
118 integer(c_int), intent(inout) :: device_number
119 integer(c_int), intent(out) :: rank
120 end subroutine cuda_init
121
122 ! -------------------------------------------------
123
124 subroutine cuda_end(context, device) bind(c, name="oct_cuda_end")
125 use iso_c_binding
126 implicit none
127
128 type(c_ptr), intent(inout) :: context
129 type(c_ptr), intent(inout) :: device
130 end subroutine cuda_end
131
132 ! -------------------------------------------------
133
134 subroutine cuda_program_map_init(program_map) bind(c, name="oct_cuda_program_map_init")
135 use iso_c_binding
136 implicit none
137
138 type(c_ptr), intent(inout) :: program_map
139 end subroutine cuda_program_map_init
140
141 ! -------------------------------------------------
142
143 subroutine cuda_program_map_end(program_map) bind(c, name="oct_cuda_program_map_end")
144 use iso_c_binding
145 implicit none
146
147 type(c_ptr), intent(inout) :: program_map
148 end subroutine cuda_program_map_end
149
150 ! -------------------------------------------------
151
152 subroutine cuda_program_register(program_map, fname, name) bind(c, name="oct_cuda_program_register")
153 use iso_c_binding
154 implicit none
155
156 type(c_ptr), intent(inout) :: program_map
157 character(kind=c_char), intent(in) :: fname(*)
158 character(kind=c_char), intent(in) :: name(*)
159 end subroutine cuda_program_register
160
161 ! -------------------------------------------------
162
163 subroutine cuda_program_build(program_map, device, fname, flags) bind(c, name="oct_cuda_program_build")
164 use iso_c_binding
165 implicit none
167 type(c_ptr), intent(inout) :: program_map
168 type(c_ptr), intent(inout) :: device
169 character(kind=c_char), intent(in) :: fname(*)
170 character(kind=c_char), intent(in) :: flags(*)
171 end subroutine cuda_program_build
172
173 ! -------------------------------------------------
174
175 subroutine cuda_program_get_kernel(kernel, program_map, fname, flags, name) &
176 bind(c, name="oct_cuda_program_get_kernel")
177 use iso_c_binding
178 implicit none
179
180 type(c_ptr), intent(inout) :: kernel
181 type(c_ptr), intent(inout) :: program_map
182 character(kind=c_char), intent(in) :: fname(*)
183 character(kind=c_char), intent(in) :: flags(*)
184 character(kind=c_char), intent(in) :: name(*)
185 end subroutine cuda_program_get_kernel
186 ! -------------------------------------------------
187
188 subroutine cuda_release_module(modul) bind(c, name="oct_cuda_release_module")
189 use iso_c_binding
190 implicit none
191
192 type(c_ptr), intent(inout) :: modul
193 end subroutine cuda_release_module
194
195 ! -------------------------------------------------
196
197 subroutine cuda_release_kernel(kernel) bind(c, name="oct_cuda_release_kernel")
198 use iso_c_binding
199 implicit none
200
201 type(c_ptr), intent(inout) :: kernel
202 end subroutine cuda_release_kernel
203
204 ! -------------------------------------------------
205
206 subroutine cuda_device_max_threads_per_block(device, max_threads) bind(c, name="oct_cuda_device_max_threads_per_block")
207 use iso_c_binding
208 implicit none
209
210 type(c_ptr), intent(inout) :: device
211 integer(c_int), intent(out) :: max_threads
213
214 ! -------------------------------------------------
215
216 subroutine cuda_kernel_max_threads_per_block(device, max_threads) bind(c, name="oct_cuda_kernel_max_threads_per_block")
217 use iso_c_binding
218 implicit none
220 type(c_ptr), intent(inout) :: device
221 integer(c_int), intent(out) :: max_threads
223
224 ! -------------------------------------------------
225
226 subroutine cuda_device_max_grid_dim_x(device, max_dim) bind(c, name="oct_cuda_device_max_grid_dim_x")
227 use iso_c_binding
228 implicit none
230 type(c_ptr), intent(inout) :: device
231 integer(c_int), intent(out) :: max_dim
232 end subroutine cuda_device_max_grid_dim_x
233
234 ! -------------------------------------------------
235
236 subroutine cuda_device_max_grid_dim_y(device, max_dim) bind(c, name="oct_cuda_device_max_grid_dim_y")
237 use iso_c_binding
238 implicit none
239
240 type(c_ptr), intent(inout) :: device
241 integer(c_int), intent(out) :: max_dim
242 end subroutine cuda_device_max_grid_dim_y
243
244 ! -------------------------------------------------
245
246 subroutine cuda_device_max_grid_dim_z(device, max_dim) bind(c, name="oct_cuda_device_max_grid_dim_z")
247 use iso_c_binding
248 implicit none
249
250 type(c_ptr), intent(inout) :: device
251 integer(c_int), intent(out) :: max_dim
252 end subroutine cuda_device_max_grid_dim_z
253
254 ! -------------------------------------------------
255
256 subroutine cuda_device_max_block_dim_x(device, max_dim) bind(c, name="oct_cuda_device_max_block_dim_x")
257 use iso_c_binding
258 implicit none
259
260 type(c_ptr), intent(inout) :: device
261 integer(c_int), intent(out) :: max_dim
262 end subroutine cuda_device_max_block_dim_x
263
264 ! -------------------------------------------------
265
266 subroutine cuda_device_max_block_dim_y(device, max_dim) bind(c, name="oct_cuda_device_max_block_dim_y")
267 use iso_c_binding
268 implicit none
269
270 type(c_ptr), intent(inout) :: device
271 integer(c_int), intent(out) :: max_dim
272 end subroutine cuda_device_max_block_dim_y
273
274 ! -------------------------------------------------
275
276 subroutine cuda_device_max_block_dim_z(device, max_dim) bind(c, name="oct_cuda_device_max_block_dim_z")
277 use iso_c_binding
278 implicit none
279
280 type(c_ptr), intent(inout) :: device
281 integer(c_int), intent(out) :: max_dim
282 end subroutine cuda_device_max_block_dim_z
284
285 ! -------------------------------------------------
286
287 subroutine cuda_device_total_memory(device, total_memory) bind(c, name="oct_cuda_device_total_memory")
288 use iso_c_binding
289 use, intrinsic :: iso_fortran_env
290 implicit none
291
292 type(c_ptr), intent(inout) :: device
293 integer(c_int64_t), intent(out) :: total_memory
294 end subroutine cuda_device_total_memory
295
296 ! -------------------------------------------------
297
298 subroutine cuda_device_shared_memory(device, shared_memory) bind(c, name="oct_cuda_device_shared_memory")
299 use iso_c_binding
300 use, intrinsic :: iso_fortran_env
301 implicit none
302
303 type(c_ptr), intent(inout) :: device
304 integer(c_int64_t), intent(out) :: shared_memory
305 end subroutine cuda_device_shared_memory
306
307 ! -------------------------------------------------
308
309 subroutine cuda_mem_alloc(cuda_ptr, size) bind(c, name="oct_cuda_mem_alloc")
310 use iso_c_binding
311 use, intrinsic :: iso_fortran_env
312 implicit none
313
314 type(c_ptr), intent(inout) :: cuda_ptr
315 integer(c_int64_t), intent(in) :: size
316 end subroutine cuda_mem_alloc
317
318 ! -------------------------------------------------
319
320 subroutine cuda_mem_free(cuda_ptr) bind(c, name="oct_cuda_mem_free")
321 use iso_c_binding
322 implicit none
323
324 type(c_ptr), intent(inout) :: cuda_ptr
325 end subroutine cuda_mem_free
326
327 ! -------------------------------------------------
328
329 subroutine cuda_alloc_arg_array(arg_array) bind(c, name="oct_cuda_alloc_arg_array")
330 use iso_c_binding
331 implicit none
332
333 type(c_ptr), intent(inout) :: arg_array
334 end subroutine cuda_alloc_arg_array
335
336 ! -------------------------------------------------
337
338 subroutine cuda_free_arg_array(arg_array) bind(c, name="oct_cuda_free_arg_array")
339 use iso_c_binding
340 implicit none
342 type(c_ptr), intent(inout) :: arg_array
343 end subroutine cuda_free_arg_array
344
345 ! -------------------------------------------------
346
347 subroutine cuda_kernel_set_arg_buffer(arg_array, cuda_ptr, arg_index) bind(c, name="oct_cuda_kernel_set_arg_buffer")
348 use iso_c_binding
349 implicit none
350
351 type(c_ptr), intent(inout) :: arg_array
352 type(c_ptr), intent(in) :: cuda_ptr
353 integer(c_int), intent(in) :: arg_index
354 end subroutine cuda_kernel_set_arg_buffer
355
356 ! -------------------------------------------------
357
358 subroutine cuda_kernel_set_arg_value(arg_array, arg, arg_index, arg_size) bind(c, name="oct_cuda_kernel_set_arg_value")
359 use iso_c_binding
360 implicit none
362 type(c_ptr), intent(inout) :: arg_array
363 type(c_ptr), intent(in) :: arg
364 integer(c_int), intent(in) :: arg_index
365 integer(c_int), intent(in) :: arg_size
366 end subroutine cuda_kernel_set_arg_value
367
368 ! -------------------------------------------------
369
370 subroutine cuda_context_synchronize() bind(c, name="oct_cuda_context_synchronize")
371 implicit none
372 end subroutine cuda_context_synchronize
373
374 ! -------------------------------------------------
375
376 subroutine cuda_synchronize_all_streams() bind(c, name="oct_cuda_synchronize_all_streams")
377 implicit none
378 end subroutine cuda_synchronize_all_streams
379
380 ! -------------------------------------------------
381
382 subroutine cuda_launch_kernel(kernel, griddim, blockdim, shared_mem, arg_array) bind(c, name="oct_cuda_launch_kernel")
383 use iso_c_binding
384 use, intrinsic :: iso_fortran_env
385 implicit none
386
387 type(c_ptr), intent(inout) :: kernel
388 integer(c_int64_t), intent(in) :: griddim
389 integer(c_int64_t), intent(in) :: blockdim
390 integer(c_int64_t), intent(in) :: shared_mem
391 type(c_ptr), intent(inout) :: arg_array
392 end subroutine cuda_launch_kernel
394 ! -------------------------------------------------
395
396 subroutine cuda_device_name(device, name) bind(c, name="oct_cuda_device_name")
397 use iso_c_binding
398 implicit none
399
400 type(c_ptr), intent(inout) :: device
401 character(kind=c_char), intent(inout) :: name(*)
402 end subroutine cuda_device_name
403
404 ! -------------------------------------------------
405
406 subroutine cuda_device_capability(device, major, minor) bind(c, name="oct_cuda_device_capability")
407 use iso_c_binding
408 implicit none
409
410 type(c_ptr), intent(inout) :: device
411 integer(c_int), intent(out) :: major
412 integer(c_int), intent(out) :: minor
413 end subroutine cuda_device_capability
414
415 ! -------------------------------------------------
416
417 subroutine cuda_driver_version(version) bind(c, name="oct_cuda_driver_version")
418 use iso_c_binding
419 implicit none
420
421 integer(c_int),intent(out) :: version
422 end subroutine cuda_driver_version
423
424 ! -------------------------------------------------
425
426 subroutine cuda_device_get_warpsize(device, warpsize) bind(c, name="oct_cuda_device_get_warpsize")
427 use iso_c_binding
428 implicit none
429
430 type(c_ptr), intent(inout) :: device
431 integer(c_int), intent(out) :: warpsize
432 end subroutine cuda_device_get_warpsize
434 subroutine cuda_deref(cuda_ptr, cuda_deref_ptr) bind(c, name="oct_cuda_deref")
435 use iso_c_binding
436 implicit none
437
438 type(c_ptr), intent(in) :: cuda_ptr
439 type(c_ptr), intent(out) :: cuda_deref_ptr
440 end subroutine cuda_deref
441
442 subroutine cuda_set_stream(stream, stream_number) bind(c, name="oct_cuda_set_stream")
443 use iso_c_binding
444 implicit none
445
446 type(c_ptr), intent(inout) :: stream
447 integer(c_int), intent(in) :: stream_number
448 end subroutine cuda_set_stream
449
450 subroutine cuda_get_stream(stream_number) bind(c, name="oct_cuda_get_stream")
451 use iso_c_binding
452 implicit none
454 integer(c_int), intent(out) :: stream_number
455 end subroutine cuda_get_stream
456
457 ! -------------------------------------------------
458
459 subroutine cuda_memcpy_htod(cuda_ptr, data, size, offset) bind(c, name="oct_cuda_memcpy_htod")
460 use iso_c_binding
461 use, intrinsic :: iso_fortran_env
462 implicit none
463
464 type(c_ptr), intent(in) :: cuda_ptr
465 type(c_ptr), intent(in) :: data
466 integer(c_int64_t), intent(in) :: size
467 integer(c_int64_t), intent(in) :: offset
468 end subroutine cuda_memcpy_htod
469
470 ! -------------------------------------------------
472 subroutine cuda_memcpy_dtoh(cuda_ptr, data, size, offset) bind(c, name="oct_cuda_memcpy_dtoh")
473 use iso_c_binding
474 use, intrinsic :: iso_fortran_env
475 implicit none
476
477 type(c_ptr), intent(in) :: cuda_ptr
478 type(c_ptr), intent(inout) :: data
479 integer(c_int64_t), intent(in) :: size
480 integer(c_int64_t), intent(in) :: offset
481 end subroutine cuda_memcpy_dtoh
482
483 ! -------------------------------------------------
484
485 subroutine cuda_memcpy_dtod(cuda_ptr_dest, cuda_ptr_src, size, offset_dest, offset_src) bind(c, name="oct_cuda_memcpy_dtod")
486 use iso_c_binding
487 use, intrinsic :: iso_fortran_env
488 implicit none
489
490 type(c_ptr), intent(inout) :: cuda_ptr_dest
491 type(c_ptr), intent(in) :: cuda_ptr_src
492 integer(c_int64_t), intent(in) :: size
493 integer(c_int64_t), intent(in) :: offset_dest
494 integer(c_int64_t), intent(in) :: offset_src
495 end subroutine cuda_memcpy_dtod
496
497 subroutine cuda_get_pointer_with_offset(buffer, offset, buffer_offset) bind(c, name="oct_cuda_get_pointer_with_offset")
498 use iso_c_binding
499 implicit none
500
501 type(c_ptr), intent(in) :: buffer
502 integer(8), intent(in) :: offset
503 type(c_ptr), intent(out) :: buffer_offset
504 end subroutine cuda_get_pointer_with_offset
505
506 subroutine cuda_clean_pointer(buffer) bind(c, name="oct_cuda_clean_pointer")
507 use iso_c_binding
508 implicit none
509
510 type(c_ptr), intent(in) :: buffer
511 end subroutine cuda_clean_pointer
513 subroutine cuda_mem_free_async(cuda_ptr) bind(c, name="oct_cuda_mem_free_async")
514 use iso_c_binding
515 implicit none
516
517 type(c_ptr), intent(inout) :: cuda_ptr
518 end subroutine cuda_mem_free_async
519
520 subroutine cuda_mem_set_async(cuda_ptr, arg, arg_size, arg_offset) bind(c, name="oct_cuda_mem_set_async")
521 use iso_c_binding
522 implicit none
523
524 type(c_ptr), intent(inout) :: cuda_ptr
525 integer(c_int8_t), intent(in) :: arg
526 integer(c_int64_t) :: arg_size
527 integer(c_int64_t) :: arg_offset
528 end subroutine cuda_mem_set_async
530 subroutine cuda_mem_alloc_async(cuda_ptr, arg_size) bind(c, name="oct_cuda_mem_alloc_async")
531 use iso_c_binding
532 implicit none
533
534 type(c_ptr), intent(inout) :: cuda_ptr
535 integer(c_int64_t) :: arg_size
536 end subroutine cuda_mem_alloc_async
538 end interface
539
540end module cuda_oct_m
541
542!! Local Variables:
543!! mode: f90
544!! coding: utf-8
545!! End:
integer, parameter, public cublas_side_left
Definition: cuda.F90:195
integer, parameter, public cublas_fill_mode_upper
Definition: cuda.F90:186
integer, parameter, public cublas_op_n
Definition: cuda.F90:175
integer, parameter, public cublas_op_c
Definition: cuda.F90:175
integer, parameter, public cublas_diag_non_unit
Definition: cuda.F90:166
integer, parameter, public cublas_op_t
Definition: cuda.F90:175
integer, parameter, public cublas_fill_mode_lower
Definition: cuda.F90:186
integer, parameter, public cublas_side_right
Definition: cuda.F90:195
integer, parameter, public cublas_diag_unit
Definition: cuda.F90:166