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, &
57 cuda_deref, &
65
66 integer, parameter, public :: &
67#ifdef HAVE_HIP
70#else
73#endif
74
75 integer, parameter, public :: &
76#ifdef HAVE_HIP
77 cublas_op_n = 111, &
78 cublas_op_t = 112, &
79 cublas_op_c = 113
80#else
81 cublas_op_n = 0, &
82 cublas_op_t = 1, &
83 cublas_op_c = 2
84#endif
85
86 integer, parameter, public :: &
87#ifdef HAVE_HIP
90#else
93#endif
94
95 integer, parameter, public :: &
96#ifdef HAVE_HIP
97 cublas_side_left = 141, &
99#else
100 cublas_side_left = 0, &
102#endif
103
104 interface
105
106 subroutine cuda_init(context, device, stream, device_number, rank)
107 use iso_c_binding
108 implicit none
109
110 type(c_ptr), intent(inout) :: context
111 type(c_ptr), intent(inout) :: device
112 type(c_ptr), intent(inout) :: stream
113 integer, intent(inout) :: device_number
114 integer, intent(out) :: rank
115 end subroutine cuda_init
117 ! -------------------------------------------------
118
119 subroutine cuda_end(context, device)
120 use iso_c_binding
121 implicit none
122
123 type(c_ptr), intent(inout) :: context
124 type(c_ptr), intent(inout) :: device
125 end subroutine cuda_end
126
127 ! -------------------------------------------------
128
129 subroutine cuda_module_map_init(module_map)
130 use iso_c_binding
131 implicit none
132
133 type(c_ptr), intent(inout) :: module_map
134 end subroutine cuda_module_map_init
135
136 ! -------------------------------------------------
137
138 subroutine cuda_module_map_end(module_map)
139 use iso_c_binding
140 implicit none
141
142 type(c_ptr), intent(inout) :: module_map
143 end subroutine cuda_module_map_end
144
145 ! -------------------------------------------------
146
147 subroutine cuda_build_program(module_map, modul, device, fname, flags) bind(c)
148 use iso_c_binding
149 implicit none
150
151 type(c_ptr), intent(inout) :: module_map
152 type(c_ptr), intent(inout) :: modul
153 type(c_ptr), intent(inout) :: device
154 character(kind=c_char), intent(in) :: fname(*)
155 character(kind=c_char), intent(in) :: flags(*)
156 end subroutine cuda_build_program
157
158 ! -------------------------------------------------
159
160 subroutine cuda_create_kernel(kernel, modul, kernel_name) bind(c)
161 use iso_c_binding
162 implicit none
163
164 type(c_ptr), intent(inout) :: kernel
165 type(c_ptr), intent(inout) :: modul
166 character(kind=c_char), intent(in) :: kernel_name(*)
167 end subroutine cuda_create_kernel
168 ! -------------------------------------------------
169
170 subroutine cuda_release_module(modul)
171 use iso_c_binding
172 implicit none
173
174 type(c_ptr), intent(inout) :: modul
175 end subroutine cuda_release_module
176
177 ! -------------------------------------------------
178
179 subroutine cuda_release_kernel(kernel)
180 use iso_c_binding
181 implicit none
182
183 type(c_ptr), intent(inout) :: kernel
184 end subroutine cuda_release_kernel
185
186 ! -------------------------------------------------
187
188 subroutine cuda_device_max_threads_per_block(device, max_threads)
189 use iso_c_binding
190 implicit none
191
192 type(c_ptr), intent(inout) :: device
193 integer, intent(out) :: max_threads
195
196 ! -------------------------------------------------
197
198 subroutine cuda_kernel_max_threads_per_block(device, max_threads)
199 use iso_c_binding
200 implicit none
202 type(c_ptr), intent(inout) :: device
203 integer, intent(out) :: max_threads
205
206 ! -------------------------------------------------
207
208 subroutine cuda_device_max_grid_dim_x(device, max_dim)
209 use iso_c_binding
210 implicit none
211
212 type(c_ptr), intent(inout) :: device
213 integer, intent(out) :: max_dim
215
216 ! -------------------------------------------------
217
218 subroutine cuda_device_max_grid_dim_y(device, max_dim)
219 use iso_c_binding
220 implicit none
221
222 type(c_ptr), intent(inout) :: device
223 integer, intent(out) :: max_dim
225
226 ! -------------------------------------------------
227
228 subroutine cuda_device_max_grid_dim_z(device, max_dim)
229 use iso_c_binding
230 implicit none
231
232 type(c_ptr), intent(inout) :: device
233 integer, intent(out) :: max_dim
234 end subroutine cuda_device_max_grid_dim_z
235
236 ! -------------------------------------------------
237
238 subroutine cuda_device_max_block_dim_x(device, max_dim)
239 use iso_c_binding
240 implicit none
241
242 type(c_ptr), intent(inout) :: device
243 integer, intent(out) :: max_dim
244 end subroutine cuda_device_max_block_dim_x
245
246 ! -------------------------------------------------
247
248 subroutine cuda_device_max_block_dim_y(device, max_dim)
249 use iso_c_binding
250 implicit none
251
252 type(c_ptr), intent(inout) :: device
253 integer, intent(out) :: max_dim
254 end subroutine cuda_device_max_block_dim_y
256 ! -------------------------------------------------
257
258 subroutine cuda_device_max_block_dim_z(device, max_dim)
259 use iso_c_binding
260 implicit none
261
262 type(c_ptr), intent(inout) :: device
263 integer, intent(out) :: max_dim
264 end subroutine cuda_device_max_block_dim_z
266
267 ! -------------------------------------------------
268
269 subroutine cuda_device_total_memory(device, total_memory)
270 use iso_c_binding
271 use, intrinsic :: iso_fortran_env
272 implicit none
273
274 type(c_ptr), intent(inout) :: device
275 integer(int64), intent(out) :: total_memory
276 end subroutine cuda_device_total_memory
277
278 ! -------------------------------------------------
279
280 subroutine cuda_device_shared_memory(device, shared_memory)
281 use iso_c_binding
282 use, intrinsic :: iso_fortran_env
283 implicit none
284
285 type(c_ptr), intent(inout) :: device
286 integer(int64), intent(out) :: shared_memory
287 end subroutine cuda_device_shared_memory
288
289 ! -------------------------------------------------
290
291 subroutine cuda_mem_alloc(cuda_ptr, size)
292 use iso_c_binding
293 use, intrinsic :: iso_fortran_env
294 implicit none
295
296 type(c_ptr), intent(inout) :: cuda_ptr
297 integer(int64), intent(in) :: size
298 end subroutine cuda_mem_alloc
299
300 ! -------------------------------------------------
301
302 subroutine cuda_mem_free(cuda_ptr)
303 use iso_c_binding
304 implicit none
305
306 type(c_ptr), intent(inout) :: cuda_ptr
307 end subroutine cuda_mem_free
308
309 ! -------------------------------------------------
310
311 subroutine cuda_alloc_arg_array(arg_array)
312 use iso_c_binding
313 implicit none
314
315 type(c_ptr), intent(inout) :: arg_array
316 end subroutine cuda_alloc_arg_array
317
318 ! -------------------------------------------------
319
320 subroutine cuda_free_arg_array(arg_array)
321 use iso_c_binding
322 implicit none
324 type(c_ptr), intent(inout) :: arg_array
325 end subroutine cuda_free_arg_array
326
327 ! -------------------------------------------------
328
329 subroutine cuda_kernel_set_arg_buffer(arg_array, cuda_ptr, arg_index)
330 use iso_c_binding
331 implicit none
332
333 type(c_ptr), intent(inout) :: arg_array
334 type(c_ptr), intent(in) :: cuda_ptr
335 integer, intent(in) :: arg_index
336 end subroutine cuda_kernel_set_arg_buffer
337
338 ! -------------------------------------------------
339
340 subroutine cuda_context_synchronize()
341 implicit none
342 end subroutine cuda_context_synchronize
344 ! -------------------------------------------------
345
347 implicit none
348 end subroutine cuda_synchronize_all_streams
349
350 ! -------------------------------------------------
351
352 subroutine cuda_launch_kernel(kernel, griddim, blockdim, shared_mem, arg_array)
353 use iso_c_binding
354 use, intrinsic :: iso_fortran_env
355 implicit none
356
357 type(c_ptr), intent(inout) :: kernel
358 integer(int64), intent(in) :: griddim
359 integer(int64), intent(in) :: blockdim
360 integer(int64), intent(in) :: shared_mem
361 type(c_ptr), intent(inout) :: arg_array
362 end subroutine cuda_launch_kernel
363
364 ! -------------------------------------------------
365
366 subroutine cuda_device_name(device, name)
367 use iso_c_binding
368 implicit none
369
370 type(c_ptr), intent(inout) :: device
371 character(kind=c_char), intent(inout) :: name(*)
372 end subroutine cuda_device_name
373
374 ! -------------------------------------------------
376 subroutine cuda_device_capability(device, major, minor)
377 use iso_c_binding
378 implicit none
379
380 type(c_ptr), intent(inout) :: device
381 integer, intent(out) :: major
382 integer, intent(out) :: minor
383 end subroutine cuda_device_capability
384
385 ! -------------------------------------------------
387 subroutine cuda_driver_version(version)
388 use iso_c_binding
389 implicit none
390
391 integer, intent(out) :: version
392 end subroutine cuda_driver_version
393
394 ! -------------------------------------------------
395
396 subroutine cuda_device_get_warpsize(device, warpsize)
397 use iso_c_binding
398 implicit none
399
400 type(c_ptr), intent(inout) :: device
401 integer, intent(out) :: warpsize
402 end subroutine cuda_device_get_warpsize
403
404 subroutine cuda_deref(cuda_ptr, cuda_deref_ptr)
405 use iso_c_binding
406 implicit none
407
408 type(c_ptr), intent(in) :: cuda_ptr
409 type(c_ptr), intent(out) :: cuda_deref_ptr
410 end subroutine cuda_deref
411
412 subroutine cuda_set_stream(stream, stream_number)
413 use iso_c_binding
414 implicit none
416 type(c_ptr), intent(inout) :: stream
417 integer, intent(in) :: stream_number
418 end subroutine cuda_set_stream
419
420 subroutine cuda_get_stream(stream_number)
421 use iso_c_binding
422 implicit none
423
424 integer, intent(out) :: stream_number
425 end subroutine cuda_get_stream
426
427 ! -------------------------------------------------
428
429 subroutine cuda_memcpy_htod(cuda_ptr, data, size, offset)
430 use iso_c_binding
431 use, intrinsic :: iso_fortran_env
432 implicit none
433
434 type(c_ptr), intent(in) :: cuda_ptr
435 type(c_ptr), intent(in) :: data
436 integer(int64), intent(in) :: size
437 integer(int64), intent(in) :: offset
438 end subroutine cuda_memcpy_htod
439
440 ! -------------------------------------------------
442 subroutine cuda_memcpy_dtoh(cuda_ptr, data, size, offset)
443 use iso_c_binding
444 use, intrinsic :: iso_fortran_env
445 implicit none
446
447 type(c_ptr), intent(in) :: cuda_ptr
448 type(c_ptr), intent(inout) :: data
449 integer(int64), intent(in) :: size
450 integer(int64), intent(in) :: offset
451 end subroutine cuda_memcpy_dtoh
452
453 ! -------------------------------------------------
454
455 subroutine cuda_memcpy_dtod(cuda_ptr_dest, cuda_ptr_src, size, offset_dest, offset_src)
456 use iso_c_binding
457 use, intrinsic :: iso_fortran_env
458 implicit none
459
460 type(c_ptr), intent(inout) :: cuda_ptr_dest
461 type(c_ptr), intent(in) :: cuda_ptr_src
462 integer(int64), intent(in) :: size
463 integer(int64), intent(in) :: offset_dest
464 integer(int64), intent(in) :: offset_src
465 end subroutine cuda_memcpy_dtod
466
467 subroutine cuda_get_pointer_with_offset(buffer, offset, buffer_offset)
468 use iso_c_binding
469 implicit none
470
471 type(c_ptr), intent(in) :: buffer
472 integer(8), intent(in) :: offset
473 type(c_ptr), intent(out) :: buffer_offset
474 end subroutine cuda_get_pointer_with_offset
475
476 subroutine cuda_clean_pointer(buffer)
477 use iso_c_binding
478 implicit none
479
480 type(c_ptr), intent(in) :: buffer
481 end subroutine cuda_clean_pointer
482 end interface
483
484end module cuda_oct_m
485
486!! Local Variables:
487!! mode: f90
488!! coding: utf-8
489!! End:
integer, parameter, public cublas_side_left
Definition: cuda.F90:190
integer, parameter, public cublas_fill_mode_upper
Definition: cuda.F90:181
integer, parameter, public cublas_op_n
Definition: cuda.F90:170
integer, parameter, public cublas_op_c
Definition: cuda.F90:170
integer, parameter, public cublas_diag_non_unit
Definition: cuda.F90:161
integer, parameter, public cublas_op_t
Definition: cuda.F90:170
integer, parameter, public cublas_fill_mode_lower
Definition: cuda.F90:181
integer, parameter, public cublas_side_right
Definition: cuda.F90:190
integer, parameter, public cublas_diag_unit
Definition: cuda.F90:161