Commit Graph

2113 Commits

Author SHA1 Message Date
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
Sameer Agarwal b83abdcb19 Add a default value for Solver::Summary::linear_solver_ordering_type
Change-Id: I5c7c9acdc37ba0755d479ac9c6c2872fe89fb492
2023-10-04 13:26:20 -07:00
Dmitriy Korchemkin 8d875a312c Fix checks for CUDA memory pools support
Change-Id: Icc07625fc0e586e8798da48fa5edfde59487d702
2023-10-04 17:46:57 +00:00
Sameer Agarwal 94335e3b9e More ClangTidy fixes
Change-Id: If7e056b0d2eddca581d87503340fdaac87adba86
2023-10-03 13:24:33 -07:00
Sameer Agarwal 399395c4f1 Miscellaneous ClangTidy fixes
Change-Id: Iba2f8b1dccb77cefde750e5079e609b2b2a3ec95
2023-10-03 11:52:09 -07:00
Sameer Agarwal c8bed4b932 Update version_history for 2.2.0rc2
Change-Id: I5ab74706e699f74213a78ee7ccb2389a5c44034e
2.2.0rc2
2023-09-30 16:02:23 -07:00
Sergiu Deitsch 4893392195 Rework MSVC warning suppression
Previously, MSVC warning C4996 was suppressed unconditionally in the
entire code base which made it difficult identifying and fixing specific
problems, particularly those in the public interface.

Prefer now to disable warnings at the specific location they occur. This
approach, however, reveals an inconsistency in how Ceres handles POSIX
functions which are declared deprecated by MSVC. Specifically, Bessel
functions use the underscore form whereas the read function does not. To
simplify the logic, we revert to POSIX compatible functions.

C++23 also deprecates std::numeric_limits<T>::has_denorm which MSVC
warns about. Here, we disable the deprecation warning locally to avoid
the warning leaking into the user code.

Fixes #1013

Change-Id: Ida8457cc8dd8770b4384a7c49d16f213b02cdec4
2023-09-30 13:37:39 +02:00
Dmitriy Korchemkin 0cea191d40 Move stream-ordered memory allocations
Change-Id: Ief116e4e77c7579612b99cf552f3d8fc54c1d42a
2023-09-29 23:02:47 +00:00
Sameer Agarwal 8e3b7d89e4 Fix a copy-pasta error
Change-Id: I2f7f7e98364f3f28245e5c379c7fe143c21d825b
2023-09-29 14:54:34 -07:00
Sameer Agarwal dc0bb8508c Various cleanups to the documentation
Fixes https://github.com/ceres-solver/ceres-solver/issues/208

Change-Id: I62c575b646260f801c95188910910ecf441fa9ac
2023-09-29 14:01:42 -07:00
Sameer Agarwal 4588b0fbbf Add an example for EvaluationCallback
Change-Id: Ia488f8b181118c8d07861149c4bd52f7217336ce
2023-09-28 21:49:32 +00:00
Sameer Agarwal 0fc3fd4fce Add documentation for examples
Also remove random.h which is not used anymore.

Change-Id: I389a0fc0fd771619e179dcf305bb0991ad1d82ff
2023-09-28 14:45:18 -07: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 83ee376d86 Add an example for IterationCallback
iteration_callback_example.cc uses the curve_fitting.cc example
and uses a custom IterationCallback to log the values of the
parameter blocks are they change over the course of the optimization.

Change-Id: I6a478a8418e237aff576ca627d9b5c0b751b8088
2023-09-27 22:39:01 +00:00
Sameer Agarwal 3712650941 Cleanup example code
Remove "using ceres:foo" directives from example code. The using
directives actually make the code harder to read unless you already
know the ceres API. By making the namespace explicit it is clear
to the reader that these are functions and objects from the Ceres
API.

Change-Id: I89b1281c754bf71c0f82e39e1607c5e40a148388
2023-09-27 14:46:54 -07:00
Sameer Agarwal 59182a42c3 Update documentation
Update the linear solver documentation thoroughly as it had
bit rotted and was flat out wrong in some places and incomplete
in others.

https://github.com/ceres-solver/ceres-solver/issues/865
https://github.com/ceres-solver/ceres-solver/issues/862

Change-Id: Ic395efabd0589a401e2b971c45869bd881b68a34
2023-09-27 09:27:29 -07:00
Sameer Agarwal d4db6e6fe6 Fix typos in the documentation for EvaluationCallback
https: //github.com/ceres-solver/ceres-solver/issues/953
Change-Id: I6631c152f794c9492e527ceff11d7d9e598b92f8
2023-09-27 09:23:46 -07:00
Sameer Agarwal dffd8cd71b Add an accessor for the CostFunctor in DynamicAutoDiffCostFunction
https://github.com/ceres-solver/ceres-solver/issues/962

Change-Id: I50c327eb7ac09a894582ee3fb3311825607640c0
2023-09-25 05:44:37 -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
2.2.0rc1
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 a1c02e8d37 Rework the Sphinx find module
* Make sphinx_rtd_theme a find module component to avoid hard-wiring it
  into the module and allowing to report the theme in case it is missing
  using the standard CMake package mechanism.
* Adjust find module cache variables names case to match the find module
  name.
* Also report sphinx-build version for completeness.
* Invoke the find module only once. Calling find_package on the same
  module is not needed.

Change-Id: I9d1bf0fcc0d44b9b37e624128812f348c5442ada
2023-09-12 20:51:48 +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
Sergiu Deitsch 863db948f3 Eliminate macOS sprintf warning
AppleClang 14.0.0.14000029 warns about a potential security problem
while invoking the sprintf C function:

    internal/ceres/fixed_array_test.cc:469:3: warning: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Wdeprecated-declarations]
      sprintf(buf.data(), "foo");  // NOLINT(runtime/printf)
      ^
    /Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/include/stdio.h:188:1: note: 'sprintf' has been explicitly marked deprecated here
    __deprecated_msg("This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.")
    ^
    /Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/include/sys/cdefs.h:215:48: note: expanded from macro '__deprecated_msg'
            #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))

Replace sprintf by snprintf to avoid this deprecation warning.

Change-Id: I6870c0bd4e390388d1d7bcec082cee272b234eba
2023-09-11 22:51:28 +02:00
Sergiu Deitsch 6f5342db68 Export ceres_cuda_kernels to project's build tree
This avoids the following CMake error when exporting Ceres build
directory to local CMake package registry:

    export called with target "ceres" which requires target
      "ceres_cuda_kernels" that is not in any export set.

Fixes #966

Change-Id: I5a75191fc414a3f138b19cb9d5850f7330f2d24a
2023-09-11 00:17:04 +02:00
Sergiu Deitsch d864d146fd Add macOS 13 runner to Github workflows
Change-Id: Ied8e255bb5d8fbeaa0c43c6af22775dda8aad1e8
2023-09-10 21:05:03 +02:00
Sameer Agarwal 01a23504d5 Add a workaround for CMake Policy CMP0148
Without this we start getting errors related to FindSphinx.cmake

I am not sure yet, what version of cmake we can assume in the wild
but the current minimum version supports the old behaviour and this
policy seems relatively recent (CMake version 3.27) so we should
have this workaround till we update our minimum required version.

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

Change-Id: I1beaac9ee27bc9ff85b64f53f72606a0424f2391
2023-09-09 07:58:49 -07:00
Sergiu Deitsch de9cbde95d Work around MinGW32 manifold_test segfault
Converting fixed size vectors to dynamic ones allows to avoid
segmentation faults in Eigen's packet math if the corresponding
expressions are invoked within GMock matchers.

Fixes #996

Change-Id: I7da5599883825ab0e580678d3d55de19095b41b1
2023-09-08 19:57:43 +02:00
Dmitriy Korchemkin 5e4b22f7fc Update CudaSparseMatrix class
- Perform temporary buffer size estimation only once
- Allow construction from existing buffers with col/row structure

Change-Id: I73c291328f1e8ed9184aba5d7058df71cbc6a15d
2023-08-31 18:56:44 +00:00
MaximSmolskiy ed9921fc24 Fix Solver::Options in documentation
Change-Id: Ia01fdba7561aac539ce96f09b3d404cbe061de11
2023-08-29 05:53:36 +03:00
Sameer Agarwal de62bf2204 Two minor fixes
1. In cuda_sparse_matrix.cc fix the order of fields in the initializer list.
2. Move a line of code to the ifdef branch which will use it.

Change-Id: If32ea14a287f845c1740e6f726c1007e86a4eeca
2023-08-20 17:53:10 +00:00
MaximSmolskiy 5f97455bea Fix typos in documentation
Change-Id: I1d39fe777c87d3480bc403ec4602dd2dd9284839
2023-08-20 20:42:05 +03:00