Skip to content

Commit

Permalink
free gpu memory, localtermination wip
Browse files Browse the repository at this point in the history
  • Loading branch information
galabovaa committed Jan 13, 2025
1 parent 6eeba2f commit f175850
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 17 deletions.
55 changes: 38 additions & 17 deletions src/pdlp/CupdlpWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ HighsStatus solveLpCupdlp(const HighsOptions& options, HighsTimer& timer,
0.0; // true objVal = sig * c'x - offset, sig = 1 (min) or -1 (max)
double sense_origin = 1; // 1 (min) or -1 (max)
int* constraint_new_idx = NULL;
cupdlp_float* x_origin = cupdlp_NULL;
cupdlp_float* y_origin = cupdlp_NULL;

void* model = NULL;
void* presolvedmodel = NULL;
Expand Down Expand Up @@ -187,8 +185,6 @@ HighsStatus solveLpCupdlp(const HighsOptions& options, HighsTimer& timer,
// CUPDLP_CALL(LP_SolvePDHG(prob, ifChangeIntParam, intParam,
// ifChangeFloatParam, floatParam, fp));

cupdlp_init_double(x_origin, nCols_origin);
cupdlp_init_double(y_origin, nRows);
// Resize the highs_solution so cuPDLP-c can use it internally
highs_solution.col_value.resize(lp.num_col_);
highs_solution.row_value.resize(lp.num_row_);
Expand Down Expand Up @@ -236,19 +232,31 @@ HighsStatus solveLpCupdlp(const HighsOptions& options, HighsTimer& timer,
analysePdlpSolution(options, lp, highs_solution);
#endif

free(cost);
free(lower);
free(upper);
free(csc_beg);
free(csc_idx);
free(csc_val);
free(rhs);
// free(cost);
// free(lower);
// free(upper);
// free(csc_beg);
// free(csc_idx);
// free(csc_val);
// free(rhs);

free(x_origin);
free(y_origin);
// free(constraint_new_idx);

free(constraint_new_idx);
// Scaling
#ifdef CUPDLP_CPU

if (scaling->rowScale != nullptr) free(scaling->rowScale);
if (scaling->colScale != nullptr) free(scaling->colScale);
free(scaling);

#else
// free problem
if (scaling) {
scaling_clear(scaling);
}
#endif

#ifdef CUPDLP_CPU
free(prob->cost);
free(prob->lower);
free(prob->upper);
Expand Down Expand Up @@ -276,10 +284,23 @@ HighsStatus solveLpCupdlp(const HighsOptions& options, HighsTimer& timer,
free(csc_cpu->colMatElem);

free(csc_cpu);
#endif

if (scaling->rowScale != nullptr) free(scaling->rowScale);
if (scaling->colScale != nullptr) free(scaling->colScale);
free(scaling);
if (cost != NULL) cupdlp_free(cost);
if (csc_beg != NULL) cupdlp_free(csc_beg);
if (csc_idx != NULL) cupdlp_free(csc_idx);
if (csc_val != NULL) cupdlp_free(csc_val);
if (rhs != NULL) cupdlp_free(rhs);
if (lower != NULL) cupdlp_free(lower);
if (upper != NULL) cupdlp_free(upper);
if (constraint_new_idx != NULL) cupdlp_free(constraint_new_idx);

// constraint type is std::vector
// if (constraint_type != NULL) cupdlp_free(constraint_type);

// free memory
csc_clear(csc_cpu);
problem_clear(prob);

return HighsStatus::kOk;
}
Expand Down
12 changes: 12 additions & 0 deletions src/pdlp/cupdlp/cuda/cupdlp_cuda_kernels.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ typedef double cupdlp_float;

dim3 cuda_gridsize(cupdlp_int n);

#define get_gpu_vec_element(vec_ptr, index, result, success) \
{ \
cublasStatus_t stat = \
cublasGetVector(1, sizeof(double), vec_ptr, 1, result, 1); \
if (stat != CUBLAS_STATUS_SUCCESS) { \
printf("data upload failed"); \
*success = 0; \
} else { \
*success = 1; \
} \
}

__global__ void element_wise_dot_kernel(cupdlp_float* x, const cupdlp_float* y,
const cupdlp_int len);

Expand Down
13 changes: 13 additions & 0 deletions src/pdlp/cupdlp/cupdlp_linalg.c
Original file line number Diff line number Diff line change
Expand Up @@ -788,3 +788,16 @@ void cupdlp_compute_interaction_and_movement(CUPDLPwork *w,
cupdlp_sub(w->buffer3, iterates->aty->data, iterates->atyUpdate->data, nCols);
cupdlp_dot(w, nCols, w->buffer2, w->buffer3, dInteraction);
}

double get_fabs_value(double* vec, int index) {
#ifdef CUPDLP_CPU
return vec[index];
#else
double result = 0;
int status = -1;
get_gpu_vec_element(vec, index, &result, &status);
if (!status)
return 0;
return result;
#endif
}

0 comments on commit f175850

Please sign in to comment.