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
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
75 subroutine device_prepare_aa_matrix(AA_d, s_d, lambda_d, d_d, mu_d, y_d, &
77 type(c_ptr) :: AA_d, s_d, lambda_d, d_d, mu_d, y_d, a_d
87 call neko_error(
'AA matrix preparation not implemented for OpenCL')
89 call neko_error(
'No device backend configured for AA matrix preparation')
91 end subroutine device_prepare_aa_matrix
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
102 call neko_error(
'no device backend configured')
104 call neko_error(
'no device backend configured')
106 end subroutine device_prepare_hessian
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
119 call neko_error(
'no device backend configured')
121 call neko_error(
'no device backend configured')
123 end subroutine device_solve_linear_system
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
139 call neko_error(
'no device backend configured')
141 call neko_error(
'no device backend configured')
143 end subroutine device_delta_1dbeam
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
150 call hip_hess(hess_d, hijx_d, ljjxinv_d, n, m)
152 call cuda_hess(hess_d, hijx_d, ljjxinv_d, n, m)
154 call neko_error(
'no device backend configured')
156 call neko_error(
'no device backend configured')
158 end subroutine device_hess
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
176 low_d, upp_d, alpha_d, beta_d, n)
179 low_d, upp_d, alpha_d, beta_d, n)
181 call neko_error(
'no device backend configured')
183 call neko_error(
'no device backend configured')
185 end subroutine device_mma_ljjxinv
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
199 low_d, upp_d, alpha_d, beta_d, n)
202 low_d, upp_d, alpha_d, beta_d, n)
204 call neko_error(
'no device backend configured')
206 call neko_error(
'no device backend configured')
208 end subroutine device_mma_dipsolvesub1
215 subroutine device_mattrans_v_mul(output_d, pij_d, lambda_d, m, n)
216 type(c_ptr) :: output_d, pij_d, lambda_d
223 call neko_error(
'no device backend configured')
225 call neko_error(
'no device backend configured')
227 end subroutine device_mattrans_v_mul
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
240 call neko_error(
'no device backend configured')
242 call neko_error(
'no device backend configured')
244 end subroutine device_mma_gensub1
247 subroutine device_mma_gensub2(low_d, upp_d, x_d, xold1_d, xold2_d, xdiff_d, &
249 type(c_ptr) :: low_d, upp_d, x_d, xold1_d, xold2_d, xdiff_d
250 real(c_rp) :: asydecr, asyincr
259 call neko_error(
'no device backend configured')
261 call neko_error(
'no device backend configured')
263 end subroutine device_mma_gensub2
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
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)
275 alpha_d, beta_d, p0j_d, q0j_d, pij_d, qij_d, n, m)
277 call neko_error(
'no device backend configured2')
279 call neko_error(
'no device backend configured3')
281 end subroutine device_mma_gensub3
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
291 call neko_error(
'no device backend configured')
293 call neko_error(
'no device backend configured')
295 end subroutine device_mma_gensub4
297 subroutine device_mma_max(xsi_d, x_d, alpha_d, n)
298 type(c_ptr) :: xsi_d, x_d, alpha_d
305 call neko_error(
'no device backend configured')
307 call neko_error(
'no device backend configured')
309 end subroutine device_mma_max
311 subroutine device_max2(a_d, b, c_d, d, n)
312 type(c_ptr) :: a_d, c_d
320 call neko_error(
'no device backend configured')
322 call neko_error(
'no device backend configured')
324 end subroutine device_max2
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
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)
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)
340 call neko_error(
'no device backend configured')
342 call neko_error(
'no device backend configured')
344 end subroutine device_rex
346 function device_lcsc2(a_d, b_d, n)
result(res)
347 type(c_ptr) :: a_d, b_d
357 call neko_error(
'no device backend configured')
359 call neko_error(
'no device backend configured')
361 end function device_lcsc2
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
367 call hip_relambda(relambda_d, x_d, upp_d, low_d, pij_d, qij_d, n, m)
369 call cuda_relambda(relambda_d, x_d, upp_d, low_d, pij_d, qij_d, n, m)
371 call neko_error(
'no device backend configured')
373 call neko_error(
'no device backend configured')
375 end subroutine device_relambda
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
386 call neko_error(
'no device backend configured')
388 call neko_error(
'no device backend configured')
390 end subroutine device_sub2cons2
392 function device_maxval(rex_d, n)
result(res)
403 call neko_error(
'no device backend configured')
405 call neko_error(
'no device backend configured')
407 end function device_maxval
409 function device_norm(rex_d, n)
result(res)
420 call neko_error(
'no device backend configured')
422 call neko_error(
'no device backend configured')
424 end function device_norm
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
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)
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)
439 call neko_error(
'no device backend configured')
441 call neko_error(
'no device backend configured')
443 end subroutine device_delx
445 subroutine device_add2inv2(a_d, b_d, c, n)
446 type(c_ptr):: a_d, b_d
454 call neko_error(
'no device backend configured')
456 call neko_error(
'no device backend configured')
458 end subroutine device_add2inv2
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
465 call hip_gg(gg_d, x_d, low_d, upp_d, pij_d, qij_d, n, m)
467 call cuda_gg(gg_d, x_d, low_d, upp_d, pij_d, qij_d, n, m)
469 call neko_error(
'no device backend configured')
471 call neko_error(
'no device backend configured')
473 end subroutine device_gg
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, &
479 beta_d, eta_d, lambda_d
480 integer(c_int) :: n, m
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)
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)
488 call neko_error(
'no device backend configured')
490 call neko_error(
'no device backend configured')
492 end subroutine device_diagx
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
499 call hip_bb(bb_d, gg_d, delx_d, diagx_d, n, m)
501 call cuda_bb(bb_d, gg_d, delx_d, diagx_d, n, m)
503 call neko_error(
'no device backend configured')
505 call neko_error(
'no device backend configured')
507 end subroutine device_bb
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
514 call hip_updatebb(bb_d, dellambda_d, dely_d, d_d, mu_d, y_d, delz, m)
516 call cuda_updatebb(bb_d, dellambda_d, dely_d, d_d, mu_d, y_d, delz, m)
518 call neko_error(
'no device backend configured')
520 call neko_error(
'no device backend configured')
522 end subroutine device_updatebb
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
528 call hip_aa(aa_d, gg_d, diagx_d, n, m)
530 call cuda_aa(aa_d, gg_d, diagx_d, n, m)
532 call neko_error(
'no device backend configured')
534 call neko_error(
'no device backend configured')
536 end subroutine device_aa
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
542 real(c_rp) :: zeta, z
544 call hip_updateaa(aa_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, y_d, &
547 call cuda_updateaa(aa_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, y_d, &
550 call neko_error(
'no device backend configured')
552 call neko_error(
'no device backend configured')
554 end subroutine device_updateaa
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
560 call hip_dx(dx_d, delx_d, diagx_d, gg_d, dlambda_d, n, m)
562 call cuda_dx(dx_d, delx_d, diagx_d, gg_d, dlambda_d, n, m)
564 call neko_error(
'no device backend configured')
566 call neko_error(
'no device backend configured')
568 end subroutine device_dx
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
574 call hip_dy(dy_d, dely_d, dlambda_d, d_d, mu_d, y_d, n)
576 call cuda_dy(dy_d, dely_d, dlambda_d, d_d, mu_d, y_d, n)
578 call neko_error(
'no device backend configured')
580 call neko_error(
'no device backend configured')
582 end subroutine device_dy
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
589 call hip_dxsi(dxsi_d, xsi_d, dx_d, x_d, alpha_d, epsi, n)
591 call cuda_dxsi(dxsi_d, xsi_d, dx_d, x_d, alpha_d, epsi, n)
593 call neko_error(
'no device backend configured')
595 call neko_error(
'no device backend configured')
597 end subroutine device_dxsi
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
604 call hip_deta(deta_d, eta_d, dx_d, x_d, beta_d, epsi, n)
606 call cuda_deta(deta_d, eta_d, dx_d, x_d, beta_d, epsi, n)
608 call neko_error(
'no device backend configured')
610 call neko_error(
'no device backend configured')
612 end subroutine device_deta
614 function device_maxval2(dxx_d, xx_d, cons, n)
result(res)
615 type(c_ptr):: dxx_d, xx_d
617 real(kind=rp),
intent(in) :: cons
626 call neko_error(
'no device backend configured')
628 call neko_error(
'no device backend configured')
630 end function device_maxval2
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
645 call neko_error(
'no device backend configured')
647 call neko_error(
'no device backend configured')
649 end function device_maxval3
653 subroutine device_kkt_rex(rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d, &
655 type(c_ptr):: rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d
656 integer(c_int) :: n, m
658 call hip_kkt_rex(rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d, n, m)
660 call cuda_kkt_rex(rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d, n, m)
662 call neko_error(
'no device backend configured')
664 call neko_error(
'no device backend configured')
666 end subroutine device_kkt_rex
670end module device_mma_math