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