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, &
48 use hip_mma_math, only: hip_mma_max, hip_max2, hip_rex, hip_lcsc2, &
57
58 implicit none
59 private
60
61
62 public :: device_mma_gensub1, device_mma_gensub2, device_mma_gensub3, &
63 device_mma_gensub4, device_mma_max, device_max2, device_rex, &
64 device_lcsc2, device_relambda, device_sub2cons2, device_maxval, &
65 device_norm, device_delx, device_add2inv2, device_gg, device_diagx, &
66 device_bb, device_updatebb, device_aa, device_updateaa, device_dx, &
67 device_dy, device_deta, device_dxsi, device_maxval2, device_maxval3, &
68 device_kkt_rex, device_mattrans_v_mul, device_mma_dipsolvesub1, &
69 device_mma_ljjxinv, device_hess, device_delta_1dbeam, &
70 device_solve_linear_system, device_prepare_hessian, &
71 device_prepare_aa_matrix
72
73contains
75 subroutine device_prepare_aa_matrix(AA_d, s_d, lambda_d, d_d, mu_d, y_d, &
76 a_d, zeta, z, m)
77 type(c_ptr) :: AA_d, s_d, lambda_d, d_d, mu_d, y_d, a_d
78 real(c_rp) :: zeta, z
79 integer, value :: m
80#if HAVE_HIP
81 call mma_prepare_aa_matrix_hip(aa_d, s_d, lambda_d, d_d, mu_d, y_d, a_d, &
82 zeta, z, m)
83#elif HAVE_CUDA
84 call mma_prepare_aa_matrix_cuda(aa_d, s_d, lambda_d, d_d, mu_d, y_d, a_d, &
85 zeta, z, m)
86#elif HAVE_OPENCL
87 call neko_error('AA matrix preparation not implemented for OpenCL')
88#else
89 call neko_error('No device backend configured for AA matrix preparation')
90#endif
91 end subroutine device_prepare_aa_matrix
92
94 subroutine device_prepare_hessian(Hess_d, y_d, d_d, mu_d, lambda_d, m)
95 type(c_ptr) :: Hess_d, y_d, d_d, mu_d, lambda_d
96 integer, value :: m
97#if HAVE_HIP
98 call mma_prepare_hessian_hip(hess_d, y_d, d_d, mu_d, lambda_d, m)
99#elif HAVE_CUDA
100 call mma_prepare_hessian_cuda(hess_d, y_d, d_d, mu_d, lambda_d, m)
101#elif HAVE_OPENCL
102 call neko_error('no device backend configured')
103#else
104 call neko_error('no device backend configured')
105#endif
106 end subroutine device_prepare_hessian
107
108 subroutine device_solve_linear_system(A_d, b_d, n, info)
109 type(c_ptr) :: A_d, b_d
110 integer(c_int), value :: n
111 integer(c_int) :: info
112#if HAVE_HIP
113 call hipsolver_wrapper(a_d, b_d, n, info)
114 ! call hip_custom_solver(A_d, b_d, n, info)
115#elif HAVE_CUDA
116 call cusolver_wrapper(a_d, b_d, n, info)
117 ! call cuda_custom_solver(A_d, b_d, n, info)
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_solve_linear_system
124
125
130 subroutine device_delta_1dbeam(Delta_d, L_total, Le, offset, n)
131 type(c_ptr) :: Delta_d
132 real(c_rp) :: L_total, Le
133 integer(c_int), value :: offset, n
134#if HAVE_HIP
135 call delta_1dbeam_hip(delta_d, l_total, le, offset, n)
136#elif HAVE_CUDA
137 call delta_1dbeam_cuda(delta_d, l_total, le, offset, n)
138#elif HAVE_OPENCL
139 call neko_error('no device backend configured')
140#else
141 call neko_error('no device backend configured')
142#endif
143 end subroutine device_delta_1dbeam
144
145
146 subroutine device_hess(Hess_d, hijx_d, Ljjxinv_d, n, m)
147 type(c_ptr):: Hess_d, hijx_d, Ljjxinv_d
148 integer(c_int) :: n, m
149#if HAVE_HIP
150 call hip_hess(hess_d, hijx_d, ljjxinv_d, n, m)
151#elif HAVE_CUDA
152 call cuda_hess(hess_d, hijx_d, ljjxinv_d, n, m)
153#elif HAVE_OPENCL
154 call neko_error('no device backend configured')
155#else
156 call neko_error('no device backend configured')
157#endif
158 end subroutine device_hess
159
160
169 subroutine device_mma_ljjxinv(Ljjxinv_d,pjlambda_d, qjlambda_d, x_d, &
170 low_d, upp_d, alpha_d, beta_d, n)
171 type(c_ptr) :: Ljjxinv_d, pjlambda_d, qjlambda_d, x_d, &
172 low_d, upp_d, alpha_d, beta_d
173 integer(c_int) :: n
174#if HAVE_HIP
175 call mma_ljjxinv_hip(ljjxinv_d, pjlambda_d, qjlambda_d, x_d, &
176 low_d, upp_d, alpha_d, beta_d, n)
177#elif HAVE_CUDA
178 call mma_ljjxinv_cuda(ljjxinv_d, pjlambda_d, qjlambda_d, x_d, &
179 low_d, upp_d, alpha_d, beta_d, n)
180#elif HAVE_OPENCL
181 call neko_error('no device backend configured')
182#else
183 call neko_error('no device backend configured')
184#endif
185 end subroutine device_mma_ljjxinv
186
187
192 subroutine device_mma_dipsolvesub1(x_d, pjlambda_d, qjlambda_d, &
193 low_d, upp_d, alpha_d, beta_d, n)
194 type(c_ptr) :: x_d, pjlambda_d, qjlambda_d, &
195 low_d, upp_d, alpha_d, beta_d
196 integer(c_int) :: n
197#if HAVE_HIP
198 call mma_dipsolvesub1_hip(x_d, pjlambda_d, qjlambda_d, &
199 low_d, upp_d, alpha_d, beta_d, n)
200#elif HAVE_CUDA
201 call mma_dipsolvesub1_cuda(x_d, pjlambda_d, qjlambda_d, &
202 low_d, upp_d, alpha_d, beta_d, n)
203#elif HAVE_OPENCL
204 call neko_error('no device backend configured')
205#else
206 call neko_error('no device backend configured')
207#endif
208 end subroutine device_mma_dipsolvesub1
209
210
215 subroutine device_mattrans_v_mul(output_d, pij_d, lambda_d, m, n)
216 type(c_ptr) :: output_d, pij_d, lambda_d
217 integer :: m, n
218#if HAVE_HIP
219 call mattrans_v_mul_hip(output_d, pij_d, lambda_d, m, n)
220#elif HAVE_CUDA
221 call mattrans_v_mul_cuda(output_d, pij_d, lambda_d, m, n)
222#elif HAVE_OPENCL
223 call neko_error('no device backend configured')
224#else
225 call neko_error('no device backend configured')
226#endif
227 end subroutine device_mattrans_v_mul
228
229
230
231 subroutine device_mma_gensub1(low_d, upp_d, x_d, xmin_d, xmax_d, asyinit, n)
232 type(c_ptr) :: low_d, upp_d, x_d, xmin_d, xmax_d
233 real(c_rp) :: asyinit
234 integer :: n
235#if HAVE_HIP
236 call mma_gensub1_hip(low_d, upp_d, x_d, xmin_d, xmax_d, asyinit, n)
237#elif HAVE_CUDA
238 call mma_gensub1_cuda(low_d, upp_d, x_d, xmin_d, xmax_d, asyinit, n)
239#elif HAVE_OPENCL
240 call neko_error('no device backend configured')
241#else
242 call neko_error('no device backend configured')
243#endif
244 end subroutine device_mma_gensub1
245
246
247 subroutine device_mma_gensub2(low_d, upp_d, x_d, xold1_d, xold2_d, xdiff_d, &
248 asydecr, asyincr, n)
249 type(c_ptr) :: low_d, upp_d, x_d, xold1_d, xold2_d, xdiff_d
250 real(c_rp) :: asydecr, asyincr
251 integer :: n
252#if HAVE_HIP
253 call mma_gensub2_hip(low_d, upp_d, x_d, xold1_d, xold2_d, xdiff_d, &
254 asydecr, asyincr, n)
255#elif HAVE_CUDA
256 call mma_gensub2_cuda(low_d, upp_d, x_d, xold1_d, xold2_d, xdiff_d, &
257 asydecr, asyincr, n)
258#elif HAVE_OPENCL
259 call neko_error('no device backend configured')
260#else
261 call neko_error('no device backend configured')
262#endif
263 end subroutine device_mma_gensub2
264
265 subroutine device_mma_gensub3(x_d, df0dx_d, dfdx_d, low_d, upp_d, min_d, &
266 max_d, alpha_d, beta_d, p0j_d, q0j_d, pij_d, qij_d, n, m)
267 type(c_ptr) :: x_d, df0dx_d, dfdx_d, low_d, upp_d, min_d, max_d, &
268 alpha_d, beta_d, p0j_d, q0j_d, pij_d, qij_d
269 integer :: n, m
270#if HAVE_HIP
271 call mma_gensub3_hip(x_d, df0dx_d, dfdx_d, low_d, upp_d, min_d, max_d, &
272 alpha_d, beta_d, p0j_d, q0j_d, pij_d, qij_d, n, m)
273#elif HAVE_CUDA
274 call mma_gensub3_cuda(x_d, df0dx_d, dfdx_d, low_d, upp_d, min_d, max_d, &
275 alpha_d, beta_d, p0j_d, q0j_d, pij_d, qij_d, n, m)
276#elif HAVE_OPENCL
277 call neko_error('no device backend configured2')
278#else
279 call neko_error('no device backend configured3')
280#endif
281 end subroutine device_mma_gensub3
282
283 subroutine device_mma_gensub4(x_d, low_d, upp_d, pij_d, qij_d, n, m, bi_d)
284 type(c_ptr) :: x_d, low_d, upp_d, pij_d, qij_d, bi_d
285 integer :: n, m
286#if HAVE_HIP
287 call mma_gensub4_hip(x_d, low_d, upp_d, pij_d, qij_d, n, m, bi_d)
288#elif HAVE_CUDA
289 call mma_gensub4_cuda(x_d, low_d, upp_d, pij_d, qij_d, n, m, bi_d)
290#elif HAVE_OPENCL
291 call neko_error('no device backend configured')
292#else
293 call neko_error('no device backend configured')
294#endif
295 end subroutine device_mma_gensub4
296
297 subroutine device_mma_max(xsi_d, x_d, alpha_d, n)
298 type(c_ptr) :: xsi_d, x_d, alpha_d
299 integer :: n
300#if HAVE_HIP
301 call hip_mma_max(xsi_d, x_d, alpha_d, n)
302#elif HAVE_CUDA
303 call cuda_mma_max(xsi_d, x_d, alpha_d, n)
304#elif HAVE_OPENCL
305 call neko_error('no device backend configured')
306#else
307 call neko_error('no device backend configured')
308#endif
309 end subroutine device_mma_max
310
311 subroutine device_max2(a_d, b, c_d, d, n)
312 type(c_ptr) :: a_d, c_d
313 real(c_rp) :: b, d
314 integer :: n
315#if HAVE_HIP
316 call hip_max2(a_d, b, c_d, d, n)
317#elif HAVE_CUDA
318 call cuda_max2(a_d, b, c_d, d, n)
319#elif HAVE_OPENCL
320 call neko_error('no device backend configured')
321#else
322 call neko_error('no device backend configured')
323#endif
324 end subroutine device_max2
325
326
327
328 subroutine device_rex(rex_d, x_d, low_d, upp_d, pij_d, p0j_d, qij_d, &
329 q0j_d, lambda_d, xsi_d, eta_d, n, m)
330 type(c_ptr) :: rex_d, x_d, low_d, upp_d, pij_d, p0j_d, qij_d, q0j_d, &
331 lambda_d, xsi_d, eta_d
332 integer(c_int) :: n, m
333#if HAVE_HIP
334 call hip_rex(rex_d, x_d, low_d, upp_d, pij_d, p0j_d, qij_d, q0j_d, &
335 lambda_d, xsi_d, eta_d, n, m)
336#elif HAVE_CUDA
337 call cuda_rex(rex_d, x_d, low_d, upp_d, pij_d, p0j_d, qij_d, q0j_d, &
338 lambda_d, xsi_d, eta_d, n, m)
339#elif HAVE_OPENCL
340 call neko_error('no device backend configured')
341#else
342 call neko_error('no device backend configured')
343#endif
344 end subroutine device_rex
345
346 function device_lcsc2(a_d, b_d, n) result(res)
347 type(c_ptr) :: a_d, b_d
348 integer(c_int) :: n
349 real(kind=rp) :: res
350 ! Default value in case of no valid backend (resolve compiler warning)
351 res = 0.0_rp
352#if HAVE_HIP
353 res = hip_lcsc2(a_d, b_d, n)
354#elif HAVE_CUDA
355 res = cuda_lcsc2(a_d, b_d, n)
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 function device_lcsc2
362
363 subroutine device_relambda(relambda_d, x_d, upp_d, low_d, pij_d, qij_d, n, m)
364 type(c_ptr) :: relambda_d, x_d, upp_d, low_d, pij_d, qij_d
365 integer(c_int) :: n, m
366#if HAVE_HIP
367 call hip_relambda(relambda_d, x_d, upp_d, low_d, pij_d, qij_d, n, m)
368#elif HAVE_CUDA
369 call cuda_relambda(relambda_d, x_d, upp_d, low_d, pij_d, qij_d, n, m)
370#elif HAVE_OPENCL
371 call neko_error('no device backend configured')
372#else
373 call neko_error('no device backend configured')
374#endif
375 end subroutine device_relambda
376
377 subroutine device_sub2cons2(rexsi_d, xsi_d, x_d, alpha_d, epsi, n)
378 type(c_ptr):: rexsi_d, xsi_d, x_d, alpha_d
379 real(kind=rp) :: epsi
380 integer(c_int) :: n
381#if HAVE_HIP
382 call hip_sub2cons2(rexsi_d, xsi_d, x_d, alpha_d, epsi, n)
383#elif HAVE_CUDA
384 call cuda_sub2cons2(rexsi_d, xsi_d, x_d, alpha_d, epsi, n)
385#elif HAVE_OPENCL
386 call neko_error('no device backend configured')
387#else
388 call neko_error('no device backend configured')
389#endif
390 end subroutine device_sub2cons2
391
392 function device_maxval(rex_d, n) result(res)
393 type(c_ptr):: rex_d
394 real(kind=rp) :: res
395 integer(c_int) :: n
396 ! Default value in case of no valid backend (resolve compiler warning)
397 res = 0.0_rp
398#if HAVE_HIP
399 res = hip_maxval(rex_d, n)
400#elif HAVE_CUDA
401 res = cuda_maxval(rex_d, n)
402#elif HAVE_OPENCL
403 call neko_error('no device backend configured')
404#else
405 call neko_error('no device backend configured')
406#endif
407 end function device_maxval
408
409 function device_norm(rex_d, n) result(res)
410 type(c_ptr):: rex_d
411 real(kind=rp) :: res
412 integer(c_int) :: n
413 ! Default value in case of no valid backend (resolve compiler warning)
414 res = 0.0_rp
415#if HAVE_HIP
416 res = hip_norm(rex_d, n)
417#elif HAVE_CUDA
418 res = cuda_norm(rex_d, n)
419#elif HAVE_OPENCL
420 call neko_error('no device backend configured')
421#else
422 call neko_error('no device backend configured')
423#endif
424 end function device_norm
425
426 subroutine device_delx(delx_d, x_d, low_d, upp_d, pij_d, qij_d, p0j_d, &
427 q0j_d, alpha_d, beta_d, lambda_d, epsi, n, m)
428 type(c_ptr):: delx_d, x_d, low_d, upp_d, pij_d, qij_d, p0j_d, q0j_d, &
429 alpha_d, beta_d, lambda_d
430 real(kind=rp) :: epsi
431 integer(c_int) :: n, m
432#if HAVE_HIP
433 call hip_delx(delx_d, x_d, low_d, upp_d, pij_d, qij_d, p0j_d, q0j_d, &
434 alpha_d, beta_d, lambda_d, epsi, n, m)
435#elif HAVE_CUDA
436 call cuda_delx(delx_d, x_d, low_d, upp_d, pij_d, qij_d, p0j_d, q0j_d, &
437 alpha_d, beta_d, lambda_d, epsi, n, m)
438#elif HAVE_OPENCL
439 call neko_error('no device backend configured')
440#else
441 call neko_error('no device backend configured')
442#endif
443 end subroutine device_delx
444
445 subroutine device_add2inv2(a_d, b_d, c, n)
446 type(c_ptr):: a_d, b_d
447 real(kind=rp) :: c
448 integer(c_int) :: n
449#if HAVE_HIP
450 call hip_add2inv2(a_d, b_d, c, n)
451#elif HAVE_CUDA
452 call cuda_add2inv2(a_d, b_d, c, n)
453#elif HAVE_OPENCL
454 call neko_error('no device backend configured')
455#else
456 call neko_error('no device backend configured')
457#endif
458 end subroutine device_add2inv2
459
460
461 subroutine device_gg(GG_d, x_d, low_d, upp_d, pij_d, qij_d, n, m)
462 type(c_ptr):: GG_d, x_d, low_d, upp_d, pij_d, qij_d
463 integer(c_int) :: n, m
464#if HAVE_HIP
465 call hip_gg(gg_d, x_d, low_d, upp_d, pij_d, qij_d, n, m)
466#elif HAVE_CUDA
467 call cuda_gg(gg_d, x_d, low_d, upp_d, pij_d, qij_d, n, m)
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 subroutine device_gg
474
475 subroutine device_diagx(diagx_d, x_d, xsi_d, low_d, upp_d, p0j_d, q0j_d, &
476 pij_d, qij_d, alpha_d, beta_d, eta_d, lambda_d, n, m)
477 type(c_ptr):: diagx_d, x_d, xsi_d, low_d, upp_d, p0j_d, q0j_d, pij_d, &
478 qij_d, alpha_d, &
479 beta_d, eta_d, lambda_d
480 integer(c_int) :: n, m
481#if HAVE_HIP
482 call hip_diagx(diagx_d, x_d, xsi_d, low_d, upp_d, p0j_d, q0j_d, pij_d, &
483 qij_d, alpha_d, beta_d, eta_d, lambda_d, n, m)
484#elif HAVE_CUDA
485 call cuda_diagx(diagx_d, x_d, xsi_d, low_d, upp_d, p0j_d, q0j_d, pij_d, &
486 qij_d, alpha_d, beta_d, eta_d, lambda_d, n, m)
487#elif HAVE_OPENCL
488 call neko_error('no device backend configured')
489#else
490 call neko_error('no device backend configured')
491#endif
492 end subroutine device_diagx
493
494
495 subroutine device_bb(bb_d, GG_d, delx_d, diagx_d, n, m)
496 type(c_ptr):: bb_d, GG_d, delx_d, diagx_d
497 integer(c_int) :: n, m
498#if HAVE_HIP
499 call hip_bb(bb_d, gg_d, delx_d, diagx_d, n, m)
500#elif HAVE_CUDA
501 call cuda_bb(bb_d, gg_d, delx_d, diagx_d, n, m)
502#elif HAVE_OPENCL
503 call neko_error('no device backend configured')
504#else
505 call neko_error('no device backend configured')
506#endif
507 end subroutine device_bb
508
509 subroutine device_updatebb(bb_d, dellambda_d, dely_d, d_d, mu_d, y_d, delz, m)
510 type(c_ptr):: bb_d, dellambda_d, dely_d, d_d, mu_d, y_d
511 integer(c_int) :: m
512 real(c_rp) :: delz
513#if HAVE_HIP
514 call hip_updatebb(bb_d, dellambda_d, dely_d, d_d, mu_d, y_d, delz, m)
515#elif HAVE_CUDA
516 call cuda_updatebb(bb_d, dellambda_d, dely_d, d_d, mu_d, y_d, delz, m)
517#elif HAVE_OPENCL
518 call neko_error('no device backend configured')
519#else
520 call neko_error('no device backend configured')
521#endif
522 end subroutine device_updatebb
523
524 subroutine device_aa(AA_d, GG_d, diagx_d, n, m)
525 type(c_ptr):: AA_d, GG_d, diagx_d
526 integer(c_int) :: n, m
527#if HAVE_HIP
528 call hip_aa(aa_d, gg_d, diagx_d, n, m)
529#elif HAVE_CUDA
530 call cuda_aa(aa_d, gg_d, diagx_d, n, m)
531#elif HAVE_OPENCL
532 call neko_error('no device backend configured')
533#else
534 call neko_error('no device backend configured')
535#endif
536 end subroutine device_aa
537
538 subroutine device_updateaa(AA_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, &
539 y_d, a_d, zeta, z, m)
540 type(c_ptr):: AA_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, y_d, a_d
541 integer(c_int) :: m
542 real(c_rp) :: zeta, z
543#if HAVE_HIP
544 call hip_updateaa(aa_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, y_d, &
545 a_d, zeta, z, m)
546#elif HAVE_CUDA
547 call cuda_updateaa(aa_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, y_d, &
548 a_d, zeta, z, m)
549#elif HAVE_OPENCL
550 call neko_error('no device backend configured')
551#else
552 call neko_error('no device backend configured')
553#endif
554 end subroutine device_updateaa
555
556 subroutine device_dx(dx_d, delx_d, diagx_d, GG_d, dlambda_d, n, m)
557 type(c_ptr):: dx_d, delx_d, diagx_d, GG_d, dlambda_d
558 integer(c_int) :: n, m
559#if HAVE_HIP
560 call hip_dx(dx_d, delx_d, diagx_d, gg_d, dlambda_d, n, m)
561#elif HAVE_CUDA
562 call cuda_dx(dx_d, delx_d, diagx_d, gg_d, dlambda_d, n, m)
563#elif HAVE_OPENCL
564 call neko_error('no device backend configured')
565#else
566 call neko_error('no device backend configured')
567#endif
568 end subroutine device_dx
569
570 subroutine device_dy(dy_d, dely_d, dlambda_d, d_d, mu_d, y_d, n)
571 type(c_ptr):: dy_d, dely_d, dlambda_d, d_d, mu_d, y_d
572 integer(c_int) :: n
573#if HAVE_HIP
574 call hip_dy(dy_d, dely_d, dlambda_d, d_d, mu_d, y_d, n)
575#elif HAVE_CUDA
576 call cuda_dy(dy_d, dely_d, dlambda_d, d_d, mu_d, y_d, n)
577#elif HAVE_OPENCL
578 call neko_error('no device backend configured')
579#else
580 call neko_error('no device backend configured')
581#endif
582 end subroutine device_dy
583
584 subroutine device_dxsi(dxsi_d, xsi_d, dx_d, x_d, alpha_d, epsi, n)
585 type(c_ptr):: dxsi_d, xsi_d, dx_d, x_d, alpha_d
586 integer(c_int) :: n
587 real(c_rp) :: epsi
588#if HAVE_HIP
589 call hip_dxsi(dxsi_d, xsi_d, dx_d, x_d, alpha_d, epsi, n)
590#elif HAVE_CUDA
591 call cuda_dxsi(dxsi_d, xsi_d, dx_d, x_d, alpha_d, epsi, n)
592#elif HAVE_OPENCL
593 call neko_error('no device backend configured')
594#else
595 call neko_error('no device backend configured')
596#endif
597 end subroutine device_dxsi
598
599 subroutine device_deta(deta_d, eta_d, dx_d, x_d, beta_d, epsi, n)
600 type(c_ptr):: deta_d, eta_d, dx_d, x_d, beta_d
601 integer(c_int) :: n
602 real(c_rp) :: epsi
603#if HAVE_HIP
604 call hip_deta(deta_d, eta_d, dx_d, x_d, beta_d, epsi, n)
605#elif HAVE_CUDA
606 call cuda_deta(deta_d, eta_d, dx_d, x_d, beta_d, epsi, n)
607#elif HAVE_OPENCL
608 call neko_error('no device backend configured')
609#else
610 call neko_error('no device backend configured')
611#endif
612 end subroutine device_deta
613
614 function device_maxval2(dxx_d, xx_d, cons, n) result(res)
615 type(c_ptr):: dxx_d, xx_d
616 integer :: n
617 real(kind=rp), intent(in) :: cons
618 real(kind=rp) :: res
619 ! Default value in case of no valid backend (resolve compiler warning)
620 res = 0.0_rp
621#if HAVE_HIP
622 res = hip_maxval2(dxx_d, xx_d, cons, n)
623#elif HAVE_CUDA
624 res = cuda_maxval2(dxx_d, xx_d, cons, n)
625#elif HAVE_OPENCL
626 call neko_error('no device backend configured')
627#else
628 call neko_error('no device backend configured')
629#endif
630 end function device_maxval2
631
632
633 function device_maxval3(dx_d, x_d, alpha_d, cons, n) result(res)
634 type(c_ptr):: dx_d, x_d, alpha_d
635 real(kind=rp), intent(in) :: cons
636 real(kind=rp) :: res
637 integer(c_int) :: n
638 ! Default value in case of no valid backend (resolve compiler warning)
639 res = 0.0_rp
640#if HAVE_HIP
641 res = hip_maxval3(dx_d, x_d, alpha_d, cons, n)
642#elif HAVE_CUDA
643 res = cuda_maxval3(dx_d, x_d, alpha_d, cons, n)
644#elif HAVE_OPENCL
645 call neko_error('no device backend configured')
646#else
647 call neko_error('no device backend configured')
648#endif
649 end function device_maxval3
650
651
652
653 subroutine device_kkt_rex(rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d, &
654 n, m)
655 type(c_ptr):: rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d
656 integer(c_int) :: n, m
657#if HAVE_HIP
658 call hip_kkt_rex(rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d, n, m)
659#elif HAVE_CUDA
660 call cuda_kkt_rex(rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d, n, m)
661#elif HAVE_OPENCL
662 call neko_error('no device backend configured')
663#else
664 call neko_error('no device backend configured')
665#endif
666 end subroutine device_kkt_rex
667
668! #endif
669
670end module device_mma_math