42#include <cuda_runtime.h>
43#include <cusolverDn.h>
46#include <neko/device/device_config.h>
47#include <neko/device/cuda/check.h>
48#include <neko/math/bcknd/device/device_mpi_reduce.h>
49#include <neko/math/bcknd/device/device_mpi_op.h>
61 void mma_update_hessian_z_cuda(
void*
Hess,
void* a,
int* m) {
75 void mma_prepare_aa_matrix_cuda(
void*
AA,
void* s,
void* lambda,
76 void* d,
void* mu,
void* y,
77 void* a,
real* zeta,
real* z,
int* m) {
79 const dim3 nblcks(((*m) + 1024 - 1) / 1024, 1, 1);
90 void mma_prepare_hessian_cuda(
void*
Hess,
void* y,
91 void* mu,
void* lambda,
int* m) {
118 for (
int i = 0; i <
M; i++) {
128 for (
int i = 0; i <
M; i++) {
142 void cuda_custom_solver(
void*
A,
void*
b,
int n,
int*
info) {
163 void cuSOLVER_wrapper(
void*
A,
void*
b,
int n,
int*
jj) {
225 void custom_solve_linear_system(
void*
A,
void*
b,
int n,
int*
info) {
249 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
255 void cuda_Hess(
void*
Hess,
void*
hijx,
void*
Ljjxinv,
int *n,
int *m) {
257 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
258 const int nb = ((*n) + 1024 - 1)/ 1024;
263 if(mma_bufred !=
NULL){
270 for (
int i = 0; i < (*m); i++){
271 for (
int j=0;
j<(*m);
j++){
286 void* low,
void* upp,
void* alpha,
void* beta,
int* n) {
288 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
296 void* low,
void* upp,
void* alpha,
void* beta,
int* n) {
298 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
305 void mattrans_v_mul_cuda(
void* output,
void* pij,
void* lambda,
308 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
314 void mma_gensub4_cuda(
const void* x,
const void* low,
const void* upp,
315 const void* pij,
const void* qij,
316 const int* n,
const int* m,
void* bi) {
323 const int nb = (
N + 1023) / 1024;
326 if (
nb > mma_red_s) {
329 if (mma_bufred !=
NULL) {
343 static_cast<const real*
>(x),
344 static_cast<const real*
>(low),
345 static_cast<const real*
>(upp),
346 static_cast<const real*
>(pij),
347 static_cast<const real*
>(qij),
350 for (
int i = 0; i <
M; ++i) {
352 temp, mma_bufred_d,
N,
M, i);
359 bi_d + i, mma_bufred_d,
sizeof(
real),
368 void mma_gensub3_cuda(
void* x,
void*
df0dx,
void*
dfdx,
void* low,
369 void* upp,
void* xmin,
void* xmax,
void* alpha,
void* beta,
370 void* p0j,
void* q0j,
void* pij,
void* qij,
int* n,
int* m) {
372 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
384 void mma_gensub3_dip_cuda(
void* x,
void*
df0dx,
void*
dfdx,
void* low,
385 void* upp,
void* xmin,
void* xmax,
void* alpha,
void* beta,
386 void* p0j,
void* q0j,
void* pij,
void* qij,
int* n,
int* m) {
388 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
400 void mma_gensub2_cuda(
void* low,
void* upp,
void* x,
void* xold1,
401 void* xold2,
void*
xdiff,
real* asydecr,
real* asyincr,
int* n) {
403 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
413 void mma_gensub1_cuda(
void* low,
void* upp,
void* x,
void* xmin,
void* xmax,
414 real* asyinit,
int* n) {
416 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
423 void cuda_mma_max(
void* xsi,
void* x,
void* alpha,
int* n) {
425 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
433 void* pij,
void* qij,
int* n,
int* m) {
435 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
436 const int nb = ((*n) + 1024 - 1)/ 1024;
439 if (
nb > mma_red_s){
441 if (mma_bufred !=
NULL) {
452 for (
int i = 0; i < (*m); i++) {
454 (temp, mma_bufred_d, (*n),(*m), i);
466 void cuda_sub2cons2(
void* a,
void*
b,
void* c,
void* d,
real*
e,
int* n) {
469 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
477 real cuda_maxval(
void* a,
int* n) {
480 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
481 const int nb = ((*n) + 1024 - 1) / 1024;
484 if (
nb > mma_red_s) {
486 if (mma_bufred !=
NULL) {
495 (
real*)a, mma_bufred_d, (*n));
506 return mma_bufred[0];
509 void cuda_delx(
void*
delx,
void* x,
void*
xlow,
void*
xupp,
void* pij,
510 void* qij,
void* p0j,
void* q0j,
void* alpha,
void* beta,
void* lambda,
514 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
523 void cuda_GG(
void*
GG,
void* x,
void*
xlow,
void*
xupp,
524 void* pij,
void* qij,
int* n,
int* m) {
526 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
533 void cuda_diagx(
void*
diagx,
void* x,
void* xsi,
void*
xlow,
void*
xupp,
534 void* p0j,
void* q0j,
void* pij,
void* qij,
void* alpha,
void* beta,
535 void* eta,
void* lambda,
int *n,
int *m) {
537 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
545 void cuda_bb(
void*
bb,
void*
GG,
void*
delx,
void*
diagx,
int *n,
int *m) {
547 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
548 const int nb = ((*n) + 1024 - 1)/ 1024;
553 if(mma_bufred !=
NULL){
560 for (
int i = 0; i < (*m); i++) {
572 void cuda_AA(
void*
AA,
void*
GG,
void*
diagx,
int *n,
int *m) {
574 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
575 const int nb = ((*n) + 1024 - 1)/ 1024;
580 if(mma_bufred !=
NULL){
587 for (
int i = 0; i < (*m); i++){
588 for (
int j=0;
j<(*m);
j++){
605 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
612 void cuda_dxsi(
void*
dxsi,
void* xsi,
void*
dx,
void* x,
615 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
622 void cuda_deta(
void*
deta,
void* eta,
void*
dx,
void* x,
625 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
632 void cuda_rex(
void*
rex,
void* x,
void*
xlow,
void*
xupp,
void* pij,
633 void* p0j,
void* qij,
void* q0j,
void* lambda,
void* xsi,
void* eta,
636 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
644 void cuda_rey(
void*
rey,
void* c,
void* d,
void* y,
void* lambda,
void* mu,
647 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
655 void cuda_sub2cons(
void * a,
void *
b,
void * c,
real *d,
int * n) {
657 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
663 real cuda_norm(
void* a,
int* n) {
665 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
666 const int nb = ((*n) + 1024 - 1)/ 1024;
670 if(mma_bufred !=
NULL){
678 ((
real*)a, mma_bufred_d, (*n));
685 return mma_bufred[0];
688 void cuda_dely(
void*
dely,
void* c,
void* d,
void* y,
void* lambda,
691 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
699 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
700 const int nb = ((*n) + 1024 - 1)/ 1024;
704 if(mma_bufred !=
NULL) {
719 return mma_bufred[0];
722 real cuda_maxval3(
void* a,
void*
b,
void* c,
real*
cons,
int* n) {
724 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
725 const int nb = ((*n) + 1024 - 1)/ 1024;
729 if(mma_bufred !=
NULL) {
743 return mma_bufred[0];
746 void cuda_kkt_rex(
void*
rex,
void*
df0dx,
void*
dfdx,
void* xsi,
747 void* eta,
void* lambda,
int* n,
int* m) {
749 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
756 void mma_dip_kkt_cuda(
void* res,
void* x,
void*
df0dx,
void*
dfdx,
757 void* xmin,
void* xmax,
void* lambda,
int* n,
int* m) {
761 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
765 (
real*)xmax, (
real*)lambda, *n, *m);
769 void cuda_maxcons(
void* a,
real*
b,
real* c,
void* d,
int* n) {
771 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
777 real cuda_lcsc2(
void *a,
void*
b,
int *n) {
779 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
780 const int nb = ((*n) + 1024 - 1)/ 1024;
782 if (
nb > mma_red_s){
784 if (mma_bufred !=
NULL) {
792 ((
real*)a, (
real*)
b, mma_bufred_d, (*n));
799 return mma_bufred[0];
802 void cuda_mpisum(
void *a,
int *n) {
803#ifdef HAVE_DEVICE_MPI
810 void cuda_add2inv2(
void* a,
void *
b,
real* c,
int* n) {
812 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
818 void cuda_max2(
void* a,
real*
b,
void* c,
real* d,
int* n) {
820 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
827 void* mu,
void* y,
real*
delz,
int *m) {
829 const dim3 nblcks(((*m+1) + 1024 - 1) / 1024, 1, 1);
836 void cuda_updateAA(
void*
AA,
void*
globaltmp_mm,
void* s,
void* lambda,
837 void* d,
void*mu,
void* y,
void* a,
real* zeta,
real* z,
int* m) {
839 const dim3 nblcks(((*m+1) + 1024 - 1) / 1024, 1, 1);
846 void cuda_dy(
void*
dy,
void*
dely,
void*
dlambda,
void* d,
void* mu,
849 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);