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
73 changes: 39 additions & 34 deletions cpp/src/barrier/barrier.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1738,13 +1738,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,
detail::cusparse_dn_vec_descr_wrapper_t<f_t> const& cusparse_y,
detail::cusparse_dn_vec_descr_view cusparse_y,

f_t beta,
rmm::device_uvector<f_t>& v,
detail::cusparse_dn_vec_descr_wrapper_t<f_t> const& cusparse_v,
detail::cusparse_dn_vec_descr_view cusparse_v,
rmm::device_uvector<f_t>& u,
detail::cusparse_dn_vec_descr_wrapper_t<f_t> const& cusparse_u,
detail::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 @@ -2006,20 +2006,20 @@ class iteration_data_t {
pinned_dense_vector_t<i_t, f_t> dz;
cusparse_info_t<i_t, f_t> cusparse_info;
cusparse_view_t<i_t, f_t> cusparse_view_;
detail::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_tmp4_;
detail::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_h_;
detail::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_dx_residual_;
detail::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_dy_;
detail::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_dx_residual_5_;
detail::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_dx_residual_6_;
detail::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_dx_;
detail::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_dx_residual_3_;
detail::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_dx_residual_4_;
detail::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_r1_;
detail::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_dual_residual_;
detail::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_y_residual_;
detail::cusparse_dn_vec_uptr cusparse_tmp4_;
detail::cusparse_dn_vec_uptr cusparse_h_;
detail::cusparse_dn_vec_uptr cusparse_dx_residual_;
detail::cusparse_dn_vec_uptr cusparse_dy_;
detail::cusparse_dn_vec_uptr cusparse_dx_residual_5_;
detail::cusparse_dn_vec_uptr cusparse_dx_residual_6_;
detail::cusparse_dn_vec_uptr cusparse_dx_;
detail::cusparse_dn_vec_uptr cusparse_dx_residual_3_;
detail::cusparse_dn_vec_uptr cusparse_dx_residual_4_;
detail::cusparse_dn_vec_uptr cusparse_r1_;
detail::cusparse_dn_vec_uptr cusparse_dual_residual_;
detail::cusparse_dn_vec_uptr cusparse_y_residual_;
// GPU ADAT multiply
detail::cusparse_dn_vec_descr_wrapper_t<f_t> cusparse_u_;
detail::cusparse_dn_vec_uptr cusparse_u_;

// Device vectors

Expand Down Expand Up @@ -2523,7 +2523,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 @@ -2543,7 +2543,7 @@ void barrier_solver_t<i_t, f_t>::gpu_compute_residuals(const rmm::device_uvector
if (data.Q.n > 0) {
raft::copy(data.d_c_.data(), data.c.data(), data.c.size(), stream_view_);
auto cusparse_d_c = data.cusparse_view_.create_vector(data.d_c_);
data.cusparse_Q_view_.spmv(1.0, cusparse_d_x, 1.0, cusparse_d_c);
data.cusparse_Q_view_.spmv(1.0, cusparse_d_x.get(), 1.0, cusparse_d_c.get());
} else {
raft::copy(data.d_c_.data(), data.c.data(), data.c.size(), stream_view_);
}
Expand All @@ -2556,7 +2556,7 @@ void barrier_solver_t<i_t, f_t>::gpu_compute_residuals(const rmm::device_uvector
// 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 @@ -2949,7 +2949,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 @@ -3050,12 +3050,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 @@ -3079,7 +3079,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 @@ -3093,7 +3094,8 @@ i_t barrier_solver_t<i_t, f_t>::gpu_compute_search_direction(iteration_data_t<i_
RAFT_CHECK_CUDA(stream_view_);
raft::copy(dx.data(), data.d_dx_.data(), data.d_dx_.size(), 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 @@ -3153,8 +3155,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 @@ -3184,8 +3187,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 @@ -3222,12 +3226,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 @@ -3382,7 +3386,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 @@ -4029,7 +4034,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::linear_programming::dual_simplex {

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};
detail::cusparse_sp_mat_uptr matA_descr;
detail::cusparse_sp_mat_uptr matDAT_descr;
detail::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