Skip to content

Commit c2c53e6

Browse files
committed
compiling GPU, test execs OK but segfault
1 parent 6edf4f2 commit c2c53e6

File tree

3 files changed

+47
-32
lines changed

3 files changed

+47
-32
lines changed

src/pdlp/CupdlpWrapper.cpp

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ HighsStatus solveLpCupdlp(const HighsOptions& options, HighsTimer& timer,
6363
0.0; // true objVal = sig * c'x - offset, sig = 1 (min) or -1 (max)
6464
double sense_origin = 1; // 1 (min) or -1 (max)
6565
int* constraint_new_idx = NULL;
66+
int *constraint_type = NULL;
6667

6768
void* model = NULL;
6869
void* presolvedmodel = NULL;
@@ -99,16 +100,18 @@ HighsStatus solveLpCupdlp(const HighsOptions& options, HighsTimer& timer,
99100
getUserParamsFromOptions(options, ifChangeIntParam, intParam,
100101
ifChangeFloatParam, floatParam);
101102

102-
std::vector<int> constraint_type(lp.num_row_);
103+
// std::vector<int> constraint_type(lp.num_row_);
103104

104105
formulateLP_highs(lp, &cost, &nCols, &nRows, &nnz, &nEqs, &csc_beg, &csc_idx,
105106
&csc_val, &rhs, &lower, &upper, &offset, &sense_origin,
106-
&nCols_origin, &constraint_new_idx, constraint_type.data());
107+
&nCols_origin, &constraint_new_idx, &constraint_type);
107108

108109
const cupdlp_int local_log_level = getCupdlpLogLevel(options);
109110
if (local_log_level) cupdlp_printf("Solving with cuPDLP-C\n");
110111

111-
H_Init_Scaling(local_log_level, scaling, nCols, nRows, cost, rhs);
112+
// H_Init_Scaling(local_log_level, scaling, nCols, nRows, cost, rhs);
113+
Init_Scaling(scaling, nCols, nRows, cost, rhs);
114+
112115
cupdlp_int ifScaling = 1;
113116

114117
CUPDLPwork* w = cupdlp_NULL;
@@ -150,8 +153,12 @@ HighsStatus solveLpCupdlp(const HighsOptions& options, HighsTimer& timer,
150153
memcpy(csc_cpu->colMatElem, csc_val, nnz * sizeof(double));
151154

152155
cupdlp_float scaling_time = getTimeStamp();
153-
PDHG_Scale_Data(local_log_level, csc_cpu, ifScaling, scaling, cost,
154-
lower, upper, rhs);
156+
157+
// PDHG_Scale_Data(local_log_level, csc_cpu, ifScaling, scaling, cost,
158+
// lower, upper, rhs);
159+
160+
PDHG_Scale_Data(csc_cpu, ifScaling, scaling, cost, lower, upper, rhs);
161+
155162
scaling_time = getTimeStamp() - scaling_time;
156163

157164
cupdlp_float alloc_matrix_time = 0.0;
@@ -200,8 +207,9 @@ HighsStatus solveLpCupdlp(const HighsOptions& options, HighsTimer& timer,
200207
nCols_origin, highs_solution.col_value.data(),
201208
highs_solution.col_dual.data(), highs_solution.row_value.data(),
202209
highs_solution.row_dual.data(), &value_valid, &dual_valid, ifSaveSol,
203-
fp_sol, constraint_new_idx, constraint_type.data(), &pdlp_model_status,
210+
fp_sol, constraint_new_idx, constraint_type, &pdlp_model_status,
204211
&pdlp_num_iter);
212+
205213
highs_info.pdlp_iteration_count = pdlp_num_iter;
206214

207215
model_status = HighsModelStatus::kUnknown;
@@ -301,7 +309,9 @@ HighsStatus solveLpCupdlp(const HighsOptions& options, HighsTimer& timer,
301309
csc_clear_host(csc_cpu);
302310
problem_clear(prob);
303311
#if !(CUPDLP_CPU)
304-
CHECK_CUDA(cudaDeviceReset())
312+
if (check_cuda_call(cudaDeviceReset(), __FILE__, __LINE__) != cudaSuccess)
313+
return HighsStatus::kError;
314+
// CHECK_CUDA(cudaDeviceReset())
305315
#endif
306316

307317
return HighsStatus::kOk;
@@ -312,7 +322,7 @@ int formulateLP_highs(const HighsLp& lp, double** cost, int* nCols, int* nRows,
312322
double** csc_val, double** rhs, double** lower,
313323
double** upper, double* offset, double* sense_origin,
314324
int* nCols_origin, int** constraint_new_idx,
315-
int* constraint_type) {
325+
int** constraint_type) {
316326
int retcode = 0;
317327

318328
// problem size for malloc
@@ -338,6 +348,7 @@ int formulateLP_highs(const HighsLp& lp, double** cost, int* nCols, int* nRows,
338348
const double* A_csc_val = lp.a_matrix_.value_.data();
339349
int has_lower, has_upper;
340350

351+
cupdlp_init_int(*constraint_type, *nRows);
341352
cupdlp_init_int(*constraint_new_idx, *nRows);
342353

343354
// recalculate nRows and nnz for Ax - z = 0
@@ -347,14 +358,14 @@ int formulateLP_highs(const HighsLp& lp, double** cost, int* nCols, int* nRows,
347358

348359
// count number of equations and rows
349360
if (has_lower && has_upper && lhs_clp[i] == rhs_clp[i]) {
350-
constraint_type[i] = EQ;
361+
*constraint_type[i] = EQ;
351362
(*nEqs)++;
352363
} else if (has_lower && !has_upper) {
353-
constraint_type[i] = GEQ;
364+
*constraint_type[i] = GEQ;
354365
} else if (!has_lower && has_upper) {
355-
constraint_type[i] = LEQ;
366+
*constraint_type[i] = LEQ;
356367
} else if (has_lower && has_upper) {
357-
constraint_type[i] = BOUND;
368+
*constraint_type[i] = BOUND;
358369
(*nCols)++;
359370
(*nnz)++;
360371
(*nEqs)++;
@@ -365,7 +376,7 @@ int formulateLP_highs(const HighsLp& lp, double** cost, int* nCols, int* nRows,
365376

366377
// what if regard free as bounded
367378
printf("Warning: constraint %d has no lower and upper bound\n", i);
368-
constraint_type[i] = BOUND;
379+
*constraint_type[i] = BOUND;
369380
(*nCols)++;
370381
(*nnz)++;
371382
(*nEqs)++;
@@ -394,7 +405,7 @@ int formulateLP_highs(const HighsLp& lp, double** cost, int* nCols, int* nRows,
394405
}
395406
// slack bounds
396407
for (int i = 0, j = nCols_clp; i < *nRows; i++) {
397-
if (constraint_type[i] == BOUND) {
408+
if (*constraint_type[i] == BOUND) {
398409
(*lower)[j] = lhs_clp[i];
399410
(*upper)[j] = rhs_clp[i];
400411
j++;
@@ -409,23 +420,23 @@ int formulateLP_highs(const HighsLp& lp, double** cost, int* nCols, int* nRows,
409420
// permute LP rhs
410421
// EQ or BOUND first
411422
for (int i = 0, j = 0; i < *nRows; i++) {
412-
if (constraint_type[i] == EQ) {
423+
if (*constraint_type[i] == EQ) {
413424
(*rhs)[j] = lhs_clp[i];
414425
(*constraint_new_idx)[i] = j;
415426
j++;
416-
} else if (constraint_type[i] == BOUND) {
427+
} else if (*constraint_type[i] == BOUND) {
417428
(*rhs)[j] = 0.0;
418429
(*constraint_new_idx)[i] = j;
419430
j++;
420431
}
421432
}
422433
// then LEQ or GEQ
423434
for (int i = 0, j = *nEqs; i < *nRows; i++) {
424-
if (constraint_type[i] == LEQ) {
435+
if (*constraint_type[i] == LEQ) {
425436
(*rhs)[j] = -rhs_clp[i]; // multiply -1
426437
(*constraint_new_idx)[i] = j;
427438
j++;
428-
} else if (constraint_type[i] == GEQ) {
439+
} else if (*constraint_type[i] == GEQ) {
429440
(*rhs)[j] = lhs_clp[i];
430441
(*constraint_new_idx)[i] = j;
431442
j++;
@@ -443,20 +454,20 @@ int formulateLP_highs(const HighsLp& lp, double** cost, int* nCols, int* nRows,
443454
// same order as in rhs
444455
// EQ or BOUND first
445456
for (int j = (*csc_beg)[i]; j < (*csc_beg)[i + 1]; j++) {
446-
if (constraint_type[A_csc_idx[j]] == EQ ||
447-
constraint_type[A_csc_idx[j]] == BOUND) {
457+
if (*constraint_type[A_csc_idx[j]] == EQ ||
458+
*constraint_type[A_csc_idx[j]] == BOUND) {
448459
(*csc_idx)[k] = (*constraint_new_idx)[A_csc_idx[j]];
449460
(*csc_val)[k] = A_csc_val[j];
450461
k++;
451462
}
452463
}
453464
// then LEQ or GEQ
454465
for (int j = (*csc_beg)[i]; j < (*csc_beg)[i + 1]; j++) {
455-
if (constraint_type[A_csc_idx[j]] == LEQ) {
466+
if (*constraint_type[A_csc_idx[j]] == LEQ) {
456467
(*csc_idx)[k] = (*constraint_new_idx)[A_csc_idx[j]];
457468
(*csc_val)[k] = -A_csc_val[j]; // multiply -1
458469
k++;
459-
} else if (constraint_type[A_csc_idx[j]] == GEQ) {
470+
} else if (*constraint_type[A_csc_idx[j]] == GEQ) {
460471
(*csc_idx)[k] = (*constraint_new_idx)[A_csc_idx[j]];
461472
(*csc_val)[k] = A_csc_val[j];
462473
k++;
@@ -466,7 +477,7 @@ int formulateLP_highs(const HighsLp& lp, double** cost, int* nCols, int* nRows,
466477

467478
// slacks for BOUND
468479
for (int i = 0, j = nCols_clp; i < *nRows; i++) {
469-
if (constraint_type[i] == BOUND) {
480+
if (*constraint_type[i] == BOUND) {
470481
(*csc_idx)[(*csc_beg)[j]] = (*constraint_new_idx)[i];
471482
(*csc_val)[(*csc_beg)[j]] = -1.0;
472483
j++;

src/pdlp/CupdlpWrapper.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#include "lp_data/HighsSolution.h"
1818
#include "pdlp/cupdlp/cupdlp.h"
1919

20+
#ifdef CUPDLP_GPU
21+
#include <cuda_runtime.h>
22+
#endif
23+
2024
typedef enum CONSTRAINT_TYPE { EQ = 0, LEQ, GEQ, BOUND } constraint_type;
2125

2226
#define cupdlp_init_int(var, size) \
@@ -84,7 +88,7 @@ int formulateLP_highs(const HighsLp& lp, double** cost, int* nCols, int* nRows,
8488
double** csc_val, double** rhs, double** lower,
8589
double** upper, double* offset, double* sign_origin,
8690
int* nCols_origin, int** constraint_new_idx,
87-
int* constraint_type);
91+
int** constraint_type);
8892

8993
cupdlp_int getCupdlpLogLevel(const HighsOptions& options);
9094

src/pdlp/cupdlp/cupdlp_scaling.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ cupdlp_retcode cupdlp_ruiz_scaling(CUPDLPcsc *csc, cupdlp_float *cost,
5757

5858
cupdlp_float *current_col_scaling = NULL; // for variable
5959
cupdlp_float *current_row_scaling = NULL; // for constraint
60-
CUPDLP_INIT_ZERO(current_col_scaling, nCols);
61-
CUPDLP_INIT_ZERO(current_row_scaling, nRows);
60+
CUPDLP_INIT_ZERO_DOUBLE(current_col_scaling, nCols);
61+
CUPDLP_INIT_ZERO_DOUBLE(current_row_scaling, nRows);
6262

6363
for (cupdlp_int i = 0; i < scaling->RuizTimes; i++) {
6464
cupdlp_zero(current_col_scaling, cupdlp_float, nCols);
@@ -131,8 +131,8 @@ cupdlp_retcode cupdlp_l2norm_scaling(CUPDLPcsc *csc, cupdlp_float *cost,
131131

132132
cupdlp_float *current_col_scaling = NULL; // for variable
133133
cupdlp_float *current_row_scaling = NULL; // for constraint
134-
CUPDLP_INIT_ZERO(current_col_scaling, nCols);
135-
CUPDLP_INIT_ZERO(current_row_scaling, nRows);
134+
CUPDLP_INIT_ZERO_DOUBLE(current_col_scaling, nCols);
135+
CUPDLP_INIT_ZERO_DOUBLE(current_row_scaling, nRows);
136136

137137
if (nRows > 0) {
138138
for (int j = 0; j < nCols; j++) {
@@ -182,8 +182,8 @@ cupdlp_retcode cupdlp_pc_scaling(CUPDLPcsc *csc, cupdlp_float *cost,
182182

183183
cupdlp_float *current_col_scaling = NULL; // for variable
184184
cupdlp_float *current_row_scaling = NULL; // for constraint
185-
CUPDLP_INIT_ZERO(current_col_scaling, nCols);
186-
CUPDLP_INIT_ZERO(current_row_scaling, nRows);
185+
CUPDLP_INIT_ZERO_DOUBLE(current_col_scaling, nCols);
186+
CUPDLP_INIT_ZERO_DOUBLE(current_row_scaling, nRows);
187187

188188
if (alpha > 2.0 || alpha < 0.0) {
189189
cupdlp_printf("alpha should be in [0, 2]\n");
@@ -403,8 +403,8 @@ cupdlp_retcode Init_Scaling(CUPDLPscaling *scaling, cupdlp_int ncols,
403403
scaling->RuizTimes = 10;
404404
scaling->RuizNorm = INFINITY;
405405
scaling->PcAlpha = 1.0;
406-
CUPDLP_INIT(scaling->colScale, ncols);
407-
CUPDLP_INIT(scaling->rowScale, nrows);
406+
CUPDLP_INIT_DOUBLE(scaling->colScale, ncols);
407+
CUPDLP_INIT_DOUBLE(scaling->rowScale, nrows);
408408

409409
for (cupdlp_int iCol = 0; iCol < ncols; iCol++) scaling->colScale[iCol] = 1.0;
410410
for (cupdlp_int iRow = 0; iRow < nrows; iRow++) scaling->rowScale[iRow] = 1.0;

0 commit comments

Comments
 (0)