@@ -158,7 +158,9 @@ void PDLPSolver::printConstraintInfo() {
158158}
159159
160160void PDLPSolver::preprocessLp () {
161+ #if PDLP_PROFILE
161162 hipdlpTimerStart (kHipdlpClockPreprocess );
163+ #endif
162164 logger_.info (
163165 " Preprocessing LP using cupdlp formulation (slack variables for "
164166 " bounds)..." );
@@ -356,13 +358,17 @@ void PDLPSolver::preprocessLp() {
356358 " , ||b|| = " + std::to_string (unscaled_rhs_norm_));
357359
358360 printConstraintInfo ();
361+ #if PDLP_PROFILE
359362 hipdlpTimerStop (kHipdlpClockPreprocess );
363+ #endif
360364}
361365
362366PostSolveRetcode PDLPSolver::postprocess (HighsSolution& solution) {
363367 logger_.info (" Post-solving the solution..." );
364368
369+ #if PDLP_PROFILE
365370 hipdlpTimerStart (kHipdlpClockPostprocess );
371+ #endif
366372 if (original_lp_ == nullptr ) {
367373 return PostSolveRetcode::DIMENSION_MISMATCH;
368374 }
@@ -486,12 +492,16 @@ PostSolveRetcode PDLPSolver::postprocess(HighsSolution& solution) {
486492 solution.dual_valid = true ;
487493 logger_.info (" Post-solve complete." );
488494
495+ #if PDLP_PROFILE
489496 hipdlpTimerStop (kHipdlpClockPostprocess );
497+ #endif
490498 return PostSolveRetcode::OK;
491499}
492500
493501void PDLPSolver::solve (std::vector<double >& x, std::vector<double >& y) {
502+ #if PDLP_PROFILE
494503 hipdlpTimerStart (kHipdlpClockSolve );
504+ #endif
495505 Timer solver_timer;
496506 const HighsLp& lp = lp_;
497507
@@ -599,9 +609,13 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
599609 */
600610 computeAverageIterateGpu ();
601611#else
612+ #if PDLP_PROFILE
602613 hipdlpTimerStart (kHipdlpClockAverageIterate );
614+ #endif
603615 computeAverageIterate (Ax_avg, ATy_avg);
616+ #if PDLP_PROFILE
604617 hipdlpTimerStop (kHipdlpClockAverageIterate );
618+ #endif
605619#endif
606620
607621 // Reset the average iterate accumulation
@@ -622,7 +636,9 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
622636 params_.tolerance , average_results, " [A-GPU]" );
623637#else
624638 // === CPU Convergence Check ===//
639+ #if PDLP_PROFILE
625640 hipdlpTimerStart (kHipdlpClockConvergenceCheck );
641+ #endif
626642 // Compute residuals for current iterate
627643 bool current_converged = checkConvergence (
628644 iter, x_current_, y_current_, Ax_cache_, ATy_cache_,
@@ -632,8 +648,10 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
632648 bool average_converged = checkConvergence (
633649 iter, x_avg_, y_avg_, Ax_avg, ATy_avg, params_.tolerance ,
634650 average_results, " [A]" , dSlackPosAvg_, dSlackNegAvg_);
651+ #if PDLP_PROFILE
635652 hipdlpTimerStop (kHipdlpClockConvergenceCheck );
636653#endif
654+ #endif
637655#if PDLP_DEBUG_LOG
638656 debugPdlpIterHeaderLog (debug_pdlp_log_file_);
639657#endif
@@ -799,19 +817,29 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
799817 a_num_cols_ * sizeof (double ),
800818 cudaMemcpyDeviceToHost));
801819#else
820+ #if PDLP_PROFILE
802821 hipdlpTimerStart (kHipdlpClockMatrixMultiply );
822+ #endif
803823 linalg::Ax (lp, x_current_, Ax_cache_);
824+ #if PDLP_PROFILE
804825 hipdlpTimerStop (kHipdlpClockMatrixMultiply );
826+ #endif
827+ #if PDLP_PROFILE
805828 hipdlpTimerStart (kHipdlpClockMatrixTransposeMultiply );
829+ #endif
806830 linalg::ATy (lp, y_current_, ATy_cache_);
831+ #if PDLP_PROFILE
807832 hipdlpTimerStop (kHipdlpClockMatrixTransposeMultiply );
833+ #endif
808834#endif
809835 restart_scheme_.SetLastRestartIter (iter);
810836 }
811837 }
812838
813839 // --- 5. Core PDHG update Step ---
840+ #if PDLP_PROFILE
814841 hipdlpTimerStart (kHipdlpClockIterateUpdate );
842+ #endif
815843 bool step_success = true ;
816844
817845 // Store current iterates before update (for next iteration's x_current_,
@@ -860,28 +888,31 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
860888 // Reset to average and terminate
861889 x = x_avg_;
862890 y = y_avg_;
891+ #if PDLP_PROFILE
863892 hipdlpTimerStop (kHipdlpClockIterateUpdate );
893+ #endif
864894 return solveReturn (TerminationStatus::ERROR);
865895 }
866896 }
867897
868898 // Compute ATy for the new iterate
869899 Ax_cache_ = Ax_next_;
870- /*
871- hipdlpTimerStart(kHipdlpClockMatrixTransposeMultiply);
872- linalg::ATy(lp, y_next_, ATy_cache_);
873- hipdlpTimerStop(kHipdlpClockMatrixTransposeMultiply);
874- */
875900 ATy_cache_ = ATy_next_;
876901
902+ #if PDLP_PROFILE
877903 hipdlpTimerStop (kHipdlpClockIterateUpdate );
904+ #endif
878905
879906 // --- 6. Update Average Iterates ---
880907 // The number of iterations since the last restart
881908 int inner_iter = iter - restart_scheme_.GetLastRestartIter ();
909+ #if PDLP_PROFILE
882910 hipdlpTimerStart (kHipdlpClockAverageIterate );
911+ #endif
883912 updateAverageIterates (x_next_, y_next_, working_params, inner_iter);
913+ #if PDLP_PROFILE
884914 hipdlpTimerStop (kHipdlpClockAverageIterate );
915+ #endif
885916
886917#ifdef CUPDLP_GPU
887918 // Update average iterates on GPU
@@ -921,7 +952,9 @@ void PDLPSolver::solveReturn(const TerminationStatus term_code) {
921952 cleanupGpu ();
922953#endif
923954 results_.term_code = term_code;
955+ #if PDLP_PROFILE
924956 hipdlpTimerStop (kHipdlpClockSolve );
957+ #endif
925958}
926959
927960void PDLPSolver::initialize () {
@@ -984,13 +1017,21 @@ void PDLPSolver::updateAverageIterates(const std::vector<double>& x,
9841017 int inner_iter) {
9851018 double dMeanStepSize = std::sqrt (stepsize_.primal_step * stepsize_.dual_step );
9861019
1020+ #if PDLP_PROFILE
9871021 hipdlpTimerStart (kHipdlpClockAverageIterateUpdateX );
1022+ #endif
9881023 for (size_t i = 0 ; i < x.size (); ++i) x_sum_[i] += x[i] * dMeanStepSize;
1024+ #if PDLP_PROFILE
9891025 hipdlpTimerStop (kHipdlpClockAverageIterateUpdateX );
1026+ #endif
9901027
1028+ #if PDLP_PROFILE
9911029 hipdlpTimerStart (kHipdlpClockAverageIterateUpdateY );
1030+ #endif
9921031 for (size_t i = 0 ; i < y.size (); ++i) y_sum_[i] += y[i] * dMeanStepSize;
1032+ #if PDLP_PROFILE
9931033 hipdlpTimerStop (kHipdlpClockAverageIterateUpdateY );
1034+ #endif
9941035
9951036 sum_weights_ += dMeanStepSize;
9961037}
@@ -1000,26 +1041,42 @@ void PDLPSolver::computeAverageIterate(std::vector<double>& ax_avg,
10001041 double dPrimalScale = sum_weights_ > 1e-10 ? 1.0 / sum_weights_ : 1.0 ;
10011042 double dDualScale = sum_weights_ > 1e-10 ? 1.0 / sum_weights_ : 1.0 ;
10021043
1044+ #if PDLP_PROFILE
10031045 hipdlpTimerStart (kHipdlpClockAverageIterateComputeX );
1046+ #endif
10041047 for (size_t i = 0 ; i < x_avg_.size (); ++i)
10051048 x_avg_[i] = x_sum_[i] * dPrimalScale;
1049+ #if PDLP_PROFILE
10061050 hipdlpTimerStop (kHipdlpClockAverageIterateComputeX );
1051+ #endif
10071052
1053+ #if PDLP_PROFILE
10081054 hipdlpTimerStart (kHipdlpClockAverageIterateComputeY );
1055+ #endif
10091056 for (size_t i = 0 ; i < y_avg_.size (); ++i) y_avg_[i] = y_sum_[i] * dDualScale;
1057+ #if PDLP_PROFILE
10101058 hipdlpTimerStop (kHipdlpClockAverageIterateComputeY );
1059+ #endif
10111060
10121061#if PDLP_DEBUG_LOG
10131062 debug_pdlp_data_.x_average_norm = linalg::vector_norm_squared (x_avg_);
10141063#endif
10151064
1065+ #if PDLP_PROFILE
10161066 hipdlpTimerStart (kHipdlpClockAverageIterateMatrixMultiply );
1067+ #endif
10171068 linalg::Ax (lp_, x_avg_, ax_avg);
1069+ #if PDLP_PROFILE
10181070 hipdlpTimerStop (kHipdlpClockAverageIterateMatrixMultiply );
1071+ #endif
10191072
1073+ #if PDLP_PROFILE
10201074 hipdlpTimerStart (kHipdlpClockAverageIterateMatrixTransposeMultiply );
1075+ #endif
10211076 linalg::ATy (lp_, y_avg_, aty_avg);
1077+ #if PDLP_PROFILE
10221078 hipdlpTimerStop (kHipdlpClockAverageIterateMatrixTransposeMultiply );
1079+ #endif
10231080
10241081#if PDLP_DEBUG_LOG
10251082 debug_pdlp_data_.ax_average_norm = linalg::vector_norm_squared (ax_avg);
@@ -1428,8 +1485,10 @@ void PDLPSolver::setup(const HighsOptions& options, HighsTimer& timer) {
14281485 (float (prop.totalGlobalMem )) / 1e9 );
14291486#endif
14301487
1488+ #if PDLP_PROFILE
14311489 hipdlp_clocks_.timer_pointer_ = &timer;
14321490 hipdlp_timer_.initialiseHipdlpClocks (hipdlp_clocks_);
1491+ #endif
14331492
14341493 params_.initialise ();
14351494 // params.eta = 0; Not set in parse_options_file
@@ -1642,21 +1701,37 @@ std::vector<double> PDLPSolver::updateY(const std::vector<double>& y,
16421701}
16431702
16441703void PDLPSolver::updateIteratesFixed () {
1704+ #if PDLP_PROFILE
16451705 hipdlpTimerStart (kHipdlpClockProjectX );
1706+ #endif
16461707 x_next_ = updateX (x_current_, ATy_cache_, stepsize_.primal_step );
1708+ #if PDLP_PROFILE
16471709 hipdlpTimerStop (kHipdlpClockProjectX );
1710+ #endif
16481711
1712+ #if PDLP_PROFILE
16491713 hipdlpTimerStart (kHipdlpClockMatrixMultiply );
1714+ #endif
16501715 linalg::Ax (lp_, x_next_, Ax_next_);
1716+ #if PDLP_PROFILE
16511717 hipdlpTimerStop (kHipdlpClockMatrixMultiply );
1718+ #endif
16521719
1720+ #if PDLP_PROFILE
16531721 hipdlpTimerStart (kHipdlpClockProjectY );
1722+ #endif
16541723 y_next_ = updateY (y_current_, Ax_cache_, Ax_next_, stepsize_.dual_step );
1724+ #if PDLP_PROFILE
16551725 hipdlpTimerStop (kHipdlpClockProjectY );
1726+ #endif
16561727
1728+ #if PDLP_PROFILE
16571729 hipdlpTimerStart (kHipdlpClockMatrixTransposeMultiply );
1730+ #endif
16581731 linalg::ATy (lp_, y_next_, ATy_next_);
1732+ #if PDLP_PROFILE
16591733 hipdlpTimerStop (kHipdlpClockMatrixTransposeMultiply );
1734+ #endif
16601735
16611736#ifdef CUPDLP_GPU
16621737 // Add this check before the memcpy
@@ -1707,7 +1782,9 @@ void PDLPSolver::updateIteratesFixed() {
17071782}
17081783
17091784void PDLPSolver::updateIteratesAdaptive () {
1785+ #if PDLP_PROFILE
17101786 hipdlpTimerStart (kHipdlpClockStepSizeAdjustment );
1787+ #endif
17111788
17121789 const double MIN_ETA = 1e-6 ;
17131790 const double MAX_ETA = 1.0 ;
@@ -1763,22 +1840,38 @@ void PDLPSolver::updateIteratesAdaptive() {
17631840 d_aty_next_, d_aty_current_);
17641841#else
17651842 // Primal update
1843+ #if PDLP_PROFILE
17661844 hipdlpTimerStart (kHipdlpClockProjectX );
1845+ #endif
17671846 xupdate = updateX (x_candidate, aty_candidate, primal_step_update);
1847+ #if PDLP_PROFILE
17681848 hipdlpTimerStop (kHipdlpClockProjectX );
1849+ #endif
17691850
1851+ #if PDLP_PROFILE
17701852 hipdlpTimerStart (kHipdlpClockMatrixMultiply );
1853+ #endif
17711854 linalg::Ax (lp_, xupdate, axupdate);
1855+ #if PDLP_PROFILE
17721856 hipdlpTimerStop (kHipdlpClockMatrixMultiply );
1857+ #endif
17731858
17741859 // Dual update with timing
1860+ #if PDLP_PROFILE
17751861 hipdlpTimerStart (kHipdlpClockProjectY );
1862+ #endif
17761863 yupdate = updateY (y_candidate, ax_candidate, axupdate, dual_step_update);
1864+ #if PDLP_PROFILE
17771865 hipdlpTimerStop (kHipdlpClockProjectY );
1866+ #endif
17781867
1868+ #if PDLP_PROFILE
17791869 hipdlpTimerStart (kHipdlpClockMatrixTransposeMultiply );
1870+ #endif
17801871 linalg::ATy (lp_, yupdate, atyupdate);
1872+ #if PDLP_PROFILE
17811873 hipdlpTimerStop (kHipdlpClockMatrixTransposeMultiply );
1874+ #endif
17821875
17831876 // Compute deltas
17841877 std::vector<double > delta_x (lp_.num_col_ );
@@ -1854,7 +1947,9 @@ void PDLPSolver::updateIteratesAdaptive() {
18541947 stepsize_.primal_step = dStepSizeUpdate / std::sqrt (stepsize_.beta );
18551948 stepsize_.dual_step = dStepSizeUpdate * std::sqrt (stepsize_.beta );
18561949
1950+ #if PDLP_PROFILE
18571951 hipdlpTimerStop (kHipdlpClockStepSizeAdjustment );
1952+ #endif
18581953}
18591954
18601955bool PDLPSolver::updateIteratesMalitskyPock (bool first_iteration) {
@@ -1911,23 +2006,29 @@ double PDLPSolver::computeNonlinearity(const std::vector<double>& delta_primal,
19112006 return nonlinearity; // cupdlp does not take absolute value
19122007}
19132008
2009+ #if PDLP_PROFILE
19142010void PDLPSolver::reportHipdlpTimer () {
19152011 hipdlp_timer_.reportHipdlpCoreClock (hipdlp_clocks_);
19162012 hipdlp_timer_.reportHipdlpSolveClock (hipdlp_clocks_);
19172013 hipdlp_timer_.reportHipdlpIterateUpdateClock (hipdlp_clocks_);
19182014 hipdlp_timer_.reportHipdlpAverageIterateClock (hipdlp_clocks_);
19192015 hipdlp_timer_.reportHipdlpMatrixMultiplyClock (hipdlp_clocks_);
19202016}
2017+ #endif
19212018
2019+ #if PDLP_PROFILE
19222020void PDLPSolver::hipdlpTimerStart (const HighsInt hipdlp_clock) {
19232021 HighsInt highs_timer_clock = hipdlp_clocks_.clock_ [hipdlp_clock];
19242022 hipdlp_clocks_.timer_pointer_ ->start (highs_timer_clock);
19252023}
2024+ #endif
19262025
2026+ #if PDLP_PROFILE
19272027void PDLPSolver::hipdlpTimerStop (const HighsInt hipdlp_clock) {
19282028 HighsInt highs_timer_clock = hipdlp_clocks_.clock_ [hipdlp_clock];
19292029 hipdlp_clocks_.timer_pointer_ ->stop (highs_timer_clock);
19302030}
2031+ #endif
19312032
19322033#if PDLP_DEBUG_LOG
19332034void PDLPSolver::closeDebugLog () {
0 commit comments