Commit Graph

1919 Commits

Author SHA1 Message Date
Sergiu Deitsch f1dfac8cd6 Reduce the number of individual PRNG instances
Use same instance of a PRNG throughout by passing it to methods and
functions as an argument to generate random numbers without breaking the
sequence.

Change-Id: Ib024bbc1ea2d14e4b9afb71857856a5fb77b1667
2022-08-13 17:14:06 +00:00
Sergiu Deitsch 79e403b15c Expand vcpkg installation instructions
Change-Id: Iad83869b1411b126beb26cfbbf5f6e9f717ff591
2022-08-13 19:04:17 +02:00
Sameer Agarwal 7b0bb0e3f5 ClangTidy cleanups
Change-Id: I514ca5fd91c08866b412021e6c0f5d6f97c4bf8f
2022-08-12 21:49:02 -07:00
Sameer Agarwal c5c2afcc91 Fix solver_test.cc for preconditioners and sparse linear algebra libraries
Change-Id: Ia391680f872ab49101f672f676cdd68fe332d1d4
2022-08-12 21:35:15 -07:00
Sameer Agarwal 07d333fb68 Refactor options checking for linear solvers
The code that verifies that the linear solver is configuration
specified by the user has grown into a rat's nest. This CL
attempts to bring some order to this madness.

Fixes https://github.com/ceres-solver/ceres-solver/issues/852

Change-Id: I3f34c0e27da13a6412117dee43ef2d9ec3835b64
2022-08-12 21:14:08 -07:00
Sameer Agarwal ba7207b0ba A number of small changes.
These changes came about from testing the power bundle adjustment
integration CL.

1. Allow Solver::Options::max_linear_solver_iterations == 0.
2. Simplify the logic for when inverse(F'F) is computed.
3. norm_b -> norm_rhs in ConjugateGradientsSolver.

Change-Id: I50c19e1f24a4cc08ed60e3a3032b96b37bcada9f
2022-08-12 06:52:37 -07:00
Mark Shachkov 20e85bbe34 Add power series expansion preconditioner
Implementation of "Power Bundle Adjustment for Large-Scale 3D
Reconstruction" by Weber et. al. added in the form of preconditioner.

Change-Id: Ie85526a5fc46f74256f6dfe9173c3571f7160f3a
2022-08-11 19:34:41 +03:00
Sameer Agarwal 04899645cc LinearOperator::FooMultiply -> LinearOperator::FooMultiplyAndAccumulate
These methods were historically poorly named and every time I read code
I get confused whether they are just multiplying or multiplying and
adding. Clarifying them also gives us the changce to introduce
RightMultiply and LeftMultiply methods in the base class which will
simplify a number call sites in a subsequent CL.

Fixes https://github.com/ceres-solver/ceres-solver/issues/855

Change-Id: Ice4fb483f1acd02527a6dd753ef0c5a66037f4b0
2022-08-10 10:03:03 -07:00
Sameer Agarwal 288a3fde6b Add missing virtual destructors to matrix adapters
Change-Id: Ieb0e67fbc9042410a6ae63e7cf0f96cc90603829
2022-08-09 22:16:38 -07:00
Sameer Agarwal 6483a2b4c2 Add Sergiu's name to the list of maintainers
Change-Id: I2e8c6af08bf6b718ab81e84a77df6f72592a954b
2022-08-09 15:23:30 -07:00
Sameer Agarwal 1cf49d6884 Update FindGlog.cmake to create glog::glog target
This change to FindGlog.cmake was originally suggested by
@KrisThielemans

Change-Id: I9277e0c7ba730bffd938371859fd574a82248253
2022-08-09 14:00:04 +00:00
Sameer Agarwal 1da72ac39e Refactor ConjugateGradientsSolver
1. Convert it from a class to a template function. Where the
   template parameter is "DenseVectorType". This allows us
   to have a single implementation of Conjugate Gradients
   without worrying about where the matrix and the vectors
   are stored or what their internal representation is.

   For the case of CPU based vectors, we abstract operations
   on Eigen vectors using eigen_vector_ops.
2. Introduce ConjugateGradientsLinearOperator which is
   templated on DenseVectorType. It is the matrix vector
   multiplication abstraction.
3. Port the tests and all usages of ConjugateGradientsSolver
   to this new implementation.
4. Introduce Eigen::Vector based RightMultiply and LeftMultiply
   methods into LinearOperator which by default delete to the
   bare pointer based interfaces.
5. Add an identity preconditioner.

These changes are being made in preparation for adding a CUDA
based CGNR solver.

Change-Id: I9da36dc6c131856dd1a4aa7e645aaf12d25dd79b
2022-08-09 13:33:08 +00:00
Julio L. Paneque f62dccdb37 Fix the Sphere and Line Manifold formulations
This PR changes the Sphere and Line Manifold formulations so that their
tangent spaces represent traveled angles (for the sphere and the line
direction vector) and traveled distance (for the line origin). These
magnitudes were previously halved according to "Hartley & Zisserman
(2nd Edition)", but in the majority of the state of the art this is not
done, following the convention that magnitudes in the tangent space of
the unit sphere represent geodesic distances traveled on that manifold.
The same scale factor appears in the Quaternion Manifold implementation
and will be studied in a further PR.

This PR also adds an additional case in the Sphere Minus operator when
hy_norm == 0. The value of y_minus_x was fixed to 0 but actually its
last term can also be Pi depending on y_last.

Finally, new unit tests for the Plus and Minus operator are added, along
with new tests for the 2D Sphere (a.k.a. Circle) Manifold.

Change-Id: I9456f1675b20da49bede5d6759aabf3cdfb26eae
2022-08-09 09:36:18 +02:00
Sameer Agarwal 3e1cc89f63 A bunch of clang-tidy fixes.
Change-Id: I1442d69eb9be91a8c368187848d65196273e3de6
2022-08-08 21:13:30 -07:00
Sameer Agarwal 80380538ab One more CATD fix
Change-Id: I1307067c070328b5733e55909783e048021c9aca
2022-08-08 20:27:14 -07:00
Sameer Agarwal 560ef46fbd A bunch of minor fixes.
1. Remove an unused variable from block_sparse_matrix.cc
2. Add explicit types to the distributions to get around
   -Wctad-maybe-unsupported

Change-Id: Ib7d606fbfe2b93ba4fce408f38ee4f7626b74ff0
2022-08-08 20:16:51 -07:00
Joydeep Biswas 67bae28c12 CUDA CGNR, Part 1: Misc. CLeanup
* Fixed an alignment bug with EventLogger.
* Added expected solutions to some LinearLeastSquaresProblem tests.
* Expanded ContextImpl to initialize cuSparse.

Change-Id: I2d7556a0509e9b7c56c9cd5cfa75cb85614395dc
2022-08-08 21:48:07 -05:00
Sameer Agarwal 5d0bca14dd Remove ceres/internal/random.h in favor of <random>
Fixes https://github.com/ceres-solver/ceres-solver/issues/854

Change-Id: Id30b8dc2221f9afe4eb83f3a9304b9b2bc7e05d4
2022-08-08 07:06:21 -07:00
Mark Shachkov d881b5ccf3 Minor fixes in comments
Add Clion project directories to gitignore.

Change-Id: Ic804059bf219a0b96cf96d717936fb5fed95a4b4
2022-08-08 16:15:46 +03:00
Sameer Agarwal 37516c968c Fix a bug in InnerProductComputer.
InnerProductComputer was assuming that the input matrix had
at least one structurally non-zero block. As a result sometimes
when InnerProductComputer.SubMatrix test generated matrices
where the submatrix was structurally zero it would cause
a segmentation fault.

This changes fixes this issue and reduces the threshold for the
minimum block density so that there is a much higher chance of
such matrices occuring as part of testing.

Fixes https://github.com/ceres-solver/ceres-solver/issues/820

Change-Id: Iec3a2431e646f0c2aac9e0b994531fa72323f329
2022-08-07 12:56:42 -07:00
Joydeep Biswas d8dad14eed CUDA Cleanup
* Renamed several interfaces to CudaBuffer for clarity and consistency.
* Added unit tests for custom Cuda kernels.
* Set specific CUDA architectures if the CMake version supports it.

Change-Id: I269fb1089b80b25e17bca772ef8d70e7894214b8
2022-08-07 07:44:32 +00:00
Joydeep Biswas c9d2ec8a9f Updates to sparse block matrix structures to support new
sparse linear solvers.

* Add methods to convert TripletSparseMatrix and BlockSparseMatrix to
  CRSMatrix structure.
* Added tests for conversion of TripletSparseMatrix and BlockSparseMatrix
  to CRSMatrix structure.
* Added documentation on the BlockSparseMatrix structure.

Change-Id: I020cfa91c301567ceeb39ff2064183c5d88c9ed5
2022-08-06 22:03:37 -05:00
Sergiu Deitsch 5fe0bd45a9 Added MinGW to Windows Github workflow
Change-Id: Id2bcd92a5464ac4888295c3dbfe9b806be95a3d9
2022-08-06 23:56:51 +02:00
Sameer Agarwal 738c027c1f Fix a logic error in iterative_refiner_test
Change-Id: I741802db37d6d9e42e38cef358e00369f6a38d06
2022-08-06 08:29:08 -07:00
Sameer Agarwal cb6ad463d0 Add mixed precision support for CPU based DenseCholesky
On problem-744-543562-pre.txt

The time spent in linear solver on my M1 Pro is

eigen        81.550970
eigen+mixed  54.107383
LAPACK       47.078127
LAPACK+mixed 28.639868

Solution quality is unaffected.

The implementation of RefinedDenseCholesky and DenseIterativeRefiner
are straightforward ports of RefinedSparseCholesky and
SparseIterativeRefiner (formerly IterativeRefiner).

It maybe possible to refactor the SparseCholesky and DenseCholesky
interfaces so that this code duplication can be removed in the
future.

Change-Id: I921334224cb97629a60390f2add822de207f7923
2022-08-05 15:30:12 -07:00
Julio L. Paneque df55682ba5 Fix Eigen error in 2D sphere manifolds
Since Eigen does not allow to have a RowMajor column vector (see
https://gitlab.com/libeigen/eigen/-/issues/416), the storage order
must be set to ColMajor in that case. This fix adds that special
case when generating 2D sphere manifolds.

Change-Id: I594932e0dafc878e0b348f72524478588e61b34d
2022-08-05 11:25:29 +02:00
Sergiu Deitsch 1cf59f61eb Set Github workflow NDK path explicitly
Change-Id: I31115293f4a80ca15a7520814055ee1268d2970f
2022-08-01 18:27:08 +02:00
Sameer Agarwal 68c53bb395 Remove ceres::LocalParameterization
Change-Id: I3bdf2f6a8857db10c984024a27f490eefd23fefa
2022-07-29 22:29:23 +00:00
Joydeep Biswas 2f660464cc Fix build issue with CUDA testing targets when compiling without gflags.
Change-Id: I926a85c30b51802a99161679cb2a28fda6e3ef47
2022-07-20 21:31:47 +05:30
Sameer Agarwal c801192d47 Minor fixes
Change-Id: I4c825bbd19b2d902d17dce37d228e23a808c87fb
2022-07-18 06:43:12 -07:00
Sameer Agarwal ce9e902b86 Fix missing CERES_METIS_VERSION
CERES_METIS_VERSION needs to be set if either Eigen or
SuiteSparse are using it. Previously, we were conditioning it
only on EIGENMETIS being ON.

Change-Id: I380a3b138b79903aa142b560ed46f438ff549a82
2022-07-14 14:21:02 +00:00
Sameer Agarwal d9a3dfbf20 Add a missing ifdef guard to dense_cholesky_test
Change-Id: Ibd924bc52b589ea70c5e7a543e1092697a0e5941
2022-07-14 06:58:49 -07:00
Sameer Agarwal 5bd43a1fa4 Speed up DenseSparseMatrix::SquareColumnNorm.
Because we store the matrix as row major matrix, the
obvious Eigen expression performs rather poorly. A straight
c++ loop speeds things up considerably.

Also replace use of matrix() with direct use of m_.

Change-Id: I3d6166df4765ad8400ab9602a54b65fd21b1d50f
2022-07-14 06:46:49 -07:00
Sameer Agarwal cbc86f6512 Fix the build when CUDA is not present
Change-Id: Ieaa483ce190ba917096c675f7ee731cb20d27bf2
2022-07-13 10:01:03 -07:00
Sameer Agarwal 5af8e64497 Update year in solver.h
Change-Id: I49ffe5a24786aa32e7677785cc91ee914956f2e6
2022-07-13 09:09:37 -07:00
Joydeep Biswas 88e08cfe71 Mixed-precision Iterative Refinement Cholesky With CUDA
* Created a new class CUDADenseCholeskyMixedPrecision, which performs
  Cholesky factorization and solving in single (fp32) precision, and
  optionally performs iterative refinement.
* Added CUDA kernels for mixed-precision solve operations
* Added more detailed timing information to the FullReport about Schur
  elimination, reduced system solves, and back-substitution.

Some test performance numbers follow.
All tests were performed on an Ubuntu 20.04 desktop with an
Intel Core i9-9940X CPU and Nvidia Quadro RTX 6000 GPU.

Tests were launched as:
./bin/bundle_adjuster --input (problem_file) \
    --num_iterations 20
    --num_threads 28
    --linear_solver dense_schur
    --dense_linear_algebra_library (cuda|lapack)
    [--mixed_precision_solves]

==================================================
problem-21-11315-pre.txt
==================================================

--------------------------------------------------
Cuda Mixed Precision
--------------------------------------------------
Cost:
Initial                          4.413239e+06
Final                            3.037864e+04
Change                           4.382861e+06
  Linear solver                      0.250703 (14)
  ├ Schur eliminate                  0.234025 (14)
  ├ Reduced solve                    0.006643 (14)
  └ Backsubstitute                   0.006598 (12)

--------------------------------------------------
Cuda
--------------------------------------------------
Cost:
Initial                          4.413239e+06
Final                            3.037864e+04
Change                           4.382861e+06
  Linear solver                      0.257517 (12)
  ├ Schur eliminate                  0.233518 (12)
  ├ Reduced solve                    0.010621 (12)
  └ Backsubstitute                   0.007124 (12)

--------------------------------------------------
Lapack (OpenBLAS)
--------------------------------------------------
Cost:
Initial                          4.413239e+06
Final                            3.037864e+04
Change                           4.382861e+06
  Linear solver                      0.332349 (12)
  ├ Schur eliminate                  0.274748 (12)
  ├ Reduced solve                    0.015966 (12)
  └ Backsubstitute                   0.034192 (12)

==================================================
problem-257-65132-pre.txt
==================================================

--------------------------------------------------
Cuda Mixed Precision
--------------------------------------------------
Cost:
Initial                          2.456242e+07
Final                            9.677593e+04
Change                           2.446565e+07
  Linear solver                      1.332367 (20)
  ├ Schur eliminate                  1.021365 (20)
  ├ Reduced solve                    0.195472 (20)
  └ Backsubstitute                   0.075582 (20)

--------------------------------------------------
Cuda
--------------------------------------------------
Cost:
Initial                          2.456242e+07
Final                            9.677547e+04
Change                           2.446565e+07
  Linear solver                      1.810176 (20)
  ├ Schur eliminate                  1.012862 (20)
  ├ Reduced solve                    0.678704 (20)
  └ Backsubstitute                   0.083925 (20)

--------------------------------------------------
Lapack (OpenBLAS)
--------------------------------------------------
Cost:
Initial                          2.456242e+07
Final                            9.677547e+04
Change                           2.446565e+07
  Linear solver                      2.376273 (20)
  ├ Schur eliminate                  0.987613 (20)
  ├ Reduced solve                    1.043873 (20)
  └ Backsubstitute                   0.310402 (20)

==================================================
problem-744-543562-pre.txt
==================================================

--------------------------------------------------
Cuda Mixed Precision
--------------------------------------------------
Cost:
Initial                          1.434881e+08
Final                            1.546895e+06
Change                           1.419412e+08
  Linear solver                     27.010088 (20)
  ├ Schur eliminate                 24.362433 (20)
  ├ Reduced solve                    1.428542 (20)
  └ Backsubstitute                   0.814266 (20)

--------------------------------------------------
Cuda
--------------------------------------------------
Cost:
Initial                          1.434881e+08
Final                            1.546895e+06
Change                           1.419412e+08
  Linear solver                     32.342513 (20)
  ├ Schur eliminate                 24.638819 (20)
  ├ Reduced solve                    6.492090 (20)
  └ Backsubstitute                   0.802184 (20)

--------------------------------------------------
Lapack (OpenBLAS)
--------------------------------------------------
Cost:
Initial                          1.434881e+08
Final                            1.546895e+06
Change                           1.419412e+08
  Linear solver                     34.152224 (20)
  ├ Schur eliminate                 24.183723 (20)
  ├ Reduced solve                    8.784413 (20)
  └ Backsubstitute                   0.795044 (20)

Change-Id: I178887e776d8f4a1e8abb99bbc205bf8c278bf79
2022-07-13 06:55:31 -05:00
Alex Stewart 290b34ef05 Fix optional SuiteSparse + METIS test-suite names to be unique
Change-Id: I539dc3edebbf1929712d5187e66ebf9f615844f8
2022-07-08 16:55:36 +01:00
Alex Stewart d038e2d837 Fix use of NESDIS with SuiteSparse in tests if METIS is not found
Change-Id: I6da004d091a463485935b7f7fa45e56dfcd4341c
2022-07-08 15:26:10 +01:00
Sergiu Deitsch 027e741a1a Eliminated MinGW warning
Change-Id: I35a852e742cc7d678c3af40e1bcd8a4f962303ee
2022-06-26 05:09:09 +00:00
Sergiu Deitsch 4e5ea292ba Fixed MSVC 2022 warning
MSVC rightfully issues warning C4305: 'if': truncation from 'size_t' to
'bool' in a static_assert condition that implicitly converts sizeof
result to a boolean.

Change-Id: Ie3b913288bfeaa7a4b362ef7f83d2505ed368641
2022-06-24 00:12:09 +02:00
Alex Stewart 83f6e08530 Fix use of conditional preprocessor checks within a macro in tests
- These are non-standard C++, and whilst they are accepted by GCC and
  Clang on *NIX and macOS, they are rejected by MSVC.

Change-Id: Ie627d74bb02ebdce3dc5e13c2010616c26cb5dea
2022-06-23 16:30:59 +01:00
Alex Stewart 70f1aac31f Fix fmin/fmax() when using Jets with float as their scalar type
Change-Id: Ie7f400763f91b0e264a50401716321587ab1d477
2022-06-23 16:05:58 +01:00
Alex Stewart 5de77f399e Fix reporting of METIS version
- Also fixes behaviour of EIGENMETIS option to match that of the other
  CMake dependency options, and ensure that its value aligns exactly
  with whether Eigen support for METIS will be compiled into Ceres.

Change-Id: Ifbf6f5d82b9ba89a156673eb6042519a985e6b04
2022-06-22 19:20:40 +01:00
Alex Stewart 11e6376675 Fix #ifdef guards around METIS usage in EigenSparse backend and tests
Change-Id: Idd1e0b7b1b2df2d402431b107dee0fa8e0fd58f5
2022-06-22 19:05:30 +01:00
Sergiu Deitsch 0c88301e66 Provide optional METIS support
* Split `CERES_NO_METIS` into two defines: `CERES_NO_PARTITION` and
  `CERES_NO_METIS`. The former refers to METIS support in SuiteSparse,
  the latter to the Eigen's MetisSupport module. This enables the use of
  sparse matrix reordering independent from SuiteSparse.
* Run Linux, macOS, and macOS Github workflows with METIS enabled
  SuiteSparse.

Fixes #808

Change-Id: I5076b7e1268d32cc3e7e56650edcbaf7fb3b59ce
2022-06-22 16:46:02 +00:00
Alex Stewart f11c256265 Fix fmin/fmax() to use Jet averaging on equality
- Prior to 48cb54d1, Ceres' fmin/fmax() for Jets followed the convention
  of std::min/max(), and always returned the first argument on equality,
  irrespective of whether this argument was natively a scalar or a Jet.
- After 48cb54d1, Ceres' fmin/fmax() instead returned the second
  argument on equality, again irrespective of whether this argument was
  natively a scalar or a Jet.
- Now on equality we average the arguments as Jets, which ensures that
  a consistent answer is produced irrespective of the ordering or type
  (Jet or scalar) of the input arguments. This also ensures that we
  preserve a non-zero derivative where it exists, excluding the edge
  case of two Jet inputs with equal but oppositely signed infinitesimal
  components.
- We retain the behaviour introduced in 48cb54d1 whereby NaNs are
  treated as missing values, following the convention of
  std::fmin/fmax().
- Raised as issue #816.

Change-Id: I01217c0e32c1be83be440e4515b57c79dd290923
2022-06-22 14:19:55 +01:00
Joydeep Biswas b90053f1ad Revert C++17 usage of std::exclusive_scan
* Unfortunately on some systems such as the Nvidia Jetson, while the
  compiler supports C++17, the STL implementations are incomplete.
  One such missing implementation is std::exclusive_scan, so this
  patch reverts to the old way of manually computing prefix sums.

Change-Id: I4192257519b0083560a4b44e2659ee44d7421105
2022-06-12 11:24:08 -05:00
Sergiu Deitsch dfce1e128d Link against threading library only if necessary
1. The platform specific threads library is only needed if we actually
   use threads. In this case, the library is not optional opposed to
   previous logic.
2. Do not hide the find module output to allow the user to understand
   what happens in case of a CMake failure to locate Threads.
3. Finally, Threads is private dependency that does need to be
   propagated to consumers unless Ceres was compiled as a static
   library.

Change-Id: I8d9d9cd42930e1ed234f69a2dba70d0ee2755b4e
2022-06-08 00:03:41 +02:00
Sergiu Deitsch 69eddfb6da Use find module to link against OpenMP
Depending on the compiler in use, linking against OpenMP may require
passing specific compiler flags instead of linking against a library.
Use the CMake OpenMP find module to abstract OpenMP activation.

Change-Id: Ib43f576ac12e2c5e9598e9586df3dfa018e9c08b
2022-06-07 23:39:39 +02:00
Sameer Agarwal b4803778c3 Update documentation for linear_solver_ordering_type
Also update obsolete documentation related to building and
using sparse linear algebra libraries.

Change-Id: I83682b43472e6a6ec4e4dad32fa21c089d518c06
2022-06-07 14:08:26 -07:00