-
Notifications
You must be signed in to change notification settings - Fork 103
C api additions #721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aliceb-nv
wants to merge
5
commits into
NVIDIA:main
Choose a base branch
from
aliceb-nv:c-api-additions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
C api additions #721
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,6 +111,20 @@ cuopt_int_t cuOptGetVersion(cuopt_int_t* version_major, | |
| */ | ||
| cuopt_int_t cuOptReadProblem(const char* filename, cuOptOptimizationProblem* problem_ptr); | ||
|
|
||
| /** | ||
| * @brief Write an optimization problem to a file. | ||
| * | ||
| * @param[in] problem - The optimization problem to write. | ||
| * @param[in] filename - The path to the output file. | ||
| * @param[in] format - The file format to use. Currently only CUOPT_FILE_FORMAT_MPS is supported. | ||
| * | ||
| * @return A status code indicating success or failure. Returns CUOPT_INVALID_ARGUMENT | ||
| * if an unsupported format is specified. | ||
| */ | ||
| cuopt_int_t cuOptWriteProblem(cuOptOptimizationProblem problem, | ||
| const char* filename, | ||
| cuopt_int_t format); | ||
|
|
||
| /** @brief Create an optimization problem of the form | ||
| * | ||
| * @verbatim | ||
|
|
@@ -681,6 +695,53 @@ cuopt_int_t cuOptGetFloatParameter(cuOptSolverSettings settings, | |
| const char* parameter_name, | ||
| cuopt_float_t* parameter_value); | ||
|
|
||
| /** | ||
| * @brief Set the initial primal solution for an LP solve. | ||
| * | ||
| * @param[in] settings - The solver settings object. | ||
| * @param[in] primal_solution - A pointer to an array of type cuopt_float_t | ||
| * of size num_variables containing the initial primal values. | ||
| * @param[in] num_variables - The number of variables (size of the primal_solution array). | ||
| * | ||
| * @return A status code indicating success or failure. | ||
| */ | ||
| cuopt_int_t cuOptSetInitialPrimalSolution(cuOptSolverSettings settings, | ||
| const cuopt_float_t* primal_solution, | ||
| cuopt_int_t num_variables); | ||
|
|
||
| /** | ||
| * @brief Set the initial dual solution for an LP solve. | ||
| * | ||
| * @param[in] settings - The solver settings object. | ||
| * @param[in] dual_solution - A pointer to an array of type cuopt_float_t | ||
| * of size num_constraints containing the initial dual values. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
| * @param[in] num_constraints - The number of constraints (size of the dual_solution array). | ||
| * | ||
| * @return A status code indicating success or failure. | ||
| */ | ||
| cuopt_int_t cuOptSetInitialDualSolution(cuOptSolverSettings settings, | ||
| const cuopt_float_t* dual_solution, | ||
| cuopt_int_t num_constraints); | ||
|
|
||
| /** | ||
| * @brief Add an initial solution (MIP start) for MIP solving. | ||
| * | ||
| * This function can be called multiple times to add multiple MIP starts. | ||
| * The solver will use these as starting points for the MIP search. | ||
| * | ||
| * @param[in] settings - The solver settings object. | ||
| * @param[in] solution - A pointer to an array of type cuopt_float_t | ||
| * of size num_variables containing the solution values. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
| * @param[in] num_variables - The number of variables (size of the solution array). | ||
| * | ||
| * @attention Currently unsupported with presolve on. | ||
| * | ||
| * @return A status code indicating success or failure. | ||
| */ | ||
| cuopt_int_t cuOptAddMIPStart(cuOptSolverSettings settings, | ||
| const cuopt_float_t* solution, | ||
| cuopt_int_t num_variables); | ||
|
|
||
| /** @brief Check if an optimization problem is a mixed integer programming problem. | ||
| * | ||
| * @param[in] problem - The optimization problem. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* clang-format off */ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| /* clang-format on */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cuopt/linear_programming/cuopt_c.h> | ||
| #include <cuopt/linear_programming/mip/solver_solution.hpp> | ||
| #include <cuopt/linear_programming/optimization_problem.hpp> | ||
| #include <cuopt/linear_programming/pdlp/solver_solution.hpp> | ||
|
|
||
| #include <raft/core/handle.hpp> | ||
|
|
||
| #include <rmm/cuda_stream_view.hpp> | ||
|
|
||
| namespace cuopt::linear_programming { | ||
|
|
||
| struct problem_and_stream_view_t { | ||
| problem_and_stream_view_t() | ||
| : op_problem(nullptr), stream_view(rmm::cuda_stream_per_thread), handle(stream_view) | ||
| { | ||
| } | ||
| raft::handle_t* get_handle_ptr() { return &handle; } | ||
| optimization_problem_t<cuopt_int_t, cuopt_float_t>* op_problem; | ||
| rmm::cuda_stream_view stream_view; | ||
| raft::handle_t handle; | ||
| }; | ||
|
|
||
| struct solution_and_stream_view_t { | ||
| solution_and_stream_view_t(bool solution_for_mip, rmm::cuda_stream_view stream_view) | ||
| : is_mip(solution_for_mip), | ||
| mip_solution_ptr(nullptr), | ||
| lp_solution_ptr(nullptr), | ||
| stream_view(stream_view) | ||
| { | ||
| } | ||
| bool is_mip; | ||
| mip_solution_t<cuopt_int_t, cuopt_float_t>* mip_solution_ptr; | ||
| optimization_problem_solution_t<cuopt_int_t, cuopt_float_t>* lp_solution_ptr; | ||
| rmm::cuda_stream_view stream_view; | ||
| }; | ||
|
|
||
| } // namespace cuopt::linear_programming |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to specify if data should be on the CPU and/or GPU?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that the C API abstracts away the reality of a GPU implementation - therefore all pointers involved are host pointers (as a result, we do not expose the stream(s) involved)
I think that if the need arises, we could create alternative versions of these functions to upload GPU data, or use something similar to cuSparse's pointer mode flag
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll note that as a new cuOpt user, I had the exact same question about host/device pointer for inputs.
I think it would be helpful to explicitly say they expect host pointers (either in the individual docstrings or in some high level place in the user guide "all C API pointers are expected to be pointers to host memory").