(git:e70887f)
Loading...
Searching...
No Matches
fft_gpu.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \note
10!> This module contains routines necessary to operate on plane waves on GPUs
11! > independently of the GPU platform.
12!> \par History
13!> BGL (06-Mar-2008) : Created
14!> AG (18-May-2012) : Refacturing:
15!> - added explicit interfaces to C routines
16!> - enable double precision complex transformations
17!> AG (11-Sept-2012) : Modifications:
18!> - use pointers if precision mapping is not required
19!> - use OMP for mapping
20!> MT (Jan 2022) : Modifications
21!> - use a generic interface for fft calls to GPUs
22!> - Support both Nvidia and AMD GPUs. Other GPUs manufacturers
23!> can be added easily.
24!> \author Benjamin G. Levine
25! **************************************************************************************************
26MODULE fft_gpu
27 USE iso_c_binding, ONLY: c_bool,&
28 c_double,&
29 c_int,&
30 c_loc,&
31 c_ptr
32 USE fft_tools, ONLY: &
35 USE kinds, ONLY: dp
36 USE mathconstants, ONLY: z_zero
38 USE pw_grid_types, ONLY: fullspace
39 USE pw_types, ONLY: pw_c1d_gs_type,&
41#include "../base/base_uses.f90"
42
43 IMPLICIT NONE
44
45 PRIVATE
46
47 PUBLIC :: fft_gpu_r3dc1d_3d
48 PUBLIC :: fft_gpu_c1dr3d_3d
49 PUBLIC :: fft_gpu_r3dc1d_3d_ps
50 PUBLIC :: fft_gpu_c1dr3d_3d_ps
51
52 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'fft_gpu'
53 LOGICAL, PARAMETER, PRIVATE :: debug_this_module = .false.
54
55CONTAINS
56
57! **************************************************************************************************
58!> \brief perform an fft followed by a gather on the gpu
59!> \param pw1 ...
60!> \param pw2 ...
61!> \author Benjamin G Levine
62! **************************************************************************************************
63 SUBROUTINE fft_gpu_r3dc1d_3d(pw1, pw2)
64 TYPE(pw_r3d_rs_type), INTENT(IN) :: pw1
65 TYPE(pw_c1d_gs_type), INTENT(INOUT) :: pw2
66
67 CHARACTER(len=*), PARAMETER :: routinen = 'fft_gpu_r3dc1d_3d'
68
69 COMPLEX(KIND=dp), POINTER :: ptr_pwout
70 INTEGER :: handle, l1, l2, l3, ngpts
71 INTEGER, DIMENSION(:), POINTER :: npts
72 INTEGER, POINTER :: ptr_ghatmap
73 REAL(kind=dp) :: scale
74 REAL(kind=dp), POINTER :: ptr_pwin
75 INTERFACE
76 SUBROUTINE fft_gpu_cfffg_c(din, zout, ghatmap, npts, ngpts, scale) BIND(C, name="fft_gpu_cfffg")
77 IMPORT
78 TYPE(c_ptr), INTENT(IN), VALUE :: din
79 TYPE(c_ptr), VALUE :: zout
80 TYPE(c_ptr), INTENT(IN), VALUE :: ghatmap
81 INTEGER(KIND=C_INT), DIMENSION(*), INTENT(IN):: npts
82 INTEGER(KIND=C_INT), INTENT(IN), VALUE :: ngpts
83 REAL(kind=c_double), INTENT(IN), VALUE :: scale
84
85 END SUBROUTINE fft_gpu_cfffg_c
86 END INTERFACE
87
88 CALL timeset(routinen, handle)
89
90 scale = 1.0_dp/real(pw1%pw_grid%ngpts, kind=dp)
91
92 ngpts = SIZE(pw2%pw_grid%gsq)
93 l1 = lbound(pw1%array, 1)
94 l2 = lbound(pw1%array, 2)
95 l3 = lbound(pw1%array, 3)
96 npts => pw1%pw_grid%npts
97
98 ! pointers to data arrays
99 ptr_pwin => pw1%array(l1, l2, l3)
100 ptr_pwout => pw2%array(1)
101
102 ! pointer to map array
103 ptr_ghatmap => pw2%pw_grid%g_hatmap(1, 1)
104
105 ! invoke the combined transformation
106#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
107 CALL fft_gpu_cfffg_c(c_loc(ptr_pwin), c_loc(ptr_pwout), c_loc(ptr_ghatmap), npts, ngpts, scale)
108#else
109 cpabort("Compiled without pw offloading.")
110#endif
111
112 CALL timestop(handle)
113 END SUBROUTINE fft_gpu_r3dc1d_3d
114
115! **************************************************************************************************
116!> \brief perform an scatter followed by a fft on the gpu
117!> \param pw1 ...
118!> \param pw2 ...
119!> \author Benjamin G Levine
120! **************************************************************************************************
121 SUBROUTINE fft_gpu_c1dr3d_3d(pw1, pw2)
122 TYPE(pw_c1d_gs_type), INTENT(IN) :: pw1
123 TYPE(pw_r3d_rs_type), INTENT(INOUT) :: pw2
124
125 CHARACTER(len=*), PARAMETER :: routinen = 'fft_gpu_c1dr3d_3d'
126
127 COMPLEX(KIND=dp), POINTER :: ptr_pwin
128 INTEGER :: handle, l1, l2, l3, ngpts, nmaps
129 INTEGER, DIMENSION(:), POINTER :: npts
130 INTEGER, POINTER :: ptr_ghatmap
131 REAL(kind=dp) :: scale
132 REAL(kind=dp), POINTER :: ptr_pwout
133 INTERFACE
134 SUBROUTINE fft_gpu_sfffc_c(zin, dout, ghatmap, npts, ngpts, nmaps, scale) BIND(C, name="fft_gpu_sfffc")
135 IMPORT
136 TYPE(c_ptr), INTENT(IN), VALUE :: zin
137 TYPE(c_ptr), VALUE :: dout
138 TYPE(c_ptr), INTENT(IN), VALUE :: ghatmap
139 INTEGER(KIND=C_INT), DIMENSION(*), INTENT(IN):: npts
140 INTEGER(KIND=C_INT), INTENT(IN), VALUE :: ngpts, nmaps
141 REAL(kind=c_double), INTENT(IN), VALUE :: scale
142 END SUBROUTINE fft_gpu_sfffc_c
143 END INTERFACE
144
145 CALL timeset(routinen, handle)
146
147 scale = 1.0_dp
148
149 ngpts = SIZE(pw1%pw_grid%gsq)
150 l1 = lbound(pw2%array, 1)
151 l2 = lbound(pw2%array, 2)
152 l3 = lbound(pw2%array, 3)
153 npts => pw1%pw_grid%npts
154
155 ! pointers to data arrays
156 ptr_pwin => pw1%array(1)
157 ptr_pwout => pw2%array(l1, l2, l3)
158
159 ! pointer to map array
160 nmaps = SIZE(pw1%pw_grid%g_hatmap, 2)
161 ptr_ghatmap => pw1%pw_grid%g_hatmap(1, 1)
162
163 ! invoke the combined transformation
164#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
165 CALL fft_gpu_sfffc_c(c_loc(ptr_pwin), c_loc(ptr_pwout), c_loc(ptr_ghatmap), npts, ngpts, nmaps, scale)
166#else
167 cpabort("Compiled without pw offloading")
168#endif
169
170 CALL timestop(handle)
171 END SUBROUTINE fft_gpu_c1dr3d_3d
172
173! **************************************************************************************************
174!> \brief perform an parallel fft followed by a gather on the gpu
175!> \param pw1 ...
176!> \param pw2 ...
177!> \author Andreas Gloess
178! **************************************************************************************************
179 SUBROUTINE fft_gpu_r3dc1d_3d_ps(pw1, pw2)
180 TYPE(pw_r3d_rs_type), INTENT(IN) :: pw1
181 TYPE(pw_c1d_gs_type), INTENT(INOUT) :: pw2
182
183 CHARACTER(len=*), PARAMETER :: routinen = 'fft_gpu_r3dc1d_3d_ps'
184
185 COMPLEX(KIND=dp), DIMENSION(:, :), POINTER :: grays, pbuf, qbuf, rbuf, sbuf
186 COMPLEX(KIND=dp), DIMENSION(:, :, :), POINTER :: tbuf
187 INTEGER :: g_pos, handle, lg, lmax, mg, mmax, mx2, &
188 mz2, n1, n2, ngpts, nmax, numtask, rp
189 INTEGER, ALLOCATABLE, DIMENSION(:) :: p2p
190 INTEGER, DIMENSION(2) :: r_dim, r_pos
191 INTEGER, DIMENSION(:), POINTER :: n, nloc, nyzray
192 INTEGER, DIMENSION(:, :, :, :), POINTER :: bo
193 REAL(kind=dp) :: scale
194 TYPE(fft_scratch_sizes) :: fft_scratch_size
195 TYPE(fft_scratch_type), POINTER :: fft_scratch
196 TYPE(mp_cart_type) :: rs_group
197
198 CALL timeset(routinen, handle)
199
200 scale = 1.0_dp/real(pw1%pw_grid%ngpts, kind=dp)
201
202 ! dimensions
203 n => pw1%pw_grid%npts
204 nloc => pw1%pw_grid%npts_local
205 grays => pw1%pw_grid%grays
206 ngpts = nloc(1)*nloc(2)*nloc(3)
207
208 !..transform
209 IF (pw1%pw_grid%para%ray_distribution) THEN
210 rs_group = pw1%pw_grid%para%group
211 nyzray => pw1%pw_grid%para%nyzray
212 bo => pw1%pw_grid%para%bo
213
214 g_pos = rs_group%mepos
215 numtask = rs_group%num_pe
216 r_dim = rs_group%num_pe_cart
217 r_pos = rs_group%mepos_cart
218
219 lg = SIZE(grays, 1)
220 mg = SIZE(grays, 2)
221 mmax = max(mg, 1)
222 lmax = max(lg, (ngpts/mmax + 1))
223
224 ALLOCATE (p2p(0:numtask - 1))
225
226 CALL rs_group%rank_compare(rs_group, p2p)
227
228 rp = p2p(g_pos)
229 mx2 = bo(2, 1, rp, 2) - bo(1, 1, rp, 2) + 1
230 mz2 = bo(2, 3, rp, 2) - bo(1, 3, rp, 2) + 1
231 n1 = maxval(bo(2, 1, :, 1) - bo(1, 1, :, 1) + 1)
232 n2 = maxval(bo(2, 2, :, 1) - bo(1, 2, :, 1) + 1)
233 nmax = max((2*n2)/numtask, 2)*mx2*mz2
234 nmax = max(nmax, n1*maxval(nyzray))
235
236 fft_scratch_size%nx = nloc(1)
237 fft_scratch_size%ny = nloc(2)
238 fft_scratch_size%nz = nloc(3)
239 fft_scratch_size%lmax = lmax
240 fft_scratch_size%mmax = mmax
241 fft_scratch_size%mx1 = bo(2, 1, rp, 1) - bo(1, 1, rp, 1) + 1
242 fft_scratch_size%mx2 = mx2
243 fft_scratch_size%my1 = bo(2, 2, rp, 1) - bo(1, 2, rp, 1) + 1
244 fft_scratch_size%mz2 = mz2
245 fft_scratch_size%lg = lg
246 fft_scratch_size%mg = mg
247 fft_scratch_size%nbx = maxval(bo(2, 1, :, 2))
248 fft_scratch_size%nbz = maxval(bo(2, 3, :, 2))
249 fft_scratch_size%mcz1 = maxval(bo(2, 3, :, 1) - bo(1, 3, :, 1) + 1)
250 fft_scratch_size%mcx2 = maxval(bo(2, 1, :, 2) - bo(1, 1, :, 2) + 1)
251 fft_scratch_size%mcz2 = maxval(bo(2, 3, :, 2) - bo(1, 3, :, 2) + 1)
252 fft_scratch_size%nmax = nmax
253 fft_scratch_size%nmray = maxval(nyzray)
254 fft_scratch_size%nyzray = nyzray(g_pos)
255 fft_scratch_size%rs_group = rs_group
256 fft_scratch_size%g_pos = g_pos
257 fft_scratch_size%r_pos = r_pos
258 fft_scratch_size%r_dim = r_dim
259 fft_scratch_size%numtask = numtask
260
261 IF (r_dim(2) > 1) THEN
262 !
263 ! real space is distributed over x and y coordinate
264 ! we have two stages of communication
265 !
266 IF (r_dim(1) == 1) THEN
267 cpabort("This processor distribution is not supported.")
268 END IF
269
270 CALL get_fft_scratch(fft_scratch, tf_type=300, n=n, fft_sizes=fft_scratch_size)
271
272 ! assign buffers
273 qbuf => fft_scratch%p2buf
274 rbuf => fft_scratch%p3buf
275 pbuf => fft_scratch%p4buf
276 sbuf => fft_scratch%p5buf
277
278 ! FFT along z
279 CALL fft_gpu_cf(pw1, qbuf)
280
281 ! Exchange data ( transpose of matrix )
282 CALL cube_transpose_2(qbuf, bo(:, :, :, 1), bo(:, :, :, 2), rbuf, fft_scratch)
283
284 ! FFT along y
285 ! use the inbuild fft-lib
286 ! CALL fft_1d(fft_scratch%fft_plan(2), rbuf, pbuf, 1.0_dp, stat)
287 ! or cufft (works faster, but is only faster if plans are stored)
288 CALL fft_gpu_1d_local(rbuf, pbuf, +1, n(2), mx2*mz2)
289
290 ! Exchange data ( transpose of matrix ) and sort
291 CALL xz_to_yz(pbuf, rs_group, r_dim, g_pos, p2p, pw1%pw_grid%para%yzp, nyzray, &
292 bo(:, :, :, 2), sbuf, fft_scratch)
293
294 ! FFT along x
295 CALL fft_gpu_fg(sbuf, pw2, scale)
296
297 CALL release_fft_scratch(fft_scratch)
298
299 ELSE
300 !
301 ! real space is only distributed over x coordinate
302 ! we have one stage of communication, after the transform of
303 ! direction x
304 !
305
306 CALL get_fft_scratch(fft_scratch, tf_type=200, n=n, fft_sizes=fft_scratch_size)
307
308 ! assign buffers
309 tbuf => fft_scratch%tbuf
310 sbuf => fft_scratch%r1buf
311
312 ! FFT along y and z
313 CALL fft_gpu_cff(pw1, tbuf)
314
315 ! Exchange data ( transpose of matrix ) and sort
316 CALL yz_to_x(tbuf, rs_group, g_pos, p2p, pw1%pw_grid%para%yzp, nyzray, &
317 bo(:, :, :, 2), sbuf, fft_scratch)
318
319 ! FFT along x
320 CALL fft_gpu_fg(sbuf, pw2, scale)
321
322 CALL release_fft_scratch(fft_scratch)
323
324 END IF
325
326 DEALLOCATE (p2p)
327
328!--------------------------------------------------------------------------
329 ELSE
330 cpabort("Not implemented (no ray_distr.) in: fft_gpu_r3dc1d_3d_ps.")
331 END IF
332
333 CALL timestop(handle)
334 END SUBROUTINE fft_gpu_r3dc1d_3d_ps
335
336! **************************************************************************************************
337!> \brief perform an parallel scatter followed by a fft on the gpu
338!> \param pw1 ...
339!> \param pw2 ...
340!> \author Andreas Gloess
341! **************************************************************************************************
342 SUBROUTINE fft_gpu_c1dr3d_3d_ps(pw1, pw2)
343 TYPE(pw_c1d_gs_type), INTENT(IN) :: pw1
344 TYPE(pw_r3d_rs_type), INTENT(INOUT) :: pw2
345
346 CHARACTER(len=*), PARAMETER :: routinen = 'fft_gpu_c1dr3d_3d_ps'
347
348 COMPLEX(KIND=dp), DIMENSION(:, :), POINTER :: grays, pbuf, qbuf, rbuf, sbuf
349 COMPLEX(KIND=dp), DIMENSION(:, :, :), POINTER :: tbuf
350 INTEGER :: g_pos, handle, lg, lmax, mg, mmax, mx2, &
351 mz2, n1, n2, ngpts, nmax, numtask, rp
352 INTEGER, ALLOCATABLE, DIMENSION(:) :: p2p
353 INTEGER, DIMENSION(2) :: r_dim, r_pos
354 INTEGER, DIMENSION(:), POINTER :: n, nloc, nyzray
355 INTEGER, DIMENSION(:, :, :, :), POINTER :: bo
356 REAL(kind=dp) :: scale
357 TYPE(fft_scratch_sizes) :: fft_scratch_size
358 TYPE(fft_scratch_type), POINTER :: fft_scratch
359 TYPE(mp_cart_type) :: rs_group
360
361 CALL timeset(routinen, handle)
362
363 scale = 1.0_dp
364
365 ! dimensions
366 n => pw1%pw_grid%npts
367 nloc => pw1%pw_grid%npts_local
368 grays => pw1%pw_grid%grays
369 ngpts = nloc(1)*nloc(2)*nloc(3)
370
371 !..transform
372 IF (pw1%pw_grid%para%ray_distribution) THEN
373 rs_group = pw1%pw_grid%para%group
374 nyzray => pw1%pw_grid%para%nyzray
375 bo => pw1%pw_grid%para%bo
376
377 g_pos = rs_group%mepos
378 numtask = rs_group%num_pe
379 r_dim = rs_group%num_pe_cart
380 r_pos = rs_group%mepos_cart
381
382 lg = SIZE(grays, 1)
383 mg = SIZE(grays, 2)
384 mmax = max(mg, 1)
385 lmax = max(lg, (ngpts/mmax + 1))
386
387 ALLOCATE (p2p(0:numtask - 1))
388
389 CALL rs_group%rank_compare(rs_group, p2p)
390
391 rp = p2p(g_pos)
392 mx2 = bo(2, 1, rp, 2) - bo(1, 1, rp, 2) + 1
393 mz2 = bo(2, 3, rp, 2) - bo(1, 3, rp, 2) + 1
394 n1 = maxval(bo(2, 1, :, 1) - bo(1, 1, :, 1) + 1)
395 n2 = maxval(bo(2, 2, :, 1) - bo(1, 2, :, 1) + 1)
396 nmax = max((2*n2)/numtask, 2)*mx2*mz2
397 nmax = max(nmax, n1*maxval(nyzray))
398
399 fft_scratch_size%nx = nloc(1)
400 fft_scratch_size%ny = nloc(2)
401 fft_scratch_size%nz = nloc(3)
402 fft_scratch_size%lmax = lmax
403 fft_scratch_size%mmax = mmax
404 fft_scratch_size%mx1 = bo(2, 1, rp, 1) - bo(1, 1, rp, 1) + 1
405 fft_scratch_size%mx2 = mx2
406 fft_scratch_size%my1 = bo(2, 2, rp, 1) - bo(1, 2, rp, 1) + 1
407 fft_scratch_size%mz2 = mz2
408 fft_scratch_size%lg = lg
409 fft_scratch_size%mg = mg
410 fft_scratch_size%nbx = maxval(bo(2, 1, :, 2))
411 fft_scratch_size%nbz = maxval(bo(2, 3, :, 2))
412 fft_scratch_size%mcz1 = maxval(bo(2, 3, :, 1) - bo(1, 3, :, 1) + 1)
413 fft_scratch_size%mcx2 = maxval(bo(2, 1, :, 2) - bo(1, 1, :, 2) + 1)
414 fft_scratch_size%mcz2 = maxval(bo(2, 3, :, 2) - bo(1, 3, :, 2) + 1)
415 fft_scratch_size%nmax = nmax
416 fft_scratch_size%nmray = maxval(nyzray)
417 fft_scratch_size%nyzray = nyzray(g_pos)
418 fft_scratch_size%rs_group = rs_group
419 fft_scratch_size%g_pos = g_pos
420 fft_scratch_size%r_pos = r_pos
421 fft_scratch_size%r_dim = r_dim
422 fft_scratch_size%numtask = numtask
423
424 IF (r_dim(2) > 1) THEN
425 !
426 ! real space is distributed over x and y coordinate
427 ! we have two stages of communication
428 !
429 IF (r_dim(1) == 1) THEN
430 cpabort("This processor distribution is not supported.")
431 END IF
432
433 CALL get_fft_scratch(fft_scratch, tf_type=300, n=n, fft_sizes=fft_scratch_size)
434
435 ! assign buffers
436 pbuf => fft_scratch%p7buf
437 qbuf => fft_scratch%p4buf
438 rbuf => fft_scratch%p3buf
439 sbuf => fft_scratch%p2buf
440
441 ! FFT along x
442 CALL fft_gpu_sf(pw1, pbuf, scale)
443
444 ! Exchange data ( transpose of matrix ) and sort
445 IF (pw1%pw_grid%grid_span /= fullspace) qbuf = z_zero
446 CALL yz_to_xz(pbuf, rs_group, r_dim, g_pos, p2p, pw1%pw_grid%para%yzp, nyzray, &
447 bo(:, :, :, 2), qbuf, fft_scratch)
448
449 ! FFT along y
450 ! use the inbuild fft-lib
451 ! CALL fft_1d(fft_scratch%fft_plan(5), qbuf, rbuf, 1.0_dp, stat)
452 ! or cufft (works faster, but is only faster if plans are stored)
453 CALL fft_gpu_1d_local(qbuf, rbuf, -1, n(2), mx2*mz2)
454
455 ! Exchange data ( transpose of matrix )
456 IF (pw1%pw_grid%grid_span /= fullspace) sbuf = z_zero
457
458 CALL cube_transpose_1(rbuf, bo(:, :, :, 2), bo(:, :, :, 1), sbuf, fft_scratch)
459
460 ! FFT along z
461 CALL fft_gpu_fc(sbuf, pw2)
462
463 CALL release_fft_scratch(fft_scratch)
464
465 ELSE
466 !
467 ! real space is only distributed over x coordinate
468 ! we have one stage of communication, after the transform of
469 ! direction x
470 !
471
472 CALL get_fft_scratch(fft_scratch, tf_type=200, n=n, fft_sizes=fft_scratch_size)
473
474 ! assign buffers
475 sbuf => fft_scratch%r1buf
476 tbuf => fft_scratch%tbuf
477
478 ! FFT along x
479 CALL fft_gpu_sf(pw1, sbuf, scale)
480
481 ! Exchange data ( transpose of matrix ) and sort
482 IF (pw1%pw_grid%grid_span /= fullspace) tbuf = z_zero
483 CALL x_to_yz(sbuf, rs_group, g_pos, p2p, pw1%pw_grid%para%yzp, nyzray, &
484 bo(:, :, :, 2), tbuf, fft_scratch)
485
486 ! FFT along y and z
487 CALL fft_gpu_ffc(tbuf, pw2)
488
489 CALL release_fft_scratch(fft_scratch)
490
491 END IF
492
493 DEALLOCATE (p2p)
494
495!--------------------------------------------------------------------------
496 ELSE
497 cpabort("Not implemented (no ray_distr.) in: fft_gpu_c1dr3d_3d_ps.")
498 END IF
499
500 CALL timestop(handle)
501 END SUBROUTINE fft_gpu_c1dr3d_3d_ps
502
503! **************************************************************************************************
504!> \brief perform a parallel real_to_complex copy followed by a 2D-FFT on the gpu
505!> \param pw1 ...
506!> \param pwbuf ...
507!> \author Andreas Gloess
508! **************************************************************************************************
509 SUBROUTINE fft_gpu_cff(pw1, pwbuf)
510 TYPE(pw_r3d_rs_type), INTENT(IN) :: pw1
511 COMPLEX(KIND=dp), DIMENSION(:, :, :), &
512 INTENT(INOUT), TARGET :: pwbuf
513
514 CHARACTER(len=*), PARAMETER :: routinen = 'fft_gpu_cff'
515
516 COMPLEX(KIND=dp), POINTER :: ptr_pwout
517 INTEGER :: handle, l1, l2, l3
518 INTEGER, DIMENSION(:), POINTER :: npts
519 REAL(kind=dp), POINTER :: ptr_pwin
520 INTERFACE
521 SUBROUTINE fft_gpu_cff_c(din, zout, npts) BIND(C, name="fft_gpu_cff")
522 IMPORT
523 TYPE(c_ptr), INTENT(IN), VALUE :: din
524 TYPE(c_ptr), VALUE :: zout
525 INTEGER(KIND=C_INT), DIMENSION(*), INTENT(IN):: npts
526 END SUBROUTINE fft_gpu_cff_c
527 END INTERFACE
528
529 CALL timeset(routinen, handle)
530
531 ! dimensions
532 npts => pw1%pw_grid%npts_local
533 l1 = lbound(pw1%array, 1)
534 l2 = lbound(pw1%array, 2)
535 l3 = lbound(pw1%array, 3)
536
537 ! pointers to data arrays
538 ptr_pwin => pw1%array(l1, l2, l3)
539 ptr_pwout => pwbuf(1, 1, 1)
540
541 ! invoke the combined transformation
542#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
543 CALL fft_gpu_cff_c(c_loc(ptr_pwin), c_loc(ptr_pwout), npts)
544#else
545 cpabort("Compiled without pw offloading")
546#endif
547
548 CALL timestop(handle)
549 END SUBROUTINE fft_gpu_cff
550
551! **************************************************************************************************
552!> \brief perform a parallel 2D-FFT followed by a complex_to_real copy on the gpu
553!> \param pwbuf ...
554!> \param pw2 ...
555!> \author Andreas Gloess
556! **************************************************************************************************
557 SUBROUTINE fft_gpu_ffc(pwbuf, pw2)
558 COMPLEX(KIND=dp), DIMENSION(:, :, :), INTENT(IN), &
559 TARGET :: pwbuf
560 TYPE(pw_r3d_rs_type), INTENT(IN) :: pw2
561
562 CHARACTER(len=*), PARAMETER :: routinen = 'fft_gpu_ffc'
563
564 COMPLEX(KIND=dp), POINTER :: ptr_pwin
565 INTEGER :: handle, l1, l2, l3
566 INTEGER, DIMENSION(:), POINTER :: npts
567 REAL(kind=dp), POINTER :: ptr_pwout
568 INTERFACE
569 SUBROUTINE fft_gpu_ffc_c(zin, dout, npts) BIND(C, name="fft_gpu_ffc")
570 IMPORT
571 TYPE(c_ptr), INTENT(IN), VALUE :: zin
572 TYPE(c_ptr), VALUE :: dout
573 INTEGER(KIND=C_INT), DIMENSION(*), INTENT(IN):: npts
574 END SUBROUTINE fft_gpu_ffc_c
575 END INTERFACE
576
577 CALL timeset(routinen, handle)
578
579 ! dimensions
580 npts => pw2%pw_grid%npts_local
581 l1 = lbound(pw2%array, 1)
582 l2 = lbound(pw2%array, 2)
583 l3 = lbound(pw2%array, 3)
584
585 ! pointers to data arrays
586 ptr_pwin => pwbuf(1, 1, 1)
587 ptr_pwout => pw2%array(l1, l2, l3)
588
589 ! invoke the combined transformation
590#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
591 CALL fft_gpu_ffc_c(c_loc(ptr_pwin), c_loc(ptr_pwout), npts)
592#else
593 cpabort("Compiled without pw offloading")
594#endif
595
596 CALL timestop(handle)
597 END SUBROUTINE fft_gpu_ffc
598
599! **************************************************************************************************
600!> \brief perform a parallel real_to_complex copy followed by a 1D-FFT on the gpu
601!> \param pw1 ...
602!> \param pwbuf ...
603!> \author Andreas Gloess
604! **************************************************************************************************
605 SUBROUTINE fft_gpu_cf(pw1, pwbuf)
606 TYPE(pw_r3d_rs_type), INTENT(IN) :: pw1
607 COMPLEX(KIND=dp), DIMENSION(:, :), INTENT(INOUT), &
608 TARGET :: pwbuf
609
610 CHARACTER(len=*), PARAMETER :: routinen = 'fft_gpu_cf'
611
612 COMPLEX(KIND=dp), POINTER :: ptr_pwout
613 INTEGER :: handle, l1, l2, l3
614 INTEGER, DIMENSION(:), POINTER :: npts
615 REAL(kind=dp), POINTER :: ptr_pwin
616 INTERFACE
617 SUBROUTINE fft_gpu_cf_c(din, zout, npts) BIND(C, name="fft_gpu_cf")
618 IMPORT
619 TYPE(c_ptr), INTENT(IN), VALUE :: din
620 TYPE(c_ptr), VALUE :: zout
621 INTEGER(KIND=C_INT), DIMENSION(*), INTENT(IN):: npts
622 END SUBROUTINE fft_gpu_cf_c
623 END INTERFACE
624
625 CALL timeset(routinen, handle)
626
627 ! dimensions
628 npts => pw1%pw_grid%npts_local
629 l1 = lbound(pw1%array, 1)
630 l2 = lbound(pw1%array, 2)
631 l3 = lbound(pw1%array, 3)
632
633 ! pointers to data arrays
634 ptr_pwin => pw1%array(l1, l2, l3)
635 ptr_pwout => pwbuf(1, 1)
636
637 ! invoke the combined transformation
638#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
639 CALL fft_gpu_cf_c(c_loc(ptr_pwin), c_loc(ptr_pwout), npts)
640#else
641 cpabort("Compiled without pw offloading")
642#endif
643 CALL timestop(handle)
644 END SUBROUTINE fft_gpu_cf
645
646! **************************************************************************************************
647!> \brief perform a parallel 1D-FFT followed by a complex_to_real copy on the gpu
648!> \param pwbuf ...
649!> \param pw2 ...
650!> \author Andreas Gloess
651! **************************************************************************************************
652 SUBROUTINE fft_gpu_fc(pwbuf, pw2)
653 COMPLEX(KIND=dp), DIMENSION(:, :), INTENT(IN), &
654 TARGET :: pwbuf
655 TYPE(pw_r3d_rs_type), INTENT(IN) :: pw2
656
657 CHARACTER(len=*), PARAMETER :: routinen = 'fft_gpu_fc'
658
659 COMPLEX(KIND=dp), POINTER :: ptr_pwin
660 INTEGER :: handle, l1, l2, l3
661 INTEGER, DIMENSION(:), POINTER :: npts
662 REAL(kind=dp), POINTER :: ptr_pwout
663 INTERFACE
664 SUBROUTINE fft_gpu_fc_c(zin, dout, npts) BIND(C, name="fft_gpu_fc")
665 IMPORT
666 TYPE(c_ptr), INTENT(IN), VALUE :: zin
667 TYPE(c_ptr), VALUE :: dout
668 INTEGER(KIND=C_INT), DIMENSION(*), INTENT(IN):: npts
669 END SUBROUTINE fft_gpu_fc_c
670 END INTERFACE
671
672 CALL timeset(routinen, handle)
673
674 npts => pw2%pw_grid%npts_local
675 l1 = lbound(pw2%array, 1)
676 l2 = lbound(pw2%array, 2)
677 l3 = lbound(pw2%array, 3)
678
679 ! pointers to data arrays
680 ptr_pwin => pwbuf(1, 1)
681 ptr_pwout => pw2%array(l1, l2, l3)
682
683 ! invoke the combined transformation
684#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
685 CALL fft_gpu_fc_c(c_loc(ptr_pwin), c_loc(ptr_pwout), npts)
686#else
687 cpabort("Compiled without pw offloading")
688#endif
689
690 CALL timestop(handle)
691 END SUBROUTINE fft_gpu_fc
692
693! **************************************************************************************************
694!> \brief perform a parallel 1D-FFT on the gpu
695!> \param pwbuf1 ...
696!> \param pwbuf2 ...
697!> \param dir ...
698!> \param n ...
699!> \param m ...
700!> \author Andreas Gloess
701! **************************************************************************************************
702 SUBROUTINE fft_gpu_1d_local(pwbuf1, pwbuf2, dir, n, m)
703 COMPLEX(KIND=dp), DIMENSION(:, :), INTENT(IN), &
704 TARGET :: pwbuf1
705 COMPLEX(KIND=dp), DIMENSION(:, :), INTENT(INOUT), &
706 TARGET :: pwbuf2
707 INTEGER, INTENT(IN) :: dir, n, m
708
709 CHARACTER(len=*), PARAMETER :: routinen = 'fft_gpu_1d_local'
710
711 COMPLEX(KIND=dp), POINTER :: ptr_pwin, ptr_pwout
712 INTEGER :: handle, ldx_in, ldx_out
713 LOGICAL :: transpose_in, transpose_out
714 INTERFACE
715 SUBROUTINE fft_gpu_f_c(zin, zout, dir, n, m, transpose_in, transpose_out, ldx_in, ldx_out) &
716 BIND(C, name="fft_gpu_1d_local")
717 IMPORT
718 TYPE(c_ptr), INTENT(IN), VALUE :: zin
719 TYPE(c_ptr), VALUE :: zout
720 LOGICAL(KIND=C_BOOL), INTENT(IN), VALUE :: dir, transpose_in, transpose_out
721 INTEGER(KIND=C_INT), INTENT(IN), VALUE :: n, m, ldx_in, ldx_out
722 END SUBROUTINE fft_gpu_f_c
723 END INTERFACE
724
725 CALL timeset(routinen, handle)
726
727 IF (n*m /= 0) THEN
728 ! pointers to data arrays
729 ptr_pwin => pwbuf1(1, 1)
730 ptr_pwout => pwbuf2(1, 1)
731
732 IF (dir > 0) THEN
733 transpose_in = .true.
734 transpose_out = .false.
735 ldx_in = m
736 ldx_out = n
737 ELSE
738 transpose_in = .false.
739 transpose_out = .true.
740 ldx_in = n
741 ldx_out = m
742 END IF
743
744 ! invoke the combined transformation
745#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
746 CALL fft_gpu_f_c(c_loc(ptr_pwin), c_loc(ptr_pwout), LOGICAL(dir > 0, C_BOOL), &
747 int(n, c_int), int(m, c_int), LOGICAL(transpose_in, C_BOOL), &
748 LOGICAL(transpose_out, C_BOOL), int(ldx_in, c_int), int(ldx_out, c_int))
749#else
750 mark_used(dir)
751 cpabort("Compiled without pw offloading")
752#endif
753 END IF
754
755 CALL timestop(handle)
756 END SUBROUTINE fft_gpu_1d_local
757! **************************************************************************************************
758!> \brief perform a parallel 1D-FFT followed by a gather on the gpu
759!> \param pwbuf ...
760!> \param pw2 ...
761!> \param scale ...
762!> \author Andreas Gloess
763! **************************************************************************************************
764 SUBROUTINE fft_gpu_fg(pwbuf, pw2, scale)
765 COMPLEX(KIND=dp), DIMENSION(:, :), INTENT(IN), &
766 TARGET :: pwbuf
767 TYPE(pw_c1d_gs_type), INTENT(IN) :: pw2
768 REAL(kind=dp), INTENT(IN) :: scale
769
770 CHARACTER(len=*), PARAMETER :: routinen = 'fft_gpu_fg'
771
772 COMPLEX(KIND=dp), POINTER :: ptr_pwin, ptr_pwout
773 INTEGER :: handle, mg, mmax, ngpts
774 INTEGER, DIMENSION(:), POINTER :: npts
775 INTEGER, POINTER :: ptr_ghatmap
776 INTERFACE
777 SUBROUTINE fft_gpu_fg_c(zin, zout, ghatmap, npts, mmax, ngpts, scale) BIND(C, name="fft_gpu_fg")
778 IMPORT
779 TYPE(c_ptr), INTENT(IN), VALUE :: zin
780 TYPE(c_ptr), VALUE :: zout
781 TYPE(c_ptr), INTENT(IN), VALUE :: ghatmap
782 INTEGER(KIND=C_INT), DIMENSION(*), INTENT(IN):: npts
783 INTEGER(KIND=C_INT), INTENT(IN), VALUE :: mmax, ngpts
784 REAL(kind=c_double), INTENT(IN), VALUE :: scale
785
786 END SUBROUTINE fft_gpu_fg_c
787 END INTERFACE
788
789 CALL timeset(routinen, handle)
790
791 ngpts = SIZE(pw2%pw_grid%gsq)
792 npts => pw2%pw_grid%npts
793
794 IF ((npts(1) /= 0) .AND. (ngpts /= 0)) THEN
795 mg = SIZE(pw2%pw_grid%grays, 2)
796 mmax = max(mg, 1)
797
798 ! pointers to data arrays
799 ptr_pwin => pwbuf(1, 1)
800 ptr_pwout => pw2%array(1)
801
802 ! pointer to map array
803 ptr_ghatmap => pw2%pw_grid%g_hatmap(1, 1)
804
805 ! invoke the combined transformation
806#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
807 CALL fft_gpu_fg_c(c_loc(ptr_pwin), c_loc(ptr_pwout), c_loc(ptr_ghatmap), npts, mmax, ngpts, scale)
808#else
809 mark_used(scale)
810 cpabort("Compiled without pw offloading")
811#endif
812 END IF
813
814 CALL timestop(handle)
815 END SUBROUTINE fft_gpu_fg
816
817! **************************************************************************************************
818!> \brief perform a parallel scatter followed by a 1D-FFT on the gpu
819!> \param pw1 ...
820!> \param pwbuf ...
821!> \param scale ...
822!> \author Andreas Gloess
823! **************************************************************************************************
824 SUBROUTINE fft_gpu_sf(pw1, pwbuf, scale)
825 TYPE(pw_c1d_gs_type), INTENT(IN) :: pw1
826 COMPLEX(KIND=dp), DIMENSION(:, :), INTENT(INOUT), &
827 TARGET :: pwbuf
828 REAL(kind=dp), INTENT(IN) :: scale
829
830 CHARACTER(len=*), PARAMETER :: routinen = 'fft_gpu_sf'
831
832 COMPLEX(KIND=dp), POINTER :: ptr_pwin, ptr_pwout
833 INTEGER :: handle, mg, mmax, ngpts, nmaps
834 INTEGER, DIMENSION(:), POINTER :: npts
835 INTEGER, POINTER :: ptr_ghatmap
836 INTERFACE
837 SUBROUTINE fft_gpu_sf_c(zin, zout, ghatmap, npts, mmax, ngpts, nmaps, scale) BIND(C, name="fft_gpu_sf")
838 IMPORT
839 TYPE(c_ptr), INTENT(IN), VALUE :: zin
840 TYPE(c_ptr), VALUE :: zout
841 TYPE(c_ptr), INTENT(IN), VALUE :: ghatmap
842 INTEGER(KIND=C_INT), DIMENSION(*), INTENT(IN):: npts
843 INTEGER(KIND=C_INT), INTENT(IN), VALUE :: mmax, ngpts, nmaps
844 REAL(kind=c_double), INTENT(IN), VALUE :: scale
845
846 END SUBROUTINE fft_gpu_sf_c
847 END INTERFACE
848
849 CALL timeset(routinen, handle)
850
851 ngpts = SIZE(pw1%pw_grid%gsq)
852 npts => pw1%pw_grid%npts
853
854 IF ((npts(1) /= 0) .AND. (ngpts /= 0)) THEN
855 mg = SIZE(pw1%pw_grid%grays, 2)
856 mmax = max(mg, 1)
857
858 ! pointers to data arrays
859 ptr_pwin => pw1%array(1)
860 ptr_pwout => pwbuf(1, 1)
861
862 ! pointer to map array
863 nmaps = SIZE(pw1%pw_grid%g_hatmap, 2)
864 ptr_ghatmap => pw1%pw_grid%g_hatmap(1, 1)
865
866 ! invoke the combined transformation
867#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
868 CALL fft_gpu_sf_c(c_loc(ptr_pwin), c_loc(ptr_pwout), c_loc(ptr_ghatmap), npts, mmax, ngpts, nmaps, scale)
869#else
870 mark_used(scale)
871 cpabort("Compiled without pw offloading")
872#endif
873 END IF
874
875 CALL timestop(handle)
876 END SUBROUTINE fft_gpu_sf
877
878END MODULE fft_gpu
subroutine, public fft_gpu_r3dc1d_3d_ps(pw1, pw2)
perform an parallel fft followed by a gather on the gpu
Definition fft_gpu.F:180
subroutine, public fft_gpu_c1dr3d_3d_ps(pw1, pw2)
perform an parallel scatter followed by a fft on the gpu
Definition fft_gpu.F:343
subroutine, public fft_gpu_r3dc1d_3d(pw1, pw2)
perform an fft followed by a gather on the gpu
Definition fft_gpu.F:64
subroutine, public fft_gpu_c1dr3d_3d(pw1, pw2)
perform an scatter followed by a fft on the gpu
Definition fft_gpu.F:122
subroutine, public yz_to_x(tb, group, my_pos, p2p, yzp, nray, bo, sb, fft_scratch)
...
Definition fft_tools.F:1879
subroutine, public yz_to_xz(sb, group, dims, my_pos, p2p, yzp, nray, bo, tb, fft_scratch)
...
Definition fft_tools.F:1996
subroutine, public cube_transpose_1(cin, boin, boout, sout, fft_scratch)
...
Definition fft_tools.F:2400
subroutine, public release_fft_scratch(fft_scratch)
...
Definition fft_tools.F:3663
subroutine, public x_to_yz(sb, group, my_pos, p2p, yzp, nray, bo, tb, fft_scratch)
...
Definition fft_tools.F:1763
subroutine, public get_fft_scratch(fft_scratch, tf_type, n, fft_sizes)
...
Definition fft_tools.F:3260
subroutine, public xz_to_yz(sb, group, dims, my_pos, p2p, yzp, nray, bo, tb, fft_scratch)
...
Definition fft_tools.F:2206
subroutine, public cube_transpose_2(cin, boin, boout, sout, fft_scratch)
...
Definition fft_tools.F:2490
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_zero
Interface to the message passing library MPI.
integer, parameter, public fullspace