42#include <hip/hip_runtime.h>
43#include <hipsolver/hipsolver.h>
46#include <neko/device/device_config.h>
47#include <neko/device/hip/check.h>
48#include <neko/math/bcknd/device/device_mpi_op.h>
59void mma_update_hessian_z_hip(
void*
Hess,
void* a,
int m) {
73void hipSOLVER_wrapper(
void*
A,
void*
b,
int n,
int*
jj) {
131void mma_prepare_aa_matrix_hip(
void*
AA,
void* s,
void* lambda,
132 void* d,
void* mu,
void* y,
133 void* a,
real zeta,
real z,
int m) {
149void mma_prepare_hessian_hip(
void*
Hess,
void* y,
150 void* mu,
void* lambda,
int m) {
179 for (
int i = 0; i <
M; i++) {
189 for (
int i = 0; i <
M; i++) {
205extern "C" void hip_custom_solver(
void*
A,
void*
b,
int n,
int*
info) {
229 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
238 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
239 const int nb = ((*n) + 1024 - 1) / 1024;
243 if (
nb > mma_red_s) {
245 if (mma_bufred !=
NULL) {
253 for (
int i = 0; i < (*m); i++) {
254 for (
int j = 0;
j < (*m);
j++) {
264 (
real*)
Hess, mma_bufred_d, 1, i +
j * (*m));
273 void* low,
void* upp,
void* alpha,
void* beta,
int* n) {
275 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
282void mma_dipsolvesub1_hip(
void* x,
void*
pjlambda,
void*
qjlambda,
void* low,
283 void* upp,
void* alpha,
void* beta,
int* n) {
285 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
292void mattrans_v_mul_hip(
void* output,
void* pij,
void* lambda,
int* m,
int* n) {
294 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
300void mma_gensub4_hip(
const void* x,
const void* low,
const void* upp,
301 const void* pij,
const void* qij,
302 const int* n,
const int* m,
void* bi) {
309 const int nb = (
N + 1023) / 1024;
312 if (
nb > mma_red_s) {
315 if (mma_bufred !=
nullptr) {
329 static_cast<const real*
>(x),
330 static_cast<const real*
>(low),
331 static_cast<const real*
>(upp),
332 static_cast<const real*
>(pij),
333 static_cast<const real*
>(qij),
336 for (
int i = 0; i <
M; ++i) {
338 temp, mma_bufred_d,
N,
M, i);
346 bi_d + i, mma_bufred_d,
sizeof(
real),
356void mma_gensub3_hip(
void* x,
void*
df0dx,
void*
dfdx,
void* low,
357 void* upp,
void* xmin,
void* xmax,
void* alpha,
358 void* beta,
void* p0j,
void* q0j,
void* pij,
359 void* qij,
int* n,
int* m) {
361 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
373void mma_gensub3_dip_hip(
void* x,
void*
df0dx,
void*
dfdx,
void* low,
374 void* upp,
void* xmin,
void* xmax,
void* alpha,
375 void* beta,
void* p0j,
void* q0j,
void* pij,
376 void* qij,
int* n,
int* m) {
378 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
390void mma_gensub2_hip(
void* low,
void* upp,
void* x,
void* xold1,
392 real* asyincr,
int* n) {
394 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
404void mma_gensub1_hip(
void* low,
void* upp,
void* x,
void* xmin,
void* xmax,
405 real* asyinit,
int* n) {
407 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
417void hip_mma_max(
void* xsi,
void* x,
void* alpha,
int* n) {
419 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
429 void* pij,
void* qij,
int* n,
int* m) {
431 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
435 if (
nb > mma_red_s) {
437 if (mma_bufred !=
NULL) {
452 for (
int i = 0; i < (*m); i++) {
454 temp, mma_bufred_d, (*n), (*m), i);
471void hip_sub2cons2(
void* a,
void*
b,
void* c,
void* d,
real*
e,
int* n) {
473 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
482real hip_maxval(
void* a,
int* n) {
484 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
488 if (
nb > mma_red_s) {
490 if (mma_bufred !=
NULL) {
499 (
real*)a, mma_bufred_d, (*n));
510 return mma_bufred[0];
514void hip_delx(
void*
delx,
void* x,
void*
xlow,
void*
xupp,
void* pij,
515 void* qij,
void* p0j,
void* q0j,
void* alpha,
void* beta,
void* lambda,
518 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
528void hip_GG(
void*
GG,
void* x,
void*
xlow,
void*
xupp,
529 void* pij,
void* qij,
int* n,
int* m) {
531 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
540void hip_diagx(
void*
diagx,
void* x,
void* xsi,
void*
xlow,
void*
xupp,
541 void* p0j,
void* q0j,
void* pij,
void* qij,
void* alpha,
void* beta,
542 void* eta,
void* lambda,
int *n,
int *m) {
544 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
554void hip_bb(
void*
bb,
void*
GG,
void*
delx,
void*
diagx,
int *n,
int *m) {
556 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
557 const int nb = ((*n) + 1024 - 1)/ 1024;
562 if (
nb > mma_red_s) {
564 if (mma_bufred !=
NULL) {
572 for (
int i = 0; i < (*m); i++) {
589void hip_AA(
void*
AA,
void*
GG,
void*
diagx,
int *n,
int *m) {
591 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
592 const int nb = ((*n) + 1024 - 1)/ 1024;
597 if (
nb > mma_red_s) {
599 if (mma_bufred !=
NULL) {
607 for (
int i = 0; i < (*m); i++) {
608 for (
int j = 0;
j < (*m);
j++) {
618 (
real*)
AA, mma_bufred_d, 1, i +
j * (*m + 1));
629 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
637void hip_dxsi(
void*
dxsi,
void* xsi,
void*
dx,
void* x,
640 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
648void hip_deta(
void*
deta,
void* eta,
void*
dx,
void* x,
651 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
659void hip_rex(
void*
rex,
void* x,
void*
xlow,
void*
xupp,
void* pij,
660 void* p0j,
void* qij,
void* q0j,
void* lambda,
void* xsi,
void* eta,
663 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
672void hip_rey(
void*
rey,
void* c,
void* d,
void* y,
void* lambda,
void* mu,
int* n) {
674 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
684void hip_sub2cons(
void *a,
void *
b,
void *c,
real *d,
int *n) {
686 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
695real hip_norm(
void* a,
int* n) {
697 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
698 const int nb = ((*n) + 1024 - 1) / 1024;
701 if (
nb > mma_red_s) {
703 if (mma_bufred !=
NULL) {
712 (
real*)a, mma_bufred_d, (*n));
724 return mma_bufred[0];
728void hip_dely(
void*
dely,
void* c,
void* d,
void* y,
void* lambda,
731 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
741 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
742 const int nb = ((*n) + 1024 - 1) / 1024;
745 if (
nb > mma_red_s) {
747 if (mma_bufred !=
NULL) {
768 return mma_bufred[0];
772real hip_maxval3(
void* a,
void*
b,
void* c,
real*
cons,
int* n) {
774 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
775 const int nb = ((*n) + 1024 - 1) / 1024;
778 if (
nb > mma_red_s) {
780 if (mma_bufred !=
NULL) {
799 return mma_bufred[0];
803void hip_kkt_rex(
void*
rex,
void*
df0dx,
void*
dfdx,
void* xsi,
804 void* eta,
void* lambda,
int* n,
int* m) {
806 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
814void mma_dip_kkt_hip(
void* res,
void* x,
void*
df0dx,
void*
dfdx,
815 void* xmin,
void* xmax,
void* lambda,
int* n,
int* m) {
819 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
823 (
real*)xmax, (
real*)lambda, *n, *m);
829void hip_maxcons(
void* a,
real*
b,
real* c,
void* d,
int* n) {
831 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
839real hip_lcsc2(
void *a,
void*
b,
int *n) {
841 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
842 const int nb = ((*n) + 1024 - 1) / 1024;
845 if (
nb > mma_red_s) {
847 if (mma_bufred !=
NULL) {
868 return mma_bufred[0];
872void hip_mpisum(
void *a,
int *n) {
873#ifdef HAVE_DEVICE_MPI
881void hip_add2inv2(
void* a,
void*
b,
real* c,
int* n) {
883 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
891void hip_max2(
void* a,
real*
b,
void* c,
real* d,
int* n) {
893 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
902 void* mu,
void* y,
real*
delz,
int* m) {
904 const dim3 nblcks(((*m + 1) + 1024 - 1) / 1024, 1, 1);
913void hip_updateAA(
void*
AA,
void*
globaltmp_mm,
void* s,
void* lambda,
914 void* d,
void* mu,
void* y,
void* a,
917 const dim3 nblcks(((*m + 1) + 1024 - 1) / 1024, 1, 1);
928 void* mu,
void* y,
int* n) {
930 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);