-
Notifications
You must be signed in to change notification settings - Fork 9
Implement the HyKKT Cholesky module #350
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 26 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
a91b140
initial solver and cuda header
adhamsi ed06b6a
cuda implementation
adhamsi 5d1f812
minimal test on cuda passes
adhamsi 19fcfc0
cpu implementation
adhamsi d461cbc
tell cmake to find cholmod
adhamsi b667e82
add template hip implementation
adhamsi 67bcfd3
dependencies
adhamsi 2eedfb4
cpu: memory freeing and unused fields
adhamsi 9733f63
Apply pre-commmit fixes
adhamsi 95c7b59
error handling and correct memory in cuda
adhamsi b37584a
randomized testing: different sparsity patterns
adhamsi a75fddb
Apply pre-commmit fixes
adhamsi 6701b7b
fix for cuda: resetting workspace
adhamsi fc5c679
Apply pre-commmit fixes
adhamsi 9210b8a
test reusing sparsity pattern
adhamsi b5f357d
Apply pre-commmit fixes
adhamsi 243367c
Apply pre-commmit fixes
adhamsi bb77551
draft: rocsolver
adhamsi 9c471ea
Apply pre-commmit fixes
adhamsi c36939a
fix build issue
adhamsi b55b8e6
documentation
adhamsi 486694f
Apply pre-commmit fixes
adhamsi 118ff08
error message when no gpu support
adhamsi 774505e
address minor review comments
adhamsi 662dbee
Apply pre-commmit fixes
adhamsi ca35833
remove commented code
adhamsi b22ce10
more detail on documentation
adhamsi f0b85fc
Apply pre-commmit fixes
adhamsi 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ set(SUITESPARSE_MODULES | |
| amd | ||
| colamd | ||
| klu | ||
| cholmod | ||
| suitesparseconfig) | ||
|
|
||
| find_library(SUITESPARSE_LIBRARY | ||
|
|
||
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 |
|---|---|---|
| @@ -1,82 +1,81 @@ | ||
| /** | ||
| * @file MemoryUtils.tpp | ||
| * | ||
| * | ||
| * Contains implementation of memory utility functions wrappers. | ||
| * All it does it calls vendor specific functions frm an abstract interface. | ||
| * | ||
| * | ||
| * @author Slaven Peles <peless@ornl.gov> | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
|
|
||
| namespace ReSolve | ||
| { | ||
| template <class Policy> | ||
| void MemoryUtils<Policy>::deviceSynchronize() | ||
| { | ||
| Policy::deviceSynchronize(); | ||
| } | ||
| template <class Policy> | ||
| void MemoryUtils<Policy>::deviceSynchronize() | ||
| { | ||
| Policy::deviceSynchronize(); | ||
| } | ||
|
|
||
| template <class Policy> | ||
| int MemoryUtils<Policy>::getLastDeviceError() | ||
| { | ||
| return Policy::getLastDeviceError(); | ||
| } | ||
|
|
||
| template <class Policy> | ||
| int MemoryUtils<Policy>::deleteOnDevice(void* v) | ||
| { | ||
| return Policy::deleteOnDevice(v); | ||
| } | ||
|
|
||
| template <class Policy> | ||
| template <typename I, typename T> | ||
| int MemoryUtils<Policy>::allocateArrayOnDevice(T** v, I n) | ||
| { | ||
| return Policy::template allocateArrayOnDevice<I, T>(v, n); | ||
| } | ||
|
|
||
| template <class Policy> | ||
| template <typename I, typename T> | ||
| int MemoryUtils<Policy>::allocateBufferOnDevice(T** v, I n) | ||
| { | ||
| return Policy::template allocateBufferOnDevice<I, T>(v, n); | ||
| } | ||
|
|
||
| template <class Policy> | ||
| template <typename I, typename T> | ||
| int MemoryUtils<Policy>::setZeroArrayOnDevice(T* v, I n) | ||
| { | ||
| return Policy::template setZeroArrayOnDevice<I, T>(v, n); | ||
| } | ||
|
|
||
| template <class Policy> | ||
| template <typename I, typename T> | ||
| int MemoryUtils<Policy>::setArrayToConstOnDevice(T* v, T c, I n) | ||
| { | ||
| return Policy::template setArrayToConstOnDevice<I, T>(v, c, n); | ||
| } | ||
|
|
||
| template <class Policy> | ||
| template <typename I, typename T> | ||
| int MemoryUtils<Policy>::copyArrayDeviceToHost(T* dst, const T* src, I n) | ||
| { | ||
| return Policy::template copyArrayDeviceToHost<I, T>(dst, src, n); | ||
| } | ||
|
|
||
| template <class Policy> | ||
| int MemoryUtils<Policy>::getLastDeviceError() | ||
| { | ||
| return Policy::getLastDeviceError(); | ||
| } | ||
| template <class Policy> | ||
| template <typename I, typename T> | ||
| int MemoryUtils<Policy>::copyArrayDeviceToDevice(T* dst, const T* src, I n) | ||
| { | ||
| return Policy::template copyArrayDeviceToDevice<I, T>(dst, src, n); | ||
| } | ||
|
|
||
| template <class Policy> | ||
| int MemoryUtils<Policy>::deleteOnDevice(void* v) | ||
| { | ||
| return Policy::deleteOnDevice(v); | ||
| } | ||
|
|
||
| template <class Policy> | ||
| template <typename I, typename T> | ||
| int MemoryUtils<Policy>::allocateArrayOnDevice(T** v, I n) | ||
| { | ||
| return Policy::template allocateArrayOnDevice<I, T>(v, n); | ||
| } | ||
|
|
||
| template <class Policy> | ||
| template <typename I, typename T> | ||
| int MemoryUtils<Policy>::allocateBufferOnDevice(T** v, I n) | ||
| { | ||
| return Policy::template allocateBufferOnDevice<I, T>(v, n); | ||
| } | ||
|
|
||
| template <class Policy> | ||
| template <typename I, typename T> | ||
| int MemoryUtils<Policy>::setZeroArrayOnDevice(T* v, I n) | ||
| { | ||
| return Policy::template setZeroArrayOnDevice<I, T>(v, n); | ||
| } | ||
|
|
||
| template <class Policy> | ||
| template <typename I, typename T> | ||
| int MemoryUtils<Policy>::setArrayToConstOnDevice(T* v, T c, I n) | ||
| { | ||
| return Policy::template setArrayToConstOnDevice<I, T>(v, c, n); | ||
| } | ||
|
|
||
| template <class Policy> | ||
| template <typename I, typename T> | ||
| int MemoryUtils<Policy>::copyArrayDeviceToHost(T* dst, const T* src, I n) | ||
| { | ||
| return Policy::template copyArrayDeviceToHost<I, T>(dst, src, n); | ||
| } | ||
|
|
||
| template <class Policy> | ||
| template <typename I, typename T> | ||
| int MemoryUtils<Policy>::copyArrayDeviceToDevice(T* dst, const T* src, I n) | ||
| { | ||
| return Policy::template copyArrayDeviceToDevice<I, T>(dst, src, n); | ||
| } | ||
|
|
||
| template <class Policy> | ||
| template <typename I, typename T> | ||
| int MemoryUtils<Policy>::copyArrayHostToDevice(T* dst, const T* src, I n) | ||
| { | ||
| return Policy::template copyArrayHostToDevice<I, T>(dst, src, n); | ||
| } | ||
| template <class Policy> | ||
| template <typename I, typename T> | ||
| int MemoryUtils<Policy>::copyArrayHostToDevice(T* dst, const T* src, I n) | ||
| { | ||
| return Policy::template copyArrayHostToDevice<I, T>(dst, src, n); | ||
| } | ||
|
|
||
| } // namespace ReSolve |
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 |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| add_subdirectory(permutation) | ||
| add_subdirectory(ruiz) | ||
| add_subdirectory(cholesky) |
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,65 @@ | ||
| #[[ | ||
|
|
||
| @brief Build ReSolve matrix module | ||
|
|
||
| @author Slaven Peles <peless@ornl.gov> | ||
|
|
||
| ]] | ||
|
|
||
| # C++ code | ||
| set(HyKKT_CHOL_SRC | ||
| CholeskySolver.cpp | ||
| CholeskySolverCpu.cpp | ||
| ) | ||
|
|
||
| # C++ code that depends on CUDA SDK libraries | ||
| set(HyKKT_CUDASDK_SRC | ||
| CholeskySolverCuda.cpp | ||
| ) | ||
|
|
||
| # and on HIP | ||
| set(HyKKT_ROCM_SRC | ||
| CholeskySolverHip.cpp | ||
| ) | ||
|
|
||
| # Header files to be installed | ||
| set(HyKKT_CHOL_HEADER_INSTALL | ||
| CholeskySolver.hpp | ||
| CholeskySolverImpl.hpp | ||
| CholeskySolverCpu.hpp | ||
| CholeskySolverCuda.hpp | ||
| CholeskySolverHip.hpp | ||
| ) | ||
|
|
||
| add_library(resolve_hykkt_chol SHARED ${HyKKT_CHOL_SRC}) | ||
|
|
||
| target_link_libraries(resolve_hykkt_chol PUBLIC ${suitesparse_cholmod}) | ||
| target_include_directories(resolve_hykkt_chol PUBLIC ${SUITESPARSE_INCLUDE_DIR}) | ||
|
|
||
| # Link to CUDA ReSolve backend if CUDA is support enabled | ||
| if (RESOLVE_USE_CUDA) | ||
| target_sources(resolve_hykkt_chol PRIVATE ${HyKKT_CUDASDK_SRC}) | ||
| target_link_libraries(resolve_hykkt_chol PUBLIC resolve_backend_cuda) | ||
| endif() | ||
|
|
||
| if (RESOLVE_USE_HIP) | ||
| target_sources(resolve_hykkt_chol PRIVATE ${HyKKT_ROCM_SRC}) | ||
| target_link_libraries(resolve_hykkt_chol PUBLIC resolve_backend_hip) | ||
| endif() | ||
|
|
||
| # Link to dummy device backend if GPU support is not enabled | ||
| if (NOT RESOLVE_USE_GPU) | ||
| target_link_libraries(resolve_hykkt_chol PUBLIC resolve_backend_cpu) | ||
| endif() | ||
|
|
||
| target_link_libraries(resolve_hykkt_chol PUBLIC resolve_workspace | ||
| resolve_vector | ||
| resolve_matrix | ||
| resolve_logger) | ||
|
|
||
| target_include_directories(resolve_hykkt_chol INTERFACE | ||
| $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}> | ||
| $<INSTALL_INTERFACE:include> | ||
| ) | ||
|
|
||
| install(FILES ${HyKKT_CHOL_HEADER_INSTALL} DESTINATION include/resolve/hykkt) |
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,109 @@ | ||
| /** | ||
| * @file CholeskySolver.cpp | ||
| * @author Adham Ibrahim (ibrahimas@ornl.gov) | ||
| * @brief Cholesky decomposition solver implementation | ||
| */ | ||
|
|
||
| #include "CholeskySolver.hpp" | ||
|
|
||
| #include "CholeskySolverCpu.hpp" | ||
| #ifdef RESOLVE_USE_CUDA | ||
| #include "CholeskySolverCuda.hpp" | ||
| #elif defined(RESOLVE_USE_HIP) | ||
| #include "CholeskySolverHip.hpp" | ||
| #endif | ||
|
|
||
| namespace ReSolve | ||
| { | ||
| using real_type = ReSolve::real_type; | ||
| using out = ReSolve::io::Logger; | ||
|
|
||
| namespace hykkt | ||
| { | ||
| /** | ||
| * @brief Cholesky Solver constructor | ||
| * @param[in] memspace - memory space to use for computations | ||
| */ | ||
| CholeskySolver::CholeskySolver(memory::MemorySpace memspace) | ||
| : memspace_(memspace) | ||
| { | ||
| if (memspace_ == memory::HOST) | ||
| { | ||
| impl_ = new CholeskySolverCpu(); | ||
| } | ||
| else | ||
| { | ||
| #ifdef RESOLVE_USE_CUDA | ||
| impl_ = new CholeskySolverCuda(); | ||
| #elif defined(RESOLVE_USE_HIP) | ||
| impl_ = new CholeskySolverHip(); | ||
| #else | ||
| out::error() << "Memory space set to DEVICE, though no GPU support enabled. Must enable RESOLVE_USE_CUDA or RESOLVE_USE_HIP.\n"; | ||
| exit(1); | ||
| #endif | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @brief Cholesky Solver destructor | ||
| */ | ||
| CholeskySolver::~CholeskySolver() | ||
| { | ||
| delete impl_; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Loads or reloads matrix pointer to the solver | ||
| * @param[in] A - pointer to the matrix in CSR format | ||
| */ | ||
| void CholeskySolver::addMatrixInfo(matrix::Csr* A) | ||
| { | ||
| A_ = A; | ||
| impl_->addMatrixInfo(A); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Performs symbolic analysis. This need only be called once | ||
| * as long as the sparsity pattern does not change. | ||
| */ | ||
| void CholeskySolver::symbolicAnalysis() | ||
| { | ||
| impl_->symbolicAnalysis(); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Sets the pivot tolerance for the solver. | ||
| * | ||
| * This is only used in the CUDA implementation. For other backends, | ||
| * it is ignored. | ||
| * | ||
| * @param[in] tol - pivot tolerance value | ||
| */ | ||
| void CholeskySolver::setPivotTolerance(real_type tol) | ||
| { | ||
| tol_ = tol; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Performs numerical factorization. | ||
| */ | ||
adhamsi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| void CholeskySolver::numericalFactorization() | ||
| { | ||
| impl_->numericalFactorization(tol_); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Solves the linear system Ax = b and stores the result in x. | ||
| * | ||
| * @pre The vector x is allocated in the given memspace. | ||
| * | ||
| * @param[out] x - pointer to the solution vector | ||
| * @param[in] b - pointer to the right-hand side vector | ||
| */ | ||
| void CholeskySolver::solve(vector::Vector* x, vector::Vector* b) | ||
| { | ||
| impl_->solve(x, b); | ||
| x->setDataUpdated(memspace_); | ||
| } | ||
| } // namespace hykkt | ||
| } // namespace ReSolve | ||
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,37 @@ | ||
| /** | ||
| * @file CholeskySolver.hpp | ||
| * @author Adham Ibrahim (ibrahimas@ornl.gov) | ||
| * @brief Cholesky decomposition solver header | ||
| */ | ||
|
|
||
| #pragma once | ||
| #include "CholeskySolverImpl.hpp" | ||
| #include <resolve/MemoryUtils.hpp> | ||
| #include <resolve/matrix/Csr.hpp> | ||
| #include <resolve/vector/Vector.hpp> | ||
|
|
||
| namespace ReSolve | ||
| { | ||
| namespace hykkt | ||
| { | ||
| class CholeskySolver | ||
| { | ||
| public: | ||
| CholeskySolver(memory::MemorySpace memspace); | ||
| ~CholeskySolver(); | ||
|
|
||
| void addMatrixInfo(matrix::Csr* A); | ||
| void symbolicAnalysis(); | ||
| void setPivotTolerance(real_type tol); | ||
| void numericalFactorization(); | ||
| void solve(vector::Vector* x, vector::Vector* b); | ||
|
|
||
| private: | ||
| memory::MemorySpace memspace_; | ||
|
|
||
| matrix::Csr* A_; | ||
| real_type tol_ = 1e-12; | ||
| CholeskySolverImpl* impl_; | ||
| }; | ||
| } // namespace hykkt | ||
| } // namespace ReSolve |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we removing this from the list of targets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolve_hykktis the target for only the Permutation class. This is a holdover from your original commit of the Permutation class. The name hasn't been changed and needs to be. The other hykkt modules are namedresolve_hykkt_ruiz, etc. But it appears adding it to the list of targets is redundant if the subdirectory is added.