Commit Graph

1345 Commits

Author SHA1 Message Date
Sameer Agarwal 6b9a690009 ClangTidy cleanup part 1
Change-Id: Id592fc68b8f184cd002df9d94a68d05fbbf9c24d
2024-07-21 14:55:46 -07:00
Sameer Agarwal 68eeba2c2c Add a missing include
Change-Id: I3060e80a69374f7a2db31121715d0d892a54d311
2024-07-21 13:25:45 -07:00
Sameer Agarwal 1e19a11f5f Add a missing include
Change-Id: I0a3fa842183bc7cb9ba00b17d6181cebc3eac50d
2024-07-21 08:24:31 -07:00
Sameer Agarwal de4ea5b4c7 Add a missing override
Change-Id: I6f610d187551fb3dca57912681e0e37eea26723f
2024-07-21 08:20:19 -07:00
Sameer Agarwal 7566ebae08 Various cleanups
Change-Id: Ie453e199a128a102bf3d5524a466f549aac0c7ce
2024-07-21 08:14:08 -07:00
Sameer Agarwal 968079f9fa Remove ASSERT macros from non-void functions
Change-Id: I891e00671e7a3ddaecf006cacb93b48379b8d9c8
2024-07-18 14:04:24 -07:00
Sameer Agarwal 6016a69bd5 Remove a header added by mistake
Change-Id: I5138804540978d6dfd2206d10a32b9d20a756d3d
2024-07-18 11:45:16 -07:00
Sameer Agarwal 57e26182f3 Add more missing headers
Change-Id: I35875ca856b7b80c622562a1c14b4c8ced10f740
2024-07-18 11:37:07 -07:00
Sameer Agarwal ea4d8c63ef Fix an incorrect include
Change-Id: I5b19dc5d4203a0603f21f1db06f4edb7fe2b76c2
2024-07-18 11:08:39 -07:00
Sameer Agarwal 14e8118a36 Add a missing header to context_impl.cc
Change-Id: I7b6c564ac67926e91543a96bfd6362471de775c8
2024-07-18 10:22:18 -07:00
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
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
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
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 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 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
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 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
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 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
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
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
Dmitriy Korchemkin 8d875a312c Fix checks for CUDA memory pools support
Change-Id: Icc07625fc0e586e8798da48fa5edfde59487d702
2023-10-04 17:46:57 +00:00
Sameer Agarwal 399395c4f1 Miscellaneous ClangTidy fixes
Change-Id: Iba2f8b1dccb77cefde750e5079e609b2b2a3ec95
2023-10-03 11:52:09 -07:00
Dmitriy Korchemkin 0cea191d40 Move stream-ordered memory allocations
Change-Id: Ief116e4e77c7579612b99cf552f3d8fc54c1d42a
2023-09-29 23:02:47 +00:00
Dmitriy Korchemkin e6b2f532b4 Parallelize PSE preconditioner
Parallelization of remaining block-diagonal matrix-vector product and
vector operations makes parallel execution slightly faster

Before (Intel 8176 CPU, 10 iterations):
-----------------------------------------------------------------------
Benchmark                                                          Time
-----------------------------------------------------------------------
PSEPreconditioner...<problem-13682-4456117-pre.txt>/1_median   26677 ms
PSEPreconditioner...<problem-13682-4456117-pre.txt>/1_stddev    26.6 ms
PSEPreconditioner...<problem-13682-4456117-pre.txt>/2_median   31037 ms
PSEPreconditioner...<problem-13682-4456117-pre.txt>/2_stddev     191 ms
PSEPreconditioner...<problem-13682-4456117-pre.txt>/4_median   16915 ms
PSEPreconditioner...<problem-13682-4456117-pre.txt>/4_stddev    98.0 ms
PSEPreconditioner...<problem-13682-4456117-pre.txt>/8_median    9175 ms
PSEPreconditioner...<problem-13682-4456117-pre.txt>/8_stddev    44.1 ms
PSEPreconditioner...<problem-13682-4456117-pre.txt>/16_median   4974 ms
PSEPreconditioner...<problem-13682-4456117-pre.txt>/16_stddev   11.5 ms

After:
-----------------------------------------------------------------------
Benchmark                                                          Time
-----------------------------------------------------------------------
PSEPreconditioner...<problem-13682-4456117-pre.txt>/1_median   26609 ms
PSEPreconditioner...<problem-13682-4456117-pre.txt>/1_stddev    69.4 ms
PSEPreconditioner...<problem-13682-4456117-pre.txt>/2_median   29178 ms
PSEPreconditioner...<problem-13682-4456117-pre.txt>/2_stddev     367 ms
PSEPreconditioner...<problem-13682-4456117-pre.txt>/4_median   16152 ms
PSEPreconditioner...<problem-13682-4456117-pre.txt>/4_stddev     106 ms
PSEPreconditioner...<problem-13682-4456117-pre.txt>/8_median    8773 ms
PSEPreconditioner...<problem-13682-4456117-pre.txt>/8_stddev    41.5 ms
PSEPreconditioner...<problem-13682-4456117-pre.txt>/16_median   4800 ms
PSEPreconditioner...<problem-13682-4456117-pre.txt>/16_stddev   14.7 ms

Change-Id: Ib1d1b0c4edf9c556a9e996c49486d2726efcc558
2023-09-28 21:11:26 +00:00
Sameer Agarwal 41672dff8c Add end-to-end BA tests for SCHUR_POWER_SERIES_EXPANSION
Also tighten the value of eta to make the iterative schur
solvers work better. This is the default value used in
bundle_adjuster.cc

Fixes https://github.com/ceres-solver/ceres-solver/issues/864
Change-Id: I48258fbbe256d6e932aaea0078b566fcd63de2fb

Change-Id: Ia5ad252cae31f415a47495fb8769421ade355bc9
2023-09-28 09:51:04 -07:00
Sameer Agarwal bea2477010 Add a missing include dir to the cuda kernels target.
This was somehow overlooked in the last patch causing the cuda
built to break.

Change-Id: Ic447103b139f6a7b607d664d02b9cbae98072ace
2023-09-22 15:28:12 -07:00
Dmitriy Korchemkin 18ea7d1c21 Runtime check for cudaMallocAsync support
Change-Id: Ia0e347d99b005d805ff2351cdb8918cc1331fc24
2023-09-22 19:25:25 +00:00
Sameer Agarwal a227045be1 Remove cuda-memcheck based tests
cuda-memcheck has been deprecated and these tests will be reinstated
once we move to compute sanitizer.

Change-Id: I7e01cffdd00ffb7404dfef2a171ebaeca017cda8
2023-09-22 06:09:04 -07:00
Sameer Agarwal d10e786ca8 Remove an unused variable from CudaSparseMatrix
Change-Id: Id9c969fda8d636dc793b98b452b2aaffacb11180
2023-09-21 22:33:38 -07:00
Sameer Agarwal 5a30cae583 Preparing for 2.2.0rc1
1. Add a version history
2. Update copyright years across the code base
3. Run format_all.sh
4. Update version strings from 2.1.0 to 2.2.0 in the docs and
   elsewhere.

Change-Id: I46d8d479d54bd6002d532785e67342106e73c9ac
2023-09-21 11:23:38 -07:00
Mark Shachkov 9cca671273 Enable compatibility with SuiteSparse 7.2.0
Change-Id: I072dc3f7c245fc2ebbdffed715ac4def20f7dccd
2023-09-17 20:57:43 +02:00
Sergiu Deitsch a57e35bbab Require at least CMake 3.16
Given we no longer support Ubuntu 18.04 due to packaged GCC lacking
C++17 support we can bump the minimum required CMake version to the one
provided by Ubuntu 20.04 which is CMake 3.16. Consequently, this allows
to drop some of the legacy CMake logic.

Change-Id: I1f05d4c5681d10aa7faa0800ef4a803be2f5b7dd
2023-09-12 19:33:00 +02:00