Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <cuopt/mathematical_optimization/cpu_pdlp_warm_start_data.hpp>
#include <cuopt/mathematical_optimization/io/data_model_view.hpp>
#include <cuopt/mathematical_optimization/io/mps_data_model.hpp>
#include <cuopt/mathematical_optimization/optimization_problem.hpp>
#include <cuopt/mathematical_optimization/optimization_problem_interface.hpp>
#include <cuopt/mathematical_optimization/solver_settings.hpp>

Expand Down Expand Up @@ -139,12 +140,13 @@ void populate_from_mps_data_model(optimization_problem_interface_t<i_t, f_t>* pr
/**
* @brief Transfer parsed MPS/QPS storage into a CPU-backed problem without copying payload arrays.
*
* For GPU-backed problems this falls back to populate_from_mps_data_model (copy/H2D path).
* For GPU-backed problems this falls back to populate_from_mps_data_model (copy/H2D path), waits
* for the copies to complete, and releases the parsed host storage.
*
* @tparam i_t Integer type for indices
* @tparam f_t Floating point type for values
* @param[out] problem The optimization problem interface to populate
* @param[in] data_model Parsed model; moved-from on return for CPU adopt
* @param[in] data_model Parsed model; moved-from on return
*/
template <typename i_t, typename f_t>
void adopt_from_mps_data_model(optimization_problem_interface_t<i_t, f_t>* problem,
Expand All @@ -155,6 +157,10 @@ void adopt_from_mps_data_model(optimization_problem_interface_t<i_t, f_t>* probl
return;
}
populate_from_mps_data_model(problem, data_model);
if (auto* gpu_problem = dynamic_cast<optimization_problem_t<i_t, f_t>*>(problem)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the = is intentional and that you didn't want == but you might want move that out of the if to be clear.

auto* gpu_problem = dynamic_cast<optimization_problem_t<i_t, f_t>*>(problem);
if (gpu_problem) {
 ...
}

gpu_problem->get_handle_ptr()->sync_stream();
data_model = {};
}
}

/**
Expand Down
26 changes: 22 additions & 4 deletions cpp/src/dual_simplex/solve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,11 @@ template <typename i_t, typename f_t>
lp_status_t solve_linear_program_with_barrier(const user_problem_t<i_t, f_t>& user_problem,
const simplex_solver_settings_t<i_t, f_t>& settings,
f_t start_time,
lp_solution_t<i_t, f_t>& solution)
lp_solution_t<i_t, f_t>& solution,
const raft::handle_t* handle_ptr)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does passing in the handle_ptr (rather than getting it from the user_problem) help reduce memory?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is refactoring that allows us to get rid of this copy:

  auto barrier_problem       = dual_simplex_problem;
  barrier_problem.handle_ptr = barrier_handle_ptr.get();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is that in the code? I see barrier_lp but that is after column scaling?

{
lp_status_t status = lp_status_t::UNSET;
lp_problem_t<i_t, f_t> original_lp(user_problem.handle_ptr, 1, 1, 1);
lp_problem_t<i_t, f_t> original_lp(handle_ptr, 1, 1, 1);

// Convert the user problem to a linear program with only equality constraints
std::vector<i_t> new_slacks;
Expand All @@ -369,14 +370,14 @@ lp_status_t solve_linear_program_with_barrier(const user_problem_t<i_t, f_t>& us

// Presolve the linear program
presolve_info_t<i_t, f_t> presolve_info;
lp_problem_t<i_t, f_t> presolved_lp(user_problem.handle_ptr, 1, 1, 1);
lp_problem_t<i_t, f_t> presolved_lp(handle_ptr, 1, 1, 1);
const i_t ok = presolve(original_lp, barrier_settings, presolved_lp, presolve_info);
if (ok == CONCURRENT_HALT_RETURN) { return lp_status_t::CONCURRENT_LIMIT; }
if (ok == TIME_LIMIT_RETURN) { return lp_status_t::TIME_LIMIT; }
if (ok == -1) { return lp_status_t::INFEASIBLE; }

// Apply columns scaling to the presolve LP
lp_problem_t<i_t, f_t> barrier_lp(user_problem.handle_ptr,
lp_problem_t<i_t, f_t> barrier_lp(handle_ptr,
presolved_lp.num_rows,
presolved_lp.num_cols,
presolved_lp.A.col_start[presolved_lp.num_cols]);
Expand Down Expand Up @@ -669,6 +670,16 @@ lp_status_t solve_linear_program_with_barrier(const user_problem_t<i_t, f_t>& us
return barrier_status;
}

template <typename i_t, typename f_t>
lp_status_t solve_linear_program_with_barrier(const user_problem_t<i_t, f_t>& user_problem,
const simplex_solver_settings_t<i_t, f_t>& settings,
f_t start_time,
lp_solution_t<i_t, f_t>& solution)
{
return solve_linear_program_with_barrier(
user_problem, settings, start_time, solution, user_problem.handle_ptr);
}

template <typename i_t, typename f_t>
lp_status_t solve_linear_program_with_barrier(const user_problem_t<i_t, f_t>& user_problem,
const simplex_solver_settings_t<i_t, f_t>& settings,
Expand Down Expand Up @@ -825,6 +836,13 @@ template lp_status_t solve_linear_program_with_barrier(
double start_time,
lp_solution_t<int, double>& solution);

template lp_status_t solve_linear_program_with_barrier(
const user_problem_t<int, double>& user_problem,
const simplex_solver_settings_t<int, double>& settings,
double start_time,
lp_solution_t<int, double>& solution,
const raft::handle_t* handle_ptr);

template lp_status_t solve_linear_program(const user_problem_t<int, double>& user_problem,
const simplex_solver_settings_t<int, double>& settings,
lp_solution_t<int, double>& solution);
Expand Down
7 changes: 7 additions & 0 deletions cpp/src/dual_simplex/solve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ lp_status_t solve_linear_program_with_barrier(const user_problem_t<i_t, f_t>& us
f_t start_time,
lp_solution_t<i_t, f_t>& solution);

template <typename i_t, typename f_t>
lp_status_t solve_linear_program_with_barrier(const user_problem_t<i_t, f_t>& user_problem,
const simplex_solver_settings_t<i_t, f_t>& settings,
f_t start_time,
lp_solution_t<i_t, f_t>& solution,
const raft::handle_t* handle_ptr);

template <typename i_t, typename f_t>
lp_status_t solve_linear_program(const user_problem_t<i_t, f_t>& user_problem,
const simplex_solver_settings_t<i_t, f_t>& settings,
Expand Down
Loading
Loading