Neko 1.99.6
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
ax_helm_full_device.F90
Go to the documentation of this file.
1! Copyright (c) 2024, The Neko Authors
2! All rights reserved.
3!
4! Redistribution and use in source and binary forms, with or without
5! modification, are permitted provided that the following conditions
6! are met:
7!
8! * Redistributions of source code must retain the above copyright
9! notice, this list of conditions and the following disclaimer.
10!
11! * Redistributions in binary form must reproduce the above
12! copyright notice, this list of conditions and the following
13! disclaimer in the documentation and/or other materials provided
14! with the distribution.
15!
16! * Neither the name of the authors nor the names of its
17! contributors may be used to endorse or promote products derived
18! from this software without specific prior written permission.
19!
20! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31! POSSIBILITY OF SUCH DAMAGE.
32!
35 use num_types, only : rp
36 use coefs, only : coef_t
37 use space, only : space_t
38 use mesh, only : mesh_t
39 use device_math, only : device_addcol4
40 use device, only : device_get_ptr
41 use num_types, only : rp
42 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
43 implicit none
44 private
45
46 type, public, extends(ax_helm_full_t) :: ax_helm_full_device_t
47 contains
48 procedure, pass(this) :: compute_vector => &
51
52#ifdef HAVE_HIP
53 interface
54 subroutine hip_ax_helm_stress_vector(au_d, av_d, aw_d, u_d, v_d, w_d, &
55 dx_d, dy_d, dz_d, dxt_d, dyt_d, dzt_d,&
56 h1_d, drdx_d, drdy_d, drdz_d, &
57 dsdx_d, dsdy_d, dsdz_d, &
58 dtdx_d, dtdy_d, dtdz_d, jacinv_d, weight3_d, nelv, lx) &
59 bind(c, name='hip_ax_helm_stress_vector')
60 use, intrinsic :: iso_c_binding
61 type(c_ptr), value :: au_d, av_d, aw_d
62 type(c_ptr), value :: u_d, v_d, w_d
63 type(c_ptr), value :: dx_d, dy_d, dz_d
64 type(c_ptr), value :: dxt_d, dyt_d, dzt_d
65 type(c_ptr), value :: h1_d
66 type(c_ptr), value :: drdx_d, drdy_d, drdz_d
67 type(c_ptr), value :: dsdx_d, dsdy_d, dsdz_d
68 type(c_ptr), value :: dtdx_d, dtdy_d, dtdz_d
69 type(c_ptr), value :: jacinv_d, weight3_d
70 integer(c_int) :: nelv, lx
71 end subroutine hip_ax_helm_stress_vector
72 end interface
73
74 interface
75 subroutine hip_ax_helm_stress_vector_part2(au_d, av_d, aw_d, u_d, &
76 v_d, w_d, h2_d, B_d, n) &
77 bind(c, name='hip_ax_helm_stress_vector_part2')
78 use, intrinsic :: iso_c_binding
79 type(c_ptr), value :: au_d, av_d, aw_d
80 type(c_ptr), value :: u_d, v_d, w_d
81 type(c_ptr), value :: h2_d, B_d
82 integer(c_int) :: n
84 end interface
85
86#elif HAVE_CUDA
87 interface
88 subroutine cuda_ax_helm_stress_vector(au_d, av_d, aw_d, u_d, v_d, w_d, &
89 dx_d, dy_d, dz_d, dxt_d, dyt_d, dzt_d,&
90 h1_d, drdx_d, drdy_d, drdz_d, &
91 dsdx_d, dsdy_d, dsdz_d, &
92 dtdx_d, dtdy_d, dtdz_d, jacinv_d, weight3_d, nelv, lx) &
93 bind(c, name='cuda_ax_helm_stress_vector')
94 use, intrinsic :: iso_c_binding
95 type(c_ptr), value :: au_d, av_d, aw_d
96 type(c_ptr), value :: u_d, v_d, w_d
97 type(c_ptr), value :: dx_d, dy_d, dz_d
98 type(c_ptr), value :: dxt_d, dyt_d, dzt_d
99 type(c_ptr), value :: h1_d
100 type(c_ptr), value :: drdx_d, drdy_d, drdz_d
101 type(c_ptr), value :: dsdx_d, dsdy_d, dsdz_d
102 type(c_ptr), value :: dtdx_d, dtdy_d, dtdz_d
103 type(c_ptr), value :: jacinv_d, weight3_d
104 integer(c_int) :: nelv, lx
105 end subroutine cuda_ax_helm_stress_vector
106 end interface
107
108 interface
109 subroutine cuda_ax_helm_stress_vector_part2(au_d, av_d, aw_d, &
110 u_d, v_d, w_d, h2_d, B_d, n) &
111 bind(c, name='cuda_ax_helm_stress_vector_part2')
112 use, intrinsic :: iso_c_binding
113 type(c_ptr), value :: au_d, av_d, aw_d
114 type(c_ptr), value :: u_d, v_d, w_d
115 type(c_ptr), value :: h2_d, B_d
116 integer(c_int) :: n
118 end interface
119
120#elif HAVE_OPENCL
121 interface
122 subroutine opencl_ax_helm_stress_vector(au_d, av_d, aw_d, u_d, v_d, w_d, &
123 dx_d, dy_d, dz_d, dxt_d, dyt_d, dzt_d,&
124 h1_d, drdx_d, drdy_d, drdz_d, &
125 dsdx_d, dsdy_d, dsdz_d, &
126 dtdx_d, dtdy_d, dtdz_d, jacinv_d, weight3_d, nelv, lx) &
127 bind(c, name='opencl_ax_helm_stress_vector')
128 use, intrinsic :: iso_c_binding
129 type(c_ptr), value :: au_d, av_d, aw_d
130 type(c_ptr), value :: u_d, v_d, w_d
131 type(c_ptr), value :: dx_d, dy_d, dz_d
132 type(c_ptr), value :: dxt_d, dyt_d, dzt_d
133 type(c_ptr), value :: h1_d
134 type(c_ptr), value :: drdx_d, drdy_d, drdz_d
135 type(c_ptr), value :: dsdx_d, dsdy_d, dsdz_d
136 type(c_ptr), value :: dtdx_d, dtdy_d, dtdz_d
137 type(c_ptr), value :: jacinv_d, weight3_d
138 integer(c_int) :: nelv, lx
139 end subroutine opencl_ax_helm_stress_vector
140 end interface
141
142 interface
143 subroutine opencl_ax_helm_stress_vector_part2(au_d, av_d, aw_d, &
144 u_d, v_d, w_d, h2_d, B_d, n) &
145 bind(c, name='opencl_ax_helm_stress_vector_part2')
146 use, intrinsic :: iso_c_binding
147 type(c_ptr), value :: au_d, av_d, aw_d
148 type(c_ptr), value :: u_d, v_d, w_d
149 type(c_ptr), value :: h2_d, B_d
150 integer(c_int) :: n
152 end interface
153#elif HAVE_METAL
154 interface
155 subroutine metal_ax_helm_stress_vector(au_d, av_d, aw_d, u_d, v_d, w_d, &
156 dx_d, dy_d, dz_d, dxt_d, dyt_d, dzt_d,&
157 h1_d, drdx_d, drdy_d, drdz_d, &
158 dsdx_d, dsdy_d, dsdz_d, &
159 dtdx_d, dtdy_d, dtdz_d, jacinv_d, weight3_d, nelv, lx) &
160 bind(c, name='metal_ax_helm_stress_vector')
161 use, intrinsic :: iso_c_binding
162 type(c_ptr), value :: au_d, av_d, aw_d
163 type(c_ptr), value :: u_d, v_d, w_d
164 type(c_ptr), value :: dx_d, dy_d, dz_d
165 type(c_ptr), value :: dxt_d, dyt_d, dzt_d
166 type(c_ptr), value :: h1_d
167 type(c_ptr), value :: drdx_d, drdy_d, drdz_d
168 type(c_ptr), value :: dsdx_d, dsdy_d, dsdz_d
169 type(c_ptr), value :: dtdx_d, dtdy_d, dtdz_d
170 type(c_ptr), value :: jacinv_d, weight3_d
171 integer(c_int) :: nelv, lx
172 end subroutine metal_ax_helm_stress_vector
173 end interface
174
175 interface
176 subroutine metal_ax_helm_stress_vector_part2(au_d, av_d, aw_d, &
177 u_d, v_d, w_d, h2_d, B_d, n) &
178 bind(c, name='metal_ax_helm_stress_vector_part2')
179 use, intrinsic :: iso_c_binding
180 type(c_ptr), value :: au_d, av_d, aw_d
181 type(c_ptr), value :: u_d, v_d, w_d
182 type(c_ptr), value :: h2_d, B_d
183 integer(c_int) :: n
184 end subroutine metal_ax_helm_stress_vector_part2
185 end interface
186#endif
187
188contains
189
190 subroutine ax_helm_full_device_compute_vector(this, au, av, aw, &
191 u, v, w, coef, msh, Xh)
192 class(ax_helm_full_device_t), intent(in) :: this
193 type(space_t), intent(in) :: Xh
194 type(mesh_t), intent(in) :: msh
195 type(coef_t), intent(in) :: coef
196 real(kind=rp), intent(inout) :: au(xh%lx, xh%ly, xh%lz, msh%nelv)
197 real(kind=rp), intent(inout) :: av(xh%lx, xh%ly, xh%lz, msh%nelv)
198 real(kind=rp), intent(inout) :: aw(xh%lx, xh%ly, xh%lz, msh%nelv)
199 real(kind=rp), intent(in) :: u(xh%lx, xh%ly, xh%lz, msh%nelv)
200 real(kind=rp), intent(in) :: v(xh%lx, xh%ly, xh%lz, msh%nelv)
201 real(kind=rp), intent(in) :: w(xh%lx, xh%ly, xh%lz, msh%nelv)
202 type(c_ptr) :: u_d, v_d, w_d
203 type(c_ptr) :: au_d, av_d, aw_d
204
205 u_d = device_get_ptr(u)
206 v_d = device_get_ptr(v)
207 w_d = device_get_ptr(w)
208
209 au_d = device_get_ptr(au)
210 av_d = device_get_ptr(av)
211 aw_d = device_get_ptr(aw)
212
213#ifdef HAVE_HIP
214 call hip_ax_helm_stress_vector(au_d, av_d, aw_d, u_d, v_d, w_d, &
215 xh%dx_d, xh%dy_d, xh%dz_d, xh%dxt_d, xh%dyt_d, xh%dzt_d, coef%h1_d, &
216 coef%drdx_d, coef%drdy_d, coef%drdz_d, &
217 coef%dsdx_d, coef%dsdy_d, coef%dsdz_d, &
218 coef%dtdx_d, coef%dtdy_d, coef%dtdz_d, &
219 coef%jacinv_d, xh%w3_d, msh%nelv, xh%lx)
220#elif HAVE_CUDA
221 call cuda_ax_helm_stress_vector(au_d, av_d, aw_d, u_d, v_d, w_d, &
222 xh%dx_d, xh%dy_d, xh%dz_d, xh%dxt_d, xh%dyt_d, xh%dzt_d, coef%h1_d, &
223 coef%drdx_d, coef%drdy_d, coef%drdz_d, &
224 coef%dsdx_d, coef%dsdy_d, coef%dsdz_d, &
225 coef%dtdx_d, coef%dtdy_d, coef%dtdz_d, &
226 coef%jacinv_d, xh%w3_d, msh%nelv, xh%lx)
227#elif HAVE_OPENCL
228 call opencl_ax_helm_stress_vector(au_d, av_d, aw_d, u_d, v_d, w_d, &
229 xh%dx_d, xh%dy_d, xh%dz_d, xh%dxt_d, xh%dyt_d, xh%dzt_d, coef%h1_d, &
230 coef%drdx_d, coef%drdy_d, coef%drdz_d, &
231 coef%dsdx_d, coef%dsdy_d, coef%dsdz_d, &
232 coef%dtdx_d, coef%dtdy_d, coef%dtdz_d, &
233 coef%jacinv_d, xh%w3_d, msh%nelv, xh%lx)
234#elif HAVE_METAL
235 call metal_ax_helm_stress_vector(au_d, av_d, aw_d, u_d, v_d, w_d, &
236 xh%dx_d, xh%dy_d, xh%dz_d, xh%dxt_d, xh%dyt_d, xh%dzt_d, coef%h1_d, &
237 coef%drdx_d, coef%drdy_d, coef%drdz_d, &
238 coef%dsdx_d, coef%dsdy_d, coef%dsdz_d, &
239 coef%dtdx_d, coef%dtdy_d, coef%dtdz_d, &
240 coef%jacinv_d, xh%w3_d, msh%nelv, xh%lx)
241#endif
242
243 if (coef%ifh2) then
244#ifdef HAVE_HIP
245 call hip_ax_helm_stress_vector_part2(au_d, av_d, aw_d, u_d, v_d, w_d, &
246 coef%h2_d, coef%B_d, coef%dof%size())
247#elif HAVE_CUDA
248 call cuda_ax_helm_stress_vector_part2(au_d, av_d, aw_d, u_d, v_d, w_d, &
249 coef%h2_d, coef%B_d, coef%dof%size())
250#elif HAVE_OPENCL
251 call opencl_ax_helm_stress_vector_part2(au_d, av_d, aw_d, u_d, v_d, &
252 w_d, coef%h2_d, coef%B_d, coef%dof%size())
253#elif HAVE_METAL
254 call metal_ax_helm_stress_vector_part2(au_d, av_d, aw_d, u_d, v_d, &
255 w_d, coef%h2_d, coef%B_d, coef%dof%size())
256#endif
257 end if
258
260
261end module ax_helm_full_device
void opencl_ax_helm_stress_vector(void *au, void *av, void *aw, void *u, void *v, void *w, void *dx, void *dy, void *dz, void *dxt, void *dyt, void *dzt, void *h1, void *drdx, void *drdy, void *drdz, void *dsdx, void *dsdy, void *dsdz, void *dtdx, void *dtdy, void *dtdz, void *jacinv, void *w3, int *nelv, int *lx)
void opencl_ax_helm_stress_vector_part2(void *au, void *av, void *aw, void *u, void *v, void *w, void *h2, void *B, int *n)
void cuda_ax_helm_stress_vector(void *au, void *av, void *aw, void *u, void *v, void *w, void *dx, void *dy, void *dz, void *dxt, void *dyt, void *dzt, void *h1, void *drdx, void *drdy, void *drdz, void *dsdx, void *dsdy, void *dsdz, void *dtdx, void *dtdy, void *dtdz, void *jacinv, void *w3, int *nelv, int *lx)
void cuda_ax_helm_stress_vector_part2(void *au, void *av, void *aw, void *u, void *v, void *w, void *h2, void *B, int *n)
Return the device pointer for an associated Fortran array.
Definition device.F90:113
subroutine ax_helm_full_device_compute_vector(this, au, av, aw, u, v, w, coef, msh, xh)
Coefficients.
Definition coef.f90:34
subroutine, public device_addcol4(a_d, b_d, c_d, d_d, n, strm)
Returns .
Device abstraction, common interface for various accelerators.
Definition device.F90:34
Defines a mesh.
Definition mesh.f90:34
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Defines a function space.
Definition space.f90:34
Matrix-vector product for a Helmholtz problem.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:63
The function space for the SEM solution fields.
Definition space.f90:64