-
Notifications
You must be signed in to change notification settings - Fork 16
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
Added Sympiler Wrapper #34
Open
ryansynk
wants to merge
14
commits into
main
Choose a base branch
from
sympiler
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9436ff4
Working sympiler wrapper
ryansynk afa30dd
Fixed bug in LinearSolverSympiler::factorize
ryansynk 3045d06
Fixed build errorr
ryansynk f062fae
Changed linux/windows to build with MKL
ryansynk d888656
Added MKL Include statement
ryansynk d4f790f
Refactored wrapper with smart pointers
ryansynk 9a0ce05
Updated to virtual destructor
ryansynk bd64223
Updated MKL settings for sympiler
8b50984
Pointed sympiler to new fork
85dafbe
Only enable on apple silicon
ryansynk 45feb17
Moved sympiler include into cpp filee
ryansynk feed5f1
Merge remote-tracking branch 'origin/main' into sympiler
jdumas b335e40
Enable Sympiler on Unix.
jdumas 7a0e47a
Added sorted=True
ryansynk 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 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 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 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,47 @@ | ||
# | ||
# Copyright 2020 Adobe. All rights reserved. | ||
# This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. You may obtain a copy | ||
# of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed under | ||
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
# OF ANY KIND, either express or implied. See the License for the specific language | ||
# governing permissions and limitations under the License. | ||
# | ||
if(TARGET sympiler::sym_sparse_blas) | ||
return() | ||
endif() | ||
|
||
message(STATUS "Third-party (external): creating target 'sympiler::sym_sparse_blas'") | ||
|
||
if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm64" OR "${CMAKE_OSX_ARCHITECTURES}" MATCHES "arm64") | ||
# apple M1 | ||
set(SYMPILER_BLAS_BACKEND "Apple" CACHE STRING "BLAS implementation for SYMPILER to use") | ||
else() | ||
# windows, linux, apple intel | ||
set(SYMPILER_BLAS_BACKEND "MKL" CACHE STRING "BLAS implementation for SYMPILER to use") | ||
endif() | ||
|
||
if(SYMPILER_BLAS_BACKEND STREQUAL "MKL") | ||
message("INCLUDING MKL") | ||
include(mkl) | ||
if(NOT TARGET MKL::MKL) | ||
add_library(MKL::MKL ALIAS mkl::mkl) | ||
endif() | ||
endif() | ||
|
||
include(CPM) | ||
CPMAddPackage( | ||
NAME sympiler | ||
GITHUB_REPOSITORY ryansynk/sympiler | ||
GIT_TAG 2fe1ef1d72b551acedd848d64b51fa5e90251804 | ||
) | ||
|
||
add_library(sympiler::sym_sparse_blas ALIAS sym_sparse_blas) | ||
|
||
include(GNUInstallDirs) | ||
target_include_directories(sym_sparse_blas INTERFACE | ||
"$<BUILD_INTERFACE:${sympiler_SOURCE_DIR}>/include" | ||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" | ||
) |
This file contains 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 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 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,95 @@ | ||
#ifdef POLYSOLVE_WITH_SYMPILER | ||
|
||
#include <polysolve/LinearSolverSympiler.hpp> | ||
#include <sympiler/parsy/cholesky_solver.h> | ||
#include <Eigen/Core> | ||
|
||
namespace polysolve | ||
{ | ||
class LinearSolverSympilerImpl | ||
{ | ||
public: | ||
LinearSolverSympilerImpl() | ||
: m_solver(nullptr), m_A_csc(std::make_unique<sym_lib::parsy::CSC>()) {} | ||
~LinearSolverSympilerImpl() = default; | ||
|
||
std::unique_ptr<sym_lib::parsy::SolverSettings> m_solver; | ||
std::unique_ptr<sym_lib::parsy::CSC> m_A_csc; | ||
polysolve::StiffnessMatrix m_A_copy; | ||
}; | ||
|
||
LinearSolverSympiler::LinearSolverSympiler() : m_pImpl(new LinearSolverSympilerImpl) {} | ||
LinearSolverSympiler::~LinearSolverSympiler() = default; | ||
|
||
void LinearSolverSympiler::setSolverMode(int _solver_mode) | ||
{ | ||
solver_mode = _solver_mode; | ||
} | ||
|
||
void LinearSolverSympiler::updateCSC() | ||
{ | ||
m_pImpl->m_A_csc->nzmax = m_pImpl->m_A_copy.nonZeros(); | ||
m_pImpl->m_A_csc->ncol = m_pImpl->m_A_csc->nrow = m_pImpl->m_A_copy.rows(); | ||
m_pImpl->m_A_csc->p = m_pImpl->m_A_copy.outerIndexPtr(); | ||
m_pImpl->m_A_csc->i = m_pImpl->m_A_copy.innerIndexPtr(); | ||
|
||
m_pImpl->m_A_csc->x = m_pImpl->m_A_copy.valuePtr(); | ||
m_pImpl->m_A_csc->stype = -1; | ||
m_pImpl->m_A_csc->packed = 1; | ||
m_pImpl->m_A_csc->sorted = 1; | ||
m_pImpl->m_A_csc->nz = nullptr; | ||
} | ||
|
||
void LinearSolverSympiler::setParameters(const json ¶ms) | ||
{ | ||
if (params.contains("Sympiler")) | ||
{ | ||
if (params["Sympiler"].contains("solver_mode")) | ||
{ | ||
setSolverMode(params["Sympiler"]["mtype"].get<int>()); | ||
} | ||
} | ||
} | ||
|
||
void LinearSolverSympiler::getInfo(json ¶ms) const | ||
{ | ||
if (factorize_status == 1) | ||
{ | ||
params["factorize_info"] = "Success"; | ||
} | ||
else | ||
{ | ||
params["factorize_info"] = "Failure"; | ||
} | ||
} | ||
|
||
void LinearSolverSympiler::analyzePattern(const StiffnessMatrix &A, const int precond_num) | ||
{ | ||
m_pImpl->m_A_copy = StiffnessMatrix(A); | ||
updateCSC(); | ||
m_pImpl->m_solver = std::make_unique<sym_lib::parsy::SolverSettings>(m_pImpl->m_A_csc.get()); | ||
m_pImpl->m_solver->symbolic_analysis(); | ||
} | ||
|
||
// Factorize system matrix | ||
void LinearSolverSympiler::factorize(const StiffnessMatrix &A) | ||
ryansynk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
// Only copy when matrix changes | ||
if (!m_pImpl->m_A_copy.isApprox(A)) | ||
{ | ||
m_pImpl->m_A_copy = StiffnessMatrix(A); | ||
updateCSC(); | ||
} | ||
factorize_status = m_pImpl->m_solver->numerical_factorization(m_pImpl->m_A_csc.get()); | ||
} | ||
|
||
// Solve the linear system Ax = b | ||
void LinearSolverSympiler::solve(const Ref<const Eigen::VectorXd> b, Ref<Eigen::VectorXd> x) | ||
{ | ||
double *x_ptr = m_pImpl->m_solver->solve_only(b.data()); | ||
x = Eigen::Map<Eigen::VectorXd>(x_ptr, x.rows(), x.cols()); | ||
} | ||
|
||
} // namespace polysolve | ||
|
||
#endif |
This file contains 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,56 @@ | ||
#ifdef POLYSOLVE_WITH_SYMPILER | ||
|
||
#include <polysolve/LinearSolver.hpp> | ||
|
||
namespace polysolve | ||
{ | ||
class LinearSolverSympilerImpl; | ||
class LinearSolverSympiler : public LinearSolver | ||
{ | ||
public: | ||
LinearSolverSympiler(); | ||
~LinearSolverSympiler(); | ||
|
||
private: | ||
POLYSOLVE_DELETE_MOVE_COPY(LinearSolverSympiler) | ||
|
||
protected: | ||
void setSolverMode(int _solver_mode); | ||
void updateCSC(); | ||
|
||
public: | ||
////////////////////// | ||
// Public interface // | ||
////////////////////// | ||
|
||
// Set solver parameters | ||
virtual void setParameters(const json ¶ms) override; | ||
|
||
// Retrieve status (success/failure) of factorization | ||
virtual void getInfo(json ¶ms) const override; | ||
|
||
// Analyze sparsity pattern | ||
virtual void analyzePattern(const StiffnessMatrix &A, const int precond_num) override; | ||
|
||
// Factorize system matrix | ||
virtual void factorize(const StiffnessMatrix &A) override; | ||
|
||
// Solve the linear system Ax = b | ||
virtual void solve(const Ref<const VectorXd> b, Ref<VectorXd> x) override; | ||
|
||
// Name of the solver type (for debugging purposes) | ||
virtual std::string name() const override { return "Sympiler"; } | ||
|
||
private: | ||
std::unique_ptr<LinearSolverSympilerImpl> m_pImpl; | ||
|
||
protected: | ||
//////////////////// | ||
// Sympiler stuff // | ||
//////////////////// | ||
int solver_mode = 0; // 0 is normal solve, 1 is row/col addition | ||
int factorize_status = -1; | ||
Comment on lines
+51
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd vote for using |
||
}; | ||
} // namespace polysolve | ||
|
||
#endif |
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.
I am curious if we really need to store a copy of the matrix. Is this done in other solvers as well?
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.
Not sure about other solvers, but itseems like sympiler needs a
SolverSettings
object, which takes a pointer directly to the values and indices of a matrix. The pointers aren't const, so I don't think there's a guarantee that the solver object won't mess with the matrix data? That's why I've been doing the copy