Skip to content
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

Declutter functionality test #218

Merged
merged 41 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
90c487d
Update rhs vector data for functionality tests.
pelesh Jan 23, 2025
5a5f210
Functioning test helper prototype.
pelesh Jan 25, 2025
2417bcd
Clean corcsolverRf test using test helper.
pelesh Jan 25, 2025
d2360b6
More decluttering of klu+rocsolverRf test.
pelesh Jan 26, 2025
b36d5c6
Add iterative refinement to rocsolverRf test.
pelesh Jan 26, 2025
24931fe
Add parameter configuration to rocsolverRf test.
pelesh Jan 26, 2025
5f5d63a
Clean up cusolverRf tests.
pelesh Jan 31, 2025
9099ccf
Add printIrSummary method to test helper.
pelesh Jan 31, 2025
9eb6032
Clean up cusolverRf setup.
pelesh Feb 1, 2025
9116acd
Simplify cusolverRf interface.
pelesh Feb 1, 2025
a00b613
Improve output formatting.
pelesh Feb 2, 2025
73152a8
Vector file I/O.
pelesh Feb 2, 2025
822e840
Template parameter for test.
pelesh Feb 3, 2025
3ba14f9
Single file generates HIP and CUDA refactorization tests.
pelesh Feb 3, 2025
b77cffa
Fix issue with calling rocsolver.
pelesh Feb 3, 2025
3d3f491
Use generic parameter setting in the example.
pelesh Feb 4, 2025
a599e5b
Create decluttered KLU example.
pelesh Feb 4, 2025
51adf75
Create more flexible test helper.
pelesh Feb 4, 2025
4268218
Cleanup of CMake for functionality tests.
pelesh Feb 4, 2025
7dc1d07
Fix installation testing.
pelesh Feb 4, 2025
f1436dd
More exhaustive installation testing.
pelesh Feb 4, 2025
1d90a5d
Single file to produce tests for randomized GMRES.
pelesh Feb 4, 2025
a783929
Fix std::isfinite issue.
pelesh Feb 4, 2025
b145d74
Declutter randomized GMRES test.
pelesh Feb 4, 2025
06555be
Decluttered system solver refactorization test.
pelesh Feb 5, 2025
ee35478
Refactor system solver refactorization test.
pelesh Feb 5, 2025
0a80274
Clean up system solver refactorization test.
pelesh Feb 5, 2025
bfccc82
Fix bug in CSC matrix class and update cusolverRf.
pelesh Feb 5, 2025
7c7a68c
Create one executable only for system refactor tests.
pelesh Feb 5, 2025
ae172cd
Use test helper in system solver GMRES tests.
pelesh Feb 5, 2025
3632b0b
Randomized GMRES test complete.
pelesh Feb 5, 2025
51b2bbb
SystemSolver refactorization test complete.
pelesh Feb 5, 2025
acafbbd
Refactorization test complete.
pelesh Feb 6, 2025
10ffb32
KLU test complete.
pelesh Feb 6, 2025
7ed385c
Test names aligned with coding style.
pelesh Feb 6, 2025
83eb855
Use lowercase CLI input strings.
pelesh Feb 6, 2025
7d53222
Fix make test_install.
pelesh Feb 6, 2025
c77f302
Update comment in resolve/LinSolverDirectCuSolverRf.cpp
pelesh Feb 6, 2025
eb590e0
Update comment in resolve/LinSolverDirectRocSparseILU0.cpp
pelesh Feb 6, 2025
16218c5
Update resolve/LinSolverDirectCuSolverRf.cpp
pelesh Feb 7, 2025
8e68dc8
Code comments and cleanup.
pelesh Feb 7, 2025
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
21 changes: 12 additions & 9 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,22 @@ set(CONSUMER_PATH ${CMAKE_INSTALL_PREFIX}/share/examples)
install(PROGRAMS test.sh DESTINATION ${CONSUMER_PATH})

# Select consumer app
if(RESOLVE_USE_CUDA)
set(RESOLVE_CONSUMER_APP "testKLU_Rf_FGMRES.cpp")
elseif(RESOLVE_USE_HIP)
set(RESOLVE_CONSUMER_APP "testKLU_RocSolver.cpp")
elseif(RESOLVE_USE_KLU)
set(RESOLVE_CONSUMER_APP "testKLU.cpp")
else()
set(RESOLVE_CONSUMER_APP "testVersion.cpp")
endif()
if(RESOLVE_USE_KLU)
if(RESOLVE_USE_CUDA)
set(RESOLVE_CONSUMER_APP "testRefactor.cpp")
elseif(RESOLVE_USE_HIP)
set(RESOLVE_CONSUMER_APP "testRefactor.cpp")
else()
set(RESOLVE_CONSUMER_APP "testKlu.cpp")
endif()
else(RESOLVE_USE_KLU)
set(RESOLVE_CONSUMER_APP "testSysGmres.cpp")
endif(RESOLVE_USE_KLU)

# Install directory with example on how to consume ReSolve
install(DIRECTORY resolve_consumer DESTINATION share/examples)
install(FILES ${PROJECT_SOURCE_DIR}/tests/functionality/${RESOLVE_CONSUMER_APP} DESTINATION share/examples/resolve_consumer RENAME consumer.cpp)
install(FILES ${PROJECT_SOURCE_DIR}/tests/functionality/TestHelper.hpp DESTINATION share/examples/resolve_consumer)

# Shell script argumets:
# 1. Path to where resolve is installed.
Expand Down
2 changes: 1 addition & 1 deletion examples/r_SysSolverHipRefine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int main(int argc, char *argv[])
vector_type* vec_x = nullptr;

ReSolve::SystemSolver* solver = new ReSolve::SystemSolver(workspace_HIP);
solver->setRefinementMethod("fgmres", "CGS2");
solver->setRefinementMethod("fgmres", "cgs2");

for (int i = 0; i < numSystems; ++i)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/resolve_consumer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ target_link_libraries(consume.exe PRIVATE ReSolve::ReSolve)
enable_testing()

# RESOLVE_DATA is set in test.sh and is the file path the matrix data files used in the testKLU_Rf_FGMRES
add_test(NAME resolve_consumer COMMAND $<TARGET_FILE:consume.exe> "${RESOLVE_DATA}")
add_test(NAME resolve_consumer COMMAND $<TARGET_FILE:consume.exe> "-d" "${RESOLVE_DATA}" "-i")
7 changes: 6 additions & 1 deletion resolve/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_subdirectory(utilities)

# C++ files
set(ReSolve_SRC
Common.hpp
LinSolver.cpp
LinSolverDirect.cpp
LinSolverIterative.cpp
Expand Down Expand Up @@ -175,4 +176,8 @@ install(TARGETS ReSolve
LIBRARY DESTINATION lib)

# install include headers
install(FILES ${ReSolve_HEADER_INSTALL} DESTINATION include/resolve)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/resolve/ # source directory
DESTINATION include/resolve # target directory
FILES_MATCHING # install only matched files
PATTERN "*.hpp" # select header files
)
2 changes: 1 addition & 1 deletion resolve/LinSolverDirectCuSolverGLU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ namespace ReSolve
Mshifts[row]++;
}
}
//Mshifts.~vector();
}

int LinSolverDirectCuSolverGLU::refactorize()
Expand Down Expand Up @@ -190,6 +189,7 @@ namespace ReSolve
&r_nrm_inf_,
info_M_,
glu_buffer_);
x->setDataUpdated(memory::DEVICE);
return status_cusolver_;
}

Expand Down
177 changes: 162 additions & 15 deletions resolve/LinSolverDirectCuSolverRf.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include <cassert>

#include <resolve/vector/Vector.hpp>
#include <resolve/matrix/Csr.hpp>
#include <resolve/matrix/Csc.hpp>
#include "LinSolverDirectCuSolverRf.hpp"

namespace ReSolve
Expand Down Expand Up @@ -28,16 +31,52 @@ namespace ReSolve
index_type* Q,
vector_type* /* rhs */)
{
assert(A->getSparseFormat() == matrix::Sparse::COMPRESSED_SPARSE_ROW &&
"Matrix A has to be in CSR format for cusolverRf input.\n");
assert(L->getSparseFormat() == U->getSparseFormat() &&
"Matrices L and U have to be in the same format for cusolverRf input.\n");

int error_sum = 0;
this->A_ = A;
index_type n = A_->getNumRows();

//remember - P and Q are generally CPU variables
// factorization data is stored in the handle. If function is called again, destroy the old handle to get rid of old data.
// factorization data is stored in the handle.
// If function is called again, destroy the old handle to get rid of old data.
if (setup_completed_) {
cusolverRfDestroy(handle_cusolverrf_);
cusolverRfCreate(&handle_cusolverrf_);
}

int error_sum = 0;
this->A_ = (matrix::Csr*) A;
index_type n = A_->getNumRows();
matrix::Csc* L_csc = nullptr;
matrix::Csc* U_csc = nullptr;
matrix::Csr* L_csr = nullptr;
matrix::Csr* U_csr = nullptr;

matrix::Sparse::SparseFormat matrix_format = L->getSparseFormat();
// std::cout << "Matrix format is " << matrix_format << "\n";

switch (L->getSparseFormat()) {
case matrix::Sparse::COMPRESSED_SPARSE_COLUMN:
// std::cout << "converting L and U factors from CSC to CSR format ...\n";
L_csc = static_cast<matrix::Csc*>(L);
U_csc = static_cast<matrix::Csc*>(U);
L_csr = new matrix::Csr(L_csc->getNumRows(), L_csc->getNumColumns(), L_csc->getNnz());
U_csr = new matrix::Csr(U_csc->getNumRows(), U_csc->getNumColumns(), U_csc->getNnz());
csc2csr(L_csc, L_csr);
csc2csr(U_csc, U_csr);
L_csr->syncData(memory::DEVICE);
U_csr->syncData(memory::DEVICE);
break;
case matrix::Sparse::COMPRESSED_SPARSE_ROW:
L_csr = dynamic_cast<matrix::Csr*>(L);
U_csr = dynamic_cast<matrix::Csr*>(U);
break;
default:
out::error() << "Matrix type for L and U factors not recognized!\n";
out::error() << "Refactorization not completed.\n";
return 1;
}

if (d_P_ == nullptr){
mem_.allocateArrayOnDevice(&d_P_, n);
Expand All @@ -64,14 +103,14 @@ namespace ReSolve
A_->getRowData(memory::DEVICE),
A_->getColData(memory::DEVICE),
A_->getValues( memory::DEVICE),
L->getNnz(),
L->getRowData(memory::DEVICE),
L->getColData(memory::DEVICE),
L->getValues( memory::DEVICE),
U->getNnz(),
U->getRowData(memory::DEVICE),
U->getColData(memory::DEVICE),
U->getValues( memory::DEVICE),
L_csr->getNnz(),
L_csr->getRowData(memory::DEVICE),
L_csr->getColData(memory::DEVICE),
L_csr->getValues( memory::DEVICE),
U_csr->getNnz(),
U_csr->getRowData(memory::DEVICE),
U_csr->getColData(memory::DEVICE),
U_csr->getValues( memory::DEVICE),
d_P_,
d_Q_,
handle_cusolverrf_);
Expand All @@ -81,16 +120,35 @@ namespace ReSolve
status_cusolverrf_ = cusolverRfAnalyze(handle_cusolverrf_);
error_sum += status_cusolverrf_;

this->A_ = A;
//default

const cusolverRfFactorization_t fact_alg =
CUSOLVERRF_FACTORIZATION_ALG0; // 0 - default, 1 or 2
const cusolverRfTriangularSolve_t solve_alg =
CUSOLVERRF_TRIANGULAR_SOLVE_ALG1; // 1- default, 2 or 3 // 1 causes error
this->setAlgorithms(fact_alg, solve_alg);

setup_completed_ = true;

// Remove temporary objects upon setup completion
switch (L->getSparseFormat()) {
case matrix::Sparse::COMPRESSED_SPARSE_COLUMN:
delete L_csr;
delete U_csr;
L_csr = nullptr;
U_csr = nullptr;
L_csc = nullptr;
U_csc = nullptr;
break;
case matrix::Sparse::COMPRESSED_SPARSE_ROW:
L_csr = nullptr;
U_csr = nullptr;
L_csc = nullptr;
U_csc = nullptr;
break;
default:
break;
}
// delete L_csr;
// delete U_csr;

return error_sum;
}
Expand Down Expand Up @@ -280,5 +338,94 @@ namespace ReSolve
params_list_["zero_pivot"] = ZERO_PIVOT;
params_list_["pivot_boost"] = PIVOT_BOOST;
}

/**
* @brief Convert CSC to CSR matrix on the host
*
* @authors Slaven Peles <[email protected]>, Daniel Reynolds (SMU), and
* David Gardner and Carol Woodward (LLNL)
*/
pelesh marked this conversation as resolved.
Show resolved Hide resolved
int LinSolverDirectCuSolverRf::csc2csr(matrix::Csc* A_csc, matrix::Csr* A_csr)
{
// int error_sum = 0; TODO: Collect error output!
assert(A_csc->getNnz() == A_csr->getNnz());
assert(A_csc->getNumRows() == A_csr->getNumRows());
assert(A_csr->getNumColumns() == A_csc->getNumColumns());

A_csr->allocateMatrixData(memory::HOST);

index_type nnz = A_csc->getNnz();
index_type n = A_csc->getNumColumns();

index_type* rowIdxCsc = A_csc->getRowData(memory::HOST);
index_type* colPtrCsc = A_csc->getColData(memory::HOST);
real_type* valuesCsc = A_csc->getValues( memory::HOST);

index_type* rowPtrCsr = A_csr->getRowData(memory::HOST);
index_type* colIdxCsr = A_csr->getColData(memory::HOST);
real_type* valuesCsr = A_csr->getValues( memory::HOST);

// Set all CSR row pointers to zero
for (index_type i = 0; i <= n; ++i) {
rowPtrCsr[i] = 0;
}

// Set all CSR values and column indices to zero
for (index_type i = 0; i < nnz; ++i) {
colIdxCsr[i] = 0;
valuesCsr[i] = 0.0;
}

// Compute number of entries per row
for (index_type i = 0; i < nnz; ++i) {
rowPtrCsr[rowIdxCsc[i]]++;
}

// Compute cumualtive sum of nnz per row
for (index_type row = 0, rowsum = 0; row < n; ++row)
{
// Store value in row pointer to temp
index_type temp = rowPtrCsr[row];

// Copy cumulative sum to the row pointer
rowPtrCsr[row] = rowsum;

// Update row sum
rowsum += temp;
}
rowPtrCsr[n] = nnz;

for (index_type col = 0; col < n; ++col)
{
// Compute positions of column indices and values in CSR matrix and store them there
// Overwrites CSR row pointers in the process
pelesh marked this conversation as resolved.
Show resolved Hide resolved
// adding to them the number of elements in that row
for (index_type jj = colPtrCsc[col]; jj < colPtrCsc[col+1]; jj++)
{
index_type row = rowIdxCsc[jj];
index_type dest = rowPtrCsr[row];

colIdxCsr[dest] = col;
valuesCsr[dest] = valuesCsc[jj];

rowPtrCsr[row]++;
}
}

// Restore CSR row pointer values
pelesh marked this conversation as resolved.
Show resolved Hide resolved
// All values in rowPtrCsr have shifted by the number of elements in that row
// for i>=1: new rowPtrCsr[i] = old rowPtrCsr[i-1] and new rowPtrCsr[0]=0
for (index_type row = 0, last = 0; row <= n; row++)
{
index_type temp = rowPtrCsr[row];
rowPtrCsr[row] = last;
last = temp;
}

// Mark data on the host as updated
A_csr->setUpdated(memory::HOST);

return 0;
}

} // namespace resolve
9 changes: 6 additions & 3 deletions resolve/LinSolverDirectCuSolverRf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace ReSolve
namespace matrix
{
class Sparse;
class Csr;
class Csc;
}

// Forward declaration of ReSolve handlers workspace
Expand Down Expand Up @@ -53,14 +55,15 @@ namespace ReSolve
bool getCliParamBool(const std::string id) const override;
int printCliParam(const std::string id) const override;

private:
void initParamList();
int csc2csr(matrix::Csc* A_csc, matrix::Csr* A_csr);

private:
enum ParamaterIDs {ZERO_PIVOT=0, PIVOT_BOOST};
real_type zero_pivot_{0.0}; ///< The value below which zero pivot is flagged.
real_type pivot_boost_{0.0}; ///< The value which is substituted for zero pivot.

private:
void initParamList();

cusolverRfHandle_t handle_cusolverrf_;
cusolverStatus_t status_cusolverrf_;

Expand Down
5 changes: 3 additions & 2 deletions resolve/LinSolverDirectRocSparseILU0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,11 @@ namespace ReSolve
* are currently redundant code (like an if (true)).
* In the future, they will be expanded to include more options.
*
* @param id - string ID for parameter to get.
* @param[in] id - string ID for parameter to get.
* @param[in] value unused/ignored
* @return int Value of the int parameter to return.
*/
int LinSolverDirectRocSparseILU0::setCliParam(const std::string id, const std::string value)
int LinSolverDirectRocSparseILU0::setCliParam(const std::string id, const std::string /* value */)
{
switch (getParamId(id))
{
Expand Down
22 changes: 6 additions & 16 deletions resolve/SystemSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,17 +388,7 @@ namespace ReSolve
status += refactorizationSolver_->setup(A_, L_, U_, P_, Q_);
}
if (refactorizationMethod_ == "cusolverrf") {
matrix::Csc* L_csc = dynamic_cast<matrix::Csc*>(L_);
matrix::Csc* U_csc = dynamic_cast<matrix::Csc*>(U_);
L_csc->syncData(memory::DEVICE);
U_csc->syncData(memory::DEVICE);
matrix::Csr* L_csr = new matrix::Csr(L_csc->getNumRows(), L_csc->getNumColumns(), L_csc->getNnz());
matrix::Csr* U_csr = new matrix::Csr(U_csc->getNumRows(), U_csc->getNumColumns(), U_csc->getNnz());
matrixHandler_->csc2csr(L_csc, L_csr, memory::DEVICE);
matrixHandler_->csc2csr(U_csc, U_csr, memory::DEVICE);
status += refactorizationSolver_->setup(A_, L_csr, U_csr, P_, Q_);
delete L_csr;
delete U_csr;
status += refactorizationSolver_->setup(A_, L_, U_, P_, Q_);

LinSolverDirectCuSolverRf* Rf = dynamic_cast<LinSolverDirectCuSolverRf*>(refactorizationSolver_);
Rf->setNumericalProperties(1e-14, 1e-1);
Expand Down Expand Up @@ -771,15 +761,15 @@ namespace ReSolve
{
// Map string input to the Gram-Schmidt variant enum
GramSchmidt::GSVariant gs_variant;
if (variant == "CGS2") {
if (variant == "cgs2") {
gs_variant = GramSchmidt::CGS2;
} else if (variant == "MGS") {
} else if (variant == "mgs") {
gs_variant = GramSchmidt::MGS;
} else if (variant == "MGS_TWO_SYNC") {
} else if (variant == "mgs_two_sync") {
gs_variant = GramSchmidt::MGS_TWO_SYNC;
} else if (variant == "MGS_PM") {
} else if (variant == "mgs_pm") {
gs_variant = GramSchmidt::MGS_PM;
} else if (variant == "CGS1") {
} else if (variant == "cgs1") {
gs_variant = GramSchmidt::CGS1;
} else {
out::warning() << "Gram-Schmidt variant " << variant << " not recognized.\n";
Expand Down
Loading