Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
device_mma_math.f90
Go to the documentation of this file.
1! Copyright (c) 2025, The Neko-TOP 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!
34 use, intrinsic :: iso_c_binding, only: c_ptr, c_int
35 use num_types, only: rp, c_rp
36 use utils, only: neko_error
37 use comm, only: neko_comm, pe_size, mpi_real_precision
38 use mpi_f08, only: mpi_sum, mpi_in_place, mpi_allreduce
45
46 implicit none
47 private
48
49! #ifdef HAVE_CUDA
50
58
59contains
60
61 subroutine device_mma_gensub1(low_d, upp_d, x_d, xmin_d, xmax_d, asyinit, n)
62 type(c_ptr) :: low_d, upp_d, x_d, xmin_d, xmax_d
63 real(c_rp) :: asyinit
64 integer :: n
65#if HAVE_HIP
66 call neko_error('no device backend configured')
67#elif HAVE_CUDA
68 call mma_gensub1_cuda(low_d, upp_d, x_d, xmin_d, xmax_d, asyinit, n)
69#elif HAVE_OPENCL
70 call neko_error('no device backend configured')
71#else
72 call neko_error('no device backend configured')
73#endif
74 end subroutine device_mma_gensub1
75
76
77 subroutine device_mma_gensub2(low_d, upp_d, x_d, xold1_d, xold2_d, xmin_d, &
78 xmax_d, asydecr, asyincr, n)
79 type(c_ptr) :: low_d, upp_d, x_d, xold1_d, xold2_d, xmin_d, xmax_d
80 real(c_rp) :: asydecr, asyincr
81 integer :: n
82#if HAVE_HIP
83 call neko_error('no device backend configured')
84#elif HAVE_CUDA
85 call mma_gensub2_cuda(low_d, upp_d, x_d, xold1_d, xold2_d, xmin_d, xmax_d, &
86 asydecr, asyincr, n)
87#elif HAVE_OPENCL
88 call neko_error('no device backend configured')
89#else
90 call neko_error('no device backend configured')
91#endif
92 end subroutine device_mma_gensub2
93
94 subroutine device_mma_gensub3(x_d, df0dx_d, dfdx_d, low_d, upp_d, min_d, &
95 max_d, alpha_d, beta_d, p0j_d, q0j_d, pij_d, qij_d, n, m)
96 type(c_ptr) :: x_d, df0dx_d, dfdx_d, low_d, upp_d, min_d, max_d, &
97 alpha_d, beta_d, p0j_d, q0j_d, pij_d, qij_d
98 integer :: n, m
99#if HAVE_HIP
100 call neko_error('no device backend configured')
101#elif HAVE_CUDA
102 call mma_gensub3_cuda(x_d, df0dx_d, dfdx_d, low_d, upp_d, min_d, max_d, &
103 alpha_d, beta_d, p0j_d, q0j_d, pij_d, qij_d, n, m)
104#elif HAVE_OPENCL
105 call neko_error('no device backend configured2')
106#else
107 call neko_error('no device backend configured3')
108#endif
109 end subroutine device_mma_gensub3
110
111 subroutine device_mma_gensub4(x_d, low_d, upp_d, pij_d, qij_d, n, m, bi_d)
112 type(c_ptr) :: x_d, low_d, upp_d, pij_d, qij_d, bi_d
113 integer :: n, m
114#if HAVE_HIP
115 call neko_error('no device backend configured')
116#elif HAVE_CUDA
117 call mma_gensub4_cuda(x_d, low_d, upp_d, pij_d, qij_d, n, m, bi_d)
118#elif HAVE_OPENCL
119 call neko_error('no device backend configured')
120#else
121 call neko_error('no device backend configured')
122#endif
123 end subroutine device_mma_gensub4
124
125 subroutine device_mma_max(xsi_d, x_d, alpha_d, n)
126 type(c_ptr) :: xsi_d, x_d, alpha_d
127 integer :: n
128#if HAVE_HIP
129 call neko_error('no device backend configured')
130#elif HAVE_CUDA
131 call cuda_mma_max(xsi_d, x_d, alpha_d, n)
132#elif HAVE_OPENCL
133 call neko_error('no device backend configured')
134#else
135 call neko_error('no device backend configured')
136#endif
137 end subroutine device_mma_max
138
139 subroutine device_max2(a_d, b, c_d, d, n)
140 type(c_ptr) :: a_d, c_d
141 real(c_rp) :: b, d
142 integer :: n
143#if HAVE_HIP
144 call neko_error('no device backend configured')
145#elif HAVE_CUDA
146 call cuda_max2(a_d, b, c_d, d, n)
147#elif HAVE_OPENCL
148 call neko_error('no device backend configured')
149#else
150 call neko_error('no device backend configured')
151#endif
152 end subroutine device_max2
153
154
155
156 subroutine device_rex(rex_d, x_d, low_d, upp_d, pij_d, p0j_d, qij_d, &
157 q0j_d, lambda_d, xsi_d, eta_d, n, m)
158 type(c_ptr) :: rex_d, x_d, low_d, upp_d, pij_d, p0j_d, qij_d, q0j_d, &
159 lambda_d, xsi_d, eta_d
160 integer(c_int) :: n, m
161#if HAVE_HIP
162 call neko_error('no device backend configured')
163#elif HAVE_CUDA
164 call cuda_rex(rex_d, x_d, low_d, upp_d, pij_d, p0j_d, qij_d, q0j_d, &
165 lambda_d, xsi_d, eta_d, n, m)
166#elif HAVE_OPENCL
167 call neko_error('no device backend configured')
168#else
169 call neko_error('no device backend configured')
170#endif
171 end subroutine device_rex
172
173 function device_lcsc2(a_d, b_d, n) result(res)
174 type(c_ptr) :: a_d, b_d
175 integer(c_int) :: n
176 real(kind=rp) :: res
177 ! Default value in case of no valid backend (resolve compiler warning)
178 res = 0.0_rp
179#if HAVE_HIP
180 call neko_error('no device backend configured')
181#elif HAVE_CUDA
182 res = cuda_lcsc2(a_d, b_d, n)
183#elif HAVE_OPENCL
184 call neko_error('no device backend configured')
185#else
186 call neko_error('no device backend configured')
187#endif
188 end function device_lcsc2
189
190 subroutine device_relambda(relambda_d, x_d, upp_d, low_d, pij_d, qij_d, n, m)
191 type(c_ptr) :: relambda_d, x_d, upp_d, low_d, pij_d, qij_d
192 integer(c_int) :: n, m
193#if HAVE_HIP
194 call neko_error('no device backend configured')
195#elif HAVE_CUDA
196 call cuda_relambda(relambda_d, x_d, upp_d, low_d, pij_d, qij_d, n, m)
197#elif HAVE_OPENCL
198 call neko_error('no device backend configured')
199#else
200 call neko_error('no device backend configured')
201#endif
202 end subroutine device_relambda
203
204 subroutine device_sub2cons2(rexsi_d, xsi_d, x_d, alpha_d, epsi, n)
205 type(c_ptr):: rexsi_d, xsi_d, x_d, alpha_d
206 real(kind=rp) :: epsi
207 integer(c_int) :: n
208#if HAVE_HIP
209 call neko_error('no device backend configured')
210#elif HAVE_CUDA
211 call cuda_sub2cons2(rexsi_d, xsi_d, x_d, alpha_d, epsi, n)
212#elif HAVE_OPENCL
213 call neko_error('no device backend configured')
214#else
215 call neko_error('no device backend configured')
216#endif
217 end subroutine device_sub2cons2
218
219 function device_maxval(rex_d, n) result(res)
220 type(c_ptr):: rex_d
221 real(kind=rp) :: res
222 integer(c_int) :: n
223 ! Default value in case of no valid backend (resolve compiler warning)
224 res = 0.0_rp
225#if HAVE_HIP
226 call neko_error('no device backend configured')
227#elif HAVE_CUDA
228 res = cuda_maxval(rex_d, n)
229#elif HAVE_OPENCL
230 call neko_error('no device backend configured')
231#else
232 call neko_error('no device backend configured')
233#endif
234 end function device_maxval
235
236 function device_norm(rex_d, n) result(res)
237 type(c_ptr):: rex_d
238 real(kind=rp) :: res
239 integer(c_int) :: n
240 ! Default value in case of no valid backend (resolve compiler warning)
241 res = 0.0_rp
242#if HAVE_HIP
243 call neko_error('no device backend configured')
244#elif HAVE_CUDA
245 res = cuda_norm(rex_d, n)
246#elif HAVE_OPENCL
247 call neko_error('no device backend configured')
248#else
249 call neko_error('no device backend configured')
250#endif
251 end function device_norm
252
253 subroutine device_delx(delx_d, x_d, low_d, upp_d, pij_d, qij_d, p0j_d, &
254 q0j_d, alpha_d, beta_d, lambda_d, epsi, n, m)
255 type(c_ptr):: delx_d, x_d, low_d, upp_d, pij_d, qij_d, p0j_d, q0j_d, &
256 alpha_d, beta_d, lambda_d
257 real(kind=rp) :: epsi
258 integer(c_int) :: n, m
259#if HAVE_HIP
260 call neko_error('no device backend configured')
261#elif HAVE_CUDA
262 call cuda_delx(delx_d, x_d, low_d, upp_d, pij_d, qij_d, p0j_d, q0j_d, &
263 alpha_d, beta_d, lambda_d, epsi, n, m)
264#elif HAVE_OPENCL
265 call neko_error('no device backend configured')
266#else
267 call neko_error('no device backend configured')
268#endif
269 end subroutine device_delx
270
271 subroutine device_add2inv2(a_d, b_d, c, n)
272 type(c_ptr):: a_d, b_d
273 real(kind=rp) :: c
274 integer(c_int) :: n
275#if HAVE_HIP
276 call neko_error('no device backend configured')
277#elif HAVE_CUDA
278 call cuda_add2inv2(a_d, b_d, c, n)
279#elif HAVE_OPENCL
280 call neko_error('no device backend configured')
281#else
282 call neko_error('no device backend configured')
283#endif
284 end subroutine device_add2inv2
285
286
287 subroutine device_gg(GG_d, x_d, low_d, upp_d, pij_d, qij_d, n, m)
288 type(c_ptr):: gg_d, x_d, low_d, upp_d, pij_d, qij_d
289 integer(c_int) :: n, m
290#if HAVE_HIP
291 call neko_error('no device backend configured')
292#elif HAVE_CUDA
293 call cuda_gg(gg_d, x_d, low_d, upp_d, pij_d, qij_d, n, m)
294#elif HAVE_OPENCL
295 call neko_error('no device backend configured')
296#else
297 call neko_error('no device backend configured')
298#endif
299 end subroutine device_gg
300
301 subroutine device_diagx(diagx_d, x_d, xsi_d, low_d, upp_d, p0j_d, q0j_d, &
302 pij_d, qij_d, alpha_d, beta_d, eta_d, lambda_d, n, m)
303 type(c_ptr):: diagx_d, x_d, xsi_d, low_d, upp_d, p0j_d, q0j_d, pij_d, &
304 qij_d, alpha_d, &
305 beta_d, eta_d, lambda_d
306 integer(c_int) :: n, m
307#if HAVE_HIP
308 call neko_error('no device backend configured')
309#elif HAVE_CUDA
310 call cuda_diagx(diagx_d, x_d, xsi_d, low_d, upp_d, p0j_d, q0j_d, pij_d, &
311 qij_d, alpha_d, beta_d, eta_d, lambda_d, n, m)
312#elif HAVE_OPENCL
313 call neko_error('no device backend configured')
314#else
315 call neko_error('no device backend configured')
316#endif
317 end subroutine device_diagx
318
319
320 subroutine device_bb(bb_d, GG_d, delx_d, diagx_d, n, m)
321 type(c_ptr):: bb_d, gg_d, delx_d, diagx_d
322 integer(c_int) :: n, m
323#if HAVE_HIP
324 call neko_error('no device backend configured')
325#elif HAVE_CUDA
326 call cuda_bb(bb_d, gg_d, delx_d, diagx_d, n, m)
327#elif HAVE_OPENCL
328 call neko_error('no device backend configured')
329#else
330 call neko_error('no device backend configured')
331#endif
332 end subroutine device_bb
333
334 subroutine device_updatebb(bb_d, dellambda_d, dely_d, d_d, mu_d, y_d, delz, m)
335 type(c_ptr):: bb_d, dellambda_d, dely_d, d_d, mu_d, y_d
336 integer(c_int) :: m
337 real(c_rp) :: delz
338#if HAVE_HIP
339 call neko_error('no device backend configured')
340#elif HAVE_CUDA
341 call cuda_updatebb(bb_d, dellambda_d, dely_d, d_d, mu_d, y_d, delz, m)
342#elif HAVE_OPENCL
343 call neko_error('no device backend configured')
344#else
345 call neko_error('no device backend configured')
346#endif
347 end subroutine device_updatebb
348
349 subroutine device_aa(AA_d, GG_d, diagx_d, n, m)
350 type(c_ptr):: aa_d, gg_d, diagx_d
351 integer(c_int) :: n, m
352#if HAVE_HIP
353 call neko_error('no device backend configured')
354#elif HAVE_CUDA
355 call cuda_aa(aa_d, gg_d, diagx_d, n, m)
356#elif HAVE_OPENCL
357 call neko_error('no device backend configured')
358#else
359 call neko_error('no device backend configured')
360#endif
361 end subroutine device_aa
362
363 subroutine device_updateaa(AA_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, &
364 y_d, a_d, zeta, z, m)
365 type(c_ptr):: aa_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, y_d, a_d
366 integer(c_int) :: m
367 real(c_rp) :: zeta, z
368#if HAVE_HIP
369 call neko_error('no device backend configured')
370#elif HAVE_CUDA
371 call cuda_updateaa(aa_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, y_d, &
372 a_d, zeta, z, m)
373#elif HAVE_OPENCL
374 call neko_error('no device backend configured')
375#else
376 call neko_error('no device backend configured')
377#endif
378 end subroutine device_updateaa
379
380 subroutine device_dx(dx_d, delx_d, diagx_d, GG_d, dlambda_d, n, m)
381 type(c_ptr):: dx_d, delx_d, diagx_d, gg_d, dlambda_d
382 integer(c_int) :: n, m
383#if HAVE_HIP
384 call neko_error('no device backend configured')
385#elif HAVE_CUDA
386 call cuda_dx(dx_d, delx_d, diagx_d, gg_d, dlambda_d, n, m)
387#elif HAVE_OPENCL
388 call neko_error('no device backend configured')
389#else
390 call neko_error('no device backend configured')
391#endif
392 end subroutine device_dx
393
394 subroutine device_dy(dy_d, dely_d, dlambda_d, d_d, mu_d, y_d, n)
395 type(c_ptr):: dy_d, dely_d, dlambda_d, d_d, mu_d, y_d
396 integer(c_int) :: n
397#if HAVE_HIP
398 call neko_error('no device backend configured')
399#elif HAVE_CUDA
400 call cuda_dy(dy_d, dely_d, dlambda_d, d_d, mu_d, y_d, n)
401#elif HAVE_OPENCL
402 call neko_error('no device backend configured')
403#else
404 call neko_error('no device backend configured')
405#endif
406 end subroutine device_dy
407
408 subroutine device_dxsi(dxsi_d, xsi_d, dx_d, x_d, alpha_d, epsi, n)
409 type(c_ptr):: dxsi_d, xsi_d, dx_d, x_d, alpha_d
410 integer(c_int) :: n
411 real(c_rp) :: epsi
412#if HAVE_HIP
413 call neko_error('no device backend configured')
414#elif HAVE_CUDA
415 call cuda_dxsi(dxsi_d, xsi_d, dx_d, x_d, alpha_d, epsi, n)
416#elif HAVE_OPENCL
417 call neko_error('no device backend configured')
418#else
419 call neko_error('no device backend configured')
420#endif
421 end subroutine device_dxsi
422
423 subroutine device_deta(deta_d, eta_d, dx_d, x_d, beta_d, epsi, n)
424 type(c_ptr):: deta_d, eta_d, dx_d, x_d, beta_d
425 integer(c_int) :: n
426 real(c_rp) :: epsi
427#if HAVE_HIP
428 call neko_error('no device backend configured')
429#elif HAVE_CUDA
430 call cuda_deta(deta_d, eta_d, dx_d, x_d, beta_d, epsi, n)
431#elif HAVE_OPENCL
432 call neko_error('no device backend configured')
433#else
434 call neko_error('no device backend configured')
435#endif
436 end subroutine device_deta
437
438 function device_maxval2(dxx_d, xx_d, cons, n) result(res)
439 type(c_ptr):: dxx_d, xx_d
440 integer :: n
441 real(kind=rp), intent(in) :: cons
442 real(kind=rp) :: res
443 ! Default value in case of no valid backend (resolve compiler warning)
444 res = 0.0_rp
445#if HAVE_HIP
446 call neko_error('no device backend configured')
447#elif HAVE_CUDA
448 res = cuda_maxval2(dxx_d, xx_d, cons, n)
449#elif HAVE_OPENCL
450 call neko_error('no device backend configured')
451#else
452 call neko_error('no device backend configured')
453#endif
454 end function device_maxval2
455
456
457 function device_maxval3(dx_d, x_d, alpha_d, cons, n) result(res)
458 type(c_ptr):: dx_d, x_d, alpha_d
459 real(kind=rp), intent(in) :: cons
460 real(kind=rp) :: res
461 integer(c_int) :: n
462 ! Default value in case of no valid backend (resolve compiler warning)
463 res = 0.0_rp
464#if HAVE_HIP
465 call neko_error('no device backend configured')
466#elif HAVE_CUDA
467 res = cuda_maxval3(dx_d, x_d, alpha_d, cons, n)
468#elif HAVE_OPENCL
469 call neko_error('no device backend configured')
470#else
471 call neko_error('no device backend configured')
472#endif
473 end function device_maxval3
474
475
476
477 subroutine device_kkt_rex(rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d, &
478 n, m)
479 type(c_ptr):: rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d
480 integer(c_int) :: n, m
481#if HAVE_HIP
482 call neko_error('no device backend configured')
483#elif HAVE_CUDA
484 call cuda_kkt_rex(rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d, n, m)
485#elif HAVE_OPENCL
486 call neko_error('no device backend configured')
487#else
488 call neko_error('no device backend configured')
489#endif
490 end subroutine device_kkt_rex
491
492! #endif
493
494end module device_mma_math
subroutine, public device_dx(dx_d, delx_d, diagx_d, gg_d, dlambda_d, n, m)
subroutine, public device_mma_gensub1(low_d, upp_d, x_d, xmin_d, xmax_d, asyinit, n)
subroutine, public device_relambda(relambda_d, x_d, upp_d, low_d, pij_d, qij_d, n, m)
real(kind=rp) function, public device_maxval2(dxx_d, xx_d, cons, n)
subroutine, public device_delx(delx_d, x_d, low_d, upp_d, pij_d, qij_d, p0j_d, q0j_d, alpha_d, beta_d, lambda_d, epsi, n, m)
subroutine, public device_mma_gensub4(x_d, low_d, upp_d, pij_d, qij_d, n, m, bi_d)
subroutine, public device_sub2cons2(rexsi_d, xsi_d, x_d, alpha_d, epsi, n)
subroutine, public device_deta(deta_d, eta_d, dx_d, x_d, beta_d, epsi, n)
subroutine, public device_rex(rex_d, x_d, low_d, upp_d, pij_d, p0j_d, qij_d, q0j_d, lambda_d, xsi_d, eta_d, n, m)
real(kind=rp) function, public device_maxval3(dx_d, x_d, alpha_d, cons, n)
subroutine, public device_diagx(diagx_d, x_d, xsi_d, low_d, upp_d, p0j_d, q0j_d, pij_d, qij_d, alpha_d, beta_d, eta_d, lambda_d, n, m)
subroutine, public device_mma_gensub3(x_d, df0dx_d, dfdx_d, low_d, upp_d, min_d, max_d, alpha_d, beta_d, p0j_d, q0j_d, pij_d, qij_d, n, m)
real(kind=rp) function, public device_norm(rex_d, n)
subroutine, public device_mma_max(xsi_d, x_d, alpha_d, n)
subroutine, public device_bb(bb_d, gg_d, delx_d, diagx_d, n, m)
subroutine, public device_dxsi(dxsi_d, xsi_d, dx_d, x_d, alpha_d, epsi, n)
subroutine, public device_mma_gensub2(low_d, upp_d, x_d, xold1_d, xold2_d, xmin_d, xmax_d, asydecr, asyincr, n)
subroutine, public device_updatebb(bb_d, dellambda_d, dely_d, d_d, mu_d, y_d, delz, m)
subroutine, public device_updateaa(aa_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, y_d, a_d, zeta, z, m)
real(kind=rp) function, public device_maxval(rex_d, n)
subroutine, public device_aa(aa_d, gg_d, diagx_d, n, m)
subroutine, public device_kkt_rex(rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d, n, m)
real(kind=rp) function, public device_lcsc2(a_d, b_d, n)
subroutine, public device_dy(dy_d, dely_d, dlambda_d, d_d, mu_d, y_d, n)
subroutine, public device_gg(gg_d, x_d, low_d, upp_d, pij_d, qij_d, n, m)
subroutine, public device_add2inv2(a_d, b_d, c, n)
subroutine, public device_max2(a_d, b, c_d, d, n)