Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e471907
small PR-ready for feedback
Bubullzz May 29, 2026
dafb3e3
the rest of the PR
Bubullzz Jun 1, 2026
a601b6d
added _t to deleter functors
Bubullzz Jun 11, 2026
803efbf
code rabbit nit comment RAFT_CUSPARSE_TRY
Bubullzz Jun 11, 2026
43013a5
style
Bubullzz Jun 11, 2026
036469d
added has_value checks and fail loudly
Bubullzz Jun 11, 2026
2eb37fd
Merge branch 'main' into replace_wrappers_with_unique_ptrs
Bubullzz Jun 11, 2026
520218a
style
Bubullzz Jun 11, 2026
5e199e8
Merge branch 'main' into replace_wrappers_with_unique_ptrs
Bubullzz Jun 11, 2026
ba95897
Merge branch 'main' into replace_wrappers_with_unique_ptrs
Bubullzz Jun 12, 2026
90f1214
Merge branch 'main' into replace_wrappers_with_unique_ptrs
Bubullzz Jun 22, 2026
b5ffd92
Merge branch 'main' into replace_wrappers_with_unique_ptrs
Bubullzz Jun 23, 2026
8bdebd7
Merge branch 'main' into replace_wrappers_with_unique_ptrs
Bubullzz Jun 25, 2026
f5eeb57
Merge branch 'main' into replace_wrappers_with_unique_ptrs
Bubullzz Jun 25, 2026
5c436b7
Merge branch 'main' into replace_wrappers_with_unique_ptrs
Bubullzz Jun 25, 2026
1afbe40
style
Bubullzz Jun 25, 2026
01562d4
Merge branch 'main' into replace_wrappers_with_unique_ptrs
Bubullzz Jul 9, 2026
7421314
Merge branch 'main' into replace_wrappers_with_unique_ptrs
Bubullzz Jul 21, 2026
96ec047
merged main
Bubullzz Sep 2, 2026
8bab7bb
Merge branch 'main' into replace_wrappers_with_unique_ptrs
Bubullzz Sep 2, 2026
cd11d0e
removed untilted whatever artifact
Bubullzz Sep 2, 2026
3e4e3cf
Merge branch 'replace_wrappers_with_unique_ptrs' of github.com:Bubull…
Bubullzz Sep 2, 2026
5de95b9
Merge branch 'main' into replace_wrappers_with_unique_ptrs
Bubullzz Sep 2, 2026
60c244b
droped anonymous namespace in cusparse_view
Bubullzz Sep 2, 2026
73bab4b
updated comment in cusparse view
Bubullzz Sep 2, 2026
b005ac7
update orther comment
Bubullzz Sep 2, 2026
8744966
updated tmp_primal and dual handling in 3rd ctor of cusparse_view
Bubullzz Sep 2, 2026
5ba38e7
remove inline at some func where it is useless
Bubullzz Sep 2, 2026
6168b08
Merge branch 'main' into replace_wrappers_with_unique_ptrs
Bubullzz Sep 3, 2026
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
73 changes: 39 additions & 34 deletions cpp/src/barrier/barrier.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1729,13 +1729,13 @@ class iteration_data_t {
// v = alpha * A * Dinv * A^T * y + beta * v
void gpu_adat_multiply(f_t alpha,
const rmm::device_uvector<f_t>& y,
pdlp::cusparse_dn_vec_descr_wrapper_t<f_t> const& cusparse_y,
pdlp::cusparse_dn_vec_descr_view cusparse_y,

f_t beta,
rmm::device_uvector<f_t>& v,
pdlp::cusparse_dn_vec_descr_wrapper_t<f_t> const& cusparse_v,
pdlp::cusparse_dn_vec_descr_view cusparse_v,
rmm::device_uvector<f_t>& u,
pdlp::cusparse_dn_vec_descr_wrapper_t<f_t> const& cusparse_u,
pdlp::cusparse_dn_vec_descr_view cusparse_u,
cusparse_view_t<i_t, f_t>& cusparse_view,
const rmm::device_uvector<f_t>& d_inv_diag) const
{
Expand Down Expand Up @@ -1974,20 +1974,20 @@ class iteration_data_t {

cusparse_info_t<i_t, f_t> cusparse_info;
cusparse_view_t<i_t, f_t> cusparse_view_;
pdlp::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_tmp4_;
pdlp::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_h_;
pdlp::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_dx_residual_;
pdlp::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_dy_;
pdlp::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_dx_residual_5_;
pdlp::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_dx_residual_6_;
pdlp::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_dx_;
pdlp::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_dx_residual_3_;
pdlp::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_dx_residual_4_;
pdlp::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_r1_;
pdlp::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_dual_residual_;
pdlp::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_y_residual_;
pdlp::cusparse_dn_vec_uptr cusparse_tmp4_;
pdlp::cusparse_dn_vec_uptr cusparse_h_;
pdlp::cusparse_dn_vec_uptr cusparse_dx_residual_;
pdlp::cusparse_dn_vec_uptr cusparse_dy_;
pdlp::cusparse_dn_vec_uptr cusparse_dx_residual_5_;
pdlp::cusparse_dn_vec_uptr cusparse_dx_residual_6_;
pdlp::cusparse_dn_vec_uptr cusparse_dx_;
pdlp::cusparse_dn_vec_uptr cusparse_dx_residual_3_;
pdlp::cusparse_dn_vec_uptr cusparse_dx_residual_4_;
pdlp::cusparse_dn_vec_uptr cusparse_r1_;
pdlp::cusparse_dn_vec_uptr cusparse_dual_residual_;
pdlp::cusparse_dn_vec_uptr cusparse_y_residual_;
// GPU ADAT multiply
pdlp::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_u_;
pdlp::cusparse_dn_vec_uptr cusparse_u_;

// Device vectors

Expand Down Expand Up @@ -2482,7 +2482,7 @@ void barrier_solver_t<i_t, f_t>::gpu_compute_residuals(const rmm::device_uvector

auto cusparse_d_x = data.cusparse_view_.create_vector(d_x);
auto descr_primal_residual = data.cusparse_view_.create_vector(data.d_primal_residual_);
data.cusparse_view_.spmv(-1.0, cusparse_d_x, 1.0, descr_primal_residual);
data.cusparse_view_.spmv(-1.0, cusparse_d_x.get(), 1.0, descr_primal_residual.get());

// Compute bound_residual = E'*u - w - E'*x
if (data.n_upper_bounds > 0) {
Expand All @@ -2507,12 +2507,12 @@ void barrier_solver_t<i_t, f_t>::gpu_compute_residuals(const rmm::device_uvector
RAFT_CHECK_CUDA(stream_view_);
if (data.Q.n > 0) {
auto descr_dual_residual = data.cusparse_view_.create_vector(data.d_dual_residual_);
data.cusparse_Q_view_.spmv(1.0, cusparse_d_x, 1.0, descr_dual_residual);
data.cusparse_Q_view_.spmv(1.0, cusparse_d_x.get(), 1.0, descr_dual_residual.get());
}
// Compute dual_residual = c - A'*y - z + E*v
auto cusparse_d_y = data.cusparse_view_.create_vector(d_y);
auto descr_dual_residual = data.cusparse_view_.create_vector(data.d_dual_residual_);
data.cusparse_view_.transpose_spmv(-1.0, cusparse_d_y, 1.0, descr_dual_residual);
data.cusparse_view_.transpose_spmv(-1.0, cusparse_d_y.get(), 1.0, descr_dual_residual.get());

if (data.n_upper_bounds > 0) {
cub::DeviceTransform::Transform(
Expand Down Expand Up @@ -2843,7 +2843,7 @@ i_t barrier_solver_t<i_t, f_t>::gpu_compute_search_direction(iteration_data_t<i_
[] HD(f_t inv_diag, f_t tmp3) { return inv_diag * tmp3; },
stream_view_.value());
RAFT_CHECK_CUDA(stream_view_);
data.cusparse_view_.spmv(1, data.cusparse_tmp4_, 1, data.cusparse_h_);
data.cusparse_view_.spmv(1, data.cusparse_tmp4_.get(), 1, data.cusparse_h_.get());
}

if (use_augmented) {
Expand Down Expand Up @@ -2937,12 +2937,12 @@ i_t barrier_solver_t<i_t, f_t>::gpu_compute_search_direction(iteration_data_t<i_

data.gpu_adat_multiply(1.0,
data.d_dy_,
cusparse_dy_,
cusparse_dy_.get(),
-1.0,
data.d_y_residual_,
data.cusparse_y_residual_,
data.cusparse_y_residual_.get(),
data.d_u_,
data.cusparse_u_,
data.cusparse_u_.get(),
data.cusparse_view_,
data.d_inv_diag);

Expand All @@ -2966,7 +2966,8 @@ i_t barrier_solver_t<i_t, f_t>::gpu_compute_search_direction(iteration_data_t<i_
data.cusparse_dy_ = data.cusparse_view_.create_vector(data.d_dy_);

// r1 <- A'*dy - r1
data.cusparse_view_.transpose_spmv(1.0, data.cusparse_dy_, -1.0, data.cusparse_r1_);
data.cusparse_view_.transpose_spmv(
1.0, data.cusparse_dy_.get(), -1.0, data.cusparse_r1_.get());

cub::DeviceTransform::Transform(
cuda::std::make_tuple(data.d_inv_diag.data(), data.d_r1_.data(), data.d_diag_.data()),
Expand All @@ -2979,7 +2980,8 @@ i_t barrier_solver_t<i_t, f_t>::gpu_compute_search_direction(iteration_data_t<i_
stream_view_.value());
RAFT_CHECK_CUDA(stream_view_);

data.cusparse_view_.transpose_spmv(-1.0, data.cusparse_dy_, 1.0, data.cusparse_dx_residual_);
data.cusparse_view_.transpose_spmv(
-1.0, data.cusparse_dy_.get(), 1.0, data.cusparse_dx_residual_.get());
cub::DeviceTransform::Transform(
cuda::std::make_tuple(data.d_dx_residual_.data(), data.d_r1_prime_.data()),
data.d_dx_residual_.data(),
Expand Down Expand Up @@ -3039,8 +3041,9 @@ i_t barrier_solver_t<i_t, f_t>::gpu_compute_search_direction(iteration_data_t<i_
data.cusparse_dx_ = data.cusparse_view_.create_vector(data.d_dx_);

data.cusparse_view_.spmv(
1.0, data.cusparse_dx_residual_5_, 0.0, data.cusparse_dx_residual_6_);
data.cusparse_view_.spmv(-1.0, data.cusparse_dx_, 1.0, data.cusparse_dx_residual_6_);
1.0, data.cusparse_dx_residual_5_.get(), 0.0, data.cusparse_dx_residual_6_.get());
data.cusparse_view_.spmv(
-1.0, data.cusparse_dx_.get(), 1.0, data.cusparse_dx_residual_6_.get());

const f_t dx_residual_6_norm =
device_vector_norm_inf<i_t, f_t>(d_dx_residual_6, stream_view_);
Expand Down Expand Up @@ -3070,8 +3073,9 @@ i_t barrier_solver_t<i_t, f_t>::gpu_compute_search_direction(iteration_data_t<i_
data.cusparse_dx_ = data.cusparse_view_.create_vector(data.d_dx_);

data.cusparse_view_.spmv(
1.0, data.cusparse_dx_residual_3_, 0.0, data.cusparse_dx_residual_4_);
data.cusparse_view_.spmv(1.0, data.cusparse_dx_, 1.0, data.cusparse_dx_residual_4_);
1.0, data.cusparse_dx_residual_3_.get(), 0.0, data.cusparse_dx_residual_4_.get());
data.cusparse_view_.spmv(
1.0, data.cusparse_dx_.get(), 1.0, data.cusparse_dx_residual_4_.get());
}

#if CHECK_FORM_ADAT
Expand Down Expand Up @@ -3108,12 +3112,12 @@ i_t barrier_solver_t<i_t, f_t>::gpu_compute_search_direction(iteration_data_t<i_
// matrix_vector_multiply(data.ADAT, 1.0, dy, -1.0, dx_residual_7);
data.gpu_adat_multiply(1.0,
data.d_dy_,
cusparse_dy_,
cusparse_dy_.get(),
-1.0,
d_dx_residual_7,
cusparse_dx_residual_7,
cusparse_dx_residual_7.get(),
data.d_u_,
data.cusparse_u_,
data.cusparse_u_.get(),
data.cusparse_view_,
data.d_inv_diag);

Expand Down Expand Up @@ -3251,7 +3255,8 @@ i_t barrier_solver_t<i_t, f_t>::gpu_compute_search_direction(iteration_data_t<i_
data.d_dual_residual_.begin());

// dual_residual <- A' * dy - E * dv
data.cusparse_view_.transpose_spmv(1.0, data.cusparse_dy_, -1.0, data.cusparse_dual_residual_);
data.cusparse_view_.transpose_spmv(
1.0, data.cusparse_dy_.get(), -1.0, data.cusparse_dual_residual_.get());

// dual_residual <- A' * dy - E * dv + dz - dual_rhs
cub::DeviceTransform::Transform(
Expand Down Expand Up @@ -3792,7 +3797,7 @@ void barrier_solver_t<i_t, f_t>::compute_primal_dual_objective(iteration_data_t<
if (data.Q.n > 0) {
auto cusparse_d_x = data.cusparse_view_.create_vector(data.d_x_);
auto cusparse_Qx = data.cusparse_view_.create_vector(data.d_Qx_);
data.cusparse_Q_view_.spmv(1.0, cusparse_d_x, 0.0, cusparse_Qx);
data.cusparse_Q_view_.spmv(1.0, cusparse_d_x.get(), 0.0, cusparse_Qx.get());
rmm::device_scalar<f_t> d_xQx(stream_view_);
RAFT_CUBLAS_TRY(raft::linalg::detail::cublasdot(lp.handle_ptr->get_cublas_handle(),
data.d_Qx_.size(),
Expand Down
36 changes: 18 additions & 18 deletions cpp/src/barrier/cusparse_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#pragma once

#include <pdlp/cusparse_view.hpp>
#include <utilities/macros.cuh>

#include <raft/sparse/detail/cusparse_wrappers.h>
Expand All @@ -17,8 +18,21 @@

#include <cusparse_v2.h>

#include <memory>
#include <type_traits>

namespace cuopt::mathematical_optimization::barrier {

struct cusparse_spgemm_deleter_t {
void operator()(cusparseSpGEMMDescr_t descr) const noexcept
{
if (descr) { CUOPT_CUSPARSE_TRY_NO_THROW(cusparseSpGEMM_destroyDescr(descr)); }
}
};

using cusparse_spgemm_uptr =
std::unique_ptr<std::remove_pointer_t<cusparseSpGEMMDescr_t>, cusparse_spgemm_deleter_t>;

template <typename i_t, typename f_t>
struct cusparse_info_t {
cusparse_info_t(raft::handle_t const* handle)
Expand All @@ -35,24 +49,10 @@ struct cusparse_info_t {
beta.set_value_async(v, handle->get_stream());
}

~cusparse_info_t()
{
if (spgemm_descr != nullptr) {
CUOPT_CUSPARSE_TRY_NO_THROW(cusparseSpGEMM_destroyDescr(spgemm_descr));
}
if (matA_descr != nullptr) { CUOPT_CUSPARSE_TRY_NO_THROW(cusparseDestroySpMat(matA_descr)); }
if (matDAT_descr != nullptr) {
CUOPT_CUSPARSE_TRY_NO_THROW(cusparseDestroySpMat(matDAT_descr));
}
if (matADAT_descr != nullptr) {
CUOPT_CUSPARSE_TRY_NO_THROW(cusparseDestroySpMat(matADAT_descr));
}
}

cusparseSpMatDescr_t matA_descr{nullptr};
cusparseSpMatDescr_t matDAT_descr{nullptr};
cusparseSpMatDescr_t matADAT_descr{nullptr};
cusparseSpGEMMDescr_t spgemm_descr{nullptr};
pdlp::cusparse_sp_mat_uptr matA_descr;
pdlp::cusparse_sp_mat_uptr matDAT_descr;
pdlp::cusparse_sp_mat_uptr matADAT_descr;
cusparse_spgemm_uptr spgemm_descr;
rmm::device_scalar<f_t> alpha;
rmm::device_scalar<f_t> beta;
rmm::device_uvector<uint8_t> buffer_size;
Expand Down
Loading
Loading