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, device_update_hessian_z
77 subroutine device_update_hessian_z(Hess_d, a_d, m)
79 type(c_ptr),
intent(in) :: hess_d
80 type(c_ptr),
intent(in) :: a_d
87 call neko_error(
'Z-term Hessian update not implemented for OpenCL')
89 call neko_error(
'No device backend configured for Z-term Hessian update')
91 end subroutine device_update_hessian_z
95 subroutine device_prepare_aa_matrix(AA_d, s_d, lambda_d, d_d, mu_d, y_d, &
97 type(c_ptr) :: aa_d, s_d, lambda_d, d_d, mu_d, y_d, a_d
107 call neko_error(
'AA matrix preparation not implemented for OpenCL')
109 call neko_error(
'No device backend configured for AA matrix preparation')
111 end subroutine device_prepare_aa_matrix
114 subroutine device_prepare_hessian(Hess_d, y_d, mu_d, lambda_d, m)
115 type(c_ptr) :: hess_d, y_d, mu_d, lambda_d
122 call neko_error(
'no device backend configured')
124 call neko_error(
'no device backend configured')
126 end subroutine device_prepare_hessian
128 subroutine device_solve_linear_system(A_d, b_d, n, info)
129 type(c_ptr) :: a_d, b_d
130 integer(c_int),
value :: n
131 integer(c_int) :: info
139 call neko_error(
'no device backend configured')
141 call neko_error(
'no device backend configured')
143 end subroutine device_solve_linear_system
150 subroutine device_delta_1dbeam(Delta_d, L_total, Le, offset, n)
151 type(c_ptr) :: delta_d
152 real(c_rp) :: l_total, le
153 integer(c_int),
value :: offset, n
159 call neko_error(
'no device backend configured')
161 call neko_error(
'no device backend configured')
163 end subroutine device_delta_1dbeam
166 subroutine device_hess(Hess_d, hijx_d, Ljjxinv_d, n, m)
167 type(c_ptr):: hess_d, hijx_d, ljjxinv_d
168 integer(c_int) :: n, m
170 call hip_hess(hess_d, hijx_d, ljjxinv_d, n, m)
172 call cuda_hess(hess_d, hijx_d, ljjxinv_d, n, m)
174 call neko_error(
'no device backend configured')
176 call neko_error(
'no device backend configured')
178 end subroutine device_hess
189 subroutine device_mma_ljjxinv(Ljjxinv_d,pjlambda_d, qjlambda_d, x_d, &
190 low_d, upp_d, alpha_d, beta_d, n)
191 type(c_ptr) :: ljjxinv_d, pjlambda_d, qjlambda_d, x_d, &
192 low_d, upp_d, alpha_d, beta_d
196 low_d, upp_d, alpha_d, beta_d, n)
199 low_d, upp_d, alpha_d, beta_d, n)
201 call neko_error(
'no device backend configured')
203 call neko_error(
'no device backend configured')
205 end subroutine device_mma_ljjxinv
212 subroutine device_mma_dipsolvesub1(x_d, pjlambda_d, qjlambda_d, &
213 low_d, upp_d, alpha_d, beta_d, n)
214 type(c_ptr) :: x_d, pjlambda_d, qjlambda_d, &
215 low_d, upp_d, alpha_d, beta_d
219 low_d, upp_d, alpha_d, beta_d, n)
222 low_d, upp_d, alpha_d, beta_d, n)
224 call neko_error(
'no device backend configured')
226 call neko_error(
'no device backend configured')
228 end subroutine device_mma_dipsolvesub1
235 subroutine device_mattrans_v_mul(output_d, pij_d, lambda_d, m, n)
236 type(c_ptr) :: output_d, pij_d, lambda_d
243 call neko_error(
'no device backend configured')
245 call neko_error(
'no device backend configured')
247 end subroutine device_mattrans_v_mul
251 subroutine device_mma_gensub1(low_d, upp_d, x_d, xmin_d, xmax_d, asyinit, n)
252 type(c_ptr) :: low_d, upp_d, x_d, xmin_d, xmax_d
253 real(c_rp) :: asyinit
260 call neko_error(
'no device backend configured')
262 call neko_error(
'no device backend configured')
264 end subroutine device_mma_gensub1
267 subroutine device_mma_gensub2(low_d, upp_d, x_d, xold1_d, xold2_d, xdiff_d, &
269 type(c_ptr) :: low_d, upp_d, x_d, xold1_d, xold2_d, xdiff_d
270 real(c_rp) :: asydecr, asyincr
279 call neko_error(
'no device backend configured')
281 call neko_error(
'no device backend configured')
283 end subroutine device_mma_gensub2
285 subroutine device_mma_gensub3(x_d, df0dx_d, dfdx_d, low_d, upp_d, min_d, &
286 max_d, alpha_d, beta_d, p0j_d, q0j_d, pij_d, qij_d, n, m)
287 type(c_ptr) :: x_d, df0dx_d, dfdx_d, low_d, upp_d, min_d, max_d, &
288 alpha_d, beta_d, p0j_d, q0j_d, pij_d, qij_d
291 call mma_gensub3_hip(x_d, df0dx_d, dfdx_d, low_d, upp_d, min_d, max_d, &
292 alpha_d, beta_d, p0j_d, q0j_d, pij_d, qij_d, n, m)
295 alpha_d, beta_d, p0j_d, q0j_d, pij_d, qij_d, n, m)
297 call neko_error(
'no device backend configured2')
299 call neko_error(
'no device backend configured3')
301 end subroutine device_mma_gensub3
303 subroutine device_mma_gensub4(x_d, low_d, upp_d, pij_d, qij_d, n, m, bi_d)
304 type(c_ptr) :: x_d, low_d, upp_d, pij_d, qij_d, bi_d
311 call neko_error(
'no device backend configured')
313 call neko_error(
'no device backend configured')
315 end subroutine device_mma_gensub4
317 subroutine device_mma_max(xsi_d, x_d, alpha_d, n)
318 type(c_ptr) :: xsi_d, x_d, alpha_d
325 call neko_error(
'no device backend configured')
327 call neko_error(
'no device backend configured')
329 end subroutine device_mma_max
331 subroutine device_max2(a_d, b, c_d, d, n)
332 type(c_ptr) :: a_d, c_d
340 call neko_error(
'no device backend configured')
342 call neko_error(
'no device backend configured')
344 end subroutine device_max2
348 subroutine device_rex(rex_d, x_d, low_d, upp_d, pij_d, p0j_d, qij_d, &
349 q0j_d, lambda_d, xsi_d, eta_d, n, m)
350 type(c_ptr) :: rex_d, x_d, low_d, upp_d, pij_d, p0j_d, qij_d, q0j_d, &
351 lambda_d, xsi_d, eta_d
352 integer(c_int) :: n, m
354 call hip_rex(rex_d, x_d, low_d, upp_d, pij_d, p0j_d, qij_d, q0j_d, &
355 lambda_d, xsi_d, eta_d, n, m)
357 call cuda_rex(rex_d, x_d, low_d, upp_d, pij_d, p0j_d, qij_d, q0j_d, &
358 lambda_d, xsi_d, eta_d, n, m)
360 call neko_error(
'no device backend configured')
362 call neko_error(
'no device backend configured')
364 end subroutine device_rex
366 function device_lcsc2(a_d, b_d, n)
result(res)
367 type(c_ptr) :: a_d, b_d
377 call neko_error(
'no device backend configured')
379 call neko_error(
'no device backend configured')
381 end function device_lcsc2
383 subroutine device_relambda(relambda_d, x_d, upp_d, low_d, pij_d, qij_d, n, m)
384 type(c_ptr) :: relambda_d, x_d, upp_d, low_d, pij_d, qij_d
385 integer(c_int) :: n, m
387 call hip_relambda(relambda_d, x_d, upp_d, low_d, pij_d, qij_d, n, m)
389 call cuda_relambda(relambda_d, x_d, upp_d, low_d, pij_d, qij_d, n, m)
391 call neko_error(
'no device backend configured')
393 call neko_error(
'no device backend configured')
395 end subroutine device_relambda
397 subroutine device_sub2cons2(rexsi_d, xsi_d, x_d, alpha_d, epsi, n)
398 type(c_ptr):: rexsi_d, xsi_d, x_d, alpha_d
399 real(kind=rp) :: epsi
406 call neko_error(
'no device backend configured')
408 call neko_error(
'no device backend configured')
410 end subroutine device_sub2cons2
412 function device_maxval(rex_d, n)
result(res)
423 call neko_error(
'no device backend configured')
425 call neko_error(
'no device backend configured')
427 end function device_maxval
429 function device_norm(rex_d, n)
result(res)
440 call neko_error(
'no device backend configured')
442 call neko_error(
'no device backend configured')
444 end function device_norm
446 subroutine device_delx(delx_d, x_d, low_d, upp_d, pij_d, qij_d, p0j_d, &
447 q0j_d, alpha_d, beta_d, lambda_d, epsi, n, m)
448 type(c_ptr):: delx_d, x_d, low_d, upp_d, pij_d, qij_d, p0j_d, q0j_d, &
449 alpha_d, beta_d, lambda_d
450 real(kind=rp) :: epsi
451 integer(c_int) :: n, m
453 call hip_delx(delx_d, x_d, low_d, upp_d, pij_d, qij_d, p0j_d, q0j_d, &
454 alpha_d, beta_d, lambda_d, epsi, n, m)
456 call cuda_delx(delx_d, x_d, low_d, upp_d, pij_d, qij_d, p0j_d, q0j_d, &
457 alpha_d, beta_d, lambda_d, epsi, n, m)
459 call neko_error(
'no device backend configured')
461 call neko_error(
'no device backend configured')
463 end subroutine device_delx
465 subroutine device_add2inv2(a_d, b_d, c, n)
466 type(c_ptr):: a_d, b_d
474 call neko_error(
'no device backend configured')
476 call neko_error(
'no device backend configured')
478 end subroutine device_add2inv2
481 subroutine device_gg(GG_d, x_d, low_d, upp_d, pij_d, qij_d, n, m)
482 type(c_ptr):: gg_d, x_d, low_d, upp_d, pij_d, qij_d
483 integer(c_int) :: n, m
485 call hip_gg(gg_d, x_d, low_d, upp_d, pij_d, qij_d, n, m)
487 call cuda_gg(gg_d, x_d, low_d, upp_d, pij_d, qij_d, n, m)
489 call neko_error(
'no device backend configured')
491 call neko_error(
'no device backend configured')
493 end subroutine device_gg
495 subroutine device_diagx(diagx_d, x_d, xsi_d, low_d, upp_d, p0j_d, q0j_d, &
496 pij_d, qij_d, alpha_d, beta_d, eta_d, lambda_d, n, m)
497 type(c_ptr):: diagx_d, x_d, xsi_d, low_d, upp_d, p0j_d, q0j_d, pij_d, &
499 beta_d, eta_d, lambda_d
500 integer(c_int) :: n, m
502 call hip_diagx(diagx_d, x_d, xsi_d, low_d, upp_d, p0j_d, q0j_d, pij_d, &
503 qij_d, alpha_d, beta_d, eta_d, lambda_d, n, m)
505 call cuda_diagx(diagx_d, x_d, xsi_d, low_d, upp_d, p0j_d, q0j_d, pij_d, &
506 qij_d, alpha_d, beta_d, eta_d, lambda_d, n, m)
508 call neko_error(
'no device backend configured')
510 call neko_error(
'no device backend configured')
512 end subroutine device_diagx
515 subroutine device_bb(bb_d, GG_d, delx_d, diagx_d, n, m)
516 type(c_ptr):: bb_d, gg_d, delx_d, diagx_d
517 integer(c_int) :: n, m
519 call hip_bb(bb_d, gg_d, delx_d, diagx_d, n, m)
521 call cuda_bb(bb_d, gg_d, delx_d, diagx_d, n, m)
523 call neko_error(
'no device backend configured')
525 call neko_error(
'no device backend configured')
527 end subroutine device_bb
529 subroutine device_updatebb(bb_d, dellambda_d, dely_d, d_d, mu_d, y_d, delz, m)
530 type(c_ptr):: bb_d, dellambda_d, dely_d, d_d, mu_d, y_d
534 call hip_updatebb(bb_d, dellambda_d, dely_d, d_d, mu_d, y_d, delz, m)
536 call cuda_updatebb(bb_d, dellambda_d, dely_d, d_d, mu_d, y_d, delz, m)
538 call neko_error(
'no device backend configured')
540 call neko_error(
'no device backend configured')
542 end subroutine device_updatebb
544 subroutine device_aa(AA_d, GG_d, diagx_d, n, m)
545 type(c_ptr):: aa_d, gg_d, diagx_d
546 integer(c_int) :: n, m
548 call hip_aa(aa_d, gg_d, diagx_d, n, m)
550 call cuda_aa(aa_d, gg_d, diagx_d, n, m)
552 call neko_error(
'no device backend configured')
554 call neko_error(
'no device backend configured')
556 end subroutine device_aa
558 subroutine device_updateaa(AA_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, &
559 y_d, a_d, zeta, z, m)
560 type(c_ptr):: aa_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, y_d, a_d
562 real(c_rp) :: zeta, z
564 call hip_updateaa(aa_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, y_d, &
567 call cuda_updateaa(aa_d, globaltmp_mm_d, s_d, lambda_d, d_d, mu_d, y_d, &
570 call neko_error(
'no device backend configured')
572 call neko_error(
'no device backend configured')
574 end subroutine device_updateaa
576 subroutine device_dx(dx_d, delx_d, diagx_d, GG_d, dlambda_d, n, m)
577 type(c_ptr):: dx_d, delx_d, diagx_d, gg_d, dlambda_d
578 integer(c_int) :: n, m
580 call hip_dx(dx_d, delx_d, diagx_d, gg_d, dlambda_d, n, m)
582 call cuda_dx(dx_d, delx_d, diagx_d, gg_d, dlambda_d, n, m)
584 call neko_error(
'no device backend configured')
586 call neko_error(
'no device backend configured')
588 end subroutine device_dx
590 subroutine device_dy(dy_d, dely_d, dlambda_d, d_d, mu_d, y_d, n)
591 type(c_ptr):: dy_d, dely_d, dlambda_d, d_d, mu_d, y_d
594 call hip_dy(dy_d, dely_d, dlambda_d, d_d, mu_d, y_d, n)
596 call cuda_dy(dy_d, dely_d, dlambda_d, d_d, mu_d, y_d, n)
598 call neko_error(
'no device backend configured')
600 call neko_error(
'no device backend configured')
602 end subroutine device_dy
604 subroutine device_dxsi(dxsi_d, xsi_d, dx_d, x_d, alpha_d, epsi, n)
605 type(c_ptr):: dxsi_d, xsi_d, dx_d, x_d, alpha_d
609 call hip_dxsi(dxsi_d, xsi_d, dx_d, x_d, alpha_d, epsi, n)
611 call cuda_dxsi(dxsi_d, xsi_d, dx_d, x_d, alpha_d, epsi, n)
613 call neko_error(
'no device backend configured')
615 call neko_error(
'no device backend configured')
617 end subroutine device_dxsi
619 subroutine device_deta(deta_d, eta_d, dx_d, x_d, beta_d, epsi, n)
620 type(c_ptr):: deta_d, eta_d, dx_d, x_d, beta_d
624 call hip_deta(deta_d, eta_d, dx_d, x_d, beta_d, epsi, n)
626 call cuda_deta(deta_d, eta_d, dx_d, x_d, beta_d, epsi, n)
628 call neko_error(
'no device backend configured')
630 call neko_error(
'no device backend configured')
632 end subroutine device_deta
634 function device_maxval2(dxx_d, xx_d, cons, n)
result(res)
635 type(c_ptr):: dxx_d, xx_d
637 real(kind=rp),
intent(in) :: cons
646 call neko_error(
'no device backend configured')
648 call neko_error(
'no device backend configured')
650 end function device_maxval2
653 function device_maxval3(dx_d, x_d, alpha_d, cons, n)
result(res)
654 type(c_ptr):: dx_d, x_d, alpha_d
655 real(kind=rp),
intent(in) :: cons
665 call neko_error(
'no device backend configured')
667 call neko_error(
'no device backend configured')
669 end function device_maxval3
673 subroutine device_kkt_rex(rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d, &
675 type(c_ptr):: rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d
676 integer(c_int) :: n, m
678 call hip_kkt_rex(rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d, n, m)
680 call cuda_kkt_rex(rex_d, df0dx_d, dfdx_d, xsi_d, eta_d, lambda_d, n, m)
682 call neko_error(
'no device backend configured')
684 call neko_error(
'no device backend configured')
686 end subroutine device_kkt_rex
690end module device_mma_math