From 1064c8a06043047b690224f3c81bd9c74d5a224c Mon Sep 17 00:00:00 2001 From: shakedregev Date: Thu, 14 Aug 2025 14:16:02 +0000 Subject: [PATCH 1/4] working on CUDA --- resolve/LinSolverDirectCuSolverGLU.cpp | 6 ------ resolve/LinSolverDirectCuSolverRf.cpp | 12 ------------ resolve/LinSolverDirectKLU.cpp | 10 ++++++++++ resolve/LinSolverDirectRocSolverRf.cpp | 4 ---- 4 files changed, 10 insertions(+), 22 deletions(-) diff --git a/resolve/LinSolverDirectCuSolverGLU.cpp b/resolve/LinSolverDirectCuSolverGLU.cpp index 977cc5a2c..5608fd7e6 100644 --- a/resolve/LinSolverDirectCuSolverGLU.cpp +++ b/resolve/LinSolverDirectCuSolverGLU.cpp @@ -1,8 +1,6 @@ #include "LinSolverDirectCuSolverGLU.hpp" -#include #include // includes memcpy -#include #include #include @@ -236,10 +234,6 @@ namespace ReSolve M_col[count++] = U_col[j]; } } - for (index_type i = 0; i < n; ++i) // this is crucial, turns out somehow the indices are not sorted - { - std::sort(M_col + M_row[i], M_col + M_row[i + 1]); - } } void LinSolverDirectCuSolverGLU::combineFactors(matrix::Sparse* L, matrix::Sparse* U) diff --git a/resolve/LinSolverDirectCuSolverRf.cpp b/resolve/LinSolverDirectCuSolverRf.cpp index 83d49b8ef..5f9f267f2 100644 --- a/resolve/LinSolverDirectCuSolverRf.cpp +++ b/resolve/LinSolverDirectCuSolverRf.cpp @@ -1,9 +1,7 @@ #include "LinSolverDirectCuSolverRf.hpp" -#include #include #include // includes memcpy -#include #include #include @@ -108,16 +106,6 @@ namespace ReSolve status_cusolverrf_ = cusolverRfSetResetValuesFastMode(handle_cusolverrf_, CUSOLVERRF_RESET_VALUES_FAST_MODE_ON); error_sum += status_cusolverrf_; - // sort L and U columns - for (index_type i = 0; i < n; ++i) - { - std::sort(L->getColData(memory::HOST) + L->getRowData(memory::HOST)[i], - L->getColData(memory::HOST) + L->getRowData(memory::HOST)[i + 1]); - std::sort(U->getColData(memory::HOST) + U->getRowData(memory::HOST)[i], - U->getColData(memory::HOST) + U->getRowData(memory::HOST)[i + 1]); - } - L->setUpdated(memory::HOST); - U->setUpdated(memory::HOST); L->syncData(memory::DEVICE); U->syncData(memory::DEVICE); status_cusolverrf_ = cusolverRfSetupDevice(n, diff --git a/resolve/LinSolverDirectKLU.cpp b/resolve/LinSolverDirectKLU.cpp index 9764740a8..b417f8d69 100644 --- a/resolve/LinSolverDirectKLU.cpp +++ b/resolve/LinSolverDirectKLU.cpp @@ -1,7 +1,9 @@ #include "LinSolverDirectKLU.hpp" +#include #include #include +#include #include #include @@ -295,6 +297,14 @@ namespace ReSolve nullptr, nullptr, &Common_); + // Sort the row indices in L and U to ensure they are in ordered CSR format + for (index_type i = 0; i < A_->getNumRows(); ++i) + { + std::sort(L_->getColData(memory::HOST) + L_->getRowData(memory::HOST)[i], + L_->getColData(memory::HOST) + L_->getRowData(memory::HOST)[i + 1]); + std::sort(U_->getColData(memory::HOST) + U_->getRowData(memory::HOST)[i], + U_->getColData(memory::HOST) + U_->getRowData(memory::HOST)[i + 1]); + } L_->setUpdated(memory::HOST); U_->setUpdated(memory::HOST); diff --git a/resolve/LinSolverDirectRocSolverRf.cpp b/resolve/LinSolverDirectRocSolverRf.cpp index 40d9a2aba..b737a7c3a 100644 --- a/resolve/LinSolverDirectRocSolverRf.cpp +++ b/resolve/LinSolverDirectRocSolverRf.cpp @@ -842,10 +842,6 @@ namespace ReSolve M_col[count++] = U_col[j]; } } - for (index_type i = 0; i < n; ++i) // this is crucial, turns out somehow the indices are not sorted - { - std::sort(M_col + M_row[i], M_col + M_row[i + 1]); - } } /** From 568180e370686a3d3277154e6af1ff1b6a76bad3 Mon Sep 17 00:00:00 2001 From: shakedregev Date: Thu, 14 Aug 2025 14:23:50 +0000 Subject: [PATCH 2/4] cuda works --- resolve/LinSolverDirectKLU.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/resolve/LinSolverDirectKLU.cpp b/resolve/LinSolverDirectKLU.cpp index b417f8d69..88fec7040 100644 --- a/resolve/LinSolverDirectKLU.cpp +++ b/resolve/LinSolverDirectKLU.cpp @@ -297,10 +297,11 @@ namespace ReSolve nullptr, nullptr, &Common_); - // Sort the row indices in L and U to ensure they are in ordered CSR format + // Sort the column indices in L and U to ensure they are in ordered CSR format + // WARNING: Values are not sorted. We currently don't use values from KLU across solvers. If we ever decide to, we will need to change this. for (index_type i = 0; i < A_->getNumRows(); ++i) { - std::sort(L_->getColData(memory::HOST) + L_->getRowData(memory::HOST)[i], + std::sort(L_->getColData(memory::HOST) + L_->getRowData(memory::HOST)[i], //Sort L's column indices from the start of Row i to the start of Row i+1 (non inclusive) L_->getColData(memory::HOST) + L_->getRowData(memory::HOST)[i + 1]); std::sort(U_->getColData(memory::HOST) + U_->getRowData(memory::HOST)[i], U_->getColData(memory::HOST) + U_->getRowData(memory::HOST)[i + 1]); From 50a871ad18d063926e332f3d0da6184175a631e9 Mon Sep 17 00:00:00 2001 From: shakedregev Date: Thu, 14 Aug 2025 14:29:47 +0000 Subject: [PATCH 3/4] Apply pre-commmit fixes --- resolve/LinSolverDirectKLU.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resolve/LinSolverDirectKLU.cpp b/resolve/LinSolverDirectKLU.cpp index 88fec7040..1506346f8 100644 --- a/resolve/LinSolverDirectKLU.cpp +++ b/resolve/LinSolverDirectKLU.cpp @@ -301,7 +301,7 @@ namespace ReSolve // WARNING: Values are not sorted. We currently don't use values from KLU across solvers. If we ever decide to, we will need to change this. for (index_type i = 0; i < A_->getNumRows(); ++i) { - std::sort(L_->getColData(memory::HOST) + L_->getRowData(memory::HOST)[i], //Sort L's column indices from the start of Row i to the start of Row i+1 (non inclusive) + std::sort(L_->getColData(memory::HOST) + L_->getRowData(memory::HOST)[i], // Sort L's column indices from the start of Row i to the start of Row i+1 (non inclusive) L_->getColData(memory::HOST) + L_->getRowData(memory::HOST)[i + 1]); std::sort(U_->getColData(memory::HOST) + U_->getRowData(memory::HOST)[i], U_->getColData(memory::HOST) + U_->getRowData(memory::HOST)[i + 1]); From 68602416dd442e39ec5bd9168b8744a217091983 Mon Sep 17 00:00:00 2001 From: Shaked Regev <35384901+shakedregev@users.noreply.github.com> Date: Thu, 14 Aug 2025 10:31:35 -0400 Subject: [PATCH 4/4] Update resolve/LinSolverDirectKLU.cpp --- resolve/LinSolverDirectKLU.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resolve/LinSolverDirectKLU.cpp b/resolve/LinSolverDirectKLU.cpp index 1506346f8..c9396a881 100644 --- a/resolve/LinSolverDirectKLU.cpp +++ b/resolve/LinSolverDirectKLU.cpp @@ -301,7 +301,7 @@ namespace ReSolve // WARNING: Values are not sorted. We currently don't use values from KLU across solvers. If we ever decide to, we will need to change this. for (index_type i = 0; i < A_->getNumRows(); ++i) { - std::sort(L_->getColData(memory::HOST) + L_->getRowData(memory::HOST)[i], // Sort L's column indices from the start of Row i to the start of Row i+1 (non inclusive) + std::sort(L_->getColData(memory::HOST) + L_->getRowData(memory::HOST)[i], // Sort L's column indices from the start of Row i to the start of Row i+1 (non inclusive). L_->getColData(memory::HOST) + L_->getRowData(memory::HOST)[i + 1]); std::sort(U_->getColData(memory::HOST) + U_->getRowData(memory::HOST)[i], U_->getColData(memory::HOST) + U_->getRowData(memory::HOST)[i + 1]);