Neko 1.99.2
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#endif
219
225
226contains
227
229 subroutine compressible_ops_device_compute_max_wave_speed(max_wave_speed, u, v, w, gamma, p, rho, n)
230 integer, intent(in) :: n
231 real(kind=rp), intent(in) :: gamma
232 type(field_t), intent(inout) :: max_wave_speed
233 type(field_t), intent(in) :: u, v, w, p, rho
234
235#ifdef HAVE_HIP
236 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)
237#elif HAVE_CUDA
238 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)
239#elif HAVE_OPENCL
240 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)
241#else
242 call neko_error('No device backend configured')
243#endif
245
247 subroutine compressible_ops_device_compute_entropy(S, p, rho, gamma, n)
248 integer, intent(in) :: n
249 real(kind=rp), intent(in) :: gamma
250 type(field_t), intent(inout) :: s
251 type(field_t), intent(in) :: p, rho
252
253#ifdef HAVE_HIP
254 call hip_compute_entropy(s%x_d, p%x_d, rho%x_d, gamma, n)
255#elif HAVE_CUDA
256 call cuda_compute_entropy(s%x_d, p%x_d, rho%x_d, gamma, n)
257#elif HAVE_OPENCL
258 call opencl_compute_entropy(s%x_d, p%x_d, rho%x_d, gamma, n)
259#else
260 call neko_error('No device backend configured')
261#endif
263
265 subroutine compressible_ops_device_update_uvw(u_d, v_d, w_d, &
266 m_x_d, m_y_d, m_z_d, rho_d, n)
267 type(c_ptr), intent(inout) :: u_d, v_d, w_d
268 type(c_ptr), intent(in) :: m_x_d, m_y_d, m_z_d, rho_d
269 integer, intent(in) :: n
270 integer :: i
271
272#ifdef HAVE_HIP
273 call hip_update_uvw(u_d, v_d, w_d, m_x_d, m_y_d, m_z_d, rho_d, n)
274#elif HAVE_CUDA
275 call cuda_update_uvw(u_d, v_d, w_d, m_x_d, m_y_d, m_z_d, rho_d, n)
276#elif HAVE_OPENCL
277 call opencl_update_uvw(u_d, v_d, w_d, m_x_d, m_y_d, m_z_d, rho_d, n)
278#else
279 call neko_error('No device backend configured')
280#endif
281
283
285 subroutine compressible_ops_device_update_mxyz_p_ruvw(m_x_d, m_y_d, m_z_d, &
286 p_d, ruvw_d, u_d, v_d, w_d, E_d, rho_d, gamma, n)
287 integer, intent(in) :: n
288 type(c_ptr), intent(inout) :: m_x_d, m_y_d, m_z_d, p_d, ruvw_d
289 type(c_ptr), intent(in) :: u_d, v_d, w_d, e_d, rho_d
290 real(kind=rp), intent(in) :: gamma
291
292
293#ifdef HAVE_HIP
294 call hip_update_mxyz_p_ruvw(m_x_d, m_y_d, m_z_d, &
295 p_d, ruvw_d, u_d, v_d, w_d, e_d, rho_d, gamma, n)
296#elif HAVE_CUDA
297 call cuda_update_mxyz_p_ruvw(m_x_d, m_y_d, m_z_d, &
298 p_d, ruvw_d, u_d, v_d, w_d, e_d, rho_d, gamma, n)
299#elif HAVE_OPENCL
300 call opencl_update_mxyz_p_ruvw(m_x_d, m_y_d, m_z_d, &
301 p_d, ruvw_d, u_d, v_d, w_d, e_d, rho_d, gamma, n)
302#else
303 call neko_error('No device backend configured')
304#endif
305
307
309 subroutine compressible_ops_device_update_e(E_d, p_d, ruvw_d, gamma, n)
310 integer, intent(in) :: n
311 type(c_ptr), intent(inout) :: e_d, p_d
312 ! ruvw = 0.5 * rho * (u^2 + v^2 + w^2)
313 type(c_ptr), intent(in) :: ruvw_d
314 real(kind=rp), intent(in) :: gamma
315
316#ifdef HAVE_HIP
317 call hip_update_e(e_d, p_d, ruvw_d, gamma, n)
318#elif HAVE_CUDA
319 call cuda_update_e(e_d, p_d, ruvw_d, gamma, n)
320#elif HAVE_OPENCL
321 call opencl_update_e(e_d, p_d, ruvw_d, gamma, n)
322#else
323 call neko_error('No device backend configured')
324#endif
325
327
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