Commit Graph

2148 Commits

Author SHA1 Message Date
Sameer Agarwal 0a53aa9054 Take abseil as a dependency
1. Add abseil-cpp as a submodule. We are tracking the latest LTS
release, which is lts_2024_01_16.
2. Replace glog/gflags with absl::log and absl::flags.
3. Remove miniglog
4. Also take a whack at making the bazel build work with
   abseil-cpp and gtest.

There are a number of TODOs in this CL that still need to be resolved.

Change-Id: I39355ed7d61375be4ebcbc8596d9cc70acc1c678
2024-07-18 00:24:49 -07:00
Sameer Agarwal 21b026aa2c Use googletest branch v1.14.x
Change-Id: I09d59a2690bd3c46595f8a4938f520add86e3a63
2024-07-09 23:00:07 +00:00
Sergiu Deitsch 8ef35d0245 Fix CTest build config parameter
Change-Id: I4b7aed9c96c07a4e2b2b58618eb5a2452c845ae2
2024-07-10 00:17:45 +02:00
Mark Shachkov 6fb3dae4ee Add cuDSS as sparse Cholesky solver
cuDSS could be used as an alternative for SuiteSparse and EigenSparse
in case if CUDA capable GPU is available.

Change-Id: I7a567093ce91363478118153e181134ed5804573
2024-07-09 20:23:18 +02:00
Sergiu Deitsch e47a42c295 Fix MSVC builds and test runs
Change-Id: I79f839b22985a6510965559af54209d89c8703a0
2024-07-08 23:48:13 +02:00
Mark Shachkov 540b1f2f7a Checkout git submodules during github CI runs.
Change-Id: Ie4e2d618ee70035004ddcaa40a31725a6a610091
2024-07-07 23:22:53 +02:00
Sameer Agarwal 6f2c319e0f Unbreak levenberg_marquardt_strategy_test
Add a missing quotation mark.

Change-Id: I9d7d3c3d6bd5ac616e0dc23f75845178294c45a6
2024-07-07 10:12:52 -07:00
Sameer Agarwal 894fd6903c Update the googletest version
We now use googletest as a git submodule instead
of the old way of converting it into a single header
and including it in the source.

This removes the dependence on googleflags for tests
to be enabled.

Change-Id: If25ea3ba7a39c2b8ba9c6effbed3e7173361b6b1
2024-07-07 09:15:27 -07:00
Sergiu Deitsch 7220e1d1e8 Use CUDA 12.5.1 in Windows Github workflow
Change-Id: I48b077d436ad67afd1e3b8bb7472997355965a12
2024-07-07 14:13:11 +02:00
Markus Hess 7f9cc571b0 Set CMAKE_CUDA_ARCHITECTURES depending on CUDAToolkit_VERSION
Compilation fails if the CUDA architecture is not supported by the
installed version of the CUDA toolkit. This commit sets the
CMAKE_CUDA_ARCHITECTURES depending on the the installed CUDA toolkit
version.

Change-Id: I4765512279ee56897388e6ea22b961aebeb0fbca
2024-06-06 12:44:55 +00:00
Sameer Agarwal 6a74af202d Remove a level of indirection when using CellInfo
The CellInfo struct contains a mutex, which interacts poorly
with some standard library containers which may move things around.
As a result we were using std::unique_ptr<CellInfo> in these
containers, but this change gets rid of that level of indirection
as std::unordered_map can construct CellInfo in place and we can
replace the use of std::vector with an array we know will not be
resized.

This improves the performance of the schur eliminator a bit but
also the performance of the block diagonal preconditioners.

Change-Id: If3ccd1273a754d9c5112e6e611ce31066b6b27b5
2024-05-30 15:53:02 -07:00
Sergiu Deitsch f8c2994dad Drop Ubuntu 20.04 and add Ubuntu 24.04 support
Change-Id: I34cb0032598c84820ead2cde8e0a083d82d0e1ce
2024-05-21 23:19:10 +02:00
Sergiu Deitsch 20954e693f Eliminate CUDA set but unused variable warning
This avoids warnings such as

    D:\a\ceres-solver\ceres-solver\internal\ceres\cuda_kernels_bsm_to_crs.cu.cc(143): warning #550-D: variable "row_nnz_e" was set but never used [D:\a\ceres-solver\ceres-solver\build_Release\internal\ceres\ceres_cuda_kernels.vcxproj]
          int row_nnz_e = 0;
              ^
                detected during instantiation of "void ceres::internal::RowBlockIdAndNNZ(int, int, int, const int *, const ceres::internal::Cell *, const ceres::internal::Block *, const ceres::internal::Block *, int *, int *, int *) [with partitioned=false]" at line 240

      Remark: The warnings can be suppressed with "-diag-suppress <warning-number>"

that is caused by compile-time conditional use of the variable.

Change-Id: I041b076a5208eeb662b8c7500d7b238965be833c
2024-05-21 23:15:31 +02:00
Sergiu Deitsch 57aba3ed0c Enable Apple linker library deduplication
CMake 3.29 introduced policy CMP0156
(https://cmake.org/cmake/help/v3.29/policy/CMP0156.html) allowing to
avoid linker warnings such as

  ld: warning: ignoring duplicate libraries: '-ldl', '-lm', 'lib/libceres.a', 'lib/libgtest.a'

Fixes #1010

Change-Id: I6c3cf15382c5de4c005bcb28ac6931196f00fe48
2024-05-21 23:12:10 +02:00
Sergiu Deitsch 1f15197be1 Drop macos-11 runner and support macos-14 instead
Change-Id: Ie2958fa64f8c76ef6cc58af3da62dbc0607ba52a
2024-05-21 21:11:07 +00:00
Sergiu Deitsch 5de0fda0f2 Update Github actions
This avoids nodejs deprecation warnings.

Change-Id: I6f2c63332018c1483ad3c6d37e87970a4d557533
2024-05-21 23:04:32 +02:00
Sergiu Deitsch 308a5bb434 Add missing include
std::copy_n is defined in <algorithm>, which is not explicitly included
and therefore causes compilation errors with the recent GCC 14.1 and/or
CUDA 12.4.1.

Change-Id: I9fcab48770ccfc5ec195dca5a190ceaad9debe81
2024-05-21 23:01:01 +02:00
Sergiu Deitsch 715865101c Remove 32-bit MinGW from CI matrix
32-bit MinGW is being phased out:

https://www.msys2.org/news/#2023-12-13-starting-to-drop-some-32-bit-packages

With eigen3 and glog packages now removed, Ceres Solver no longer can be
built using stock MinGW. Therefore, we remove the support altogether.

Change-Id: I42d4ca3d15e7f3a5ddfa2eae409db7d87aed99ea
2024-05-21 22:45:48 +02:00
Sameer Agarwal f71181a92d Remove remaining references to CXSparse
Also remove examples/Makefile.example as it is hopelessly
out of date.

Change-Id: I2ed2f0c4768eacbf65cf76299c7a8b3474eb750b
2024-05-21 12:20:49 -07:00
Mark Shachkov 522210a08d Reuse macro to format version string
Change-Id: Ib21f2d8f06b6594dae410681d16a738b8b75c89a
2024-05-07 01:47:41 +02:00
Johannes Schönberger cd2dd06e9a Fix clang16 compiler warnings
Fixes the following two warnings:

preconditioner.h:64:11: warning: field 'f_block_size' will be initialized after field 'elimination_groups' [-Wreorder-ctor]
block_sparse_matrix.cc:70:19: warning: unused parameter 'values' [-Wunused-parameter]

Change-Id: I5cc55ca387b3f12259096c1531c263279650bd49
2024-04-22 17:22:03 +00:00
Yuriy Chernyshov 1f2e6313a5 Add missing std qualifiers
Change-Id: Ib7bc432c56f7a8ba062a6d74a206733872c3d089
2024-04-22 17:20:54 +00:00
Markus Heß 125c068829 Link static cuda libs when ceres is build static
Change-Id: I8821a2df5302cf164b6f80d6787ae795691d6b32
2024-04-03 11:09:40 +02:00
Sameer Agarwal 62c03d6ff3 Revert "Update Eigen::BDCSVD usage to comply with Eigen 3.4"
This reverts commit 4027f69975.

Reason for revert: This breaks the build because this constructor syntax is only present in the unstable/development version of eigen. So the macro check is incorrect.

Change-Id: I1e664208c7c50041e295aeb7c4b65259f9f2fc8f
2024-02-01 05:00:25 +00:00
Xiaodong Huang 4027f69975 Update Eigen::BDCSVD usage to comply with Eigen 3.4
Change-Id: Ida9360071056cbbc8cf3dff4dd34e6a3119200d4
2024-02-01 08:32:49 +08:00
Sameer Agarwal 1b2ebabf5d Typo fixes in the documentation
Contributed by @sarlinpe

Change-Id: I26435bbcb4b99886c7df76cfb798fcf13589db2d
2024-01-30 09:11:24 -08:00
MaximSmolskiy 2ffeb943ad Fix typo in AutoDiffManifold comment and docs
Change-Id: I0b50e3e10661578e68f713e34a59f65b3692e745
2024-01-29 03:19:37 +03:00
Sameer Agarwal da34da3da2 Remove CreateFakeBundleAdjustmentPartitionedJacobian
This function is not used and is not written correctly to
deal with the case wherre Schur specialization is disabled.

Change-Id: I48509317e6df5f9cdc37c81e879fad425bb2d037
2024-01-26 11:58:00 -08:00
Sameer Agarwal 85b2c418a6 ClangTidy fixes
Change-Id: I127f50920ee1f1754b94763b5d3cb01a24aa28cb
2024-01-23 09:16:36 -08:00
Sergiu Deitsch 91773746be Simplify instantiation of cost functions and their functors
If arguments are passed to a cost function that can be used to construct
the functor, the latter will be instantiated by the cost function using
std::make_unique to ensure exception safety. This not only avoids static
analysis warnings caused by calling new but also spelling the cost
functor type name multiple times.

Also expand deduction guides for instantiating
Dynamic(Auto|Numeric)DiffCostFunction from std::unique_ptr enabled
constructor overloads.

Finally, make CostFunction default move constructible and assignable but
only through derived classes. This in turn allows derived classes to be
movable without relying on custom implementations of corresponding
operators.

Change-Id: Idee8b9871d862bc9f9f8b5a8d0bedc52863e93c0
2024-01-23 01:34:27 +01:00
Sergiu Deitsch 8b88a9ab49 Use C++17 Bessel functions
Move Bessel functions availability checks from configuration time to
inclusion time to be more robust and allow the use of ABI compatible
compilers (e.g., Ceres is compiled using Clang but is used in a project
compiled using GCC.)

Since libc++ does not yet implement special math functions, we fallback
to their POSIX implementation if available. However, then only the
deprecated BesselJ{0,1,n} are provided.

Fixes #814

Change-Id: Ic3e62452b36e90cb22644cc8e553e3dd1881193f
2024-01-22 20:42:59 +01:00
Sergiu Deitsch 84436f791c Use native CMake TBB package configuration
Starting Ubuntu 20.04, TBB is shipped with a native CMake package
configuration making the find module contained in Ceres no longer
necessary.

Fixes #1036

Change-Id: Ia1a18d004aa53dd0b654a8cd94daea60ea1feb98
2024-01-19 18:51:24 +00:00
Sergiu Deitsch 556a56f21f Do not assume Homebrew usage
Let the user decide whether Homebrew packages are to be used.

Fixes #1038

Change-Id: I5cab1cc447f3fe570a8c02d20add465606e6d726
2024-01-17 21:00:05 +01:00
Sergiu Deitsch 3fd2a72cc5 MinGW no longer provides a 32-bit METIS package
Change-Id: I63b6efd29589b68cf4d16b1ef41c85b3ee437063
2024-01-17 20:48:53 +01:00
Sameer Agarwal e776a6f1a1 Unbreak the Bazel build.
The build was broken because parallel_for.cc was deleted
and new file parallel_vector_ops.cc was added.

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

Change-Id: I5b7a03b97134da55d408e57747634a5943a0e0aa
2024-01-16 16:56:17 -08:00
Dmitriy Korchemkin 095d483927 Skip structure detection on preprocessor failure
Change-Id: I679ff2045ab0ac5da64e72d87e0c78054369da5c
2023-10-28 18:45:44 +00:00
MaximSmolskiy a0876309a6 Fix typos in comments
Change-Id: I17faeb9b9a4cd40de7651eea3ff011e48910f059
2023-10-22 00:23:58 +03:00
Sameer Agarwal 7749737319 Fix search on ceres-solver.org
Thanks to Roger Labbe for reporting this and Sergiu Deitsch for
debugging it

Change-Id: I7f53b339a1e4d6862b341c60bcf81b77770052bf
2023-10-13 14:26:12 -07:00
Sameer Agarwal 85331393dc Update docs for 2.2.0.
Change-Id: Ib8fd3918d7bfda52212aa02c3c7573eb4dace270
2.2.0
2023-10-12 18:12:09 -07:00
Sameer Agarwal 2120eae674 Optimize the computation of the LM diagonal in TinySolver
This eliminates an entire vector and computation of a square root
followed by a squaring.

Thanks to @rlabbe for pointing this out.

Change-Id: I0de117b31b9332c61e687f18466d7cb2e2ac611e
2023-10-11 15:14:33 +00:00
Dmitriy Korchemkin 611b139b1b Fix Solver::Options::callbacks type in documentation
Change-Id: I66374bd1b45670a1bcd5924287d855d9c44826e2
2023-10-11 14:30:10 +00:00
Sameer Agarwal b652d3b4f1 Unbreak the windows build
Change-Id: Ia838b94c7ce1bad178200ce705f02b460b0f266d
2023-10-09 15:10:37 -07:00
Sameer Agarwal b79c4d3505 ClangTidy fixes
Change-Id: I26a8bbce337dbd0b5fc18bc1345d9ccbee275080
2023-10-09 09:29:49 -07:00
Sameer Agarwal 76af132d02 Update docs for 2.2.0RC3
Change-Id: I56a7ac2fdc33293c5abb3685de21811caa37997c
2.2.0rc3
2023-10-09 08:59:17 -07:00
Dmitriy Korchemkin dc7a859752 Single-threaded operations on small vectors
As pointed out by several users, introduction of parallel operations on
vectors severely impacts solver performance on small problems, with time
consumption increasing with the number of threads.

In order to minimize overhead of trying to execute small tasks using a
large number of threads, task scheduling mechanism was changed to avoid
scheduling all tasks at once.

However, there is still a large difference in exectuion time because the
main thread always launches the next thread before starting doing the
work. This leads to several orders of magnitude slowdown when going from
a single-threaded execution (which follows a fast-forward path to a
single loop over all indices, without any synchronization involved)
to a two-thread execution:

/bin/parallel_vector_operations_benchmark
-------------------------------------------
Benchmark                              Time
-------------------------------------------
SetZero/128                         12.8 ns
SetZeroParallel/128/1               16.6 ns
SetZeroParallel/128/2               2211 ns

In order to eliminate this effect, we limit the block-size of parallel
execution of vector operations to 2^16 elements (thus, starting parallel
execution only for vectors of at least 2^17 elements).

Threshold of 2^16 elements was choosen by evaluating thresholds from
2^10 to 2^20 (only powers of 2), with 2^14..2^20 significantly reducing
worst-case runtime degradation.

Details can be found in discussion of the issue at
https://github.com/ceres-solver/ceres-solver/issues/1016

Change-Id: I555c882d63ee53323ceb426743b970f989b65503
2023-10-09 13:55:30 +00:00
Sameer Agarwal b379ab768c Remove MaxNumThreadsAvailable
It is just a wrapper around ThreadPool::MaxNumThreadsAvailable
and has just one callsite.

Change-Id: Ic4b496c86a9760d1024ff34db305ea8db99705d8
2023-10-09 05:59:28 -07:00
Dmitriy Korchemkin 354002f989 Schedule task in ParallerFor from the previous task
As pointed out by several users, introduction of parallel operations on
vectors severely impacts solver performance on small problems, with time
consumption increasing with the number of threads.

The problem is two-fold:
 - Single-threaded execution is faster than multi-threaded
 - Overhead of multi-threaded execution increases dramaticaly when
   number of threads is increased

Supposedly, the second problem is due to ParallelInvoke scheduling
a task for each thread via ThreadPool.
When the time required to perform computations is smaller than costs of
scheduling task, runtime becomes linear in num_threads.
Moreover, main thread competes with working threads for mutex in
ConcurrentQueue.

In order to limit scheduling overhead and minimize lock contention,
each new task is scheduled from the previous one, if:
 - Number of scheduled tasks is less than num_threads
 - At the moment of creating the task not all work has been done

Correctness is granted by atomicity of thread_id counter.

SchedulerBenchmark mini-benchmark was added to illustrate the issue.
Each iteration of parallel loop performs change of a single value.

With the previous scheduling strategy, increasing number of threads
leads to significant increase of runtime:
-----------------------------------------------------
Benchmark                           Time   Iterations
-----------------------------------------------------
SchedulerBenchmark/128/1         14.1 ns     49496153
SchedulerBenchmark/128/2         3965 ns       240173
SchedulerBenchmark/128/4        13162 ns        71478
SchedulerBenchmark/128/8        30643 ns        29614
SchedulerBenchmark/128/16       63694 ns        10000
SchedulerBenchmark/256/1         24.1 ns     28943598
SchedulerBenchmark/256/2         3878 ns       227498
SchedulerBenchmark/256/4        13293 ns        69817
SchedulerBenchmark/256/8        31117 ns        32640
SchedulerBenchmark/256/16       59503 ns        14910
SchedulerBenchmark/1024/1        56.7 ns     12048398
SchedulerBenchmark/1024/2        4346 ns       203140
SchedulerBenchmark/1024/4       13487 ns        66736
SchedulerBenchmark/1024/8       30982 ns        33090
SchedulerBenchmark/1024/16      63199 ns        14762
SchedulerBenchmark/4096/1         189 ns      3633540
SchedulerBenchmark/4096/2        5932 ns       131884
SchedulerBenchmark/4096/4       14784 ns        61236
SchedulerBenchmark/4096/8       35857 ns        29276
SchedulerBenchmark/4096/16      63934 ns        10000

With new scheduling strategy, increasing requested number of threads
does not result in that high increase of runtime
-----------------------------------------------------
Benchmark                           Time   Iterations
-----------------------------------------------------
SchedulerBenchmark/128/1         14.1 ns     49323498
SchedulerBenchmark/128/2         2411 ns       362916
SchedulerBenchmark/128/4         3556 ns       243026
SchedulerBenchmark/128/8         4346 ns       200626
SchedulerBenchmark/128/16        5066 ns       169698
SchedulerBenchmark/256/1         24.2 ns     28960018
SchedulerBenchmark/256/2         2330 ns       388470
SchedulerBenchmark/256/4         3864 ns       219233
SchedulerBenchmark/256/8         4399 ns       195225
SchedulerBenchmark/256/16        5111 ns       161858
SchedulerBenchmark/1024/1        55.9 ns     12204777
SchedulerBenchmark/1024/2        2541 ns       329807
SchedulerBenchmark/1024/4        3977 ns       222628
SchedulerBenchmark/1024/8        4607 ns       193548
SchedulerBenchmark/1024/16       5031 ns       160285
SchedulerBenchmark/4096/1         188 ns      3714433
SchedulerBenchmark/4096/2        4203 ns       188284
SchedulerBenchmark/4096/4        4832 ns       171811
SchedulerBenchmark/4096/8        5605 ns       159093
SchedulerBenchmark/4096/16       6425 ns       126861

(both runs were executed on 28-core 56-thread cpu)

Change-Id: I91eca783280598997bfe6abd28019847731692e4
2023-10-06 20:25:16 +00:00
Sameer Agarwal a9b3fcff42 Minor update to docs
Change-Id: I886f5aa1614f66b57d7fa33233afca9bb7fabb72
2023-10-05 09:12:33 -07:00
Sergiu Deitsch 5ccab18be9 Drop use of POSIX M_PI_2 and M_PI_4
Change-Id: I310fcf3c3c369d46b2c7b1be0831e48eb559fb9d
2023-10-05 00:26:46 +02:00
Sergiu Deitsch 4519b8d774 Drop use of POSIX M_PI
Change-Id: I37342a366161bb13d6456ecc67569fe12705e05c
2023-10-04 22:59:15 +02:00