Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
compressible_ops_device.F90
Go to the documentation of this file.
1! Copyright (c) 2025, 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, intrinsic :: iso_c_binding, only: c_ptr, c_int
36 use num_types, only: rp, c_rp
37 use field, only: field_t
38 use utils, only: neko_error
39 implicit none
40 private
41
42#ifdef HAVE_HIP
43 interface
44 subroutine hip_compute_max_wave_speed(max_wave_speed_d, u_d, v_d, w_d, &
45 gamma, p_d, rho_d, n) &
46 bind(c, name = 'hip_compute_max_wave_speed')
47 use, intrinsic :: iso_c_binding
48 import c_rp
49 type(c_ptr), value :: max_wave_speed_d, u_d, v_d, w_d, p_d, rho_d
50 real(c_rp) :: gamma
51 integer(c_int) :: n
52 end subroutine hip_compute_max_wave_speed
53 end interface
54
55 interface
56 subroutine hip_compute_entropy(S_d, p_d, rho_d, gamma, n) &
57 bind(c, name = 'hip_compute_entropy')
58 use, intrinsic :: iso_c_binding
59 import c_rp
60 type(c_ptr), value :: S_d, p_d, rho_d
61 real(c_rp) :: gamma
62 integer(c_int) :: n
63 end subroutine hip_compute_entropy
64 end interface
65
66 interface
67 subroutine hip_update_uvw(u_d, v_d, w_d, m_x_d, &
68 m_y_d, m_z_d, rho_d, n) &
69 bind(c, name = 'hip_update_uvw')
70 use, intrinsic :: iso_c_binding
71 import c_rp
72 type(c_ptr), value :: u_d, v_d, w_d, m_x_d, m_y_d, m_z_d, rho_d
73 integer(c_int) :: n
74 end subroutine hip_update_uvw
75 end interface
76
77 interface
78 subroutine hip_update_mxyz_p_ruvw(m_x_d, m_y_d, m_z_d, &
79 p_d, ruvw_d, u_d, v_d, w_d, E_d, rho_d, gamma, n) &
80 bind(c, name = 'hip_update_mxyz_p_ruvw')
81 use, intrinsic :: iso_c_binding
82 import c_rp
83 type(c_ptr), value :: u_d, v_d, w_d, m_x_d, m_y_d, m_z_d, rho_d
84 type(c_ptr), value :: p_d, ruvw_d, E_d
85 real(c_rp) :: gamma
86 integer(c_int) :: n
87 end subroutine hip_update_mxyz_p_ruvw
88 end interface
89
90 interface
91 subroutine hip_update_e(E_d, p_d, ruvw_d, gamma, n) &
92 bind(c, name = 'hip_update_e')
93 use, intrinsic :: iso_c_binding
94 import c_rp
95 type(c_ptr), value :: p_d, E_d, ruvw_d
96 real(c_rp) :: gamma
97 integer(c_int) :: n
98 end subroutine hip_update_e
99 end interface
100
101#elif HAVE_CUDA
102 interface
103 subroutine cuda_compute_max_wave_speed(max_wave_speed_d, u_d, v_d, w_d, &
104 gamma, p_d, rho_d, n) &
105 bind(c, name = 'cuda_compute_max_wave_speed')
106 use, intrinsic :: iso_c_binding
107 import c_rp
108 type(c_ptr), value :: max_wave_speed_d, u_d, v_d, w_d, p_d, rho_d
109 real(c_rp) :: gamma
110 integer(c_int) :: n
111 end subroutine cuda_compute_max_wave_speed
112 end interface
113
114 interface
115 subroutine cuda_compute_entropy(S_d, p_d, rho_d, gamma, n) &
116 bind(c, name = 'cuda_compute_entropy')
117 use, intrinsic :: iso_c_binding
118 import c_rp
119 type(c_ptr), value :: S_d, p_d, rho_d
120 real(c_rp) :: gamma
121 integer(c_int) :: n
122 end subroutine cuda_compute_entropy
123 end interface
124
125 interface
126 subroutine cuda_update_uvw(u_d, v_d, w_d, m_x_d, &
127 m_y_d, m_z_d, rho_d, n) &
128 bind(c, name = 'cuda_update_uvw')
129 use, intrinsic :: iso_c_binding
130 import c_rp
131 type(c_ptr), value :: u_d, v_d, w_d, m_x_d, m_y_d, m_z_d, rho_d
132 integer(c_int) :: n
133 end subroutine cuda_update_uvw
134 end interface
135
136 interface
137 subroutine cuda_update_mxyz_p_ruvw(m_x_d, m_y_d, m_z_d, &
138 p_d, ruvw_d, u_d, v_d, w_d, E_d, rho_d, gamma, n) &
139 bind(c, name = 'cuda_update_mxyz_p_ruvw')
140 use, intrinsic :: iso_c_binding
141 import c_rp
142 type(c_ptr), value :: u_d, v_d, w_d, m_x_d, m_y_d, m_z_d, rho_d
143 type(c_ptr), value :: p_d, ruvw_d, E_d
144 real(c_rp) :: gamma
145 integer(c_int) :: n
146 end subroutine cuda_update_mxyz_p_ruvw
147 end interface
148
149 interface
150 subroutine cuda_update_e(E_d, p_d, ruvw_d, gamma, n) &
151 bind(c, name = 'cuda_update_e')
152 use, intrinsic :: iso_c_binding
153 import c_rp
154 type(c_ptr), value :: p_d, E_d, ruvw_d
155 real(c_rp) :: gamma
156 integer(c_int) :: n
157 end subroutine cuda_update_e
158 end interface
159
160#elif HAVE_OPENCL
161 interface
162 subroutine opencl_compute_max_wave_speed(max_wave_speed_d, u_d, v_d, w_d, &
163 gamma, p_d, rho_d, n) &
164 bind(c, name = 'opencl_compute_max_wave_speed')
165 use, intrinsic :: iso_c_binding
166 import c_rp
167 type(c_ptr), value :: max_wave_speed_d, u_d, v_d, w_d, p_d, rho_d
168 real(c_rp), value :: gamma
169 integer(c_int), value :: n
170 end subroutine opencl_compute_max_wave_speed
171 end interface
172
173 interface
174 subroutine opencl_compute_entropy(S_d, p_d, rho_d, gamma, n) &
175 bind(c, name = 'opencl_compute_entropy')
176 use, intrinsic :: iso_c_binding
177 import c_rp
178 type(c_ptr), value :: S_d, p_d, rho_d
179 real(c_rp), value :: gamma
180 integer(c_int), value :: n
181 end subroutine opencl_compute_entropy
182 end interface
183
184 interface
185 subroutine opencl_update_uvw(u_d, v_d, w_d, m_x_d, &
186 m_y_d, m_z_d, rho_d, n) &
187 bind(c, name = 'opencl_update_uvw')
188 use, intrinsic :: iso_c_binding
189 import c_rp
190 type(c_ptr), value :: u_d, v_d, w_d, m_x_d, m_y_d, m_z_d, rho_d
191 integer(c_int), value :: n
192 end subroutine opencl_update_uvw
193 end interface
194
195 interface
196 subroutine opencl_update_mxyz_p_ruvw(m_x_d, m_y_d, m_z_d, &
197 p_d, ruvw_d, u_d, v_d, w_d, E_d, rho_d, gamma, n) &
198 bind(c, name = 'opencl_update_mxyz_p_ruvw')
199 use, intrinsic :: iso_c_binding
200 import c_rp
201 type(c_ptr), value :: u_d, v_d, w_d, m_x_d, m_y_d, m_z_d, rho_d
202 type(c_ptr), value :: p_d, ruvw_d, E_d
203 real(c_rp), value :: gamma
204 integer(c_int), value :: n
205 end subroutine opencl_update_mxyz_p_ruvw
206 end interface
207
208 interface
209 subroutine opencl_update_e(E_d, p_d, ruvw_d, gamma, n) &
210 bind(c, name = 'opencl_update_e')
211 use, intrinsic :: iso_c_binding
212 import c_rp
213 type(c_ptr), value :: p_d, E_d, ruvw_d
214 real(c_rp), value :: gamma
215 integer(c_int), value :: n
216 end subroutine opencl_update_e
217 end interface
218#elif HAVE_METAL
219 interface
220 subroutine metal_compute_max_wave_speed(max_wave_speed_d, u_d, v_d, w_d, &
221 gamma, p_d, rho_d, n) &
222 bind(c, name = 'metal_compute_max_wave_speed')
223 use, intrinsic :: iso_c_binding
224 import c_rp
225 type(c_ptr), value :: max_wave_speed_d, u_d, v_d, w_d, p_d, rho_d
226 real(c_rp), value :: gamma
227 integer(c_int), value :: n
228 end subroutine metal_compute_max_wave_speed
229 end interface
230
231 interface
232 subroutine metal_compute_entropy(S_d, p_d, rho_d, gamma, n) &
233 bind(c, name = 'metal_compute_entropy')
234 use, intrinsic :: iso_c_binding
235 import c_rp
236 type(c_ptr), value :: S_d, p_d, rho_d
237 real(c_rp), value :: gamma
238 integer(c_int), value :: n
239 end subroutine metal_compute_entropy
240 end interface
241
242 interface
243 subroutine metal_update_uvw(u_d, v_d, w_d, m_x_d, &
244 m_y_d, m_z_d, rho_d, n) &
245 bind(c, name = 'metal_update_uvw')
246 use, intrinsic :: iso_c_binding
247 import c_rp
248 type(c_ptr), value :: u_d, v_d, w_d, m_x_d, m_y_d, m_z_d, rho_d
249 integer(c_int), value :: n
250 end subroutine metal_update_uvw
251 end interface
252
253 interface
254 subroutine metal_update_mxyz_p_ruvw(m_x_d, m_y_d, m_z_d, &
255 p_d, ruvw_d, u_d, v_d, w_d, E_d, rho_d, gamma, n) &
256 bind(c, name = 'metal_update_mxyz_p_ruvw')
257 use, intrinsic :: iso_c_binding
258 import c_rp
259 type(c_ptr), value :: u_d, v_d, w_d, m_x_d, m_y_d, m_z_d, rho_d
260 type(c_ptr), value :: p_d, ruvw_d, E_d
261 real(c_rp), value :: gamma
262 integer(c_int), value :: n
263 end subroutine metal_update_mxyz_p_ruvw
264 end interface
265
266 interface
267 subroutine metal_update_e(E_d, p_d, ruvw_d, gamma, n) &
268 bind(c, name = 'metal_update_e')
269 use, intrinsic :: iso_c_binding
270 import c_rp
271 type(c_ptr), value :: p_d, E_d, ruvw_d
272 real(c_rp), value :: gamma
273 integer(c_int), value :: n
274 end subroutine metal_update_e
275 end interface
276#endif
277
283
284contains
285
287 subroutine compressible_ops_device_compute_max_wave_speed(max_wave_speed, u, v, w, gamma, p, rho, n)
288 integer, intent(in) :: n
289 real(kind=rp), intent(in) :: gamma
290 type(field_t), intent(inout) :: max_wave_speed
291 type(field_t), intent(in) :: u, v, w, p, rho
292
293#ifdef HAVE_HIP
294 call hip_compute_max_wave_speed(max_wave_speed%x_d, u%x_d, v%x_d, w%x_d, gamma, p%x_d, rho%x_d, n)
295#elif HAVE_CUDA
296 call cuda_compute_max_wave_speed(max_wave_speed%x_d, u%x_d, v%x_d, w%x_d, gamma, p%x_d, rho%x_d, n)
297#elif HAVE_OPENCL
298 call opencl_compute_max_wave_speed(max_wave_speed%x_d, u%x_d, v%x_d, w%x_d, gamma, p%x_d, rho%x_d, n)
299#elif HAVE_METAL
300 call metal_compute_max_wave_speed(max_wave_speed%x_d, u%x_d, v%x_d, w%x_d, gamma, p%x_d, rho%x_d, n)
301#else
302 call neko_error('No device backend configured')
303#endif
305
307 subroutine compressible_ops_device_compute_entropy(S, p, rho, gamma, n)
308 integer, intent(in) :: n
309 real(kind=rp), intent(in) :: gamma
310 type(field_t), intent(inout) :: s
311 type(field_t), intent(in) :: p, rho
312
313#ifdef HAVE_HIP
314 call hip_compute_entropy(s%x_d, p%x_d, rho%x_d, gamma, n)
315#elif HAVE_CUDA
316 call cuda_compute_entropy(s%x_d, p%x_d, rho%x_d, gamma, n)
317#elif HAVE_OPENCL
318 call opencl_compute_entropy(s%x_d, p%x_d, rho%x_d, gamma, n)
319#elif HAVE_METAL
320 call metal_compute_entropy(s%x_d, p%x_d, rho%x_d, gamma, n)
321#else
322 call neko_error('No device backend configured')
323#endif
325
327 subroutine compressible_ops_device_update_uvw(u_d, v_d, w_d, &
328 m_x_d, m_y_d, m_z_d, rho_d, n)
329 type(c_ptr), intent(inout) :: u_d, v_d, w_d
330 type(c_ptr), intent(in) :: m_x_d, m_y_d, m_z_d, rho_d
331 integer, intent(in) :: n
332 integer :: i
333
334#ifdef HAVE_HIP
335 call hip_update_uvw(u_d, v_d, w_d, m_x_d, m_y_d, m_z_d, rho_d, n)
336#elif HAVE_CUDA
337 call cuda_update_uvw(u_d, v_d, w_d, m_x_d, m_y_d, m_z_d, rho_d, n)
338#elif HAVE_OPENCL
339 call opencl_update_uvw(u_d, v_d, w_d, m_x_d, m_y_d, m_z_d, rho_d, n)
340#elif HAVE_METAL
341 call metal_update_uvw(u_d, v_d, w_d, m_x_d, m_y_d, m_z_d, rho_d, n)
342#else
343 call neko_error('No device backend configured')
344#endif
345
347
349 subroutine compressible_ops_device_update_mxyz_p_ruvw(m_x_d, m_y_d, m_z_d, &
350 p_d, ruvw_d, u_d, v_d, w_d, E_d, rho_d, gamma, n)
351 integer, intent(in) :: n
352 type(c_ptr), intent(inout) :: m_x_d, m_y_d, m_z_d, p_d, ruvw_d
353 type(c_ptr), intent(in) :: u_d, v_d, w_d, e_d, rho_d
354 real(kind=rp), intent(in) :: gamma
355
356
357#ifdef HAVE_HIP
358 call hip_update_mxyz_p_ruvw(m_x_d, m_y_d, m_z_d, &
359 p_d, ruvw_d, u_d, v_d, w_d, e_d, rho_d, gamma, n)
360#elif HAVE_CUDA
361 call cuda_update_mxyz_p_ruvw(m_x_d, m_y_d, m_z_d, &
362 p_d, ruvw_d, u_d, v_d, w_d, e_d, rho_d, gamma, n)
363#elif HAVE_OPENCL
364 call opencl_update_mxyz_p_ruvw(m_x_d, m_y_d, m_z_d, &
365 p_d, ruvw_d, u_d, v_d, w_d, e_d, rho_d, gamma, n)
366#elif HAVE_METAL
367 call metal_update_mxyz_p_ruvw(m_x_d, m_y_d, m_z_d, &
368 p_d, ruvw_d, u_d, v_d, w_d, e_d, rho_d, gamma, n)
369#else
370 call neko_error('No device backend configured')
371#endif
372
374
376 subroutine compressible_ops_device_update_e(E_d, p_d, ruvw_d, gamma, n)
377 integer, intent(in) :: n
378 type(c_ptr), intent(inout) :: e_d, p_d
379 ! ruvw = 0.5 * rho * (u^2 + v^2 + w^2)
380 type(c_ptr), intent(in) :: ruvw_d
381 real(kind=rp), intent(in) :: gamma
382
383#ifdef HAVE_HIP
384 call hip_update_e(e_d, p_d, ruvw_d, gamma, n)
385#elif HAVE_CUDA
386 call cuda_update_e(e_d, p_d, ruvw_d, gamma, n)
387#elif HAVE_OPENCL
388 call opencl_update_e(e_d, p_d, ruvw_d, gamma, n)
389#elif HAVE_METAL
390 call metal_update_e(e_d, p_d, ruvw_d, gamma, n)
391#else
392 call neko_error('No device backend configured')
393#endif
394
396
void opencl_compute_entropy(void *S_d, void *p_d, void *rho_d, real gamma, int n)
void cuda_compute_entropy(void *S_d, void *p_d, void *rho_d, real *gamma, int *n)
void opencl_compute_max_wave_speed(void *max_wave_speed, void *u, void *v, void *w, real gamma, void *p, void *rho, int n)
void cuda_compute_max_wave_speed(void *max_wave_speed_d, void *u_d, void *v_d, void *w_d, real *gamma, void *p_d, void *rho_d, int *n)
void opencl_update_uvw(void *u, void *v, void *w, void *m_x, void *m_y, void *m_z, void *rho, int n)
void opencl_update_e(void *E, void *p, void *ruvw, real gamma, int n)
void opencl_update_mxyz_p_ruvw(void *m_x, void *m_y, void *m_z, void *p, void *ruvw, void *u, void *v, void *w, void *E, void *rho, real gamma, int n)
void cuda_update_uvw(void *u, void *v, void *w, void *m_x, void *m_y, void *m_z, void *rho, int *n)
void cuda_update_mxyz_p_ruvw(void *m_x, void *m_y, void *m_z, void *p, void *ruvw, void *u, void *v, void *w, void *E, void *rho, real *gamma, int *n)
void cuda_update_e(void *E, void *p, void *ruvw, real *gamma, int *n)
Device implementation of compressible flow operations.
subroutine, public compressible_ops_device_compute_entropy(s, p, rho, gamma, n)
Compute entropy field S = 1/(gamma-1) * rho * (log(p) - gamma * log(rho)) on device.
subroutine, public compressible_ops_device_update_uvw(u_d, v_d, w_d, m_x_d, m_y_d, m_z_d, rho_d, n)
Update u,v,w fields.
subroutine, public compressible_ops_device_update_mxyz_p_ruvw(m_x_d, m_y_d, m_z_d, p_d, ruvw_d, u_d, v_d, w_d, e_d, rho_d, gamma, n)
Update m_x, m_y, m_z, p, ruvw, fields.
subroutine, public compressible_ops_device_compute_max_wave_speed(max_wave_speed, u, v, w, gamma, p, rho, n)
Compute maximum wave speed for compressible flows on device.
subroutine, public compressible_ops_device_update_e(e_d, p_d, ruvw_d, gamma, n)
Update E field.
Defines a field.
Definition field.f90:34
integer, parameter, public c_rp
Definition num_types.f90:13
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Utilities.
Definition utils.f90:35