Commit Graph

18 Commits

Author SHA1 Message Date
Sameer Agarwal 667062dcc8 Introduce BlockSparseMatrixData
A number of algorithms like the SchurEliminator do not need
access to the full BlockSparseMatrix interface. They only
need read only access to the values array and the block structure.

This change introduces, BlockSparseDataMatrix a struct that carries
these two bits of information and modifies the Schur type algorithms
to use it.

What this change will allow us to do, in a subsequent CL is to
take the values array of a BlockSparseMatrix and pair it with
a different blocks structure for subset preconditioning.

Change-Id: I1808f12531b586c9ff4d6a70b3d390c7b0d9f441
2019-09-24 06:53:30 -07:00
Sameer Agarwal 71d638ef32 Add a specialized schur eliminator.
Add a new specialized Schur Eliminator for the case where there is
exactly one F block and all dimensions are known at compile time.

Benchmark on my macbook shoes ~3x speedup for Eliminate and 4x speedup for BackSubstitute.
Similar speedups are observed on other platforms.

------------------------------------------------------------------------------------------
Benchmark                                                   Time           CPU Iterations
------------------------------------------------------------------------------------------
BM_SchurEliminatorEliminate/10                           4176 ns       4132 ns     153522
BM_SchurEliminatorEliminate/64                          24392 ns      24234 ns      29993
BM_SchurEliminatorEliminate/512                        169632 ns     168709 ns       3872
BM_SchurEliminatorEliminate/4096                      1296407 ns    1292873 ns        519
BM_SchurEliminatorEliminate/10000                     3159652 ns    3149532 ns        216
BM_SchurEliminatorForOneFBlockEliminate/10               1187 ns       1184 ns     603953
BM_SchurEliminatorForOneFBlockEliminate/64               7917 ns       7898 ns      87558
BM_SchurEliminatorForOneFBlockEliminate/512             57629 ns      57485 ns      12035
BM_SchurEliminatorForOneFBlockEliminate/4096           484680 ns     480757 ns       1459
BM_SchurEliminatorForOneFBlockEliminate/10000         1157237 ns    1150735 ns        566
BM_SchurEliminatorBackSubstitute/10                       681 ns        679 ns    1070500
BM_SchurEliminatorBackSubstitute/64                      3899 ns       3887 ns     182883
BM_SchurEliminatorBackSubstitute/512                    33632 ns      33467 ns      22582
BM_SchurEliminatorBackSubstitute/4096                  241117 ns     240257 ns       2884
BM_SchurEliminatorBackSubstitute/10000                 631869 ns     626992 ns       1146
BM_SchurEliminatorForOneFBlockBackSubstitute/10           139 ns        138 ns    5021341
BM_SchurEliminatorForOneFBlockBackSubstitute/64           898 ns        892 ns     780396
BM_SchurEliminatorForOneFBlockBackSubstitute/512         7344 ns       7286 ns      87059
BM_SchurEliminatorForOneFBlockBackSubstitute/4096       57634 ns      57345 ns      11642
BM_SchurEliminatorForOneFBlockBackSubstitute/10000     153129 ns     152320 ns       4949

Change-Id: Iae64e96c91beb44b807df0e0572d202df7cdaed8
2019-08-05 07:15:41 -07:00
Sameer Agarwal 2ffddaccfe Use override & final instead of just using virtual.
This is safer than using virtual and this lead to a minor
bug fixes.

Change-Id: Id69cb1cc569bf6bf245f22f029c7871b6c712568
2019-07-25 16:29:14 -07:00
Kuang Fangjun 189f0c2f6e fix typos.
Change-Id: I9255d3c6cc0604b227ddfe065c2cdb770dceaf5c
2018-09-23 10:56:34 +08:00
Sameer Agarwal 94712db5c7 Convert calls to CHECK_NOTNULL to CHECK.
CHECK_NOTNULL is being deprecated and removed from the
glog library.

Change-Id: I4a6d1eec6e82a768c7861c8f776bf1f9c0b50c74
2018-08-28 08:14:19 -07:00
Sameer Agarwal 2dd82fb8a0 Relax the limitation that SchurEliminator::Eliminate requires a rhs.
When using the SchurEliminator to compute a preconditioner, there
is no rhs. This CL removes that limitation and simplifies the
call sites in the two preconditioners.

https://github.com/ceres-solver/ceres-solver/issues/271

Change-Id: I05b8518fdc9f0d1a6d88ae76d3a7e8e838e7204a
2018-07-10 06:18:01 +00:00
Keir Mierle 7c4e8a454e Replace scoped_ptr with C++11's unique_ptr
Change-Id: Ib5a504c491e3a79af52a95accf009df473470c6b
2018-04-02 14:47:47 -07:00
Sameer Agarwal fc9336e12a Deprecate mutex.h
Use C++11's std::mutex and std::lock_guard instead.

Change-Id: If8d513d5d8f2ee2a49c1ebb249ffa93e4a80086b
2018-04-02 06:03:06 -07:00
Mike Vitus f408f89e8b Adds a Ceres Context structure.
A Ceres Context holds common global state that can be re-used within
Ceres.  The Context current contains a thread pool if compiling with
C++11 threading support.  Threads are expensive to create and destroy so
it is good to maintain across multiple Ceres solves.

Tested by compiling with and without TBB support and ran unit tests. Ran
bazel as well.

Change-Id: I82f598dfae642aa0e81a6039dc174608a5e8dbfb
2018-02-26 10:37:53 -08:00
Yury Prokazov 4ffec20a44 Add TBB threading support.
There are platforms where OpenMP is not available. This
patch adds support for Intel Threading Building Blocks (TBB)
as an alternative threading backend.

Change-Id: I94497d7cba0c3cfaccfc992169236f17fe948ae9
2017-09-25 12:43:14 +02:00
Sameer Agarwal 0859fe8a57 Integrate InvertPSDMatrix into the SchurEliminator.
SchurEliminator::Init now takes a bool that tells it whether
it can assume that the diagonal blocks it is inverting can
be assumed to be full rank or not.

This information is then passed onto InvertPSDMatrix.

Change-Id: I26037b6233f2aad5584fed245f631c3959928afe
2017-04-25 10:08:45 -07:00
Keir Mierle 7492b0d8de Update copyright headers with new year and URL
Since Ceres is moving to using GitHub for issues, and the Google
Code URL in the current copyright header will soon become invalid,
update all the headers.

Change-Id: I1fce70375d1bcf098591f07b4d8f01a5c1e0789c
2015-03-18 05:43:23 +00:00
Sameer Agarwal bcc865f81c Remove using namespace std;
For historical reasons we had a "using namespace std;" in port.h. This
is generally a bad idea. So removing it and along the way doing a bunch
of cpplint cleanup.

Change-Id: Ia125601a55ae62695e247fb0250df4c6f86c46c6
2015-01-07 14:26:53 -08:00
Sameer Agarwal c1e10d9f57 Death to BlockSparseMatrixBase
Change-Id: I13b2b951297ae81bfab0a7b4991a791ed91d594c
2013-04-24 19:15:39 +00:00
Sameer Agarwal 487250eb27 Minor cleanups.
1. Further BLAS and heap allocation cleanups in  schur_eliminator_impl.h
2. Modularize blas.h using macros.
3. Lint cleanups from William Rucklidge.
4. Small changes to jet.h
5. ResidualBlock now uses blas.h

Performance improvements:

For static and dynamic sized blocks, the peformance is not changed much.

-use_quaternions -ordering user -linear_solver sparse_schur

                                        master         change
problem: 16-22106
gcc                                        3.4            3.3
clang                                      2.8            2.7

problem: 49-7776
gcc                                        1.7            1.7
clang                                      1.4            1.4

problem: 245-198739
gcc                                       80.1           79.6
clang                                     80.6           76.2

problem: 257-65132
gcc                                       12.2           12.0
clang                                     10.4           10.2

problem: 356-226730
gcc                                       99.0           96.8
clang                                     88.9           88.3

problem: 744-543562
gcc                                      361.5          356.2
clang                                    352.7          343.5

problem: 1024-110968
gcc                                       45.9           45.6
clang                                     42.6           42.1

However, performance when using local parameterizations is
significantly improved due to residual_block.cc using blas.h

-use_quaternions -use_local_parameterization -ordering user -linear_solver sparse_schur

                                        master         change
problem: 16-22106
gcc                                        3.6            3.3
clang                                      3.5            2.8

problem: 49-7776
gcc                                        1.8            1.6
clang                                      1.7            1.4

problem: 245-198739
gcc                                       79.7           76.1
clang                                     79.7           73.0

problem: 257-65132
gcc                                       12.8           11.9
clang                                     12.3            9.8

problem: 356-226730
gcc                                      101.9           93.5
clang                                    105.0           86.8

problem: 744-543562
gcc                                      367.9          350.5
clang                                    355.3          323.1

problem: 1024-110968
gcc                                       43.0           40.3
clang                                     41.0           37.5

Change-Id: I6dcf7476ddaa77cb116558d112a9cf1e832f5fc9
2013-04-14 09:33:11 -07:00
Sameer Agarwal 296fa9b127 Replace Eigen block operations with small GEMM and GEMV loops.
1. Add Matrix-Matrix and Matrix-Vector multiply functions.
2. Replace Eigen usage in SchurEliminator with these custom
   matrix operations.
3. Save on some memory allocations in ChunkOuterProduct.
4. Replace LDLT with LLT.

As a result on problem-16-22106-pre.txt, the linear solver time
goes down from 1.2s to 0.64s.

Change-Id: I2daa667960e0a1e8834489965a30be31f37fd87f
2013-04-02 18:04:39 -07:00
Sameer Agarwal 31730ef55d DenseSparseMatrix is now column-major.
1. Introduce new typdefs in eigen.h to allow for column
   major matrices.

2. Clean up old unused typedefs, and the aligned typedefs
   since they do not actually add any real performance.

3. Made eigen.h conform to the google style guide by removing
   the using directives. They were polluting the ceres namespace.

4. Made the template specialization generator work again.

Change-Id: Ic2268c784534b737ebd6e1a043e2a327adaeca37
2013-03-03 17:08:32 -08:00
Keir Mierle 8ebb073038 Initial commit of Ceres Solver. 2012-04-30 23:09:08 -07:00