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