Line data Source code
1 : !!****m* ABINIT/m_ompgpu_utils
2 : !! NAME
3 : !! m_ompgpu_utils
4 : !!
5 : !! FUNCTION
6 : !! Collection of routines useful for leveraging OpenMP GPU offload capabilities.
7 : !!
8 : !! COPYRIGHT
9 : !! Copyright (C) 2000-2026 ABINIT group (MT)
10 : !! This file is distributed under the terms of the
11 : !! GNU General Public License, see ~abinit/COPYING
12 : !! or http://www.gnu.org/copyleft/gpl.txt .
13 : !!
14 : !! SOURCE
15 :
16 : #if defined HAVE_CONFIG_H
17 : #include "config.h"
18 : #endif
19 :
20 : #include "abi_common.h"
21 :
22 : module m_ompgpu_utils
23 :
24 : use defs_basis
25 : use m_errors
26 : use m_abicore
27 : use m_xmpi
28 : use, intrinsic :: iso_c_binding, only : c_loc, c_associated
29 :
30 : implicit none
31 :
32 : private
33 :
34 :
35 : #ifdef HAVE_OPENMP_OFFLOAD
36 : ! pointer to GPU buffers
37 : integer, pointer, save :: cur_kg_k(:,:) => null()
38 : integer, pointer, save :: cur_kg_kp(:,:) => null()
39 : real(dp), pointer, save :: cur_ffnl_k(:,:,:,:) => null()
40 : real(dp), pointer, save :: cur_ph3d_k(:,:,:) => null()
41 : integer, pointer, save :: cur_kg_k_gather(:,:) => null()
42 : #endif
43 :
44 : public :: ompgpu_load_hamilt_buffers
45 : public :: ompgpu_free_hamilt_buffers
46 :
47 : contains
48 :
49 0 : subroutine ompgpu_load_hamilt_buffers(kg_k,kg_kp,ffnl_k,ph3d_k,kg_k_gather)
50 : integer,intent(in),target :: kg_k(:,:), kg_kp(:,:)
51 : real(dp),intent(in),target :: ffnl_k(:,:,:,:),ph3d_k(:,:,:)
52 : integer,intent(in),target,optional :: kg_k_gather(:,:)
53 :
54 : #ifdef HAVE_OPENMP_OFFLOAD
55 : if(associated(cur_kg_k)) call ompgpu_free_hamilt_buffers()
56 :
57 : cur_kg_k => kg_k
58 : cur_ffnl_k => ffnl_k
59 : cur_ph3d_k => ph3d_k
60 : !$OMP TARGET ENTER DATA MAP(to:kg_k,ffnl_k,ph3d_k)
61 : if (.not. c_associated(c_loc(kg_k), c_loc(kg_kp))) then
62 : cur_kg_kp => kg_kp
63 : !$OMP TARGET ENTER DATA MAP(to:kg_kp)
64 : end if
65 : if(present(kg_k_gather)) then
66 : cur_kg_k_gather => kg_k_gather
67 : !$OMP TARGET ENTER DATA MAP(to:kg_k_gather)
68 : end if
69 : #else
70 : ABI_UNUSED((/kg_k,kg_kp,kg_k_gather/))
71 : ABI_UNUSED((/ffnl_k,ph3d_k/))
72 0 : ABI_BUG("ABINIT wasn't compiled with OpenMP GPU offloading, aborting.")
73 : #endif
74 0 : end subroutine ompgpu_load_hamilt_buffers
75 :
76 0 : subroutine ompgpu_free_hamilt_buffers()
77 : #ifdef HAVE_OPENMP_OFFLOAD
78 :
79 : !$OMP TARGET EXIT DATA MAP(release:cur_kg_k,cur_ffnl_k,cur_ph3d_k)
80 : cur_ffnl_k => null()
81 : cur_ph3d_k => null()
82 : cur_kg_k => null()
83 : if(associated(cur_kg_kp)) then
84 : !$OMP TARGET EXIT DATA MAP(release:cur_kg_kp)
85 : cur_kg_kp => null()
86 : end if
87 : if(associated(cur_kg_k_gather)) then
88 : !$OMP TARGET EXIT DATA MAP(release:cur_kg_k_gather)
89 : cur_kg_k_gather => null()
90 : end if
91 : #else
92 0 : ABI_BUG("ABINIT wasn't compiled with OpenMP GPU offloading, aborting.")
93 : #endif
94 0 : end subroutine ompgpu_free_hamilt_buffers
95 :
96 : end module m_ompgpu_utils
97 : !!***
|