-
Notifications
You must be signed in to change notification settings - Fork 767
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
Merging the Eigen Backend and Common Interface for Linear Solvers #111
Conversation
gtsam/linear/GaussianFactorGraph.cpp
Outdated
@@ -100,26 +100,34 @@ namespace gtsam { | |||
} | |||
|
|||
/* ************************************************************************* */ | |||
vector<boost::tuple<size_t, size_t, double> > GaussianFactorGraph::sparseJacobian() const { | |||
vector<boost::tuple<size_t, size_t, double> > | |||
GaussianFactorGraph::sparseJacobian( |
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.
Could we do this function (with its tests) in a separate PR? Then this PR can be exclusively about linear solvers.
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.
This change is in 837a09e, which is a late commit in Mandy's work on the Eigen backend. I can definitely separate them into different PRs, but I don't really see it as necessary because they will be rewritten in this PR anyway.
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.
@gchenfc please move these GFG functions and their tests to a separate PR to be merged first?
gtsam/linear/LinearSolver.h
Outdated
#include <gtsam/linear/VectorValues.h> | ||
|
||
namespace gtsam { | ||
class LinearSolver { |
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.
Docs
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.
Will do :)
gtsam/linear/LinearSolverParams.cpp
Outdated
@@ -0,0 +1,5 @@ | |||
// |
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.
doxygen. Does this file need to exist?
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.
Will change if there is nothing to implement
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.
Also, does all the Ordering
stuff actually belong to LinearSolverParams
?
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.
Yeah, it’s an important property for direct solvers...
Hopefully (as a |
f4000a4
to
4551b65
Compare
@ProfFan I propose you do a PR "Linearize straight to sparse matrix" to this branch. |
I'll add some results in my optimization efforts: Merging the sparse matrix generationContrary to initial projections, the speedup gained is minimal. It appears that generation of a sparse matrix with Eigen's ProfilingI profiled the timeSFMBAL script with the following results: Flamegraph: https://storage.cloud.google.com/pastebin-bucket/flamegraph-gtsam-eigen.svg It turns out that the major overheads are:
Nevertheless, the current setup allows us to have other backends as well, so I will start experimenting with SuiteSparse and cuSPARSE to see if there are any benefits. |
Fixed a bug in the sparse Eigen solver, now the result:
Compared to
We are 14% faster with Eigen's solver. Flamegraph: https://storage.googleapis.com/pastebin-bucket/flamegraph_gtsam_eigen_solver_v2.svg |
This commit further gains 1s timing advantage:
However, profiling shows that further improvement is unlikely under the Eigen Sparse framework. |
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.
- Eigen's LDLT Cholesky (22%) computes the ordering even there is no (natural) ordering
It is crucial that Eigen does not compute it’s own ordering. If needed (really!!??), we need to make a copy of Eigen’s LDL that does not. We cannot compare any solver with any other solver if the ordering changes. And almost the whole point of GTSAM is that we control the ordering, nobody else.
gtsam/linear/LinearSolverParams.h
Outdated
* -------------------------------------------------------------------------- */ | ||
|
||
/** | ||
* @file LinearSolver.h |
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.
fix
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.
fixed
gtsam/linear/LinearSolverParams.h
Outdated
|
||
/** | ||
* @file LinearSolver.h | ||
* @brief Common Interface for Linear Solvers |
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.
fix
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.
fixed
@dellaert To clarify: what I mean is that eigen spends some time computes the natural (identity) ordering as a part of the solving process, which is an overhead but we still control the ordering because this (Eigen) ordering is identity. |
I did some more tests with the Eigen solver and TBB. TBB is giving me a boost on my macOS 10.15. (1:04 without TBB, 0:54 with TBB). If we turn on MKL and use MKL's |
I solved the issue that Eigen is computing a "null" ordering. Now we do not have that overhead anymore (saved another 2 seconds) |
Nice. Let's merge the other PR (after you get rid of O(m) mallocs :-)) and then have another chat about the timing. |
|
Not fully understanding. TBB with eigen solver, or with sequential cholesky? Maybe make a colab that does all timings and nicely formats? (all currently supported linear solvers in this branch, ie. old solvers + Eigen cholesky and QR) |
With SuiteSparse (CHOLMOD) solver & TBB ON:
|
Cool. I’m not totally understanding the timing numbers (wall 22s == CPU 22s so does cholmod not use multicore?) |
@dellaert The actual timing is the last line: Just got a mind-blowing result, I reran the timing on my Linux (same hardware), and On my Linux:
|
Exactly the same iterations:
But 20x faster... |
Wow! Yeah, malloc on Mac has always been super-slow, which is one guess as to what is going on. Is it also with clang or is this with gcc? Finally, is this with or without TBB? SEQUENTIAL_CHOLESKY does not really exploit multi-threading, for that try MULTIFRONTAL_CHLESKY. |
What do you mean? Just linux boot on your macbook? |
My workstation (i7-8700K, 6c12t, 4.7GHz), dual-booted with macOS and Linux. BTW, I think based on the current benchmarks it is better to get a dataset bigger than BAL to guide further efforts. |
You can just use a larger BAL dataset: https://grail.cs.washington.edu/projects/bal/ |
Some preliminary observations:
There also seems to be a bug in SEQUENTIAL_CHOLESKY, as the convergence is different from all other solvers: Normal:
SEQUENTIAL_CHOLESKY:
|
…lization constants.
Some Hybrid Improvements
This is a placeholder for Travis to run CI tests. Also a place for commenting on the possible design goals and decisions.
This change is