Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
ax_helm_compr_device.F90
Go to the documentation of this file.
1! Copyright (c) 2026, 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!
36 use num_types, only : rp
37 use coefs, only : coef_t
38 use space, only : space_t
39 use mesh, only : mesh_t
40 use device_math, only : device_addcol4
41 use device, only : device_get_ptr
42 use utils, only : neko_error
43 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
44 implicit none
45 private
46
53 type, public, extends(ax_helm_device_t) :: ax_helm_compr_device_t
54 contains
55 procedure, pass(this) :: compute => ax_helm_compr_device_compute
56 procedure, pass(this) :: compute_vector => &
59
60#ifdef HAVE_HIP
61 interface
62 subroutine hip_ax_helm_compr(w_d, u_d, &
63 dx_d, dy_d, dz_d, dxt_d, dyt_d, dzt_d, &
64 h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d, ind_d, nelv, lx) &
65 bind(c, name='hip_ax_helm_compr')
66 use, intrinsic :: iso_c_binding
67 type(c_ptr), value :: w_d, u_d
68 type(c_ptr), value :: dx_d, dy_d, dz_d
69 type(c_ptr), value :: dxt_d, dyt_d, dzt_d
70 type(c_ptr), value :: h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d
71 type(c_ptr), value :: ind_d
72 integer(c_int) :: nelv, lx
73 end subroutine hip_ax_helm_compr
74 end interface
75
76 interface
77 subroutine hip_ax_helm_compr_vector(au_d, av_d, aw_d, u_d, v_d, w_d, &
78 dx_d, dy_d, dz_d, dxt_d, dyt_d, dzt_d, &
79 h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d, ind_d, nelv, lx) &
80 bind(c, name='hip_ax_helm_compr_vector')
81 use, intrinsic :: iso_c_binding
82 type(c_ptr), value :: au_d, av_d, aw_d
83 type(c_ptr), value :: u_d, v_d, w_d
84 type(c_ptr), value :: dx_d, dy_d, dz_d
85 type(c_ptr), value :: dxt_d, dyt_d, dzt_d
86 type(c_ptr), value :: h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d
87 type(c_ptr), value :: ind_d
88 integer(c_int) :: nelv, lx
89 end subroutine hip_ax_helm_compr_vector
90 end interface
91
92 interface
93 subroutine hip_ax_helm_vector_part2(au_d, av_d, aw_d, u_d, v_d, w_d, &
94 h2_d, B_d, n) bind(c, name='hip_ax_helm_vector_part2')
95 use, intrinsic :: iso_c_binding
96 type(c_ptr), value :: au_d, av_d, aw_d
97 type(c_ptr), value :: u_d, v_d, w_d
98 type(c_ptr), value :: h2_d, B_d
99 integer(c_int) :: n
100 end subroutine hip_ax_helm_vector_part2
101 end interface
102#elif HAVE_CUDA
103 interface
104 subroutine cuda_ax_helm_compr(w_d, u_d, &
105 dx_d, dy_d, dz_d, dxt_d, dyt_d, dzt_d, &
106 h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d, ind_d, nelv, lx) &
107 bind(c, name='cuda_ax_helm_compr')
108 use, intrinsic :: iso_c_binding
109 type(c_ptr), value :: w_d, u_d
110 type(c_ptr), value :: dx_d, dy_d, dz_d
111 type(c_ptr), value :: dxt_d, dyt_d, dzt_d
112 type(c_ptr), value :: h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d
113 type(c_ptr), value :: ind_d
114 integer(c_int) :: nelv, lx
115 end subroutine cuda_ax_helm_compr
116 end interface
117
118 interface
119 subroutine cuda_ax_helm_compr_vector(au_d, av_d, aw_d, u_d, v_d, w_d, &
120 dx_d, dy_d, dz_d, dxt_d, dyt_d, dzt_d, &
121 h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d, ind_d, nelv, lx) &
122 bind(c, name='cuda_ax_helm_compr_vector')
123 use, intrinsic :: iso_c_binding
124 type(c_ptr), value :: au_d, av_d, aw_d
125 type(c_ptr), value :: u_d, v_d, w_d
126 type(c_ptr), value :: dx_d, dy_d, dz_d
127 type(c_ptr), value :: dxt_d, dyt_d, dzt_d
128 type(c_ptr), value :: h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d
129 type(c_ptr), value :: ind_d
130 integer(c_int) :: nelv, lx
131 end subroutine cuda_ax_helm_compr_vector
132 end interface
133
134 interface
135 subroutine cuda_ax_helm_vector_part2(au_d, av_d, aw_d, u_d, v_d, w_d, &
136 h2_d, B_d, n) bind(c, name='cuda_ax_helm_vector_part2')
137 use, intrinsic :: iso_c_binding
138 type(c_ptr), value :: au_d, av_d, aw_d
139 type(c_ptr), value :: u_d, v_d, w_d
140 type(c_ptr), value :: h2_d, B_d
141 integer(c_int) :: n
142 end subroutine cuda_ax_helm_vector_part2
143 end interface
144#elif HAVE_OPENCL
145 interface
146 subroutine opencl_ax_helm_compr(w_d, u_d, &
147 dx_d, dy_d, dz_d, dxt_d, dyt_d, dzt_d, &
148 h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d, ind_d, nelv, lx) &
149 bind(c, name='opencl_ax_helm_compr')
150 use, intrinsic :: iso_c_binding
151 type(c_ptr), value :: w_d, u_d
152 type(c_ptr), value :: dx_d, dy_d, dz_d
153 type(c_ptr), value :: dxt_d, dyt_d, dzt_d
154 type(c_ptr), value :: h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d
155 type(c_ptr), value :: ind_d
156 integer(c_int) :: nelv, lx
157 end subroutine opencl_ax_helm_compr
158 end interface
159
160 interface
161 subroutine opencl_ax_helm_compr_vector(au_d, av_d, aw_d, u_d, v_d, w_d, &
162 dx_d, dy_d, dz_d, dxt_d, dyt_d, dzt_d, &
163 h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d, ind_d, nelv, lx) &
164 bind(c, name='opencl_ax_helm_compr_vector')
165 use, intrinsic :: iso_c_binding
166 type(c_ptr), value :: au_d, av_d, aw_d
167 type(c_ptr), value :: u_d, v_d, w_d
168 type(c_ptr), value :: dx_d, dy_d, dz_d
169 type(c_ptr), value :: dxt_d, dyt_d, dzt_d
170 type(c_ptr), value :: h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d
171 type(c_ptr), value :: ind_d
172 integer(c_int) :: nelv, lx
173 end subroutine opencl_ax_helm_compr_vector
174 end interface
175
176 interface
177 subroutine opencl_ax_helm_vector_part2(au_d, av_d, aw_d, u_d, v_d, w_d, &
178 h2_d, B_d, n) bind(c, name='opencl_ax_helm_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 opencl_ax_helm_vector_part2
185 end interface
186#elif HAVE_METAL
187 interface
188 subroutine metal_ax_helm_compr(w_d, u_d, &
189 dx_d, dy_d, dz_d, dxt_d, dyt_d, dzt_d, &
190 h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d, ind_d, nelv, lx) &
191 bind(c, name='metal_ax_helm_compr')
192 use, intrinsic :: iso_c_binding
193 type(c_ptr), value :: w_d, u_d
194 type(c_ptr), value :: dx_d, dy_d, dz_d
195 type(c_ptr), value :: dxt_d, dyt_d, dzt_d
196 type(c_ptr), value :: h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d
197 type(c_ptr), value :: ind_d
198 integer(c_int) :: nelv, lx
199 end subroutine metal_ax_helm_compr
200 end interface
201
202 interface
203 subroutine metal_ax_helm_compr_vector(au_d, av_d, aw_d, u_d, v_d, w_d, &
204 dx_d, dy_d, dz_d, dxt_d, dyt_d, dzt_d, &
205 h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d, ind_d, nelv, lx) &
206 bind(c, name='metal_ax_helm_compr_vector')
207 use, intrinsic :: iso_c_binding
208 type(c_ptr), value :: au_d, av_d, aw_d
209 type(c_ptr), value :: u_d, v_d, w_d
210 type(c_ptr), value :: dx_d, dy_d, dz_d
211 type(c_ptr), value :: dxt_d, dyt_d, dzt_d
212 type(c_ptr), value :: h1_d, g11_d, g22_d, g33_d, g12_d, g13_d, g23_d
213 type(c_ptr), value :: ind_d
214 integer(c_int) :: nelv, lx
215 end subroutine metal_ax_helm_compr_vector
216 end interface
217
218 interface
219 subroutine metal_ax_helm_vector_part2(au_d, av_d, aw_d, u_d, v_d, w_d, &
220 h2_d, B_d, n) bind(c, name='metal_ax_helm_vector_part2')
221 use, intrinsic :: iso_c_binding
222 type(c_ptr), value :: au_d, av_d, aw_d
223 type(c_ptr), value :: u_d, v_d, w_d
224 type(c_ptr), value :: h2_d, B_d
225 integer(c_int) :: n
226 end subroutine metal_ax_helm_vector_part2
227 end interface
228#endif
229
230contains
231
232 subroutine ax_helm_compr_device_compute(this, w, u, coef, msh, Xh)
233 class(ax_helm_compr_device_t), intent(in) :: this
234 type(mesh_t), intent(in) :: msh
235 type(space_t), intent(in) :: Xh
236 type(coef_t), intent(in) :: coef
237 real(kind=rp), intent(inout) :: w(xh%lx, xh%ly, xh%lz, msh%nelv)
238 real(kind=rp), intent(in) :: u(xh%lx, xh%ly, xh%lz, msh%nelv)
239 type(c_ptr) :: u_d, w_d
240
241 if (.not. allocated(coef%compression_inds)) then
242 call this%ax_helm_device_t%compute(w, u, coef, msh, xh)
243 return
244 end if
245
246 if (size(coef%compression_inds) .ne. msh%nelv) then
247 call neko_error('Compressed geometric factors do not match the mesh')
248 end if
249
250 u_d = device_get_ptr(u)
251 w_d = device_get_ptr(w)
252
253#ifdef HAVE_HIP
254 call hip_ax_helm_compr(w_d, u_d, xh%dx_d, xh%dy_d, xh%dz_d, &
255 xh%dxt_d, xh%dyt_d, xh%dzt_d, coef%h1_d, &
256 coef%G11_compr_d, coef%G22_compr_d, coef%G33_compr_d, &
257 coef%G12_compr_d, coef%G13_compr_d, coef%G23_compr_d, &
258 coef%compression_inds_d, msh%nelv, xh%lx)
259#elif HAVE_CUDA
260 call cuda_ax_helm_compr(w_d, u_d, xh%dx_d, xh%dy_d, xh%dz_d, &
261 xh%dxt_d, xh%dyt_d, xh%dzt_d, coef%h1_d, &
262 coef%G11_compr_d, coef%G22_compr_d, coef%G33_compr_d, &
263 coef%G12_compr_d, coef%G13_compr_d, coef%G23_compr_d, &
264 coef%compression_inds_d, msh%nelv, xh%lx)
265#elif HAVE_OPENCL
266 call opencl_ax_helm_compr(w_d, u_d, xh%dx_d, xh%dy_d, xh%dz_d, &
267 xh%dxt_d, xh%dyt_d, xh%dzt_d, coef%h1_d, &
268 coef%G11_compr_d, coef%G22_compr_d, coef%G33_compr_d, &
269 coef%G12_compr_d, coef%G13_compr_d, coef%G23_compr_d, &
270 coef%compression_inds_d, msh%nelv, xh%lx)
271#elif HAVE_METAL
272 call metal_ax_helm_compr(w_d, u_d, xh%dx_d, xh%dy_d, xh%dz_d, &
273 xh%dxt_d, xh%dyt_d, xh%dzt_d, coef%h1_d, &
274 coef%G11_compr_d, coef%G22_compr_d, coef%G33_compr_d, &
275 coef%G12_compr_d, coef%G13_compr_d, coef%G23_compr_d, &
276 coef%compression_inds_d, msh%nelv, xh%lx)
277#endif
278
279 if (coef%ifh2) then
280 call device_addcol4(w_d, coef%h2_d, coef%B_d, u_d, coef%dof%size())
281 end if
282
283 end subroutine ax_helm_compr_device_compute
284
285 subroutine ax_helm_compr_device_compute_vector(this, au, av, aw, &
286 u, v, w, coef, msh, Xh)
287 class(ax_helm_compr_device_t), intent(in) :: this
288 type(space_t), intent(in) :: Xh
289 type(mesh_t), intent(in) :: msh
290 type(coef_t), intent(in) :: coef
291 real(kind=rp), intent(inout) :: au(xh%lx, xh%ly, xh%lz, msh%nelv)
292 real(kind=rp), intent(inout) :: av(xh%lx, xh%ly, xh%lz, msh%nelv)
293 real(kind=rp), intent(inout) :: aw(xh%lx, xh%ly, xh%lz, msh%nelv)
294 real(kind=rp), intent(in) :: u(xh%lx, xh%ly, xh%lz, msh%nelv)
295 real(kind=rp), intent(in) :: v(xh%lx, xh%ly, xh%lz, msh%nelv)
296 real(kind=rp), intent(in) :: w(xh%lx, xh%ly, xh%lz, msh%nelv)
297 type(c_ptr) :: u_d, v_d, w_d
298 type(c_ptr) :: au_d, av_d, aw_d
299
300 if (.not. allocated(coef%compression_inds)) then
301 call this%ax_helm_device_t%compute_vector(au, av, aw, u, v, w, &
302 coef, msh, xh)
303 return
304 end if
305
306 if (size(coef%compression_inds) .ne. msh%nelv) then
307 call neko_error('Compressed geometric factors do not match the mesh')
308 end if
309
310 u_d = device_get_ptr(u)
311 v_d = device_get_ptr(v)
312 w_d = device_get_ptr(w)
313
314 au_d = device_get_ptr(au)
315 av_d = device_get_ptr(av)
316 aw_d = device_get_ptr(aw)
317
318#ifdef HAVE_HIP
319 call hip_ax_helm_compr_vector(au_d, av_d, aw_d, u_d, v_d, w_d, &
320 xh%dx_d, xh%dy_d, xh%dz_d, xh%dxt_d, xh%dyt_d, xh%dzt_d, coef%h1_d, &
321 coef%G11_compr_d, coef%G22_compr_d, coef%G33_compr_d, &
322 coef%G12_compr_d, coef%G13_compr_d, coef%G23_compr_d, &
323 coef%compression_inds_d, msh%nelv, xh%lx)
324#elif HAVE_CUDA
325 call cuda_ax_helm_compr_vector(au_d, av_d, aw_d, u_d, v_d, w_d, &
326 xh%dx_d, xh%dy_d, xh%dz_d, xh%dxt_d, xh%dyt_d, xh%dzt_d, coef%h1_d, &
327 coef%G11_compr_d, coef%G22_compr_d, coef%G33_compr_d, &
328 coef%G12_compr_d, coef%G13_compr_d, coef%G23_compr_d, &
329 coef%compression_inds_d, msh%nelv, xh%lx)
330#elif HAVE_OPENCL
331 call opencl_ax_helm_compr_vector(au_d, av_d, aw_d, u_d, v_d, w_d, &
332 xh%dx_d, xh%dy_d, xh%dz_d, xh%dxt_d, xh%dyt_d, xh%dzt_d, coef%h1_d, &
333 coef%G11_compr_d, coef%G22_compr_d, coef%G33_compr_d, &
334 coef%G12_compr_d, coef%G13_compr_d, coef%G23_compr_d, &
335 coef%compression_inds_d, msh%nelv, xh%lx)
336#elif HAVE_METAL
337 call metal_ax_helm_compr_vector(au_d, av_d, aw_d, u_d, v_d, w_d, &
338 xh%dx_d, xh%dy_d, xh%dz_d, xh%dxt_d, xh%dyt_d, xh%dzt_d, coef%h1_d, &
339 coef%G11_compr_d, coef%G22_compr_d, coef%G33_compr_d, &
340 coef%G12_compr_d, coef%G13_compr_d, coef%G23_compr_d, &
341 coef%compression_inds_d, msh%nelv, xh%lx)
342#endif
343
344 if (coef%ifh2) then
345#ifdef HAVE_HIP
346 call hip_ax_helm_vector_part2(au_d, av_d, aw_d, u_d, v_d, w_d, &
347 coef%h2_d, coef%B_d, coef%dof%size())
348#elif HAVE_CUDA
349 call cuda_ax_helm_vector_part2(au_d, av_d, aw_d, u_d, v_d, w_d, &
350 coef%h2_d, coef%B_d, coef%dof%size())
351#elif HAVE_OPENCL
352 call opencl_ax_helm_vector_part2(au_d, av_d, aw_d, u_d, v_d, w_d, &
353 coef%h2_d, coef%B_d, coef%dof%size())
354#elif HAVE_METAL
355 call metal_ax_helm_vector_part2(au_d, av_d, aw_d, u_d, v_d, w_d, &
356 coef%h2_d, coef%B_d, coef%dof%size())
357#endif
358 end if
359
361
362end module ax_helm_compr_device
void opencl_ax_helm_vector_part2(void *au, void *av, void *aw, void *u, void *v, void *w, void *h2, void *B, int *n)
Definition ax_helm.c:341
void cuda_ax_helm_vector_part2(void *au, void *av, void *aw, void *u, void *v, void *w, void *h2, void *B, int *n)
Definition ax_helm.cu:497
void opencl_ax_helm_compr(void *w, void *u, void *dx, void *dy, void *dz, void *dxt, void *dyt, void *dzt, void *h1, void *g11, void *g22, void *g33, void *g12, void *g13, void *g23, void *ind, int *nelv, int *lx)
void opencl_ax_helm_compr_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 *g11, void *g22, void *g33, void *g12, void *g13, void *g23, void *ind, int *nelv, int *lx)
void cuda_ax_helm_compr_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 *g11, void *g22, void *g33, void *g12, void *g13, void *g23, void *ind, int *nelv, int *lx)
void cuda_ax_helm_compr(void *w, void *u, void *dx, void *dy, void *dz, void *dxt, void *dyt, void *dzt, void *h1, void *g11, void *g22, void *g33, void *g12, void *g13, void *g23, void *ind, int *nelv, int *lx)
Return the device pointer for an associated Fortran array.
Definition device.F90:113
Device Helmholtz matrix-vector product on compressed geometric factors.
subroutine ax_helm_compr_device_compute(this, w, u, coef, msh, xh)
subroutine ax_helm_compr_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:14
Defines a function space.
Definition space.f90:34
Utilities.
Definition utils.f90:35
Device matrix-vector product for a Helmholtz problem, reading the geometric factors from their compr...
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:136
The function space for the SEM solution fields.
Definition space.f90:64