Commit Graph

1800 Commits

Author SHA1 Message Date
Sameer Agarwal 4ad787ce19 Fix the bazel build
Change-Id: I38c684b816b5e377aa873cf35d13b1181aa152db
2022-02-27 07:50:56 -08:00
Sameer Agarwal ae4d95df6e Two small clang-tidy fixes
Change-Id: I1eb3b5aabc9586958d618c680ca1a2c6ed501fd4
2022-02-27 05:41:07 -08:00
Sergiu Deitsch f0851667be Fix MSVC compilation errors
Disable the definition of `min`/`max` macros by defining `NOMINMAX`
and prevent macro substitution in the public interface.

Also, quiet floating-point comparisons are defined as template functions
by the MSVC STL which causes compilation errors due to ambiguities in
resolving the template parameter types.

Fixes #668
Fixes #716
Fixes #718

Change-Id: I5fe7832a6a3a7ad0421a2557527528c34b88e9c7
2022-02-27 13:24:42 +01:00
Sergiu Deitsch c8658c8992 Modernize more
Apply clang-tidy Google and modernize fixes without trailing return type
using:

$ clang-tidy -p <build-dir> \
  -checks='-*,google-*,modernize-*,-modernize-use-trailing-return-type' {} -fix

Change-Id: I7450cc58ea9abf928f73a467e87876083217fa26
2022-02-26 22:16:56 +00:00
Sergiu Deitsch 46b3495a4f Standardize path handling using GNUInstallDirs
Fixes #649

Change-Id: Iefb3e7be69a04474db0fc768b47f4f3636c8a587
2022-02-25 23:59:34 +00:00
Alex Stewart 98bc3ca17a Fix shared library build due to missing compile features specification
Change-Id: Ib4c7f0b18b8770ab8cb09b15b9cc17f90042ceb0
2022-02-25 19:07:21 +00:00
Sameer Agarwal 8fe8ebc3a6 Add final specifier to public classes
Change-Id: Ib7291dc68d5d4141ee821689743481fc84768606
2022-02-18 15:51:17 -08:00
Sameer Agarwal 84e1696f4e Add final specifier to internal classes.
This should help the compiler devirtualize a bunch of function
calls.

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

Change-Id: I9913e68d85e0e9c9f955a249cc710a657875c869
2022-02-18 18:07:06 +00:00
Sameer Agarwal 518970f81e Context should be exported
Change-Id: I451a7f471a6b93d1d32dc003adaa3c5c315fef9f
2022-02-18 09:54:40 -08:00
Sergiu Deitsch 09ec4997fa Cleanup examples
Remove logic invoked based on obsolete variable definitions. Use new
(explicit) target_link_libraries syntax to link binaries against
dependencies. Do not rely on prior knowledge about the compiler for
specifying flags and system libraries but instead directly test their
presence to be more robust.

Change-Id: I76e0d10fae6eba4b343048e4404f0a9b08c7cb6c
2022-02-18 00:53:44 +01:00
William Rucklidge 90e58e10fd Add missing #include.
Change-Id: If32d858c9d9eec9f53753007e0831e56f25d32d4
2022-02-17 11:40:45 -05:00
Sameer Agarwal 15348abe90 Add CUDA based bundle adjustment tests.
Also refactor the logic for generating ba tests a bit
breaking it into dense, sparse and iterative tests.

Change-Id: I6b33e3b047ef900b12907bd150febe4744779b7a
2022-02-15 12:36:18 -08:00
Sergiu Deitsch 57ec9dc92e Do not enforce a specific C++ standard
Current language standard selection mechanism is quite convoluted and
the logic for propagating a specific C++ language standard (which cannot
be fully enforced anyway) is unnecessarily complicated. Instead
communicate the minimum required C++ standard and let CMake handle the
requirement. This allows the compiler and consumers to use newer
language revisions if available. The language standard used to compile
Ceres solver can still be set via `CMAKE_CXX_STANDARD`.

Move to CMake 3.10 which is supported by Ubuntu 18.04 LTS and simplify
the corresponding language features request.

Change-Id: Ib1f95e2bc5f06bf1275a62565d303eb0f114d127
2022-02-15 21:14:29 +01:00
Sergiu Deitsch 99698f0535 Fix Apple Clang weak symbols warnings
Change-Id: I71eba56ca37060c83d05ff14d6f9bfaef61e9493
2022-02-15 21:00:22 +01:00
Joydeep Biswas 8e08421628 Add support for dense CUDA solvers #3
1. Add CUDA initialization and cleanup management to the
   ContextImpl object. The ContextImpl is now solely responsible
   for managing CUDA-related resources.
2. All CUDA dense solvers now use lazy CUDA initialization
   via the ContextImpl object.

Change-Id: Ief456860c72e462367ee997d389c19e2bff50baf
2022-02-15 13:26:12 -06:00
Sameer Agarwal aff51c907d Revert "Do not enforce a specific C++ standard"
This reverts commit d839b77928.

Reason for revert: Breaks the BUILD on macOS

Change-Id: I49f448ed4942cc88df9e4ad3b78d56f6be04351d
2022-02-15 19:17:02 +00:00
Sergiu Deitsch 527c3f7da0 Fixed gflags dependency
Both test_util and gtest depend directly on gflags.

Change-Id: Ia3699f4710cb86710ffd547149ffa08e678f6df9
2022-02-15 19:44:05 +01:00
Sergiu Deitsch d839b77928 Do not enforce a specific C++ standard
Current language standard selection mechanism is quite convoluted and
the logic for propagating a specific C++ language standard (which cannot
be fully enforced anyway) is unnecessarily complicated. Instead
communicate the minimum required C++ standard and let CMake handle the
requirement. This allows the compiler and consumers to use newer
language revisions if available. The language standard used to compile
Ceres solver can still be set via `CMAKE_CXX_STANDARD`.

Move to CMake 3.10 which is supported by Ubuntu 18.04 LTS and simplify
the corresponding language features request.

Change-Id: Id3526c69990315289e7ea0fbcdeaa6af79d24d03
2022-02-15 19:10:51 +01:00
Sergiu Deitsch f71167c628 Fixed missing include in minilog build
Change-Id: Ib4ff0595a6a496848922d9cb8462b2cd4cb83e99
2022-02-15 17:17:05 +00:00
Sameer Agarwal 47502b8339 Miscellaneous CUDA related changes.
1. Fix a stupid error in types.cc
2. Update documentation for Solver::Options::dense_linear_algebra_library_type
3. Add a note to installation.rst to update the installation docs.
4. Mention GPU acceleration in features.rst

Change-Id: Id63202ff090e23bbb211d2ee458559fb8046281d
2022-02-14 21:45:34 -08:00
Sameer Agarwal bb29966810 Check CUDA is available in solver.cc
Add logic for checking for availability of CUDA as the
dense linear algebra library before allowing the user
to use it.

Change-Id: I0ceafa1052632504b33685bc731366ef6933e518
2022-02-14 13:47:47 -08:00
Joydeep Biswas 7d2e4152ec Add support for dense CUDA solvers #2
1. Add CUDADenseQR & tests.
   CUDADenseQR uses the cuSolverDN LAPACK implementation
   of QR factorization. A key limitation, however, is that
   this solver does not perform singularity checking --
   this is because cuSolverDN does not have a trtrs
   implementation; we instead use cuBLAS' trsv for
   backsubstitution.
2. All CPU -> GPU memory transfers are now async, and both
   CUDADenseQR and CUDADenseCholesky explicitly manage their
   own streams for async operations.
3. Simplified CUDADenseCholesky to only use the legacy 32-bit
   cuSolverDN API.

Change-Id: I2a9b7b65469658ddfe33b5b2a3892c8744d6e437
2022-02-14 15:22:39 -06:00
Sergiu Deitsch f90833f5fa Simplify symbol export
Currently, the logic for exporting symbols is rather complicated: when
tests are enabled internal symbols are exported in addition to the
public symbols. Such logic causes several problems. (1) Test binaries
link against a Ceres build that is different from the final release
since fewer optimizations are applied if more symbols are exported. (2)
Also, some toolchains hide symbols by default breaking the existing
logic eventually causing linker errors.

Since internal symbols are not intended to be used outside of the
project, we can compile them into object files and use exactly the same
binary code both for the final build and the tests without relying on
conditionals.

By default, all symbols are now hidden unless annotated as public.
Internal symbols are explicitly marked as not being exported in case
users chose not to hide symbols by default.

Change-Id: I589dd10be2f6f438508783cf99d141af0120057b
2022-02-14 20:19:08 +01:00
Sergiu Deitsch c6158e0ab5 Replace NULL by nullptr
Change-Id: I200a40678091b984a01635d8637a487b7ad5cc13
2022-02-14 19:22:21 +01:00
Sameer Agarwal 7e4f5a51ba Remove blas.h/cc as they are not used anymore.
Change-Id: I120631c8fc66ddee5829b89bb5b98dc2ac80ff1f
2022-02-14 09:36:16 -08:00
John Harrison e0fef6ef05 Add cmake option ENABLE_BITCODE for iOS builds
Change-Id: Ib56c711c626044754c1c3a397d7c4648c4ec089d
2022-02-13 15:54:24 +00:00
Sameer Agarwal 446487c54c Add <memory> header to all files using std::unique_ptr.
Fixes https://github.com/ceres-solver/ceres-solver/issues/758

Change-Id: I884819ec62cf7dcb95368eb46f3c03a46bb5243f
2022-02-12 08:12:05 -08:00
Sameer Agarwal 9c5f29d46d Use compiler attributes instead of [[deprecated]]
This change is needed because compiler attributes and c++
annotations like [[deprecated]] do not mix well and we need that
for our public API.

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

Change-Id: I79eda795f2912f9af9ab36ee24b8428b47104743
2022-02-11 09:29:21 -08:00
Sameer Agarwal 44039af2cb Convert factory functions to return std::unique_ptrs.
https://github.com/ceres-solver/ceres-solver/issues/755

Change-Id: I8ff028ca6082a5f448f3891214af03971d565937
2022-02-10 16:16:37 -08:00
Sergiu Deitsch 708a2a7233 Silence LocalParameterization deprecation warnings
Suppress warnings in all Ceres targets without leaking suppressions into
user code (fixes #750).

Change-Id: I3aa1063cb0aae547865a15311ac286ef6d81a955
2022-02-10 20:55:25 +00:00
Sergiu Deitsch de69e657a6 Fix another missing declaration warning
Change-Id: I895e16f3e43792bd7f92560709f9ebf6374c4777
2022-02-10 20:53:19 +01:00
Sergiu Deitsch 677711138a Fix segmentation fault in AVX2 builds
Enabling the AVX2 instruction set causes a segmentation fault in mocked
manifold tests. This is due to Eigen vectors stored in a std::shared_ptr
for which the memory allocated by gmock is not aligned even though it is
expected to be by Eigen for correct use of packet math.

The problem does not occur if Ceres is compiled with C++17 (or later)
enabled due to the support for aligned new allocations.

Change-Id: I711abe9439cc411bd7a8b4936f3b93af07b7fbd6
2022-02-10 16:21:55 +01:00
Sameer Agarwal 0141ca090c Deprecate LocalParameterizations
Add [[deprecate]] notices to everything LocalParameterization
related.

Make sure that Ceres can be compiled without triggering
deprecation warnings.

Update the documentation:

a. Add deprecation notices.
b. Document interaction between LocalParameterization and Manifold
   coexisting in the Problem.
c. Add documentation for Manifold(s)

Change-Id: Ie4ad48963c83fded86e533c8c60561af402fbaff
2022-02-10 06:36:47 -08:00
Sergiu Deitsch fdfa5184a5 Fix missing declaration warning
Change-Id: I690b81af11bb98930d0a0d1c8d5d4d6d75f61bd3
2022-02-10 15:29:40 +01:00
Johannes Beck 4742bf3862 Add LineManifold.
This MR ports the LineParameterization of manifolds. The unit test are
rewritten to use the manifold test facilities.

The LineManifold is extended so that it can also handle dynamic size
ambient space dimensions.

Change-Id: I1fe3cd34b56f74b72ca028c34f5368e9df9fe4d7
2022-02-10 08:52:01 +01:00
Sergiu Deitsch c14f360e63 Drop trivial special members
Do not define trivial constructors or destructors unless necessary
(e.g., for implementing pimpl) following the rule of zero. Define
virtual base class destructors out-of-line to avoid emitting vtables in
every translation unit.

Change-Id: Iea2d8978e62a8ee5a97b86cbb4e858d56e0fb274
2022-02-09 21:30:14 +01:00
Sameer Agarwal ae65219e04 ClangTidy cleanups
1. NULL -> nullptr
2. foo.reset(new Bar) -> = foo = std::make_unique<Bar>()
3. Missing std library includes & prefixes

Change-Id: I260b261b484554be681ee5a7398126fdb3b3a789
2022-02-09 10:06:49 -08:00
Sergiu Deitsch a35bd1bf90 Use = default for trivial special members
Applied changes correspond to clang-tidy fixes
stemming from the modernize-use-equals-default check.

Change-Id: I254b0908a76d464131564b637cd0e42a6b03fb5a
2022-02-09 18:38:52 +01:00
Sameer Agarwal db67e621e4 Fix dense_cholesky_test.cc comma handling.
Change-Id: I61e73a99b089ac083d9b5f0c784aa1a3c5ee7a02
2022-02-08 17:13:05 -08:00
Sergiu Deitsch 484d3414e4 Replace virtual keyword by override
virtual can be ambiguous. Applied changes correspond to clang-tidy fixes
stemming from the modernize-use-override check.

Change-Id: I973afd4680a5df587419777504aeb94467196b89
2022-02-09 00:34:05 +01:00
Sameer Agarwal 2092a720ec Fix some nits.
Change-Id: I1af74d6ae8c6c368642989f1b1e857999264a454
2022-02-08 13:40:39 -08:00
Joydeep Biswas 36d6d86908 Add support for dense CUDA solvers #1
1. Add CUDADenseCholesky64Bit, CUDADenseCholesky32Bit, & tests.
   CUDADenseCholesky32Bit uses the legacy versions of potrf/potrs
   in cuSolverDN, while CUDADenseCholesky64Bit uses the new 64-bit
   versions available since Cuda 11.1. The legacy versions are
   provided since some platforms such as the Nvidia Jetsons only
   support Cuda 10.2.
2. Expose CUDA as a new option under DenseLinearAlgebraLibraryType.
   The relevant option to string and string to option helper functions
   are modified accordingly.
3. Add cuda as a dense_linear_algebra_library option in bundle_adjuster
   to demonstrate the use of the new CUDA option.

Change-Id: I23615e1d301df5185ed646b3e33ee802508dae86
2022-02-07 19:26:29 -06:00
Johannes Beck af5e48c71f Add SphereManifold.
This MR adds SphereManifold ported from
HomogeneousVectorParameterization. Additionally the minus operator
and jacobian evaluation was implemented.

The unit tests were almost completly reimplemented and uses the
test facilities provided for manifolds.

Change-Id: Iccf72a2333bc921ff24c4d831db35020c653ee86
2022-02-07 22:19:37 +01:00
Sergiu Deitsch 182cb01c57 Normalize Jet classification and comparison
Complete support for all floating-point classification functions
(fpclassify, signbit) and consistently apply all overloads recursively
to the scalar part of a Jet only. This is now inline with how comparison
operators work. Sanity checks of derivatives should be performed
explicitly on the dual part of a Jet due an ambiguity on reducing the
classification results of multiple values.

Provide an fdim overload (in addition to fmin and fmax) and support
quiet versions of comparison operators also applied recursively to the
scalar part of a Jet but without type promotion.

Additionally, deprecate Ceres legacy classification functions. New code
should use C++11 function names for consistency.

Finally, simplify expressions using introduced scalar classification and
comparison.

Change-Id: I397e37425760717b991eb7ae5da0892f20c5a365
2022-02-07 21:51:42 +01:00
Sameer Agarwal 9dbd289897 Loosen tolerances in dense_qr_test.cc
Change-Id: I97f093f5f374465ca40d2a1a774373a3718e3302
2022-02-07 12:20:35 -08:00
Sameer Agarwal cab853fd5f Add DenseQR Interface
1. Add EigenDenseQR & tests.
   This implementation now uses an in place decomposition,
   which means that we are not allocating, deallocating
   memory every call.
2. Add LAPACKDenseQR and tests.
   The LAPACK implementation instead of using dgels which is a
   routine which does the factorization and solve in one
   call, now uses dgeqrf for factorization and then
   dormqr and dtrtrs for solving. This allows us to
   have a factorize and solve interface like DenseCholesky.
   And opens the door to iterative refinement and mixed
   precision solves.
3. The refactor also allows us to simplify the interface to
   DenseSparseMatrix considerably. The internals of this
   class were complicated because we had the AppendDiagonal
   and RemoveDiagonal methods and we did not want to allocate
   deallocate memory every call. But since we pay the cost
   of the copy anyways, we can just hold that buffer
   in DenseQRSolver.
4. Delete lapack.cc/h
5. The net result is that everything seems to be a bit faster.
   For LAPACK we are not doing some of the scaling work that
   dgels was doing. For Eigen I think it maybe the inplace
   decomposition.

Benchmark                                                                     Time             CPU      Time Old      Time New       CPU Old       CPU New
----------------------------------------------------------------------------------------------------------------------------------------------------------
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/1/1                          -0.1154         -0.1159           692           612           691           611
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/2/1                          -0.1601         -0.1553           717           603           712           601
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/3/1                          -0.1673         -0.1575           733           610           724           610
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/6/2                          -0.1008         -0.1003           886           797           884           796
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/10/3                         -0.1489         -0.1514          1283          1092          1281          1087
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/12/4                         -0.1040         -0.1104          1556          1394          1553          1381
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/20/5                         -0.0007         -0.0097          1911          1910          1908          1890
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/40/5                         -0.1033         -0.1022          2981          2673          2957          2655
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/100/10                       -0.0147         +0.0015          9275          9138          9026          9040
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/200/10                       -0.1408         -0.1284         15093         12968         14778         12880
BM_DenseSolver<ceres::EIGEN, ceres::DENSE_QR>/200/20                       -0.0310         -0.0355         38973         37765         38837         37460
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/1/1                         -0.1228         -0.1256           736           646           731           640
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/2/1                         -0.1401         -0.1396           740           636           735           633
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/3/1                         -0.1731         -0.1695           744           615           738           613
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/6/2                         -0.1399         -0.1408          1121           965          1113           956
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/10/3                        -0.1110         -0.1145          1571          1397          1560          1382
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/12/4                        -0.1411         -0.1417          2006          1722          1993          1710
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/20/5                        -0.1740         -0.1729          2741          2264          2724          2253
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/40/5                        -0.0966         -0.1123          3462          3128          3425          3040
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/100/10                      -0.0387         -0.0998         10365          9964         10339          9307
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/200/10                      -0.2044         -0.2049         16031         12754         15998         12720
BM_DenseSolver<ceres::LAPACK, ceres::DENSE_QR>/200/20                      -0.2391         -0.2386         35777         27223         35716         27193

Change-Id: I782f0d7664efe1435eebda92ddf47a0fe66c9c72
2022-02-07 11:54:01 -08:00
Alex Stewart 8ae054ad91 Fix missing declaration warning in autodiff_manifold_test
Change-Id: I33326faaf3f204db5e9e255d87c82d83ec4b710f
2022-02-07 14:42:49 +00:00
Sameer Agarwal 408af7b1a8 Move the constructor and destructor for SchurComplementSolver
Change-Id: I277778d039b6acfe03e0c46f91bd71673f215345
2022-02-07 06:39:47 -08:00
Sameer Agarwal d51672d1cc Move the constructor and destructor for DenseSchurComplementSolver
Change-Id: I8d852c3e6af28d6d70742f0d1607154d47bec9bd
2022-02-07 06:26:07 -08:00
Sameer Agarwal 177b2f99dc Use benchmark version 1.6 compatible syntax.
This is needed to make the dense_linear_solver_benchmark.cc
compile with the currently stable versions of the benchmark
library available on various linux distributions.

Change-Id: I1e391d5c2d16250d213bcfa3d50f9560aad9a363
2022-02-07 05:54:13 -08:00