-
Notifications
You must be signed in to change notification settings - Fork 9
Randomized solver (both cuda and hip) #83
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0769ba4
Randomized (F)GMRES solver with ILU0 preconditioner
kswirydo 0315b5b
Update resolve/LinSolverDirectRocSparseILU0.hpp
kswirydo 76c24fd
Update resolve/LinSolverDirectRocSparseILU0.cpp
kswirydo 36bad31
Fix warnings in rand-gmres-dev2 branch. (#93)
pelesh 03d3a66
fixing the failing rocm rand solver
kswirydo 0ac0955
Fix bugs, add functionality tests.
pelesh 927433e
working uda rand solver test
d217b5b
working rand HIP test
kswirydo 7fa67ad
Fix CMake issue that was tripping functionality tests.
pelesh 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
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,128 @@ | ||
| #include <string> | ||
| #include <iostream> | ||
| #include <iomanip> | ||
|
|
||
| #include <resolve/matrix/Coo.hpp> | ||
| #include <resolve/matrix/Csr.hpp> | ||
| #include <resolve/matrix/Csc.hpp> | ||
| #include <resolve/vector/Vector.hpp> | ||
| #include <resolve/matrix/io.hpp> | ||
| #include <resolve/matrix/MatrixHandler.hpp> | ||
| #include <resolve/vector/VectorHandler.hpp> | ||
| #include <resolve/LinSolverDirectKLU.hpp> | ||
| #include <resolve/LinSolverDirectRocSparseILU0.hpp> | ||
| #include <resolve/LinSolverIterativeRandFGMRES.hpp> | ||
| #include <resolve/workspace/LinAlgWorkspace.hpp> | ||
|
|
||
| using namespace ReSolve::constants; | ||
|
|
||
| int main(int argc, char *argv[]) | ||
| { | ||
| // Use the same data types as those you specified in ReSolve build. | ||
| using real_type = ReSolve::real_type; | ||
| using vector_type = ReSolve::vector::Vector; | ||
|
|
||
| (void) argc; // TODO: Check if the number of input parameters is correct. | ||
| std::string matrixFileName = argv[1]; | ||
| std::string rhsFileName = argv[2]; | ||
|
|
||
|
|
||
| ReSolve::matrix::Coo* A_coo; | ||
| ReSolve::matrix::Csr* A; | ||
| ReSolve::LinAlgWorkspaceHIP* workspace_HIP = new ReSolve::LinAlgWorkspaceHIP(); | ||
| workspace_HIP->initializeHandles(); | ||
| ReSolve::MatrixHandler* matrix_handler = new ReSolve::MatrixHandler(workspace_HIP); | ||
| ReSolve::VectorHandler* vector_handler = new ReSolve::VectorHandler(workspace_HIP); | ||
| real_type* rhs = nullptr; | ||
| real_type* x = nullptr; | ||
|
pelesh marked this conversation as resolved.
|
||
|
|
||
| vector_type* vec_rhs; | ||
| vector_type* vec_x; | ||
| vector_type* vec_r; | ||
|
|
||
| ReSolve::GramSchmidt* GS = new ReSolve::GramSchmidt(vector_handler, ReSolve::GramSchmidt::cgs2); | ||
|
|
||
| ReSolve::LinSolverDirectRocSparseILU0* Rf = new ReSolve::LinSolverDirectRocSparseILU0(workspace_HIP); | ||
| ReSolve::LinSolverIterativeRandFGMRES* FGMRES = new ReSolve::LinSolverIterativeRandFGMRES(matrix_handler, vector_handler,ReSolve::LinSolverIterativeRandFGMRES::cs, GS, "hip"); | ||
|
|
||
| std::cout << std::endl << std::endl << std::endl; | ||
| std::cout << "========================================================================================================================"<<std::endl; | ||
| std::cout << "Reading: " << matrixFileName<< std::endl; | ||
| std::cout << "========================================================================================================================"<<std::endl; | ||
| std::cout << std::endl; | ||
| std::ifstream mat_file(matrixFileName); | ||
| if(!mat_file.is_open()) | ||
| { | ||
| std::cout << "Failed to open file " << matrixFileName << "\n"; | ||
| return -1; | ||
| } | ||
| std::ifstream rhs_file(rhsFileName); | ||
| if(!rhs_file.is_open()) | ||
| { | ||
| std::cout << "Failed to open file " << rhsFileName << "\n"; | ||
| return -1; | ||
| } | ||
| A_coo = ReSolve::io::readMatrixFromFile(mat_file); | ||
| A = new ReSolve::matrix::Csr(A_coo->getNumRows(), | ||
| A_coo->getNumColumns(), | ||
| A_coo->getNnz(), | ||
| A_coo->symmetric(), | ||
| A_coo->expanded()); | ||
|
|
||
| rhs = ReSolve::io::readRhsFromFile(rhs_file); | ||
| x = new real_type[A->getNumRows()]; | ||
| vec_rhs = new vector_type(A->getNumRows()); | ||
| vec_x = new vector_type(A->getNumRows()); | ||
| vec_x->allocate(ReSolve::memory::HOST); | ||
| //iinit guess is 0U | ||
| vec_x->allocate(ReSolve::memory::DEVICE); | ||
| vec_x->setToZero(ReSolve::memory::DEVICE); | ||
| vec_r = new vector_type(A->getNumRows()); | ||
| std::cout<<"Finished reading the matrix and rhs, size: "<<A->getNumRows()<<" x "<<A->getNumColumns()<< ", nnz: "<< A->getNnz()<< ", symmetric? "<<A->symmetric()<< ", Expanded? "<<A->expanded()<<std::endl; | ||
| mat_file.close(); | ||
| rhs_file.close(); | ||
|
|
||
| matrix_handler->coo2csr(A_coo,A, "hip"); | ||
| vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE); | ||
| //Now call direct solver | ||
| real_type norm_b; | ||
| matrix_handler->setValuesChanged(true, "hip"); | ||
|
|
||
| Rf->setup(A); | ||
| FGMRES->setRestart(150); | ||
| FGMRES->setMaxit(2500); | ||
| FGMRES->setTol(1e-12); | ||
| FGMRES->setup(A); | ||
| GS->setup(FGMRES->getKrand(), FGMRES->getRestart()); | ||
|
|
||
| //matrix_handler->setValuesChanged(true, "hip"); | ||
| FGMRES->resetMatrix(A); | ||
| FGMRES->setupPreconditioner("LU", Rf); | ||
| FGMRES->setFlexible(1); | ||
|
|
||
| vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE); | ||
| FGMRES->solve(vec_rhs, vec_x); | ||
|
|
||
| norm_b = vector_handler->dot(vec_rhs, vec_rhs, "hip"); | ||
| norm_b = sqrt(norm_b); | ||
| std::cout << "FGMRES: init nrm: " | ||
| << std::scientific << std::setprecision(16) | ||
| << FGMRES->getInitResidualNorm()/norm_b | ||
| << " final nrm: " | ||
| << FGMRES->getFinalResidualNorm()/norm_b | ||
| << " iter: " << FGMRES->getNumIter() << "\n"; | ||
|
|
||
|
|
||
| delete A; | ||
| delete A_coo; | ||
| delete Rf; | ||
| delete [] x; | ||
| delete [] rhs; | ||
| delete vec_r; | ||
| delete vec_x; | ||
| delete workspace_HIP; | ||
| delete matrix_handler; | ||
| delete vector_handler; | ||
|
|
||
| return 0; | ||
| } | ||
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,128 @@ | ||
| #include <string> | ||
| #include <iostream> | ||
| #include <iomanip> | ||
|
|
||
| #include <resolve/matrix/Coo.hpp> | ||
| #include <resolve/matrix/Csr.hpp> | ||
| #include <resolve/matrix/Csc.hpp> | ||
| #include <resolve/vector/Vector.hpp> | ||
| #include <resolve/matrix/io.hpp> | ||
| #include <resolve/matrix/MatrixHandler.hpp> | ||
| #include <resolve/vector/VectorHandler.hpp> | ||
| #include <resolve/LinSolverDirectKLU.hpp> | ||
| #include <resolve/LinSolverDirectCuSparseILU0.hpp> | ||
| #include <resolve/LinSolverIterativeRandFGMRES.hpp> | ||
| #include <resolve/workspace/LinAlgWorkspace.hpp> | ||
|
|
||
| using namespace ReSolve::constants; | ||
|
|
||
| int main(int argc, char *argv[]) | ||
| { | ||
| // Use the same data types as those you specified in ReSolve build. | ||
| using real_type = ReSolve::real_type; | ||
| using vector_type = ReSolve::vector::Vector; | ||
|
|
||
| (void) argc; // TODO: Check if the number of input parameters is correct. | ||
| std::string matrixFileName = argv[1]; | ||
| std::string rhsFileName = argv[2]; | ||
|
|
||
|
|
||
| ReSolve::matrix::Coo* A_coo; | ||
| ReSolve::matrix::Csr* A; | ||
| ReSolve::LinAlgWorkspaceCUDA* workspace_CUDA = new ReSolve::LinAlgWorkspaceCUDA(); | ||
| workspace_CUDA->initializeHandles(); | ||
| ReSolve::MatrixHandler* matrix_handler = new ReSolve::MatrixHandler(workspace_CUDA); | ||
| ReSolve::VectorHandler* vector_handler = new ReSolve::VectorHandler(workspace_CUDA); | ||
| real_type* rhs = nullptr; | ||
| real_type* x = nullptr; | ||
|
|
||
| vector_type* vec_rhs; | ||
| vector_type* vec_x; | ||
| vector_type* vec_r; | ||
|
|
||
| ReSolve::GramSchmidt* GS = new ReSolve::GramSchmidt(vector_handler, ReSolve::GramSchmidt::cgs2); | ||
|
|
||
| ReSolve::LinSolverDirectCuSparseILU0* Rf = new ReSolve::LinSolverDirectCuSparseILU0(workspace_CUDA); | ||
| ReSolve::LinSolverIterativeRandFGMRES* FGMRES = new ReSolve::LinSolverIterativeRandFGMRES(matrix_handler, vector_handler,ReSolve::LinSolverIterativeRandFGMRES::fwht, GS, "cuda"); | ||
|
|
||
| std::cout << std::endl << std::endl << std::endl; | ||
| std::cout << "========================================================================================================================"<<std::endl; | ||
| std::cout << "Reading: " << matrixFileName<< std::endl; | ||
| std::cout << "========================================================================================================================"<<std::endl; | ||
| std::cout << std::endl; | ||
| std::ifstream mat_file(matrixFileName); | ||
| if(!mat_file.is_open()) | ||
| { | ||
| std::cout << "Failed to open file " << matrixFileName << "\n"; | ||
| return -1; | ||
| } | ||
| std::ifstream rhs_file(rhsFileName); | ||
| if(!rhs_file.is_open()) | ||
| { | ||
| std::cout << "Failed to open file " << rhsFileName << "\n"; | ||
| return -1; | ||
| } | ||
| A_coo = ReSolve::io::readMatrixFromFile(mat_file); | ||
| A = new ReSolve::matrix::Csr(A_coo->getNumRows(), | ||
| A_coo->getNumColumns(), | ||
| A_coo->getNnz(), | ||
| A_coo->symmetric(), | ||
| A_coo->expanded()); | ||
|
|
||
| rhs = ReSolve::io::readRhsFromFile(rhs_file); | ||
| x = new real_type[A->getNumRows()]; | ||
| vec_rhs = new vector_type(A->getNumRows()); | ||
| vec_x = new vector_type(A->getNumRows()); | ||
| vec_x->allocate(ReSolve::memory::HOST); | ||
| //iinit guess is 0U | ||
| vec_x->allocate(ReSolve::memory::DEVICE); | ||
| vec_x->setToZero(ReSolve::memory::DEVICE); | ||
| vec_r = new vector_type(A->getNumRows()); | ||
| std::cout<<"Finished reading the matrix and rhs, size: "<<A->getNumRows()<<" x "<<A->getNumColumns()<< ", nnz: "<< A->getNnz()<< ", symmetric? "<<A->symmetric()<< ", Expanded? "<<A->expanded()<<std::endl; | ||
| mat_file.close(); | ||
| rhs_file.close(); | ||
|
|
||
| matrix_handler->coo2csr(A_coo,A, "cuda"); | ||
| vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE); | ||
| //Now call direct solver | ||
| real_type norm_b; | ||
| matrix_handler->setValuesChanged(true, "cuda"); | ||
|
|
||
| Rf->setup(A, nullptr, nullptr, nullptr, nullptr, vec_rhs); | ||
| FGMRES->setRestart(800); | ||
| FGMRES->setMaxit(800); | ||
| FGMRES->setTol(1e-12); | ||
| FGMRES->setup(A); | ||
| GS->setup(FGMRES->getKrand(), FGMRES->getRestart()); | ||
|
|
||
| //matrix_handler->setValuesChanged(true, "cuda"); | ||
| FGMRES->resetMatrix(A); | ||
| FGMRES->setupPreconditioner("LU", Rf); | ||
| FGMRES->setFlexible(1); | ||
|
|
||
| vec_rhs->update(rhs, ReSolve::memory::HOST, ReSolve::memory::DEVICE); | ||
| FGMRES->solve(vec_rhs, vec_x); | ||
|
|
||
| norm_b = vector_handler->dot(vec_rhs, vec_rhs, "cuda"); | ||
| norm_b = sqrt(norm_b); | ||
| std::cout << "FGMRES: init nrm: " | ||
| << std::scientific << std::setprecision(16) | ||
| << FGMRES->getInitResidualNorm()/norm_b | ||
| << " final nrm: " | ||
| << FGMRES->getFinalResidualNorm()/norm_b | ||
| << " iter: " << FGMRES->getNumIter() << "\n"; | ||
|
|
||
|
|
||
| delete A; | ||
| delete A_coo; | ||
| delete Rf; | ||
| delete [] x; | ||
| delete [] rhs; | ||
| delete vec_r; | ||
| delete vec_x; | ||
| delete workspace_CUDA; | ||
| delete matrix_handler; | ||
| delete vector_handler; | ||
|
|
||
| return 0; | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.