Skip to content

Commit 3bbeacb

Browse files
committed
all updates from the past year
1 parent 93dac86 commit 3bbeacb

File tree

12 files changed

+551
-301
lines changed

12 files changed

+551
-301
lines changed

src/pdlp/cupdlp/cupdlp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "pdlp/cupdlp/cupdlp_linalg.h"
88
#include "pdlp/cupdlp/cupdlp_proj.h"
99
#include "pdlp/cupdlp/cupdlp_restart.h"
10-
#include "pdlp/cupdlp/cupdlp_scaling_cuda.h"
10+
#include "pdlp/cupdlp/cupdlp_scaling.h"
1111
#include "pdlp/cupdlp/cupdlp_solver.h"
1212
#include "pdlp/cupdlp/cupdlp_step.h"
1313
#include "pdlp/cupdlp/cupdlp_utils.h"

src/pdlp/cupdlp/cupdlp_cs.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ double cupdlp_dcs_norm(const cupdlp_dcs *A);
2020
int cupdlp_dcs_print(const cupdlp_dcs *A, int brief);
2121

2222
/* utilities */
23-
void *_dcs_calloc(int n, size_t size);
23+
void *cupdlp_dcs_calloc(int n, size_t size);
2424
void *cupdlp_dcs_free(void *p);
2525
void *cupdlp_dcs_realloc(void *p, int n, size_t size, int *ok);
2626
cupdlp_dcs *cupdlp_dcs_spalloc(int m, int n, int nzmax, int values, int t);
@@ -31,7 +31,6 @@ void *cupdlp_dcs_malloc(int n, size_t size);
3131
/* utilities */
3232
double cupdlp_dcs_cumsum(int *p, int *c, int n);
3333
cupdlp_dcs *cupdlp_dcs_done(cupdlp_dcs *C, void *w, void *x, int ok);
34-
int *cupdlp_dcs_idone(int *p, cupdlp_dcs *C, void *w, int ok);
3534
cupdlp_dcs *cupdlp_dcs_transpose(const cupdlp_dcs *A, int values);
3635

3736
#define IS_CSC(A) (A && (A->nz == -1))

src/pdlp/cupdlp/cupdlp_defs.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,12 @@ struct CUPDLP_ITERATES {
330330
cupdlp_float *xLastRestart;
331331
cupdlp_float *yLastRestart;
332332

333-
CUPDLPvec *x, *xUpdate, *xAverage, *y, *yUpdate, *yAverage, *ax, *axUpdate,
334-
*axAverage, *aty, *atyUpdate, *atyAverage;
333+
CUPDLPvec *x[2]; // in iteration k, x^k stored in x[k % 2], x^{k+1} created in x[k + 1 % 2]
334+
CUPDLPvec *y[2];
335+
CUPDLPvec *ax[2];
336+
CUPDLPvec *aty[2];
337+
CUPDLPvec *xAverage, *yAverage, *axAverage, *atyAverage;
338+
335339
};
336340

337341
struct CUPDLP_STEPSIZE {
@@ -415,7 +419,9 @@ struct CUPDLP_WORK {
415419
#ifndef CUPDLP_CPU
416420
// CUDAmv *MV;
417421
cusparseHandle_t cusparsehandle;
418-
void *dBuffer;
422+
void *dBuffer_csc_ATy;
423+
void *dBuffer_csr_Ax;
424+
419425
// cusparseDnVecDescr_t vecbuffer;
420426
cublasHandle_t cublashandle;
421427
#endif

src/pdlp/cupdlp/cupdlp_linalg.c

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -395,19 +395,16 @@ void Ax_single_gpu(CUPDLPwork *w, cusparseDnVecDescr_t vecX,
395395

396396
switch (w->problem->data->matrix_format) {
397397
case CSR_CSC:
398-
// cuda_csc_Ax(w->cusparsehandle, w->problem->data->csc_matrix->cuda_csc,
399-
// vecX, vecAx, w->dBuffer, alpha, beta);
400-
401-
cuda_csr_Ax(w->cusparsehandle, w->problem->data->csr_matrix->cuda_csr,
402-
vecX, vecAx, w->dBuffer, alpha, beta);
398+
cuda_csr_Ax(w->cusparsehandle, w->problem->data->csr_matrix->cuda_csr,
399+
vecX, vecAx, w->dBuffer_csr_Ax, alpha, beta);
403400
break;
404401
case CSC:
405-
cuda_csc_Ax(w->cusparsehandle, w->problem->data->csc_matrix->cuda_csc,
406-
vecX, vecAx, w->dBuffer, alpha, beta);
402+
cupdlp_printf("Error: Ax_single_gpu requires CSR matrix\n");
403+
exit(1);
407404
break;
408405
case CSR:
409406
cuda_csr_Ax(w->cusparsehandle, w->problem->data->csr_matrix->cuda_csr,
410-
vecX, vecAx, w->dBuffer, alpha, beta);
407+
vecX, vecAx, w->dBuffer_csr_Ax, alpha, beta);
411408
break;
412409
default:
413410
cupdlp_printf("Error: Unknown matrix format in Ax_single_gpu\n");
@@ -430,18 +427,16 @@ void ATy_single_gpu(CUPDLPwork *w, cusparseDnVecDescr_t vecY,
430427

431428
switch (w->problem->data->matrix_format) {
432429
case CSR_CSC:
433-
// cuda_csr_ATy(w->cusparsehandle, w->problem->data->csr_matrix->cuda_csr,
434-
// vecY, vecATy, w->dBuffer, alpha, beta);
435-
cuda_csc_ATy(w->cusparsehandle, w->problem->data->csc_matrix->cuda_csc,
436-
vecY, vecATy, w->dBuffer, alpha, beta);
430+
cuda_csc_ATy(w->cusparsehandle, w->problem->data->csc_matrix->cuda_csc,
431+
vecY, vecATy, w->dBuffer_csc_ATy, alpha, beta);
437432
break;
438433
case CSC:
439434
cuda_csc_ATy(w->cusparsehandle, w->problem->data->csc_matrix->cuda_csc,
440-
vecY, vecATy, w->dBuffer, alpha, beta);
435+
vecY, vecATy, w->dBuffer_csc_ATy, alpha, beta);
441436
break;
442437
case CSR:
443-
cuda_csr_ATy(w->cusparsehandle, w->problem->data->csr_matrix->cuda_csr,
444-
vecY, vecATy, w->dBuffer, alpha, beta);
438+
cupdlp_printf("Error: ATy_single_gpu requires CSC matrix\n");
439+
exit(1);
445440
break;
446441
default:
447442
printf("Error: Unknown matrix format in Ax_single_gpu\n");
@@ -477,7 +472,7 @@ void Ax(CUPDLPwork *w, CUPDLPvec *ax, const CUPDLPvec *x) {
477472
break;
478473
case MULTI_GPU:
479474
#ifndef CUPDLP_CPU
480-
Ax_multi_gpu(d, ax, x);
475+
Ax_multi_gpu(d, ax->data, x->data);
481476
#else
482477
printf("GPU not supported in CPU build\n");
483478
exit(1);
@@ -757,6 +752,7 @@ void cupdlp_initvec(cupdlp_float *x, const cupdlp_float val,
757752
#endif
758753
}
759754

755+
/*
760756
void cupdlp_sub(cupdlp_float *xout, const cupdlp_float *x1,
761757
const cupdlp_float *x2, const cupdlp_int len) {
762758
#ifndef CUPDLP_CPU
@@ -767,6 +763,7 @@ void cupdlp_sub(cupdlp_float *xout, const cupdlp_float *x1,
767763
cupdlp_axpy(NULL, len, &alpha, x2, xout);
768764
#endif
769765
}
766+
*/
770767

771768
void cupdlp_compute_interaction_and_movement(CUPDLPwork *w,
772769
cupdlp_float *dMovement,
@@ -778,15 +775,25 @@ void cupdlp_compute_interaction_and_movement(CUPDLPwork *w,
778775
cupdlp_float dX = 0.0;
779776
cupdlp_float dY = 0.0;
780777

781-
cupdlp_sub(w->buffer2, iterates->x->data, iterates->xUpdate->data, nCols);
782-
cupdlp_twoNorm(w, nCols, w->buffer2, &dX);
783-
cupdlp_sub(w->buffer3, iterates->y->data, iterates->yUpdate->data, nRows);
784-
cupdlp_twoNorm(w, nRows, w->buffer3, &dY);
785-
786-
*dMovement = pow(dX, 2.0) * 0.5 * beta + pow(dY, 2.0) / (2.0 * beta);
787-
788-
cupdlp_sub(w->buffer3, iterates->aty->data, iterates->atyUpdate->data, nCols);
789-
cupdlp_dot(w, nCols, w->buffer2, w->buffer3, dInteraction);
778+
cupdlp_int iter = w->timers->nIter;
779+
CUPDLPvec *x = iterates->x[iter % 2];
780+
CUPDLPvec *y = iterates->y[iter % 2];
781+
CUPDLPvec *aty = iterates->aty[iter % 2];
782+
CUPDLPvec *xUpdate = iterates->x[(iter + 1) % 2];
783+
CUPDLPvec *yUpdate = iterates->y[(iter + 1) % 2];
784+
CUPDLPvec *atyUpdate = iterates->aty[(iter + 1) % 2];
785+
786+
#if !(CUPDLP_CPU) && USE_KERNELS
787+
cupdlp_movement_interaction_cuda(&dX, &dY, dInteraction, w->buffer2,
788+
xUpdate->data, x->data, yUpdate->data, y->data, atyUpdate->data, aty->data, nRows, nCols);
789+
#else
790+
cupdlp_diffTwoNormSquared(w, x->data, xUpdate->data, nCols, &dX);
791+
cupdlp_diffTwoNormSquared(w, y->data, yUpdate->data, nRows, &dY);
792+
// Δx' (AΔy)
793+
cupdlp_diffDotDiff(w, x->data, xUpdate->data, aty->data, atyUpdate->data,
794+
nCols, dInteraction);
795+
#endif
796+
*dMovement = dX * 0.5 * beta + dY / (2.0 * beta);
790797
}
791798

792799
// WIP iinfnormabslocaltermination

src/pdlp/cupdlp/cupdlp_proj.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ void PDHG_Project_Bounds(CUPDLPwork *work, cupdlp_float *r) {
2424
cupdlp_projlb(r, problem->lower, problem->nCols);
2525
}
2626

27-
void PDHG_Project_Row_Duals(CUPDLPwork *work, cupdlp_float *r) {
28-
CUPDLPproblem *problem = work->problem;
27+
// void PDHG_Project_Row_Duals(CUPDLPwork *work, cupdlp_float *r) {
28+
// CUPDLPproblem *problem = work->problem;
2929

30-
// cupdlp_projPositive(r + problem->nEqs, r + problem->nEqs, problem->nRows -
31-
// problem->nEqs);
32-
cupdlp_projPos(r + problem->nEqs, problem->nRows - problem->nEqs);
33-
}
30+
// // cupdlp_projPositive(r + problem->nEqs, r + problem->nEqs, problem->nRows -
31+
// // problem->nEqs);
32+
// cupdlp_projPos(r + problem->nEqs, problem->nRows - problem->nEqs);
33+
// }
3434

3535
// void PDHG_Restart_Iterate(CUPDLPwork *pdhg)
3636
// {
@@ -97,6 +97,12 @@ void PDHG_Restart_Iterate_GPU(CUPDLPwork *pdhg) {
9797

9898
if (restart_choice == PDHG_NO_RESTART) return;
9999

100+
cupdlp_int iter = pdhg->timers->nIter;
101+
CUPDLPvec *x = iterates->x[iter % 2];
102+
CUPDLPvec *y = iterates->y[iter % 2];
103+
CUPDLPvec *ax = iterates->ax[iter % 2];
104+
CUPDLPvec *aty = iterates->aty[iter % 2];
105+
100106
stepsize->dSumPrimalStep = 0.0;
101107
stepsize->dSumDualStep = 0.0;
102108
CUPDLP_ZERO_VEC(iterates->xSum, cupdlp_float, problem->nCols);
@@ -114,14 +120,11 @@ void PDHG_Restart_Iterate_GPU(CUPDLPwork *pdhg) {
114120
// cupdlp_copy(iterates->aty, iterates->atyAverage, cupdlp_float,
115121
// problem->nCols);
116122

117-
CUPDLP_COPY_VEC(iterates->x->data, iterates->xAverage->data, cupdlp_float,
118-
problem->nCols);
119-
CUPDLP_COPY_VEC(iterates->y->data, iterates->yAverage->data, cupdlp_float,
120-
problem->nRows);
121-
CUPDLP_COPY_VEC(iterates->ax->data, iterates->axAverage->data, cupdlp_float,
122-
problem->nRows);
123-
CUPDLP_COPY_VEC(iterates->aty->data, iterates->atyAverage->data,
124-
cupdlp_float, problem->nCols);
123+
CUPDLP_COPY_VEC(x->data, iterates->xAverage->data, cupdlp_float, problem->nCols);
124+
CUPDLP_COPY_VEC(y->data, iterates->yAverage->data, cupdlp_float, problem->nRows);
125+
CUPDLP_COPY_VEC(ax->data, iterates->axAverage->data, cupdlp_float, problem->nRows);
126+
CUPDLP_COPY_VEC(aty->data, iterates->atyAverage->data, cupdlp_float, problem->nCols);
127+
125128
} else {
126129
resobj->dPrimalFeasLastRestart = resobj->dPrimalFeas;
127130
resobj->dDualFeasLastRestart = resobj->dDualFeas;
@@ -133,10 +136,9 @@ void PDHG_Restart_Iterate_GPU(CUPDLPwork *pdhg) {
133136
// cupdlp_copy(iterates->xLastRestart, iterates->x, cupdlp_float,
134137
// problem->nCols); cupdlp_copy(iterates->yLastRestart, iterates->y,
135138
// cupdlp_float, problem->nRows);
136-
CUPDLP_COPY_VEC(iterates->xLastRestart, iterates->x->data, cupdlp_float,
137-
problem->nCols);
138-
CUPDLP_COPY_VEC(iterates->yLastRestart, iterates->y->data, cupdlp_float,
139-
problem->nRows);
139+
140+
CUPDLP_COPY_VEC(iterates->xLastRestart, x->data, cupdlp_float, problem->nCols);
141+
CUPDLP_COPY_VEC(iterates->yLastRestart, y->data, cupdlp_float, problem->nRows);
140142

141143
iterates->iLastRestartIter = timers->nIter;
142144

src/pdlp/cupdlp/cupdlp_proj.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
void PDHG_Project_Bounds(CUPDLPwork *work, double *r);
1212

13-
void PDHG_Project_Row_Duals(CUPDLPwork *work, double *r);
13+
// void PDHG_Project_Row_Duals(CUPDLPwork *work, double *r);
1414

1515
void PDHG_Restart_Iterate(CUPDLPwork *pdhg);
1616

0 commit comments

Comments
 (0)