Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
device_mma_math.f90
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!
33module device_mma_math
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
39 use cuda_mma_math, only: cuda_mma_max, cuda_max2, cuda_rex, cuda_lcsc2, &
46 use hip_mma_math, only: hip_mma_max, hip_max2, hip_rex, hip_lcsc2, &
53
54 implicit none
55 private
56
57
58 public :: device_mma_gensub1, device_mma_gensub2, device_mma_gensub3, &
59 device_mma_gensub4, device_mma_max, device_max2, device_rex, &
60 device_lcsc2, device_relambda, device_sub2cons2, device_maxval, &
61 device_norm, device_delx, device_add2inv2, device_gg, device_diagx, &
62 device_bb, device_updatebb, device_aa, device_updateaa, device_dx, &
63 device_dy, device_deta, device_dxsi, device_maxval2, device_maxval3, &
64 device_kkt_rex, device_mattrans_v_mul, device_mma_dipsolvesub1, &
65 device_mma_ljjxinv, device_hess
66
67contains
68
69 subroutine device_hess(Hess_d, hijx_d, Ljjxinv_d, n, m)
70 type(c_ptr):: Hess_d, hijx_d, Ljjxinv_d
71 integer(c_int) :: n, m
72#if HAVE_HIP
73 call hip_hess(hess_d, hijx_d, ljjxinv_d, n, m)
74#elif HAVE_CUDA
75 call cuda_hess(hess_d, hijx_d, ljjxinv_d, n, m)
76#elif HAVE_OPENCL
77 call neko_error('no device backend configured')
78#else
79 call neko_error('no device backend configured')
80#endif
81 end subroutine device_hess
82
83 subroutine device_mma_ljjxinv(Ljjxinv_d,pjlambda_d, qjlambda_d, x_d, &
84 low_d, upp_d, alpha_d, beta_d, n)
85 !--------------------------------------------------------------------------!
86 ! A device support to do the following calculation needed for the !
87 ! dualsubsolve for MMA: !
88 ! Ljjxinv= - 1 / ( (2*pjlambda/(upp - x)**3) + & !
89 ! (2*qjlambda/(x - low)**3)) ! !
90 ! !
91 ! And then remove the sensitivity for the active primal constraints !
92 ! Ljjxinv = merge(0.0_rp, Ljjxinv, x .eq. alpha) !
93 ! Ljjxinv = merge(0.0_rp, Ljjxinv, x .eq. beta) !
94 !--------------------------------------------------------------------------!
95 type(c_ptr) :: Ljjxinv_d, pjlambda_d, qjlambda_d, x_d, &
96 low_d, upp_d, alpha_d, beta_d
97 integer(c_int) :: n
98#if HAVE_HIP
99 call mma_ljjxinv_hip(ljjxinv_d, pjlambda_d, qjlambda_d, x_d, &
100 low_d, upp_d, alpha_d, beta_d, n)
101#elif HAVE_CUDA
102 call mma_ljjxinv_cuda(ljjxinv_d, pjlambda_d, qjlambda_d, x_d, &
103 low_d, upp_d, alpha_d, beta_d, n)
104#elif HAVE_OPENCL
105 call neko_error('no device backend configured')
106#else
107 call neko_error('no device backend configured')
108#endif
109 end subroutine device_mma_ljjxinv
110
111
112 subroutine device_mma_dipsolvesub1(x_d, pjlambda_d, qjlambda_d, &
113 low_d, upp_d, alpha_d, beta_d, n)
114 !--------------------------------------------------------------------------!
115 ! A device support to do the following calculation needed for the !
116 ! dualsubsolve for MMA: !
117 ! x = (sqrt(pjlambda) * low + sqrt(qjlambda) * upp) / & !
118 ! (sqrt(pjlambda) + sqrt(qjlambda)) ! !
119 !--------------------------------------------------------------------------!
120 type(c_ptr) :: x_d, pjlambda_d, qjlambda_d, &
121 low_d, upp_d, alpha_d, beta_d
122 integer(c_int) :: n
123#if HAVE_HIP
124 call mma_dipsolvesub1_hip(x_d, pjlambda_d, qjlambda_d, &
125 low_d, upp_d, alpha_d, beta_d, n)
126#elif HAVE_CUDA
127 call mma_dipsolvesub1_cuda(x_d, pjlambda_d, qjlambda_d, &
128 low_d, upp_d, alpha_d, beta_d, n)
129#elif HAVE_OPENCL
130 call neko_error('no device backend configured')
131#else
132 call neko_error('no device backend configured')
133#endif
134 end subroutine device_mma_dipsolvesub1
135
136
137 subroutine device_mattrans_v_mul(output_d, pij_d, lambda_d, m, n)
138 !--------------------------------------------------------------------------!
139 ! A device support to do the following matrix multiplication !
140 ! output = matmul(transpose(pij), lambda) !
141 ! where matrix pij is mxn, vector lambda is of size m and the output !
142 ! vector is of size n !
143 !--------------------------------------------------------------------------!
144 type(c_ptr) :: output_d, pij_d, lambda_d
145 integer :: m, n
146#if HAVE_HIP
147 call mattrans_v_mul_hip(output_d, pij_d, lambda_d, m, n)
148#elif HAVE_CUDA
149 call mattrans_v_mul_cuda(output_d, pij_d, lambda_d, m, n)
150#elif HAVE_OPENCL
151 call neko_error('no device backend configured')
152#else
153 call neko_error('no device backend configured')
154#endif
155 end subroutine device_mattrans_v_mul
156
157
158
159 subroutine device_mma_gensub1(low_d, upp_d, x_d, xmin_d, xmax_d, asyinit, n)
160 type(c_ptr) :: low_d, upp_d, x_d, xmin_d, xmax_d
161 real(c_rp) :: asyinit
162 integer :: n
163#if HAVE_HIP
164 call mma_gensub1_hip(low_d, upp_d, x_d, xmin_d, xmax_d, asyinit, n)
165#elif HAVE_CUDA
166 call mma_gensub1_cuda(low_d, upp_d, x_d, xmin_d, xmax_d, asyinit, n)
167#elif HAVE_OPENCL
168 call neko_error('no device backend configured')
169#else
170 call neko_error('no device backend configured')
171#endif
172 end subroutine device_mma_gensub1
173
174
175 subroutine device_mma_gensub2(low_d, upp_d, x_d, xold1_d, xold2_d, xdiff_d, &
176 asydecr, asyincr, n)
177 type(c_ptr) :: low_d, upp_d, x_d, xold1_d, xold2_d, xdiff_d
178 real(c_rp) :: asydecr, asyincr
179 integer :: n
180#if HAVE_HIP
181 call mma_gensub2_hip(low_d, upp_d, x_d, xold1_d, xold2_d, xdiff_d, &
182 asydecr, asyincr, n)
183#elif HAVE_CUDA
184 call mma_gensub2_cuda(low_d, upp_d, x_d, xold1_d, xold2_d, xdiff_d, &
185 asydecr, asyincr, n)
186#elif HAVE_OPENCL
187 call neko_error('no device backend configured')
188#else
189 call neko_error('no device backend configured')
190#endif
191 end subroutine device_mma_gensub2
192
193 subroutine device_mma_gensub3(x_d, df0dx_d, dfdx_d, low_d, upp_d, min_d, &
194 max_d, alpha_d, beta_d, p0j_d, q0j_d, pij_d, qij_d, n, m)
195 type(c_ptr) :: x_d, df0dx_d, dfdx_d, low_d, upp_d, min_d, max_d, &
196 alpha_d, beta_d, p0j_d, q0j_d, pij_d, qij_d
197 integer :: n, m
198#if HAVE_HIP
199 call mma_gensub3_hip(x_d, df0dx_d, dfdx_d, low_d, upp_d, min_d, max_d, &
200 alpha_d, beta_d, p0j_d, q0j_d, pij_d, qij_d, n, m)
201#elif HAVE_CUDA
202 call mma_gensub3_cuda(x_d, df0dx_d, dfdx_d, low_d, upp_d, min_d, max_d, &
203 alpha_d, beta_d, p0j_d, q0j_d, pij_d, qij_d, n, m)
204#elif HAVE_OPENCL
205 call neko_error('no device backend configured2')
206#else
207 call neko_error('no device backend configured3')
208#endif
209 end subroutine device_mma_gensub3
210
211 subroutine device_mma_gensub4(x_d, low_d, upp_d, pij_d, qij_d, n, m, bi_d)
212 type(c_ptr) :: x_d, low_d, upp_d, pij_d, qij_d, bi_d
213 integer :: n, m
214#if HAVE_HIP
215 call mma_gensub4_hip(x_d, low_d, upp_d, pij_d, qij_d, n, m, bi_d)
216#elif HAVE_CUDA
217 call mma_gensub4_cuda(x_d, low_d, upp_d, pij_d, qij_d, n, m, bi_d)
218#elif HAVE_OPENCL
219 call neko_error('no device backend configured')
220#else
221 call neko_error('no device backend configured')
222#endif
223 end subroutine device_mma_gensub4
224
225 subroutine device_mma_max(xsi_d, x_d, alpha_d, n)
226 type(c_ptr) :: xsi_d, x_d, alpha_d
227 integer :: n
228#if HAVE_HIP
229 call hip_mma_max(xsi_d, x_d, alpha_d, n)
230#elif HAVE_CUDA
231 call cuda_mma_max(xsi_d, x_d, alpha_d, n)
232#elif HAVE_OPENCL
233 call neko_error('no device backend configured')
234#else
235 call neko_error('no device backend configured')
236#endif
237 end subroutine device_mma_max
238
239 subroutine device_max2(a_d, b, c_d, d, n)
240 type(c_ptr) :: a_d, c_d
241 real(c_rp) :: b, d
242 integer :: n
243#if HAVE_HIP
244 call hip_max2(a_d, b, c_d, d, n)
245#elif HAVE_CUDA
246 call cuda_max2(a_d, b, c_d, d, n)
247#elif HAVE_OPENCL
248 call neko_error('no device backend configured')
249#else
250 call neko_error('no device backend configured')
251#endif
252 end subroutine device_max2
253
254
255
256 subroutine device_rex(rex_d, x_d, low_d, upp_d, pij_d, p0j_d, qij_d, &
257 q0j_d, lambda_d, xsi_d, eta_d, n, m)
258 type(c_ptr) :: rex_d, x_d, low_d, upp_d, pij_d, p0j_d, qij_d, q0j_d, &
259 lambda_d, xsi_d, eta_d
260 integer(c_int) :: n, m
261#if HAVE_HIP
262 call hip_rex(rex_d, x_d, low_d, upp_d, pij_d, p0j_d, qij_d, q0j_d, &
263 lambda_d, xsi_d, eta_d, n, m)
264#elif HAVE_CUDA
265 call cuda_rex(rex_d, x_d, low_d, upp_d, pij_d, p0j_d, qij_d, q0j_d, &
266 lambda_d, xsi_d, eta_d, n, m)
267#elif HAVE_OPENCL
268 call neko_error('no device backend configured')
269#else
270 call neko_error('no device backend configured')
271#endif
272 end subroutine device_rex
273
274 function device_lcsc2(a_d, b_d, n) result(res)
275 type(c_ptr) :: a_d, b_d
276 integer(c_int) :: n
277 real(kind=rp) :: res
278 ! Default value in case of no valid backend (resolve compiler warning)
279 res = 0.0_rp
280#if HAVE_HIP
281 res = hip_lcsc2(a_d, b_d, n)
282#elif HAVE_CUDA
283 res = cuda_lcsc2(a_d, b_d, n)
284#elif HAVE_OPENCL
285 call neko_error('no device backend configured')
286#else
287 call neko_error('no device backend configured')
288#endif
289 end function device_lcsc2
290
291 subroutine device_relambda(relambda_d, x_d, upp_d, low_d, pij_d, qij_d, n, m)
292 type(c_ptr) :: relambda_d, x_d, upp_d, low_d, pij_d, qij_d
293 integer(c_int) :: n, m
294#if HAVE_HIP
295 call hip_relambda(relambda_d, x_d, upp_d, low_d, pij_d, qij_d, n, m)
296#elif HAVE_CUDA
297 call cuda_relambda(relambda_d, x_d, upp_d, low_d, pij_d, qij_d, n, m)
298#elif HAVE_OPENCL
299 call neko_error('no device backend configured')
300#else
301 call neko_error('no device backend configured')
302#endif
303 end subroutine device_relambda
304
305 subroutine device_sub2cons2(rexsi_d, xsi_d, x_d, alpha_d, epsi, n)
306 type(c_ptr):: rexsi_d, xsi_d, x_d, alpha_d
307 real(kind=rp) :: epsi
308 integer(c_int) :: n
309#if HAVE_HIP
310 call hip_sub2cons2(rexsi_d, xsi_d, x_d, alpha_d, epsi, n)
311#elif HAVE_CUDA
312 call cuda_sub2cons2(rexsi_d, xsi_d, x_d, alpha_d, epsi, n)
313#elif HAVE_OPENCL
314 call neko_error('no device backend configured')
315#else
316 call neko_error('no device backend configured')
317#endif
318 end subroutine device_sub2cons2
319
320 function device_maxval(rex_d, n) result(res)
321 type(c_ptr):: rex_d
322 real(kind=rp) :: res
323 integer(c_int) :: n
324 ! Default value in case of no valid backend (resolve compiler warning)
325 res = 0.0_rp
326#if HAVE_HIP
327 res = hip_maxval(rex_d, n)
328#elif HAVE_CUDA
329 res = cuda_maxval(rex_d, n)
330#elif HAVE_OPENCL
331 call neko_error('no device backend configured')
332#else
333 call neko_error('no device backend configured')
334#endif
335 end function device_maxval
336
337 function device_norm(rex_d, n) result(res)
338 type(c_ptr):: rex_d
339 real(kind=rp) :: res
340 integer(c_int) :: n
341 ! Default value in case of no valid backend (resolve compiler warning)
342 res = 0.0_rp
343#if HAVE_HIP
344 res = hip_norm(rex_d, n)
345#elif HAVE_CUDA
346 res = cuda_norm(rex_d, n)
347#elif HAVE_OPENCL
348 call neko_error('no device backend configured')
349#else
350 call neko_error('no device backend configured')
351#endif
352 end function device_norm
353
354 subroutine device_delx(delx_d, x_d, low_d, upp_d, pij_d, qij_d, p0j_d, &
355 q0j_d, alpha_d, beta_d, lambda_d, epsi, n, m)
356 type(c_ptr):: delx_d, x_d, low_d, upp_d, pij_d, qij_d, p0j_d, q0j_d, &
357 alpha_d, beta_d, lambda_d
358 real(kind=rp) :: epsi
359 integer(c_int) :: n, m
360#if HAVE_HIP
361 call hip_delx(delx_d, x_d, low_d, upp_d, pij_d, qij_d, p0j_d, q0j_d, &
362 alpha_d, beta_d, lambda_d, epsi, n, m)
363#elif HAVE_CUDA
364 call cuda_delx(delx_d, x_d, low_d, upp_d, pij_d, qij_d, p0j_d, q0j_d, &
365 alpha_d, beta_d, lambda_d, epsi, n, m)
366#elif HAVE_OPENCL
367 call neko_error('no device backend configured')
368#else
369 call neko_error('no device backend configured')
370#endif
371 end subroutine device_delx
372
373 subroutine device_add2inv2(a_d, b_d, c, n)
374 type(c_ptr):: a_d, b_d
375 real(kind=rp) :: c
376 integer(c_int) :: n
377#if HAVE_HIP
378 call hip_add2inv2(a_d, b_d, c, n)
379#elif HAVE_CUDA
380 call cuda_add2inv2(a_d, b_d, c, n)
381#elif HAVE_OPENCL
382 call neko_error('no device backend configured')
383#else
384 call neko_error('no device backend configured')
385#endif
386 end subroutine device_add2inv2
387
388
389 subroutine device_gg(GG_d, x_d, low_d, upp_d, pij_d, qij_d, n, m)
390 type(c_ptr):: GG_d, x_d, low_d, upp_d, pij_d, qij_d
391 integer(c_int) :: n, m
392#if HAVE_HIP
393 call hip_gg(gg_d, x_d, low_d, upp_d, pij_d, qij_d, n, m)
394#elif HAVE_CUDA
395 call cuda_gg(gg_d, x_d, low_d, upp_d, pij_d, qij_d, n, m)
396#elif HAVE_OPENCL
397 call neko_error('no device backend configured')
398#else
399 call neko_error('no device backend configured')
400#endif
401 end subroutine device_gg
402
403 subroutine device_diagx(diagx_d, x_d, xsi_d, low_d, upp_d, p0j_d, q0j_d, &
404 pij_d, qij_d, alpha_d, beta_d, eta_d, lambda_d, n, m)
405 type(c_ptr):: diagx_d, x_d, xsi_d, low_d, upp_d, p0j_d, q0j_d, pij_d, &
406 qij_d, alpha_d, &
407 beta_d, eta_d, lambda_d
408 integer(c_int) :: n, m
409#if HAVE_HIP
410 call hip_diagx(diagx_d, x_d, xsi_d, low_d, upp_d, p0j_d, q0j_d, pij_d, &
411 qij_d, alpha_d, beta_d, eta_d, lambda_d, n, m)
412#elif HAVE_CUDA
413 call cuda_diagx(diagx_d, x_d, xsi_d, low_d, upp_d, p0j_d, q0j_d, pij_d, &
414 qij_d, alpha_d, beta_d, eta_d, lambda_d, n, m)
415#elif HAVE_OPENCL
416 call neko_error('no device backend configured')
417#else
418 call neko_error('no device backend configured')
419#endif
420 end subroutine device_diagx
421
422
423 subroutine device_bb(bb_d, GG_d, delx_d, diagx_d, n, m)
424 type(c_ptr):: bb_d, GG_d, delx_d, diagx_d
425 integer(c_int) :: n, m
426#if HAVE_HIP
427 call hip_bb(bb_d, gg_d, delx_d, diagx_d, n, m)
428#elif HAVE_CUDA
429 call cuda_bb(bb_d, gg_d, delx_d, diagx_d, n, m)
430#elif HAVE_OPENCL
431 call neko_error('no device backend configured')
432#else
433 call neko_error('no device backend configured')
434#endif
435 end subroutine device_bb
436
437 subroutine device_updatebb(bb_d, dellambda_d, dely_d, d_d, mu_d, y_d, delz, m)
438 type(c_ptr):: bb_d, dellambda_d, dely_d, d_d, mu_d, y_d
439 integer(c_int) :: m
440 real(c_rp) :: delz
441#if HAVE_HIP
442 call hip_updatebb(bb_d, dellambda_d, dely_d, d_d, mu_d, y_d, delz, m)
443#elif HAVE_CUDA
444 call cuda_updatebb(bb_d, dellambda_d, dely_d, d_d, mu_d, y_d, delz, m)
445#elif HAVE_OPENCL
446 call neko_error('no device backend configured')
447#else
448 call neko_error('no device backend configured')
449#endif
450 end subroutine device_updatebb
451
452 subroutine device_aa(AA_d, GG_d, diagx_d, n, m)
453 type(c_ptr):: AA_d, GG_d, diagx_d
454 integer(c_int) :: n, m
455#if HAVE_HIP
456 call hip_aa(aa_d, gg_d, diagx_d, n, m)
457#elif HAVE_CUDA
458 call cuda_aa(aa_d, gg_d, diagx_d, n, m)
459#elif HAVE_OPENCL
460 call neko_error('no device backend configured')
461#else
462 call neko_error('no device backend configured')
463#endif
464 end subroutine device_aa
465
466 subroutine device_updateaa(AA_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, &
467 y_d, a_d, zeta, z, m)
468 type(c_ptr):: AA_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, y_d, a_d
469 integer(c_int) :: m
470 real(c_rp) :: zeta, z
471#if HAVE_HIP
472 call hip_updateaa(aa_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, y_d, &
473 a_d, zeta, z, m)
474#elif HAVE_CUDA
475 call cuda_updateaa(aa_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, y_d, &
476 a_d, zeta, z, m)
477#elif HAVE_OPENCL
478 call neko_error('no device backend configured')
479#else
480 call neko_error('no device backend configured')
481#endif
482 end subroutine device_updateaa
483
484 subroutine device_dx(dx_d, delx_d, diagx_d, GG_d, dlambda_d, n, m)
485 type(c_ptr):: dx_d, delx_d, diagx_d, GG_d, dlambda_d
486 integer(c_int) :: n, m
487#if HAVE_HIP
488 call hip_dx(dx_d, delx_d, diagx_d, gg_d, dlambda_d, n, m)
489#elif HAVE_CUDA
490 call cuda_dx(dx_d, delx_d, diagx_d, gg_d, dlambda_d, n, m)
491#elif HAVE_OPENCL
492 call neko_error('no device backend configured')
493#else
494 call neko_error('no device backend configured')
495#endif
496 end subroutine device_dx
497
498 subroutine device_dy(dy_d, dely_d, dlambda_d, d_d, mu_d, y_d, n)
499 type(c_ptr):: dy_d, dely_d, dlambda_d, d_d, mu_d, y_d
500 integer(c_int) :: n
501#if HAVE_HIP
502 call hip_dy(dy_d, dely_d, dlambda_d, d_d, mu_d, y_d, n)
503#elif HAVE_CUDA
504 call cuda_dy(dy_d, dely_d, dlambda_d, d_d, mu_d, y_d, n)
505#elif HAVE_OPENCL
506 call neko_error('no device backend configured')
507#else
508 call neko_error('no device backend configured')
509#endif
510 end subroutine device_dy
511
512 subroutine device_dxsi(dxsi_d, xsi_d, dx_d, x_d, alpha_d, epsi, n)
513 type(c_ptr):: dxsi_d, xsi_d, dx_d, x_d, alpha_d
514 integer(c_int) :: n
515 real(c_rp) :: epsi
516#if HAVE_HIP
517 call hip_dxsi(dxsi_d, xsi_d, dx_d, x_d, alpha_d, epsi, n)
518#elif HAVE_CUDA
519 call cuda_dxsi(dxsi_d, xsi_d, dx_d, x_d, alpha_d, epsi, n)
520#elif HAVE_OPENCL
521 call neko_error('no device backend configured')
522#else
523 call neko_error('no device backend configured')
524#endif
525 end subroutine device_dxsi
526
527 subroutine device_deta(deta_d, eta_d, dx_d, x_d, beta_d, epsi, n)
528 type(c_ptr):: deta_d, eta_d, dx_d, x_d, beta_d
529 integer(c_int) :: n
530 real(c_rp) :: epsi
531#if HAVE_HIP
532 call hip_deta(deta_d, eta_d, dx_d, x_d, beta_d, epsi, n)
533#elif HAVE_CUDA
534 call cuda_deta(deta_d, eta_d, dx_d, x_d, beta_d, epsi, n)
535#elif HAVE_OPENCL
536 call neko_error('no device backend configured')
537#else
538 call neko_error('no device backend configured')
539#endif
540 end subroutine device_deta
541
542 function device_maxval2(dxx_d, xx_d, cons, n) result(res)
543 type(c_ptr):: dxx_d, xx_d
544 integer :: n
545 real(kind=rp), intent(in) :: cons
546 real(kind=rp) :: res
547 ! Default value in case of no valid backend (resolve compiler warning)
548 res = 0.0_rp
549#if HAVE_HIP
550 res = hip_maxval2(dxx_d, xx_d, cons, n)
551#elif HAVE_CUDA
552 res = cuda_maxval2(dxx_d, xx_d, cons, n)
553#elif HAVE_OPENCL
554 call neko_error('no device backend configured')
555#else
556 call neko_error('no device backend configured')
557#endif
558 end function device_maxval2
559
560
561 function device_maxval3(dx_d, x_d, alpha_d, cons, n) result(res)
562 type(c_ptr):: dx_d, x_d, alpha_d
563 real(kind=rp), intent(in) :: cons
564 real(kind=rp) :: res
565 integer(c_int) :: n
566 ! Default value in case of no valid backend (resolve compiler warning)
567 res = 0.0_rp
568#if HAVE_HIP
569 res = hip_maxval3(dx_d, x_d, alpha_d, cons, n)
570#elif HAVE_CUDA
571 res = cuda_maxval3(dx_d, x_d, alpha_d, cons, n)
572#elif HAVE_OPENCL
573 call neko_error('no device backend configured')
574#else
575 call neko_error('no device backend configured')
576#endif
577 end function device_maxval3
578
579
580
581 subroutine device_kkt_rex(rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d, &
582 n, m)
583 type(c_ptr):: rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d
584 integer(c_int) :: n, m
585#if HAVE_HIP
586 call hip_kkt_rex(rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d, n, m)
587#elif HAVE_CUDA
588 call cuda_kkt_rex(rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d, n, m)
589#elif HAVE_OPENCL
590 call neko_error('no device backend configured')
591#else
592 call neko_error('no device backend configured')
593#endif
594 end subroutine device_kkt_rex
595
596! #endif
597
598end module device_mma_math