Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,20 @@ FetchContent_MakeAvailable(pslp)
# -----------------------------------------------------------------------------
set(CORE_SOURCES
src/cuhsdlp.c
src/mps_parser.c
src/presolver.c
src/utils/matrix_formats.c
src/utils/pid_controller.c
src/cone_projector.cu
src/preconditioner.cu
src/result.cu
src/setup.cu
src/solver.cu
src/spmv_backend.cu
src/termination_checker.cu
src/step_control/active_set_boost.cu
src/step_control/pid_controller.c
src/step_control/power_iteration.cu
src/utils/display.cu
src/utils/power_iteration.cu
src/utils/mps_parser.c
src/utils/utils.cu)

# Set common include directories for the core libraries
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ After building the project, the `./build/cuhsdlp` binary can be invoked from the
| Option | Type | Description | Default |
| :--- | :--- | :--- | :--- |
| `--step_size_factor` | `float` | Step-size scaling factor in (0, 1). | `0.998` |
| `--no_active_set_step_size_boost` | `flag` | Disable active-set step-size boosting. | enabled |
| `--singular_value_max_iter` | `int` | Max power iterations for σ_max(A). | `5000` |
| `--singular_value_tol` | `float` | Power-iteration tolerance. | `1e-4` |
| `--cone_newton_max_iter` | `int` | Max Newton iterations for cone projection. | `100` |
Expand Down
17 changes: 17 additions & 0 deletions include/cuhsdlp_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ extern "C"
double necessary_reduction_for_restart;
} restart_parameters_t;

typedef struct
{
bool step_size_boost;
int window_iterations;
double relative_tol;
double safety_factor;
double min_raise_ratio;
double reestimate_change_ratio;
double divergence_ceiling_ratio;
double divergence_margin;
int max_reverts;
} active_set_parameters_t;

typedef struct
{
double eps_optimal_relative;
Expand All @@ -132,6 +145,7 @@ extern "C"
cone_parameters_t cone_params;
termination_criteria_t termination_criteria;
restart_parameters_t restart_params;
active_set_parameters_t active_set_params;
} pdhg_parameters_t;

typedef struct
Expand Down Expand Up @@ -171,6 +185,9 @@ extern "C"
double final_step_size_primal;
double final_step_size_dual;
double final_step_size_homogeneous;
int active_set_raise_count;
int active_set_revert_count;
int active_set_power_iteration_count;
} cuhsdlp_result_t;

typedef enum
Expand Down
58 changes: 58 additions & 0 deletions internal/active_set_boost.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Copyright 2026 Haihao Lu

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#pragma once

#include "internal_types.h"
#include <stdbool.h>

#ifdef __cplusplus
extern "C"
{
#endif

static inline bool is_active_set_boost_enabled(
const pdhg_parameters_t *params)
{
return params->active_set_params.step_size_boost &&
params->active_set_params.max_reverts > 0;
}

void initialize_active_set(
pdhg_solver_state_t *state,
const pdhg_parameters_t *params);

void active_set_free(active_set_state_t *active_set);

void update_active_set_masks(
pdhg_solver_state_t *state,
const pdhg_parameters_t *params);

bool should_revert_active_set_boost(
const pdhg_solver_state_t *state,
const pdhg_parameters_t *params);

void try_raise_active_set_step_size(
pdhg_solver_state_t *state,
const pdhg_parameters_t *params);

void revert_active_set_step_size(
pdhg_solver_state_t *state,
const pdhg_parameters_t *params);

#ifdef __cplusplus
}
#endif
2 changes: 2 additions & 0 deletions internal/cone_projector.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void update_dual_box_cone_projection(
double *current_dual,
double *reflected_dual,
double *evaluation_dual,
double *constraint_dual_projection_input,
const double *initial_dual,
const double *gradient,
const double *step_size_d,
Expand All @@ -67,6 +68,7 @@ void update_primal_box_cone_resolvent(
double *current_primal,
double *reflected_primal,
double *evaluation_primal,
double *variable_primal_projection_input,
const double *initial_primal,
const double *gradient,
const double *objective_d,
Expand Down
10 changes: 10 additions & 0 deletions internal/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ extern "C"

void display_iteration_stats(const pdhg_solver_state_t *state, bool verbose, bool is_restart);

void display_active_set_boost_raise(
const pdhg_parameters_t *params,
double previous_step_size,
double updated_step_size,
double masked_constraint_norm);

void display_active_set_boost_revert(
const pdhg_solver_state_t *state,
const pdhg_parameters_t *params);

void pdhg_final_log(
const cuhsdlp_result_t *result,
const pdhg_parameters_t *params);
Expand Down
47 changes: 40 additions & 7 deletions internal/internal_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ typedef struct {
double step_size_dual;
double step_size_homogeneous;
double step_size_base;
double step_size;
int total_count;
int inner_count;
int restart_count;
Expand Down Expand Up @@ -109,6 +110,44 @@ typedef struct {
void *buffer;
} spmv_plan_t;

typedef struct sv_estimator_ctx sv_estimator_ctx_t;

typedef struct {
double *primal_solution_d;
double *dual_solution_d;
double *hsd_scalars_d;
double *constraint_cone_scale_d;
double primal_weight;
pid_state_t pid;
} active_set_anchor_t;

typedef struct {
int variables_added;
int variables_removed;
int constraints_added;
int constraints_removed;
} active_set_mask_changes_t;

typedef struct {
double *constraint_dual_projection_input_d;
double *variable_primal_projection_input_d;
int *variable_last_free_iter_d;
int *constraint_last_binding_iter_d;
bool *free_variable_mask_d;
bool *binding_constraint_mask_d;
active_set_mask_changes_t *mask_changes_d;
sv_estimator_ctx_t *sv_estimator;
int free_variable_count;
int binding_constraint_count;
int mask_changes_since_estimate;
bool raise_checked;
double step_size_ceiling;
active_set_anchor_t anchor;
int raise_count;
int revert_count;
int power_iteration_count;
} active_set_state_t;

typedef struct {
int num_variables;
int num_constraints;
Expand Down Expand Up @@ -151,7 +190,6 @@ typedef struct {
cusparseDnVecDescr_t spmv_delta_dual_solution;
cusparseDnVecDescr_t spmv_primal_product;
cusparseDnVecDescr_t spmv_dual_product;
cusparseDnVecDescr_t spmv_power_iteration_normalized_vector;
spmv_plan_t matA_spmv_plan;
spmv_plan_t matAt_spmv_plan;
void *cub_reduce_workspace_d;
Expand Down Expand Up @@ -205,12 +243,6 @@ typedef struct {
double *hsd_dual_scale_current_d;
double *hsd_dual_scale_pdhg_d;
double *hsd_dual_scale_reflected_d;

double *power_iteration_normalized_vector_d;
double *power_iteration_vector_norm_scalar_d;
double *power_iter_sigma_squared_mp;
double *power_iter_residual_norm_mp;

double *primal_residual_d;
double *dual_residual_d;
double *primal_infeasibility_stationarity_residual_d;
Expand All @@ -221,6 +253,7 @@ typedef struct {
box_newton_state_t primal_box_cone_state;

solver_control_t control;
active_set_state_t active_set;

double *pdhg_reduce_d;
double *pdhg_primal_norm_d;
Expand Down
7 changes: 7 additions & 0 deletions internal/matrix_formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ extern "C"
int **row_ptr, int **col_ind,
double **vals, int *nnz_out);

void transpose_csr_and_build_map(
const lp_problem_t *problem,
int **transpose_row_ptr,
int **transpose_col_ind,
double **transpose_val,
int **transpose_map);

#ifdef __cplusplus
}
#endif
43 changes: 40 additions & 3 deletions internal/power_iteration.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,52 @@ limitations under the License.
#pragma once

#include "internal_types.h"
#include <stdbool.h>

#ifdef __cplusplus
extern "C"
{
#endif

double estimate_maximum_singular_value(
pdhg_solver_state_t *state,
const power_iteration_parameters_t *power_iter_params);
typedef enum
{
SV_ESTIMATOR_CONVERGED = 0,
SV_ESTIMATOR_EARLY_EXIT = 1,
SV_ESTIMATOR_MAX_ITER = 2,
SV_ESTIMATOR_DEGENERATE = 3,
} sv_estimator_status_t;

typedef struct
{
int max_iter;
double tol;
const bool *row_mask_d;
const bool *column_mask_d;
double early_exit_singular_value_threshold;
} sv_estimator_opts_t;

typedef struct
{
sv_estimator_status_t status;
double max_singular_value;
int iterations;
} sv_estimator_result_t;

sv_estimator_ctx_t *sv_estimator_create(
cusparseHandle_t sparse_handle,
cublasHandle_t blas_handle,
cudaStream_t stream,
curandGenerator_t curand_gen,
const cu_sparse_matrix_csr_t *matrix,
const cu_sparse_matrix_csr_t *transpose,
int num_rows,
int num_columns);

sv_estimator_result_t sv_estimator_run(
sv_estimator_ctx_t *ctx,
const sv_estimator_opts_t *opts);

void sv_estimator_free(sv_estimator_ctx_t *ctx);

#ifdef __cplusplus
}
Expand Down
9 changes: 9 additions & 0 deletions internal/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ extern "C"
void *safe_calloc(size_t num, size_t size);
void *safe_realloc(void *ptr, size_t new_size);

void allocate_zeroed_device_buffer(void **dst, size_t bytes);

void allocate_and_copy_to_device(
void **dst,
const void *src,
size_t bytes);

void allocate_cub_reduce_workspace(pdhg_solver_state_t *state);

void reduce_device_sum(
pdhg_solver_state_t *state,
const double *input,
Expand Down
21 changes: 13 additions & 8 deletions src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ void print_usage(const char *prog_name)
fprintf(stderr, " --no_bound_obj_rescaling Disable bound objective rescaling.\n");
fprintf(stderr, "\n Solver algorithm:\n");
fprintf(stderr, " --step_size_factor <float> Step size scaling factor in (0, 1) (default: 0.998).\n");
fprintf(stderr, " --no_active_set_step_size_boost Disable active-set step-size boosting (default: enabled).\n");
fprintf(stderr, " --singular_value_max_iter <int> Max iterations for singular value estimation (default: 5000).\n");
fprintf(stderr, " --singular_value_tol <float> Tolerance for singular value estimation (default: 1e-4).\n");
fprintf(stderr, " --cone_newton_max_iter <int> Max Newton iterations for cone projection (default: 100).\n");
Expand Down Expand Up @@ -206,6 +207,7 @@ int main(int argc, char *argv[])
{"pock_chambolle_alpha", required_argument, 0, 1004},
{"no_bound_obj_rescaling", no_argument, 0, 1005},
{"step_size_factor", required_argument, 0, 1006},
{"no_active_set_step_size_boost", no_argument, 0, 1007},
{"singular_value_max_iter", required_argument, 0, 1008},
{"singular_value_tol", required_argument, 0, 1009},
{"cone_newton_max_iter", required_argument, 0, 1010},
Expand All @@ -214,10 +216,10 @@ int main(int argc, char *argv[])
{"iter_limit", required_argument, 0, 1013},
{"eps_opt", required_argument, 0, 1014},
{"eps_feas", required_argument, 0, 1015},
{"eps_farkas_homogeneous", required_argument, 0, 1019},
{"eps_farkas_displacement", required_argument, 0, 1016},
{"eval_freq", required_argument, 0, 1017},
{"opt_norm", required_argument, 0, 1018},
{"eps_farkas_homogeneous", required_argument, 0, 1016},
{"eps_farkas_displacement", required_argument, 0, 1017},
{"eval_freq", required_argument, 0, 1018},
{"opt_norm", required_argument, 0, 1019},
{"verbose", no_argument, 0, 'v'},
{0, 0, 0, 0}};

Expand Down Expand Up @@ -256,6 +258,9 @@ int main(int argc, char *argv[])
&params.step_size_params.step_size_factor))
return 1;
break;
case 1007:
params.active_set_params.step_size_boost = false;
break;
case 1008:
if (!parse_int_arg("--singular_value_max_iter", optarg,
&params.power_iter_params.max_iter))
Expand Down Expand Up @@ -296,22 +301,22 @@ int main(int argc, char *argv[])
&params.termination_criteria.eps_feasible_relative))
return 1;
break;
case 1019:
case 1016:
if (!parse_double_arg("--eps_farkas_homogeneous", optarg,
&params.termination_criteria.eps_farkas_homogeneous))
return 1;
break;
case 1016:
case 1017:
if (!parse_double_arg("--eps_farkas_displacement", optarg,
&params.termination_criteria.eps_farkas_displacement))
return 1;
break;
case 1017:
case 1018:
if (!parse_int_arg("--eval_freq", optarg,
&params.termination_evaluation_frequency))
return 1;
break;
case 1018:
case 1019:
{
const char *norm_str = optarg;
if (strcmp(norm_str, "l2") == 0)
Expand Down
Loading