36 use,
intrinsic :: iso_c_binding, only: c_ptr, c_int
37 use num_types,
only: rp, c_rp
38 use utils,
only: neko_error
39 use comm,
only: neko_comm, pe_size, mpi_real_precision
40 use mpi_f08,
only: mpi_sum, mpi_in_place, mpi_allreduce
64 public :: device_mma_gensub1, device_mma_gensub2, device_mma_gensub3, &
65 device_mma_gensub4, device_mma_max, device_max2, device_rex, &
66 device_lcsc2, device_relambda, device_sub2cons2, device_maxval, &
67 device_norm, device_delx, device_add2inv2, device_gg, device_diagx, &
68 device_bb, device_updatebb, device_aa, device_updateaa, device_dx, &
69 device_dy, device_deta, device_dxsi, device_maxval2, device_maxval3, &
70 device_kkt_rex, device_mattrans_v_mul, device_mma_dipsolvesub1, &
71 device_mma_ljjxinv, device_hess, device_delta_1dbeam, &
72 device_solve_linear_system, device_prepare_hessian, &
73 device_prepare_aa_matrix
77 subroutine device_prepare_aa_matrix(AA_d, s_d, lambda_d, d_d, mu_d, y_d, &
79 type(c_ptr) :: aa_d, s_d, lambda_d, d_d, mu_d, y_d, a_d
89 call neko_error(
'AA matrix preparation not implemented for OpenCL')
91 call neko_error(
'No device backend configured for AA matrix preparation')
93 end subroutine device_prepare_aa_matrix
96 subroutine device_prepare_hessian(Hess_d, y_d, d_d, mu_d, lambda_d, m)
97 type(c_ptr) :: hess_d, y_d, d_d, mu_d, lambda_d
104 call neko_error(
'no device backend configured')
106 call neko_error(
'no device backend configured')
108 end subroutine device_prepare_hessian
110 subroutine device_solve_linear_system(A_d, b_d, n, info)
111 type(c_ptr) :: a_d, b_d
112 integer(c_int),
value :: n
113 integer(c_int) :: info
121 call neko_error(
'no device backend configured')
123 call neko_error(
'no device backend configured')
125 end subroutine device_solve_linear_system
132 subroutine device_delta_1dbeam(Delta_d, L_total, Le, offset, n)
133 type(c_ptr) :: delta_d
134 real(c_rp) :: l_total, le
135 integer(c_int),
value :: offset, n
141 call neko_error(
'no device backend configured')
143 call neko_error(
'no device backend configured')
145 end subroutine device_delta_1dbeam
148 subroutine device_hess(Hess_d, hijx_d, Ljjxinv_d, n, m)
149 type(c_ptr):: hess_d, hijx_d, ljjxinv_d
150 integer(c_int) :: n, m
152 call hip_hess(hess_d, hijx_d, ljjxinv_d, n, m)
154 call cuda_hess(hess_d, hijx_d, ljjxinv_d, n, m)
156 call neko_error(
'no device backend configured')
158 call neko_error(
'no device backend configured')
160 end subroutine device_hess
171 subroutine device_mma_ljjxinv(Ljjxinv_d,pjlambda_d, qjlambda_d, x_d, &
172 low_d, upp_d, alpha_d, beta_d, n)
173 type(c_ptr) :: ljjxinv_d, pjlambda_d, qjlambda_d, x_d, &
174 low_d, upp_d, alpha_d, beta_d
178 low_d, upp_d, alpha_d, beta_d, n)
181 low_d, upp_d, alpha_d, beta_d, n)
183 call neko_error(
'no device backend configured')
185 call neko_error(
'no device backend configured')
187 end subroutine device_mma_ljjxinv
194 subroutine device_mma_dipsolvesub1(x_d, pjlambda_d, qjlambda_d, &
195 low_d, upp_d, alpha_d, beta_d, n)
196 type(c_ptr) :: x_d, pjlambda_d, qjlambda_d, &
197 low_d, upp_d, alpha_d, beta_d
201 low_d, upp_d, alpha_d, beta_d, n)
204 low_d, upp_d, alpha_d, beta_d, n)
206 call neko_error(
'no device backend configured')
208 call neko_error(
'no device backend configured')
210 end subroutine device_mma_dipsolvesub1
217 subroutine device_mattrans_v_mul(output_d, pij_d, lambda_d, m, n)
218 type(c_ptr) :: output_d, pij_d, lambda_d
225 call neko_error(
'no device backend configured')
227 call neko_error(
'no device backend configured')
229 end subroutine device_mattrans_v_mul
233 subroutine device_mma_gensub1(low_d, upp_d, x_d, xmin_d, xmax_d, asyinit, n)
234 type(c_ptr) :: low_d, upp_d, x_d, xmin_d, xmax_d
235 real(c_rp) :: asyinit
242 call neko_error(
'no device backend configured')
244 call neko_error(
'no device backend configured')
246 end subroutine device_mma_gensub1
249 subroutine device_mma_gensub2(low_d, upp_d, x_d, xold1_d, xold2_d, xdiff_d, &
251 type(c_ptr) :: low_d, upp_d, x_d, xold1_d, xold2_d, xdiff_d
252 real(c_rp) :: asydecr, asyincr
261 call neko_error(
'no device backend configured')
263 call neko_error(
'no device backend configured')
265 end subroutine device_mma_gensub2
267 subroutine device_mma_gensub3(x_d, df0dx_d, dfdx_d, low_d, upp_d, min_d, &
268 max_d, alpha_d, beta_d, p0j_d, q0j_d, pij_d, qij_d, n, m)
269 type(c_ptr) :: x_d, df0dx_d, dfdx_d, low_d, upp_d, min_d, max_d, &
270 alpha_d, beta_d, p0j_d, q0j_d, pij_d, qij_d
273 call mma_gensub3_hip(x_d, df0dx_d, dfdx_d, low_d, upp_d, min_d, max_d, &
274 alpha_d, beta_d, p0j_d, q0j_d, pij_d, qij_d, n, m)
277 alpha_d, beta_d, p0j_d, q0j_d, pij_d, qij_d, n, m)
279 call neko_error(
'no device backend configured2')
281 call neko_error(
'no device backend configured3')
283 end subroutine device_mma_gensub3
285 subroutine device_mma_gensub4(x_d, low_d, upp_d, pij_d, qij_d, n, m, bi_d)
286 type(c_ptr) :: x_d, low_d, upp_d, pij_d, qij_d, bi_d
293 call neko_error(
'no device backend configured')
295 call neko_error(
'no device backend configured')
297 end subroutine device_mma_gensub4
299 subroutine device_mma_max(xsi_d, x_d, alpha_d, n)
300 type(c_ptr) :: xsi_d, x_d, alpha_d
307 call neko_error(
'no device backend configured')
309 call neko_error(
'no device backend configured')
311 end subroutine device_mma_max
313 subroutine device_max2(a_d, b, c_d, d, n)
314 type(c_ptr) :: a_d, c_d
322 call neko_error(
'no device backend configured')
324 call neko_error(
'no device backend configured')
326 end subroutine device_max2
330 subroutine device_rex(rex_d, x_d, low_d, upp_d, pij_d, p0j_d, qij_d, &
331 q0j_d, lambda_d, xsi_d, eta_d, n, m)
332 type(c_ptr) :: rex_d, x_d, low_d, upp_d, pij_d, p0j_d, qij_d, q0j_d, &
333 lambda_d, xsi_d, eta_d
334 integer(c_int) :: n, m
336 call hip_rex(rex_d, x_d, low_d, upp_d, pij_d, p0j_d, qij_d, q0j_d, &
337 lambda_d, xsi_d, eta_d, n, m)
339 call cuda_rex(rex_d, x_d, low_d, upp_d, pij_d, p0j_d, qij_d, q0j_d, &
340 lambda_d, xsi_d, eta_d, n, m)
342 call neko_error(
'no device backend configured')
344 call neko_error(
'no device backend configured')
346 end subroutine device_rex
348 function device_lcsc2(a_d, b_d, n)
result(res)
349 type(c_ptr) :: a_d, b_d
359 call neko_error(
'no device backend configured')
361 call neko_error(
'no device backend configured')
363 end function device_lcsc2
365 subroutine device_relambda(relambda_d, x_d, upp_d, low_d, pij_d, qij_d, n, m)
366 type(c_ptr) :: relambda_d, x_d, upp_d, low_d, pij_d, qij_d
367 integer(c_int) :: n, m
369 call hip_relambda(relambda_d, x_d, upp_d, low_d, pij_d, qij_d, n, m)
371 call cuda_relambda(relambda_d, x_d, upp_d, low_d, pij_d, qij_d, n, m)
373 call neko_error(
'no device backend configured')
375 call neko_error(
'no device backend configured')
377 end subroutine device_relambda
379 subroutine device_sub2cons2(rexsi_d, xsi_d, x_d, alpha_d, epsi, n)
380 type(c_ptr):: rexsi_d, xsi_d, x_d, alpha_d
381 real(kind=rp) :: epsi
388 call neko_error(
'no device backend configured')
390 call neko_error(
'no device backend configured')
392 end subroutine device_sub2cons2
394 function device_maxval(rex_d, n)
result(res)
405 call neko_error(
'no device backend configured')
407 call neko_error(
'no device backend configured')
409 end function device_maxval
411 function device_norm(rex_d, n)
result(res)
422 call neko_error(
'no device backend configured')
424 call neko_error(
'no device backend configured')
426 end function device_norm
428 subroutine device_delx(delx_d, x_d, low_d, upp_d, pij_d, qij_d, p0j_d, &
429 q0j_d, alpha_d, beta_d, lambda_d, epsi, n, m)
430 type(c_ptr):: delx_d, x_d, low_d, upp_d, pij_d, qij_d, p0j_d, q0j_d, &
431 alpha_d, beta_d, lambda_d
432 real(kind=rp) :: epsi
433 integer(c_int) :: n, m
435 call hip_delx(delx_d, x_d, low_d, upp_d, pij_d, qij_d, p0j_d, q0j_d, &
436 alpha_d, beta_d, lambda_d, epsi, n, m)
438 call cuda_delx(delx_d, x_d, low_d, upp_d, pij_d, qij_d, p0j_d, q0j_d, &
439 alpha_d, beta_d, lambda_d, epsi, n, m)
441 call neko_error(
'no device backend configured')
443 call neko_error(
'no device backend configured')
445 end subroutine device_delx
447 subroutine device_add2inv2(a_d, b_d, c, n)
448 type(c_ptr):: a_d, b_d
456 call neko_error(
'no device backend configured')
458 call neko_error(
'no device backend configured')
460 end subroutine device_add2inv2
463 subroutine device_gg(GG_d, x_d, low_d, upp_d, pij_d, qij_d, n, m)
464 type(c_ptr):: gg_d, x_d, low_d, upp_d, pij_d, qij_d
465 integer(c_int) :: n, m
467 call hip_gg(gg_d, x_d, low_d, upp_d, pij_d, qij_d, n, m)
469 call cuda_gg(gg_d, x_d, low_d, upp_d, pij_d, qij_d, n, m)
471 call neko_error(
'no device backend configured')
473 call neko_error(
'no device backend configured')
475 end subroutine device_gg
477 subroutine device_diagx(diagx_d, x_d, xsi_d, low_d, upp_d, p0j_d, q0j_d, &
478 pij_d, qij_d, alpha_d, beta_d, eta_d, lambda_d, n, m)
479 type(c_ptr):: diagx_d, x_d, xsi_d, low_d, upp_d, p0j_d, q0j_d, pij_d, &
481 beta_d, eta_d, lambda_d
482 integer(c_int) :: n, m
484 call hip_diagx(diagx_d, x_d, xsi_d, low_d, upp_d, p0j_d, q0j_d, pij_d, &
485 qij_d, alpha_d, beta_d, eta_d, lambda_d, n, m)
487 call cuda_diagx(diagx_d, x_d, xsi_d, low_d, upp_d, p0j_d, q0j_d, pij_d, &
488 qij_d, alpha_d, beta_d, eta_d, lambda_d, n, m)
490 call neko_error(
'no device backend configured')
492 call neko_error(
'no device backend configured')
494 end subroutine device_diagx
497 subroutine device_bb(bb_d, GG_d, delx_d, diagx_d, n, m)
498 type(c_ptr):: bb_d, gg_d, delx_d, diagx_d
499 integer(c_int) :: n, m
501 call hip_bb(bb_d, gg_d, delx_d, diagx_d, n, m)
503 call cuda_bb(bb_d, gg_d, delx_d, diagx_d, n, m)
505 call neko_error(
'no device backend configured')
507 call neko_error(
'no device backend configured')
509 end subroutine device_bb
511 subroutine device_updatebb(bb_d, dellambda_d, dely_d, d_d, mu_d, y_d, delz, m)
512 type(c_ptr):: bb_d, dellambda_d, dely_d, d_d, mu_d, y_d
516 call hip_updatebb(bb_d, dellambda_d, dely_d, d_d, mu_d, y_d, delz, m)
518 call cuda_updatebb(bb_d, dellambda_d, dely_d, d_d, mu_d, y_d, delz, m)
520 call neko_error(
'no device backend configured')
522 call neko_error(
'no device backend configured')
524 end subroutine device_updatebb
526 subroutine device_aa(AA_d, GG_d, diagx_d, n, m)
527 type(c_ptr):: aa_d, gg_d, diagx_d
528 integer(c_int) :: n, m
530 call hip_aa(aa_d, gg_d, diagx_d, n, m)
532 call cuda_aa(aa_d, gg_d, diagx_d, n, m)
534 call neko_error(
'no device backend configured')
536 call neko_error(
'no device backend configured')
538 end subroutine device_aa
540 subroutine device_updateaa(AA_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, &
541 y_d, a_d, zeta, z, m)
542 type(c_ptr):: aa_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, y_d, a_d
544 real(c_rp) :: zeta, z
546 call hip_updateaa(aa_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, y_d, &
549 call cuda_updateaa(aa_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, y_d, &
552 call neko_error(
'no device backend configured')
554 call neko_error(
'no device backend configured')
556 end subroutine device_updateaa
558 subroutine device_dx(dx_d, delx_d, diagx_d, GG_d, dlambda_d, n, m)
559 type(c_ptr):: dx_d, delx_d, diagx_d, gg_d, dlambda_d
560 integer(c_int) :: n, m
562 call hip_dx(dx_d, delx_d, diagx_d, gg_d, dlambda_d, n, m)
564 call cuda_dx(dx_d, delx_d, diagx_d, gg_d, dlambda_d, n, m)
566 call neko_error(
'no device backend configured')
568 call neko_error(
'no device backend configured')
570 end subroutine device_dx
572 subroutine device_dy(dy_d, dely_d, dlambda_d, d_d, mu_d, y_d, n)
573 type(c_ptr):: dy_d, dely_d, dlambda_d, d_d, mu_d, y_d
576 call hip_dy(dy_d, dely_d, dlambda_d, d_d, mu_d, y_d, n)
578 call cuda_dy(dy_d, dely_d, dlambda_d, d_d, mu_d, y_d, n)
580 call neko_error(
'no device backend configured')
582 call neko_error(
'no device backend configured')
584 end subroutine device_dy
586 subroutine device_dxsi(dxsi_d, xsi_d, dx_d, x_d, alpha_d, epsi, n)
587 type(c_ptr):: dxsi_d, xsi_d, dx_d, x_d, alpha_d
591 call hip_dxsi(dxsi_d, xsi_d, dx_d, x_d, alpha_d, epsi, n)
593 call cuda_dxsi(dxsi_d, xsi_d, dx_d, x_d, alpha_d, epsi, n)
595 call neko_error(
'no device backend configured')
597 call neko_error(
'no device backend configured')
599 end subroutine device_dxsi
601 subroutine device_deta(deta_d, eta_d, dx_d, x_d, beta_d, epsi, n)
602 type(c_ptr):: deta_d, eta_d, dx_d, x_d, beta_d
606 call hip_deta(deta_d, eta_d, dx_d, x_d, beta_d, epsi, n)
608 call cuda_deta(deta_d, eta_d, dx_d, x_d, beta_d, epsi, n)
610 call neko_error(
'no device backend configured')
612 call neko_error(
'no device backend configured')
614 end subroutine device_deta
616 function device_maxval2(dxx_d, xx_d, cons, n)
result(res)
617 type(c_ptr):: dxx_d, xx_d
619 real(kind=rp),
intent(in) :: cons
628 call neko_error(
'no device backend configured')
630 call neko_error(
'no device backend configured')
632 end function device_maxval2
635 function device_maxval3(dx_d, x_d, alpha_d, cons, n)
result(res)
636 type(c_ptr):: dx_d, x_d, alpha_d
637 real(kind=rp),
intent(in) :: cons
647 call neko_error(
'no device backend configured')
649 call neko_error(
'no device backend configured')
651 end function device_maxval3
655 subroutine device_kkt_rex(rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d, &
657 type(c_ptr):: rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d
658 integer(c_int) :: n, m
660 call hip_kkt_rex(rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d, n, m)
662 call cuda_kkt_rex(rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d, n, m)
664 call neko_error(
'no device backend configured')
666 call neko_error(
'no device backend configured')
668 end subroutine device_kkt_rex
672end module device_mma_math