Neko 1.99.11
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
device_constrain_mixed_bc.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!
33!> Device wrappers for basis-aware mixed boundary-condition constraint kernels.
34!! These routines operate on a resolved mixed-node mask together with a local
35!! orthonormal basis stored as nodewise normal and tangent vectors. They are
36!! used to impose homogeneous or prescribed constraints on vector fields in the
37!! local `(n, t1, t2)` basis on device backends.
39 use num_types, only : c_rp, rp
40 use utils, only : neko_error
41 use device, only : glb_cmd_queue
42 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
43 implicit none
44 private
45
46#ifdef HAVE_HIP
47 interface
48 subroutine hip_constrain_mixed_bc_zero(mixed_msk, x, y, z, &
49 constraint_n, constraint_t1, constraint_t2, n, t1, t2, m, strm) &
50 bind(c, name = 'hip_constrain_mixed_bc_zero')
51 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
52 implicit none
53 integer(c_int) :: constraint_n, constraint_t1, constraint_t2
54 integer(c_int) :: m
55 type(c_ptr), value :: mixed_msk, x, y, z, n, t1, t2, strm
56 end subroutine hip_constrain_mixed_bc_zero
57
58 subroutine hip_constrain_mixed_bc_set(mixed_msk, x, y, z, &
59 constraint_n, constraint_t1, constraint_t2, n, t1, t2, &
60 values_n, values_t1, values_t2, m, strm) &
61 bind(c, name = 'hip_constrain_mixed_bc_set')
62 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
63 implicit none
64 integer(c_int) :: constraint_n, constraint_t1, constraint_t2
65 integer(c_int) :: m
66 type(c_ptr), value :: mixed_msk, x, y, z, n, t1, t2
67 type(c_ptr), value :: values_n, values_t1, values_t2, strm
68 end subroutine hip_constrain_mixed_bc_set
69
70 subroutine hip_constrain_mixed_bc_set_const(mixed_msk, x, y, z, &
71 constraint_n, constraint_t1, constraint_t2, n, t1, t2, &
72 value_n, value_t1, value_t2, m, strm) &
73 bind(c, name = 'hip_constrain_mixed_bc_set_const')
74 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
75 import c_rp
76 implicit none
77 real(c_rp) :: value_n, value_t1, value_t2
78 integer(c_int) :: constraint_n, constraint_t1, constraint_t2
79 integer(c_int) :: m
80 type(c_ptr), value :: mixed_msk, x, y, z, n, t1, t2, strm
82 end interface
83#elif HAVE_CUDA
84 interface
85 subroutine cuda_constrain_mixed_bc_zero(mixed_msk, x, y, z, &
86 constraint_n, constraint_t1, constraint_t2, n, t1, t2, m, strm) &
87 bind(c, name = 'cuda_constrain_mixed_bc_zero')
88 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
89 implicit none
90 integer(c_int) :: constraint_n, constraint_t1, constraint_t2
91 integer(c_int) :: m
92 type(c_ptr), value :: mixed_msk, x, y, z, n, t1, t2, strm
93 end subroutine cuda_constrain_mixed_bc_zero
94
95 subroutine cuda_constrain_mixed_bc_set(mixed_msk, x, y, z, &
96 constraint_n, constraint_t1, constraint_t2, n, t1, t2, &
97 values_n, values_t1, values_t2, m, strm) &
98 bind(c, name = 'cuda_constrain_mixed_bc_set')
99 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
100 implicit none
101 integer(c_int) :: constraint_n, constraint_t1, constraint_t2
102 integer(c_int) :: m
103 type(c_ptr), value :: mixed_msk, x, y, z, n, t1, t2
104 type(c_ptr), value :: values_n, values_t1, values_t2, strm
105 end subroutine cuda_constrain_mixed_bc_set
106
107 subroutine cuda_constrain_mixed_bc_set_const(mixed_msk, x, y, z, &
108 constraint_n, constraint_t1, constraint_t2, n, t1, t2, &
109 value_n, value_t1, value_t2, m, strm) &
110 bind(c, name = 'cuda_constrain_mixed_bc_set_const')
111 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
112 import c_rp
113 implicit none
114 real(c_rp) :: value_n, value_t1, value_t2
115 integer(c_int) :: constraint_n, constraint_t1, constraint_t2
116 integer(c_int) :: m
117 type(c_ptr), value :: mixed_msk, x, y, z, n, t1, t2, strm
119 end interface
120#elif HAVE_OPENCL
121 interface
122 subroutine opencl_constrain_mixed_bc_zero(mixed_msk, x, y, z, &
123 constraint_n, constraint_t1, constraint_t2, n, t1, t2, m, strm) &
124 bind(c, name = 'opencl_constrain_mixed_bc_zero')
125 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
126 implicit none
127 integer(c_int) :: constraint_n, constraint_t1, constraint_t2
128 integer(c_int) :: m
129 type(c_ptr), value :: mixed_msk, x, y, z, n, t1, t2, strm
130 end subroutine opencl_constrain_mixed_bc_zero
131
132 subroutine opencl_constrain_mixed_bc_set(mixed_msk, x, y, z, &
133 constraint_n, constraint_t1, constraint_t2, n, t1, t2, &
134 values_n, values_t1, values_t2, m, strm) &
135 bind(c, name = 'opencl_constrain_mixed_bc_set')
136 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
137 implicit none
138 integer(c_int) :: constraint_n, constraint_t1, constraint_t2
139 integer(c_int) :: m
140 type(c_ptr), value :: mixed_msk, x, y, z, n, t1, t2
141 type(c_ptr), value :: values_n, values_t1, values_t2, strm
142 end subroutine opencl_constrain_mixed_bc_set
143
144 subroutine opencl_constrain_mixed_bc_set_const(mixed_msk, x, y, z, &
145 constraint_n, constraint_t1, constraint_t2, n, t1, t2, &
146 value_n, value_t1, value_t2, m, strm) &
147 bind(c, name = 'opencl_constrain_mixed_bc_set_const')
148 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
149 import c_rp
150 implicit none
151 real(c_rp) :: value_n, value_t1, value_t2
152 integer(c_int) :: constraint_n, constraint_t1, constraint_t2
153 integer(c_int) :: m
154 type(c_ptr), value :: mixed_msk, x, y, z, n, t1, t2, strm
156 end interface
157#elif HAVE_METAL
158 interface
159 subroutine metal_constrain_mixed_bc_zero(mixed_msk, x, y, z, &
160 constraint_n, constraint_t1, constraint_t2, n, t1, t2, m, strm) &
161 bind(c, name = 'metal_constrain_mixed_bc_zero')
162 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
163 implicit none
164 integer(c_int) :: constraint_n, constraint_t1, constraint_t2
165 integer(c_int) :: m
166 type(c_ptr), value :: mixed_msk, x, y, z, n, t1, t2, strm
167 end subroutine metal_constrain_mixed_bc_zero
168
169 subroutine metal_constrain_mixed_bc_set(mixed_msk, x, y, z, &
170 constraint_n, constraint_t1, constraint_t2, n, t1, t2, &
171 values_n, values_t1, values_t2, m, strm) &
172 bind(c, name = 'metal_constrain_mixed_bc_set')
173 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
174 implicit none
175 integer(c_int) :: constraint_n, constraint_t1, constraint_t2
176 integer(c_int) :: m
177 type(c_ptr), value :: mixed_msk, x, y, z, n, t1, t2
178 type(c_ptr), value :: values_n, values_t1, values_t2, strm
179 end subroutine metal_constrain_mixed_bc_set
180
181 subroutine metal_constrain_mixed_bc_set_const(mixed_msk, x, y, z, &
182 constraint_n, constraint_t1, constraint_t2, n, t1, t2, &
183 value_n, value_t1, value_t2, m, strm) &
184 bind(c, name = 'metal_constrain_mixed_bc_set_const')
185 use, intrinsic :: iso_c_binding, only : c_ptr, c_int
186 import c_rp
187 implicit none
188 real(c_rp) :: value_n, value_t1, value_t2
189 integer(c_int) :: constraint_n, constraint_t1, constraint_t2
190 integer(c_int) :: m
191 type(c_ptr), value :: mixed_msk, x, y, z, n, t1, t2, strm
192 end subroutine metal_constrain_mixed_bc_set_const
193 end interface
194#endif
195
199
200contains
201
202 !> Constrain mixed-boundary projections by zeroing the selected local
203 !! components on the device.
204 !! @param[in] mixed_msk Device pointer to the resolved mixed-node mask.
205 !! @param[inout] x Device pointer to the x-component field.
206 !! @param[inout] y Device pointer to the y-component field.
207 !! @param[inout] z Device pointer to the z-component field.
208 !! @param[in] constraint_n Nonzero if the normal component is constrained.
209 !! @param[in] constraint_t1 Nonzero if the first tangent component is
210 !! constrained.
211 !! @param[in] constraint_t2 Nonzero if the second tangent component is
212 !! constrained.
213 !! @param[in] n Device pointer to the nodewise normal vectors.
214 !! @param[in] t1 Device pointer to the nodewise first tangent vectors.
215 !! @param[in] t2 Device pointer to the nodewise second tangent vectors.
216 !! @param[in] m Number of resolved mixed nodes.
217 !! @param[in] strm Optional backend stream/queue to launch on.
218 subroutine device_constrain_mixed_bc_zero(mixed_msk, x, y, z, &
219 constraint_n, constraint_t1, constraint_t2, n, t1, t2, m, strm)
220 integer, intent(in) :: constraint_n, constraint_t1, constraint_t2
221 integer, intent(in) :: m
222 type(c_ptr), intent(in) :: mixed_msk, x, y, z
223 type(c_ptr), intent(in) :: n, t1, t2
224 type(c_ptr), intent(in), optional :: strm
225 type(c_ptr) :: strm_
226
227 if (m .lt. 1) return
228
229 if (present(strm)) then
230 strm_ = strm
231 else
232 strm_ = glb_cmd_queue
233 end if
234
235#ifdef HAVE_HIP
236 call hip_constrain_mixed_bc_zero(mixed_msk, x, y, z, &
237 constraint_n, constraint_t1, constraint_t2, n, t1, t2, m, strm_)
238#elif HAVE_CUDA
239 call cuda_constrain_mixed_bc_zero(mixed_msk, x, y, z, &
240 constraint_n, constraint_t1, constraint_t2, n, t1, t2, m, strm_)
241#elif HAVE_OPENCL
242 call opencl_constrain_mixed_bc_zero(mixed_msk, x, y, z, &
243 constraint_n, constraint_t1, constraint_t2, n, t1, t2, m, strm_)
244#elif HAVE_METAL
245 call metal_constrain_mixed_bc_zero(mixed_msk, x, y, z, &
246 constraint_n, constraint_t1, constraint_t2, n, t1, t2, m, strm_)
247#else
248 call neko_error('No device backend configured for mixed BC constraint')
249#endif
250
251 end subroutine device_constrain_mixed_bc_zero
252
253 !> Constrain mixed-boundary projections by assigning prescribed local
254 !! components derived from nodewise target vectors on the device.
255 !! @param[in] mixed_msk Device pointer to the resolved mixed-node mask.
256 !! @param[inout] x Device pointer to the x-component field.
257 !! @param[inout] y Device pointer to the y-component field.
258 !! @param[inout] z Device pointer to the z-component field.
259 !! @param[in] constraint_n Nonzero if the normal component is constrained.
260 !! @param[in] constraint_t1 Nonzero if the first tangent component is
261 !! constrained.
262 !! @param[in] constraint_t2 Nonzero if the second tangent component is
263 !! constrained.
264 !! @param[in] n Device pointer to the nodewise normal vectors.
265 !! @param[in] t1 Device pointer to the nodewise first tangent vectors.
266 !! @param[in] t2 Device pointer to the nodewise second tangent vectors.
267 !! @param[in] values_n Device pointer to the x-components of the target
268 !! vectors.
269 !! @param[in] values_t1 Device pointer to the y-components of the target
270 !! vectors.
271 !! @param[in] values_t2 Device pointer to the z-components of the target
272 !! vectors.
273 !! @param[in] m Number of resolved mixed nodes.
274 !! @param[in] strm Optional backend stream/queue to launch on.
275 subroutine device_constrain_mixed_bc_set(mixed_msk, x, y, z, &
276 constraint_n, constraint_t1, constraint_t2, n, t1, t2, &
277 values_n, values_t1, values_t2, m, strm)
278 integer, intent(in) :: constraint_n, constraint_t1, constraint_t2
279 integer, intent(in) :: m
280 type(c_ptr), intent(in) :: mixed_msk, x, y, z
281 type(c_ptr), intent(in) :: n, t1, t2
282 type(c_ptr), intent(in) :: values_n, values_t1, values_t2
283 type(c_ptr), intent(in), optional :: strm
284 type(c_ptr) :: strm_
285
286 if (m .lt. 1) return
287
288 if (present(strm)) then
289 strm_ = strm
290 else
291 strm_ = glb_cmd_queue
292 end if
293
294#ifdef HAVE_HIP
295 call hip_constrain_mixed_bc_set(mixed_msk, x, y, z, &
296 constraint_n, constraint_t1, constraint_t2, n, t1, t2, &
297 values_n, values_t1, values_t2, m, strm_)
298#elif HAVE_CUDA
299 call cuda_constrain_mixed_bc_set(mixed_msk, x, y, z, &
300 constraint_n, constraint_t1, constraint_t2, n, t1, t2, &
301 values_n, values_t1, values_t2, m, strm_)
302#elif HAVE_OPENCL
303 call opencl_constrain_mixed_bc_set(mixed_msk, x, y, z, &
304 constraint_n, constraint_t1, constraint_t2, n, t1, t2, &
305 values_n, values_t1, values_t2, m, strm_)
306#elif HAVE_METAL
307 call metal_constrain_mixed_bc_set(mixed_msk, x, y, z, &
308 constraint_n, constraint_t1, constraint_t2, n, t1, t2, &
309 values_n, values_t1, values_t2, m, strm_)
310#else
311 call neko_error('No device backend configured for mixed BC constraint')
312#endif
313
314 end subroutine device_constrain_mixed_bc_set
315
316 !> Constrain mixed-boundary projections by assigning prescribed local
317 !! components derived from a constant target vector on the device.
318 !! @param[in] mixed_msk Device pointer to the resolved mixed-node mask.
319 !! @param[inout] x Device pointer to the x-component field.
320 !! @param[inout] y Device pointer to the y-component field.
321 !! @param[inout] z Device pointer to the z-component field.
322 !! @param[in] constraint_n Nonzero if the normal component is constrained.
323 !! @param[in] constraint_t1 Nonzero if the first tangent component is
324 !! constrained.
325 !! @param[in] constraint_t2 Nonzero if the second tangent component is
326 !! constrained.
327 !! @param[in] n Device pointer to the nodewise normal vectors.
328 !! @param[in] t1 Device pointer to the nodewise first tangent vectors.
329 !! @param[in] t2 Device pointer to the nodewise second tangent vectors.
330 !! @param[in] value_n x-component of the constant target vector.
331 !! @param[in] value_t1 y-component of the constant target vector.
332 !! @param[in] value_t2 z-component of the constant target vector.
333 !! @param[in] m Number of resolved mixed nodes.
334 !! @param[in] strm Optional backend stream/queue to launch on.
335 subroutine device_constrain_mixed_bc_set_const(mixed_msk, x, y, z, &
336 constraint_n, constraint_t1, constraint_t2, n, t1, t2, &
337 value_n, value_t1, value_t2, m, strm)
338 integer, intent(in) :: constraint_n, constraint_t1, constraint_t2
339 integer, intent(in) :: m
340 real(kind=rp), intent(in) :: value_n, value_t1, value_t2
341 type(c_ptr), intent(in) :: mixed_msk, x, y, z
342 type(c_ptr), intent(in) :: n, t1, t2
343 type(c_ptr), intent(in), optional :: strm
344 type(c_ptr) :: strm_
345
346 if (m .lt. 1) return
347
348 if (present(strm)) then
349 strm_ = strm
350 else
351 strm_ = glb_cmd_queue
352 end if
353
354#ifdef HAVE_HIP
355 call hip_constrain_mixed_bc_set_const(mixed_msk, x, y, z, &
356 constraint_n, constraint_t1, constraint_t2, n, t1, t2, &
357 value_n, value_t1, value_t2, m, strm_)
358#elif HAVE_CUDA
359 call cuda_constrain_mixed_bc_set_const(mixed_msk, x, y, z, &
360 constraint_n, constraint_t1, constraint_t2, n, t1, t2, &
361 value_n, value_t1, value_t2, m, strm_)
362#elif HAVE_OPENCL
363 call opencl_constrain_mixed_bc_set_const(mixed_msk, x, y, z, &
364 constraint_n, constraint_t1, constraint_t2, n, t1, t2, &
365 value_n, value_t1, value_t2, m, strm_)
366#elif HAVE_METAL
367 call metal_constrain_mixed_bc_set_const(mixed_msk, x, y, z, &
368 constraint_n, constraint_t1, constraint_t2, n, t1, t2, &
369 value_n, value_t1, value_t2, m, strm_)
370#else
371 call neko_error('No device backend configured for mixed BC constraint')
372#endif
373
375
void opencl_constrain_mixed_bc_set(void *mixed_msk, void *x, void *y, void *z, int *constraint_n, int *constraint_t1, int *constraint_t2, void *n, void *t1, void *t2, void *values_n, void *values_t1, void *values_t2, int *m, cl_command_queue cmd_queue)
void opencl_constrain_mixed_bc_set_const(void *mixed_msk, void *x, void *y, void *z, int *constraint_n, int *constraint_t1, int *constraint_t2, void *n, void *t1, void *t2, real *value_n, real *value_t1, real *value_t2, int *m, cl_command_queue cmd_queue)
void opencl_constrain_mixed_bc_zero(void *mixed_msk, void *x, void *y, void *z, int *constraint_n, int *constraint_t1, int *constraint_t2, void *n, void *t1, void *t2, int *m, cl_command_queue cmd_queue)
void cuda_constrain_mixed_bc_zero(void *mixed_msk, void *x, void *y, void *z, int *constraint_n, int *constraint_t1, int *constraint_t2, void *n, void *t1, void *t2, int *m, cudaStream_t strm)
void cuda_constrain_mixed_bc_set(void *mixed_msk, void *x, void *y, void *z, int *constraint_n, int *constraint_t1, int *constraint_t2, void *n, void *t1, void *t2, void *values_n, void *values_t1, void *values_t2, int *m, cudaStream_t strm)
void cuda_constrain_mixed_bc_set_const(void *mixed_msk, void *x, void *y, void *z, int *constraint_n, int *constraint_t1, int *constraint_t2, void *n, void *t1, void *t2, real *value_n, real *value_t1, real *value_t2, int *m, cudaStream_t strm)
Device wrappers for basis-aware mixed boundary-condition constraint kernels. These routines operate o...
subroutine, public device_constrain_mixed_bc_zero(mixed_msk, x, y, z, constraint_n, constraint_t1, constraint_t2, n, t1, t2, m, strm)
Constrain mixed-boundary projections by zeroing the selected local components on the device.
subroutine, public device_constrain_mixed_bc_set_const(mixed_msk, x, y, z, constraint_n, constraint_t1, constraint_t2, n, t1, t2, value_n, value_t1, value_t2, m, strm)
Constrain mixed-boundary projections by assigning prescribed local components derived from a constant...
subroutine, public device_constrain_mixed_bc_set(mixed_msk, x, y, z, constraint_n, constraint_t1, constraint_t2, n, t1, t2, values_n, values_t1, values_t2, m, strm)
Constrain mixed-boundary projections by assigning prescribed local components derived from nodewise t...
Device abstraction, common interface for various accelerators.
Definition device.F90:34
type(c_ptr), bind(C), public glb_cmd_queue
Global command queue.
Definition device.F90:52
integer, parameter, public c_rp
Definition num_types.f90:15
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Utilities.
Definition utils.f90:35