Skip to content

Commit b12018c

Browse files
committed
seperate CPU&GPU
1 parent 3bce550 commit b12018c

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

highs/pdlp/hipdlp/pdhg.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,9 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
492492
}
493493

494494
// --- 0. Using PowerMethod to estimate the largest eigenvalue ---
495+
#ifdef CUPDLP_GPU
495496
setupGpu();
497+
#endif
496498
initializeStepSizes();
497499
PrimalDualParams working_params = params_;
498500
working_params.omega = std::sqrt(stepsize_.dual_step / stepsize_.primal_step);
@@ -521,7 +523,7 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
521523
CUDA_CHECK(cudaMemcpy(d_x_avg_, d_x_current_, a_num_cols_ * sizeof(double), cudaMemcpyDeviceToDevice));
522524
linalgGpuAx(d_x_current_, d_ax_current_);
523525
#endif
524-
526+
linalg::project_bounds(lp_, x_current_);
525527
linalg::project_bounds(lp_, x_sum_);
526528
linalg::project_bounds(lp_, x_avg_);
527529
linalg::Ax(lp, x_current_, Ax_cache_);
@@ -597,7 +599,7 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
597599
SolverResults current_results;
598600
SolverResults average_results;
599601

600-
602+
#ifdef CUPDLP_GPU
601603
//=== GPU Convergence Check ===//
602604
bool current_converged_gpu = checkConvergenceGpu(
603605
iter, d_x_current_, d_y_current_,
@@ -634,7 +636,7 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
634636
results_ = average_results;
635637
return solveReturn(TerminationStatus::OPTIMAL);
636638
}
637-
639+
#endif
638640
// === CPU Convergence Check ===//
639641
hipdlpTimerStart(kHipdlpClockConvergenceCheck);
640642
// Compute residuals for current iterate
@@ -849,7 +851,9 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
849851
}
850852

851853
void PDLPSolver::solveReturn(const TerminationStatus term_code) {
854+
#ifdef CUPDLP_GPU
852855
cleanupGpu();
856+
#endif
853857
results_.term_code = term_code;
854858
hipdlpTimerStop(kHipdlpClockSolve);
855859
}
@@ -1810,7 +1814,7 @@ void PDLPSolver::closeDebugLog() {
18101814
// =============================================================================
18111815
// SECTION 5: GPU Part
18121816
// =============================================================================
1813-
1817+
#ifdef CUPDLP_GPU
18141818
void PDLPSolver::setupGpu(){
18151819
//1. Initialize cuSPARSE
18161820
CUSPARSE_CHECK(cusparseCreate(&cusparse_handle_));
@@ -2179,4 +2183,5 @@ void PDLPSolver::computeAverageIterateGpu() {
21792183
// Recompute Ax_avg and ATy_avg on GPU
21802184
linalgGpuAx(d_x_avg_, d_ax_avg_);
21812185
linalgGpuATy(d_y_avg_, d_aty_avg_);
2182-
}
2186+
}
2187+
#endif

highs/pdlp/hipdlp/pdhg.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ class PDLPSolver {
169169
std::vector<double> Ax_next_, ATy_next_;
170170
std::vector<double> K_times_x_diff_;
171171

172+
#ifdef CUPDLP_GPU
172173
// --- GPU methods ---
173174
void setupGpu();
174175
void cleanupGpu();
@@ -264,6 +265,7 @@ class PDLPSolver {
264265
void computeStepSizeRatioGpu(PrimalDualParams& working_params);
265266
void updateAverageIteratesGpu(int inner_iter);
266267
void computeAverageIterateGpu();
268+
#endif
267269
};
268270

269271
#endif

0 commit comments

Comments
 (0)