Commit Graph

1990 Commits

Author SHA1 Message Date
Alex Stewart 9aa52c6ff7 Use FindCUDAToolkit for CMake >= 3.17
- Enables relocatable installs if the CUDA libraries are not installed
  in a location on the LD_LIBRARY_PATH.
- Also bump the minimum CMake version to 3.11 to reflect the issue
  reported in #903.

Change-Id: I333882b7238c76104d739c7054f29cc35cc4e919
2022-11-06 00:05:52 +00:00
Alex Stewart 47e03a6d89 Add const accessor for Problem::Options used by Problem
Change-Id: I0fc48178c411887d4487a34599050d342f5344a2
2022-11-05 12:55:28 +00:00
Sameer Agarwal d6a9310098 Clang Tidy Fixes
Change-Id: I65558225cc537e86428caa5081bde165968bfab3
2022-11-01 10:46:50 -07:00
Sameer Agarwal 9364e31ee8 Fix a regression in SuiteSparse::AnalyzeCholesky
When AnalyzeCholesky is called on a Jacobian which has been
pre-ordered in the preprocessor, we assume a NATURAL ordering.
In this case, asking CHOLMOD to do a postordering is detrimental
to the performance. This regression was introduced in

https://github.com/ceres-solver/ceres-solver/commit/d09f7e9d5e3bfab2d7ec7e81fd6a55786edca17a

based on an email exchange with Prof. Tim Davis the author of CHOLMOD
who suggested that this should be innocous. Unfortunately this is not
the case. The following table shows the performance of bundle_adjuster
on a variety of problems. This matches the performance of the
bundle adjuster before the CL that introduced the regression.

                               Before      After
problem-49-7776-pre.txt
SPARSE_NORMAL_CHOLESKY + AMD      0.8        0.6
SPARSE_NORMAL_CHOLESKY + NESDIS   0.8        0.6
SPARSE_SCHUR + AMD                0.1        0.1
SPARSE_SCHUR + NESDIS             0.1        0.1

problem-1778-993923-pre.txt
SPARSE_NORMAL_CHOLESKY + AMD    247.1      197.0
SPARSE_NORMAL_CHOLESKY + NESDIS 234.0      193.2
SPARSE_SCHUR + AMD               78.7       71.8
SPARSE_SCHUR + NESDIS            78.7       71.4

problem-1031-110968-pre.txt
SPARSE_NORMAL_CHOLESKY + AMD     26.1       22.4
SPARSE_NORMAL_CHOLESKY + NESDIS  26.0       23.0
SPARSE_SCHUR + AMD               14.9       13.1
SPARSE_SCHUR + NESDIS            14.9       13.1

problem-356-226730-pre.txt
SPARSE_NORMAL_CHOLESKY + AMD     43.9       34.7
SPARSE_NORMAL_CHOLESKY + NESDIS  42.5       34.8
SPARSE_SCHUR + AMD                6.8        6.1
SPARSE_SCHUR + NESDIS             6.8        6.1

problem-951-708276-pre.txt
SPARSE_NORMAL_CHOLESKY + AMD    170.3      139.0
SPARSE_NORMAL_CHOLESKY + NESDIS 168.9      139.8
SPARSE_SCHUR + AMD               52.3       47.9
SPARSE_SCHUR + NESDIS            52.0       47.7

Change-Id: I6421060dd835ab2fc81d270238f6f67e29f3ecd5
2022-10-31 15:03:37 -07:00
Alex Stewart 89b3e1f88f Remove unused includes of gflags and gtest
Change-Id: Ie299a043c1095db4f85bd434f4bd9517e7641e06
2022-10-31 19:30:48 +00:00
Alex Stewart 9840790038 Fix missing regex dependency for gtest on QNX
- On QNX gtest requires linking of the system regex library.
- This mirrors gtests' own library build here:
  https://github.com/google/googletest/blob/main/googletest/CMakeLists.txt#L158

Change-Id: I207cf8874f6fce9cfe50faa0414ad70cf355759e
2022-10-31 18:07:32 +00:00
Alex Stewart 6b296f27ff Fix missing namespace qualification and docs for Manifold gtest macro
Change-Id: Iae9a0d13191a777921208cb58d919f0e85b1bf92
2022-10-30 17:49:11 +00:00
Dmitriy Korchemkin 6685e629f9 AddBlockStructureTranspose to BlockSparseMatrix
Add structure of transposed matrix to BlockSparseMatrix

Number of non-zero values per row block and cumulative non-zero
values count are maintained for transposed structure

Change-Id: Icf38bb7a734ca695c788579eece1c92d36d78e54
2022-10-28 02:10:59 +03:00
Sameer Agarwal 699e3f3b39 Fix a link error in evaluation_benchmark.cc
Change-Id: I82ab8adc9c53e14ea2bd2398b978b41f60cca7d7
2022-10-26 16:51:44 -07:00
Dmitriy Korchemkin 19a3d07f90 Add multiplication benchmarks on BAL data
Change-Id: I3cf122c689b6de789f2c697a3bb37dbe3b531b52
2022-10-26 19:11:25 +03:00
Tyler Hovanec b221b12941 Format code with clang-format.
This was created from a clean repo and running `./scripts/format_all.sh`

Change-Id: I0837e74bc74462da3ce5e7fbae9d03033a910c58
2022-10-26 11:40:41 +00:00
Alex Stewart ccf32d70c7 Purge all remaining references to (defunct) LocalParameterization
Change-Id: Iad2a49bfa6916c22929d822e07f754ef77ed023d
2022-10-19 20:00:20 +01:00
Sameer Agarwal 5f8c406e22 struct ContextImpl -> class ContextImpl
Change-Id: I3bb63c41dab8b0dfaf891b188295a91fe9a4d5a8
2022-10-13 21:49:00 -07:00
Mike Vitus 9893c534c0 Several cleanups.
- Removes dead code.
- Changes to use std::make_unique.

Change-Id: I7921d78606554ca55fbedf719372749663b5464c
2022-10-05 14:12:37 -07:00
Sameer Agarwal a78a574727 ClangTidy fixes
Change-Id: I1bccb4ea27a9010e869265436c8bfbcb72fb1484
2022-09-30 11:05:56 -07:00
Dmitriy Korchemkin b1fe603305 Parallel right products for partitioned view
Parallel implementations for right-multiply by dense vector for:
 - Partitioned matrix view
 - Block-sparse matrix
 - CRS matrix (non-symmetric only)

When coupled with non-interleaving indexes in parallel for, this
simple aproach provides a reasonable speedup.
For example, in CRS case difference with GPGPU approach reduces
closer to memory throughput ratio for high enough core count.

./bin/spmv_benchmark
-------------------------------------------------------------------
Benchmark                                                      Time
-------------------------------------------------------------------
BM_BlockSparseRightMultiplyAndAccumulateBA/1              28.5   ms
BM_BlockSparseRightMultiplyAndAccumulateBA/2              15.7   ms
BM_BlockSparseRightMultiplyAndAccumulateBA/4               9.01  ms
BM_BlockSparseRightMultiplyAndAccumulateBA/8               5.60  ms
BM_BlockSparseRightMultiplyAndAccumulateBA/16              3.86  ms
BM_BlockSparseRightMultiplyAndAccumulateBA/28              3.84  ms
BM_BlockSparseRightMultiplyAndAccumulateUnstructured/1    23.8   ms
BM_BlockSparseRightMultiplyAndAccumulateUnstructured/2    15.0   ms
BM_BlockSparseRightMultiplyAndAccumulateUnstructured/4     8.01  ms
BM_BlockSparseRightMultiplyAndAccumulateUnstructured/8     4.02  ms
BM_BlockSparseRightMultiplyAndAccumulateUnstructured/16    2.39  ms
BM_BlockSparseRightMultiplyAndAccumulateUnstructured/28    1.68  ms
BM_BlockSparseLeftMultiplyAndAccumulateBA                 30.7   ms
BM_BlockSparseLeftMultiplyAndAccumulateUnstructured       41.5   ms
BM_CRSRightMultiplyAndAccumulateBA/1                      24.1   ms
BM_CRSRightMultiplyAndAccumulateBA/2                      13.6   ms
BM_CRSRightMultiplyAndAccumulateBA/4                       8.70  ms
BM_CRSRightMultiplyAndAccumulateBA/8                       5.34  ms
BM_CRSRightMultiplyAndAccumulateBA/16                      3.99  ms
BM_CRSRightMultiplyAndAccumulateBA/28                      4.00  ms
BM_CRSRightMultiplyAndAccumulateUnstructured/1            21.1   ms
BM_CRSRightMultiplyAndAccumulateUnstructured/2            10.83  ms
BM_CRSRightMultiplyAndAccumulateUnstructured/4             5.88  ms
BM_CRSRightMultiplyAndAccumulateUnstructured/8             3.68  ms
BM_CRSRightMultiplyAndAccumulateUnstructured/16            2.21  ms
BM_CRSRightMultiplyAndAccumulateUnstructured/28            1.71  ms
BM_CRSLeftMultiplyAndAccumulateBA                         23.6   ms
BM_CRSLeftMultiplyAndAccumulateUnstructured               22.5   ms
BM_CudaRightMultiplyAndAccumulateBA                        0.679 ms
BM_CudaRightMultiplyAndAccumulateUnstructured              0.480 ms
BM_CudaLeftMultiplyAndAccumulateBA                         0.774 ms
BM_CudaLeftMultiplyAndAccumulateUnstructured               0.361 ms

./bin/partitioned_matrix_view_benchmark
-----------------------------------------------------------------
Benchmark                                                    Time
-----------------------------------------------------------------
BM_PatitionedViewRightMultiplyAndAccumulateE_Static/1    18.5  ms
BM_PatitionedViewRightMultiplyAndAccumulateE_Static/2    10.7  ms
BM_PatitionedViewRightMultiplyAndAccumulateE_Static/4     6.34 ms
BM_PatitionedViewRightMultiplyAndAccumulateE_Static/8     4.26 ms
BM_PatitionedViewRightMultiplyAndAccumulateE_Static/16    3.86 ms
BM_PatitionedViewRightMultiplyAndAccumulateE_Static/28    3.75 ms
BM_PatitionedViewRightMultiplyAndAccumulateF_Static/1    18.8  ms
BM_PatitionedViewRightMultiplyAndAccumulateF_Static/2    11.9  ms
BM_PatitionedViewRightMultiplyAndAccumulateF_Static/4     6.94 ms
BM_PatitionedViewRightMultiplyAndAccumulateF_Static/8     4.41 ms
BM_PatitionedViewRightMultiplyAndAccumulateF_Static/16    3.63 ms
BM_PatitionedViewRightMultiplyAndAccumulateF_Static/28    3.86 ms

Timings correspond to intel 8176 cpu and 2080ti nvidia gpu,
with OpenMP threading backend.

Change-Id: Idc07d0563103d057ca3c8412de81a7823fe232af
2022-09-30 17:23:13 +03:00
Sameer Agarwal 16668eedf3 Fix a memory leak in ContextImpl
A typo in the Teardown code caused it to not
destroy the cusolver handles, and thus leak memory.

Change-Id: Id52661dd58dcd0356027e350ba78d381484dc2b6
2022-09-28 17:35:40 -07:00
Sameer Agarwal d129938d58 Third time is the charm
Change-Id: I14b3093988b3238e3f490db5dbb282f536fb2abe
2022-09-28 16:53:47 -07:00
Sameer Agarwal 4129b214a6 More fixes to cuda_dense_cholesky_test.cc
Change-Id: If3f67b8161ef139f3860054001e54c18fc5a9b74
2022-09-28 16:50:01 -07:00
Sameer Agarwal 5c01d25733 Remove unused variables from cuda_dense_cholesky_test.cc
Change-Id: I418f219eb98a22d0844a76513be4e08374dd3b87
2022-09-28 15:43:15 -07:00
Sameer Agarwal 5e877ae69a Fix the Bazel build
Fixes https://github.com/ceres-solver/ceres-solver/issues/893

Change-Id: I95802354bc8a00848573c564fe75c5e87ddf8fae
2022-09-25 20:26:02 -07:00
Dmitriy Korchemkin d89290ffa4 Fix evalution_benchmark compilability
Change-Id: Ib2d26595fa0e281bafa4eec983846d9513d4ea6c
2022-09-24 00:41:26 +03:00
Sameer Agarwal ae7f456e36 ClangTidy fixes
Change-Id: I7dd02360e519c8e6aed9584728e13a98c5268f9e
2022-09-22 22:04:05 -07:00
Sameer Agarwal 9438c370f5 Restore the semantics of TrustRegionMinimizer
A previous change to fix a bug related to how x_norm was being
initialized changed the semantics of the TrustRegionMinimizer
loop. With the bug, the parameter_tolerance was being ignored
till the first successful step was encountered.

parameter_tolerance based convergence is a hack anyways, so
restoring the previous semantics is reasonable and will preserve
existing code/tests that depend on this behaviour.

Change-Id: Ia00ca6c47f77e74dee64ad746f4299a9eab0eb7e
2022-09-22 17:28:52 -07:00
Joydeep Biswas c964fce90c Fix bug in cuda_kernels_test
* Use the context stream, not the default stream, since all
  CUDA operations now operate on the context stream.

Change-Id: I24c872c467f13ee4d276fc04d6822b79a18070fc
2022-09-22 13:16:41 -05:00
Sameer Agarwal afaad5678e Fix a typo
Change-Id: I07ef0598cb9f7bb41f4cdf3e274e01e9b3a33174
2022-09-22 09:14:24 -07:00
Dmitriy Korchemkin b7116824b7 Evaluation benchmark
Benchmark for evaluation of residuals and evaluation of both residuals
and jacobian.

For each input file (in BAL format) specified on the command line two
sets of benchmarks are created for different number of threads.

BAL data is preloaded before starting benchmark.

Usage:
./bin/evaluation_benchmark [flags] input_1.txt ... input_N.txt

Change-Id: I543df65f483e3b186f52785b68bd5e2b3e3552a3
2022-09-21 13:40:03 +03:00
hs293go 2b89ce66f0 Add generalized Euler Angle conversions
Conversions function include Euler Angles to / from Rotation Matrices
and Quaternions. They are generalized for any Euler convention that can
be specified in the arguments. Algorithm is from "Euler angle
conversion", Ken Shoemake, Graphics Gems IV

Change-Id: I7f9ddc0b8d686efca16299d2ba374295744376ce
2022-09-20 22:14:19 +00:00
Sameer Agarwal 8230edc6ce ClangTidy fixes
Change-Id: I0ed084f56ce2ce268fd353ae3150dd11e759fa66
2022-09-20 21:13:54 +00:00
Sameer Agarwal 9a28947636 Speed up locking when num_threads = 1.
This is done by locking a dummy mutex when num_threads = 1.

Before on Mac M1 Pro
BM_BlockSparseJacobiPreconditionerBA/1              55724955 ns     55150500 ns           12
BM_BlockSparseJacobiPreconditionerBA/2              32243968 ns     32119545 ns           22
BM_BlockSparseJacobiPreconditionerBA/4              21749220 ns     21448485 ns           33
BM_BlockSparseJacobiPreconditionerBA/8              31190360 ns     27924520 ns           25
BM_BlockSparseJacobiPreconditionerBA/16             31130365 ns     26186656 ns           32
BM_BlockCRSJacobiPreconditionerBA/1                 60739399 ns     60737750 ns           12
BM_BlockCRSJacobiPreconditionerBA/2                 35197331 ns     34524650 ns           20
BM_BlockCRSJacobiPreconditionerBA/4                 21977577 ns     21241606 ns           33
BM_BlockCRSJacobiPreconditionerBA/8                 31597485 ns     27892000 ns           25
BM_BlockCRSJacobiPreconditionerBA/16                31097307 ns     21841367 ns           30
BM_BlockSparseJacobiPreconditionerUnstructured/1    63510295 ns     63488833 ns           12
BM_BlockSparseJacobiPreconditionerUnstructured/2    34208964 ns     34063333 ns           21
BM_BlockSparseJacobiPreconditionerUnstructured/4    22443432 ns     22145455 ns           33
BM_BlockSparseJacobiPreconditionerUnstructured/8    24571793 ns     22801323 ns           31
BM_BlockSparseJacobiPreconditionerUnstructured/16   23507892 ns     20859250 ns           36
BM_BlockCRSJacobiPreconditionerUnstructured/1       63282292 ns     63280273 ns           11
BM_BlockCRSJacobiPreconditionerUnstructured/2       32994633 ns     32845810 ns           21
BM_BlockCRSJacobiPreconditionerUnstructured/4       18249372 ns     17526200 ns           40
BM_BlockCRSJacobiPreconditionerUnstructured/8       16539623 ns     15937341 ns           44
BM_BlockCRSJacobiPreconditionerUnstructured/16      16549527 ns     12850294 ns           51

After

--------------------------------------------------------------------------------------------
Benchmark                                                  Time             CPU   Iterations
--------------------------------------------------------------------------------------------
BM_BlockSparseJacobiPreconditionerBA/1              44348891 ns     44348875 ns           16
BM_BlockSparseJacobiPreconditionerBA/2              32840149 ns     32706476 ns           21
BM_BlockSparseJacobiPreconditionerBA/4              22318142 ns     21904419 ns           31
BM_BlockSparseJacobiPreconditionerBA/8              31322712 ns     27964120 ns           25
BM_BlockSparseJacobiPreconditionerBA/16             31742625 ns     26624577 ns           26
BM_BlockCRSJacobiPreconditionerBA/1                 49870369 ns     49869714 ns           14
BM_BlockCRSJacobiPreconditionerBA/2                 34901023 ns     34234900 ns           20
BM_BlockCRSJacobiPreconditionerBA/4                 21946689 ns     21215394 ns           33
BM_BlockCRSJacobiPreconditionerBA/8                 31461558 ns     27728360 ns           25
BM_BlockCRSJacobiPreconditionerBA/16                30792414 ns     23063968 ns           31
BM_BlockSparseJacobiPreconditionerUnstructured/1    62120649 ns     61979750 ns           12
BM_BlockSparseJacobiPreconditionerUnstructured/2    33806314 ns     33729526 ns           19
BM_BlockSparseJacobiPreconditionerUnstructured/4    22195685 ns     21831500 ns           32
BM_BlockSparseJacobiPreconditionerUnstructured/8    25003440 ns     22765452 ns           31
BM_BlockSparseJacobiPreconditionerUnstructured/16   24746505 ns     19425364 ns           33
BM_BlockCRSJacobiPreconditionerUnstructured/1       57506343 ns     57502077 ns           13
BM_BlockCRSJacobiPreconditionerUnstructured/2       33691442 ns     33584810 ns           21
BM_BlockCRSJacobiPreconditionerUnstructured/4       18121943 ns     17579050 ns           40
BM_BlockCRSJacobiPreconditionerUnstructured/8       17624991 ns     16086568 ns           44
BM_BlockCRSJacobiPreconditionerUnstructured/16      16493819 ns     13160882 ns           51

Change-Id: Ieac097f5e06a08b48170dcfb06b5145f1ee512e6
2022-09-20 13:47:33 -07:00
Sameer Agarwal 739f2a25ae Parallelize block_jacobi_preconditioner
Use ParallelFor to parallelize both versions of the
block Jacobi preconditioner. Also add benchmarks for
varying number of threads.

Benchmark on M1 Mac Pro

Before:
-----------------------------------------------------------------------------------------
Benchmark                                               Time             CPU   Iterations
-----------------------------------------------------------------------------------------
BM_BlockSparseJacobiPreconditionerBA             44847927 ns     44788313 ns           16
BM_BlockCRSJacobiPreconditionerBA                48772330 ns     48723571 ns           14
BM_BlockSparseJacobiPreconditionerUnstructured   62385231 ns     62306818 ns           11
BM_BlockCRSJacobiPreconditionerUnstructured      60671473 ns     60577727 ns           11

After:
--------------------------------------------------------------------------------------------
Benchmark                                                  Time             CPU   Iterations
--------------------------------------------------------------------------------------------
BM_BlockSparseJacobiPreconditionerBA/1              53314862 ns     53302308 ns           13
BM_BlockSparseJacobiPreconditionerBA/2              33601214 ns     33295143 ns           21
BM_BlockSparseJacobiPreconditionerBA/4              28162794 ns     27224167 ns           30
BM_BlockSparseJacobiPreconditionerBA/8              31402448 ns     28038760 ns           25
BM_BlockSparseJacobiPreconditionerBA/16             30820813 ns     22625233 ns           30
BM_BlockCRSJacobiPreconditionerBA/1                 60348194 ns     60332167 ns           12
BM_BlockCRSJacobiPreconditionerBA/2                 35489954 ns     34782050 ns           20
BM_BlockCRSJacobiPreconditionerBA/4                 23636360 ns     22547032 ns           31
BM_BlockCRSJacobiPreconditionerBA/8                 31688798 ns     27857800 ns           25
BM_BlockCRSJacobiPreconditionerBA/16                30806695 ns     20562516 ns           31
BM_BlockSparseJacobiPreconditionerUnstructured/1    59793396 ns     59788583 ns           12
BM_BlockSparseJacobiPreconditionerUnstructured/2    35192900 ns     34968900 ns           20
BM_BlockSparseJacobiPreconditionerUnstructured/4    30171145 ns     28924480 ns           25
BM_BlockSparseJacobiPreconditionerUnstructured/8    24982583 ns     23193172 ns           29
BM_BlockSparseJacobiPreconditionerUnstructured/16   23370546 ns     18389694 ns           36
BM_BlockCRSJacobiPreconditionerUnstructured/1       63204538 ns     63204545 ns           11
BM_BlockCRSJacobiPreconditionerUnstructured/2       34466060 ns     34193429 ns           21
BM_BlockCRSJacobiPreconditionerUnstructured/4       22712230 ns     20491147 ns           34
BM_BlockCRSJacobiPreconditionerUnstructured/8       16701833 ns     16190395 ns           43
BM_BlockCRSJacobiPreconditionerUnstructured/16      16762565 ns     12857304 ns           56

Note that single threaded performance gets worse. Performance goes up for 2 and 4 threads
and then essentially stalls.

Change-Id: I96a5d2f719545e14c03d73e71c8c0564e8c1c729
2022-09-20 08:43:19 -07:00
Dmitriy Korchemkin c0c4f93940 Change implementation of parallel for
Implemented templated invocation routines for ParallelFor backends
in order to improve loop body inlining.

Several modifications of ParallelFor implementation using CXX threads:
 - Index order changed from interleaved to sequential
 - Static task scheduling replaced with dynamic (controlled by
   kWorkBlocksPerThread)
 - Changed index retrieval to atomic

Modifications of OpenMP backend:
 - Changed loop scheduling to guided

Changing index order from interleaved to sequential in parallel seem
to significantly improve run-times of parallel loops, for example in
evaluation of jacobian and residuals.

Other modifications provide minor improvements for unbalanced
sub-problem lengths and parallel for loops with small number of
computation per operation.

Single-threaded performance was improved by avoiding costs of
wrapping parallel loop bodies in std::function.

On BAL dataset the following improvements in time consumed for
evaluation of residuals or jacobian and residuals were observed:

                                     OLD           NEW        OLD/NEW
                 dataset threads     r     J     r     J     r     J
problem-257-65132-pre.txt      1 0.025  0.079  0.025  0.074 1.016 1.056
problem-257-65132-pre.txt      2 0.030  0.062  0.022  0.050 1.333 1.246
problem-257-65132-pre.txt      4 0.023  0.052  0.014  0.034 1.592 1.515
problem-257-65132-pre.txt      8 0.015  0.035  0.010  0.025 1.477 1.401
problem-257-65132-pre.txt     16 0.011  0.027  0.008  0.019 1.365 1.377
problem-356-226730-pre.txt     1 0.150  0.442  0.147  0.412 1.017 1.070
problem-356-226730-pre.txt     2 0.155  0.322  0.100  0.281 1.542 1.145
problem-356-226730-pre.txt     4 0.129  0.291  0.089  0.196 1.439 1.485
problem-356-226730-pre.txt     8 0.091  0.184  0.066  0.139 1.381 1.319
problem-356-226730-pre.txt    16 0.070  0.148  0.055  0.110 1.272 1.340
problem-1723-156502-pre.txt    1 0.084  0.243  0.082  0.229 1.023 1.063
problem-1723-156502-pre.txt    2 0.088  0.188  0.055  0.154 1.589 1.222
problem-1723-156502-pre.txt    4 0.072  0.159  0.049  0.108 1.475 1.475
problem-1723-156502-pre.txt    8 0.050  0.105  0.037  0.077 1.348 1.368
problem-1723-156502-pre.txt   16 0.038  0.083  0.030  0.062 1.269 1.344
problem-1778-993923-pre.txt    1 0.621  1.777  0.609  1.667 1.018 1.065
problem-1778-993923-pre.txt    2 0.621  1.273  0.415  1.199 1.494 1.061
problem-1778-993923-pre.txt    4 0.514  1.140  0.361  0.786 1.421 1.449
problem-1778-993923-pre.txt    8 0.365  0.808  0.277  0.559 1.319 1.443
problem-1778-993923-pre.txt   16 0.279  0.608  0.223  0.441 1.252 1.379
problem-13682-4456117-pre.txt  1 3.877 10.726  3.738 10.082 1.037 1.063
problem-13682-4456117-pre.txt  2 3.310  7.170  2.423  6.448 1.366 1.111
problem-13682-4456117-pre.txt  4 3.070  6.344  2.064  4.474 1.486 1.417
problem-13682-4456117-pre.txt  8 2.051  4.612  1.527  3.133 1.343 1.472
problem-13682-4456117-pre.txt 16 1.549  3.453  1.218  2.488 1.271 1.387

Run time in seconds for a single evaluation, using evaluation_benchmark
numactl -N 0 -m 0 ./bin/evaluation_benchmark --bal_root ${path_to_BAL}
Evaluation was performed on 28-core CPU.

Note: performance when running across numa-nodes degrades in both old
and proposed implementations, thus the test was executed limiting memory
and compute resources allocation to a single numa-node.

Change-Id: Ia195580bdab9d05c95ac983bfe37b045eecfaf49
2022-09-20 11:06:22 +03:00
Joydeep Biswas fc826c5780 CUDA Cleanup
* All Cuda* objects now take in a ContextImpl* during
  construction, and save the context instead of individual
  handles.
* Since we no longer use the legacy default stream, we need to
  explicitly synchronize the stream before performing GPU->CPU
  transfers, and CudaBuffer is responsible for such synchronization
  when asked to perform GPU to CPU transfers.
* Remove all manual syncs and relegate syncing to CudaBuffer
  before performing GPU to CPU transfers.

Change-Id: Ic73cb24174a1e09842827323280e90241716cc20
2022-09-19 10:02:53 -05:00
Sameer Agarwal 660af905fb Fix a bug in TrustRegionMinimizer.
The value of x_norm_ was computed and then incorrectly set to -1.
This meant that ParameterToleranceReached was using the incorrect
value till such time as the minimizer made its first successful
step.

This change removes the member variable and just computes
the norm of x inside ParameterToleranceReached.

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

Thanks to Anton Adanasyev for reporting this.

Change-Id: Ib4d52a45c2d925557ce2c5b57de8a9fa37da6c70
2022-09-19 07:53:27 -07:00
Sameer Agarwal 4cd257cf4a Let NumericDiffFirstOrderFunction take a dynamically sized parameter vector
Also fix a template naming lint along the way.

Change-Id: Iabb98aeec2ff9609a19c3778b9ea2da37771c985
2022-09-16 10:16:35 -07:00
Joydeep Biswas 6c27ac6d50 Fix repeated SpMV Benchmark
Change-Id: I9180cb548a865665f74e1b082c11741a1b87b5ab
2022-09-14 08:37:49 -05:00
Sameer Agarwal 430a292aca Add a missing include
Change-Id: I3c7e43e053366f3d3c38484b65025285d771f330
2022-09-12 17:17:17 -07:00
Sameer Agarwal 858b4b89b5 More ClangTidy fixes
Change-Id: Ib0c450531b362b528aa02b07461fdca97d6055b4
2022-09-12 17:12:22 -07:00
Sameer Agarwal e9e9957401 ClangTidy fixes
Change-Id: Ifc6adb4d6e78668d25d2f06043e0f0d766acdc05
2022-09-12 16:20:30 -07:00
Sameer Agarwal 7f8e930a02 Fix lint errors
Change-Id: I368075a235b4404bb80cd5a7a91f0dad2d202137
2022-09-12 12:17:07 -07:00
Sameer Agarwal f86a3bdbea Unify Block handling across matrix types
Previously some matrices used Block to keep track of
row/column block sizes and some would just use ints, and
then compute the position of each row and column from it.

By uniformly using Block everywhere, we reduce duplicate
computation and data copies.

I also cleaned up a bunch of c++17 related stuff as I edited
these files.

Change-Id: I4c86b1593fd4c91f9057fbb38314f62f303e0477
2022-09-11 07:31:28 -07:00
Sameer Agarwal 5f19468794 clang-formated source
Change-Id: Ia15a55ae053e38d19e1fe7bbc6e452f5d0d1d3ed
2022-09-01 17:01:58 -07:00
Joydeep Biswas 00a05cf70f CUDA SDK Version-based SpMV Selection
* The algorithm enum value for SpMV is now selected based on the
  version of the CUDA runtime that Ceres is compiled against.

Change-Id: I2e0e39f1cbdb8ac26d2a9d45f4ebfc09b96d872b
2022-08-30 10:13:32 -05:00
Sameer Agarwal de0f74e40a Optimize the BlockCRSJacobiPreconditioner
Instead of iterating row-wise, use the row block structure
to update the preconditioner one row block at a time.

While benchmarking, I also found an opportunity to speed up
BlockSparseJacobiPreconditiner.

Before
-----------------------------------------------------------------------------------------
Benchmark                                               Time             CPU   Iterations
-----------------------------------------------------------------------------------------
BM_BlockSparseJacobiPreconditioner              132122392 ns    132103000 ns            5
BM_BlockCRSJacobiPreconditionerBA                73365217 ns     73335800 ns           10
BM_BlockSparseJacobiPreconditionerUnstructured   92407762 ns     92407714 ns            7
BM_BlockCRSJacobiPreconditionerUnstructured      72256367 ns     72256400 ns           10

After

-----------------------------------------------------------------------------------------
Benchmark                                               Time             CPU   Iterations
-----------------------------------------------------------------------------------------
BM_BlockSparseJacobiPreconditionerBA             39723456 ns     39722222 ns           18
BM_BlockCRSJacobiPreconditionerBA                46561625 ns     46561667 ns           15
BM_BlockSparseJacobiPreconditionerUnstructured   52676208 ns     52676167 ns           12
BM_BlockCRSJacobiPreconditionerUnstructured      54430564 ns     54421462 ns           13

Change-Id: I6da8e044b26f0c24481deee5722322a606e9e5ca
2022-08-28 17:24:28 -07:00
Sameer Agarwal ba65ddd311 Improvements to benchmarks
1. Add CreateFakeBundleAdjustmentJacobian to create
   bundle adjustment structured jacobians.
2. sparse_linear_operator_benchmark -> spmv_benchmark
3. Refactor spmv_benchmark to use CreateFakeBundleAdjustmentJacobian.
4. Add BA and unstructured Jacobian variants of spmv benchmarks
5. Add BA and unstructured Jacobian benchmarks for the block Jacobi
   preconditioner.
6. Fix BlockSparseMatrix::ToCompressedRowSparseMatrix to add the
   row and column block structure to the output.

Change-Id: I737a3d7d82dad665b1f2e7886c2c3aedd702ffcd
2022-08-28 07:20:53 +03:00
Joydeep Biswas 42352e2e2a Added CUDA Jacobi Preconditioner
* Added CudaCpuPreconditionerWrapper, a templated wrapper to leverage
  existing CPU preconditioners that provide CompressedRowSparse
  representation, for use with CudaCgnrSolver.
* Added CudaJacobiPreconditioner as a specific instantiation of
  CudaCpuPreconditionerWrapper over BlockCRSJacobiPreconditioner.

The resulting Jacobi-preconditioned CudaCgnrSolver exhibits moderate
increase in speed with a healthy increase in numerical stability.
Examples of running CudaCgnrSolver with Jacobi vs. Identity
preconditioner for bundle adjustment on problem-13682-4456117-pre.txt
on a desktop computer with an Intel(R) Core(TM) i9-9940X CPU @ 3.30GHz
and an Nvidia Quadro RTX 6000 GPU.

A known issue is that the Jacobi preconditioner update is slow - this
can be sped up in the future by multithreading on the CPU, or by
computing the preconditioner on the GPU.

====================================================================
CUDA CGNR + IDENTITY Preconditioner
====================================================================
iter      cost      cost_change  |gradient|   |step|    tr_ratio  tr_radius  ls_iter  iter_time  total_time
   0  1.126372e+09    0.00e+00    3.02e+15   0.00e+00   0.00e+00  1.00e+04        0    9.17e+00    2.70e+01
   1  3.796903e+07    1.09e+09    1.08e+15   6.48e+03   9.95e-01  3.00e+04       49    1.55e+01    4.24e+01
   2  3.529024e+21   -3.53e+21    1.08e+15   1.93e+04  -2.25e+14  1.50e+04      500    3.79e+01    8.03e+01
   3  7.952482e+09   -7.91e+09    1.08e+15   1.63e+04  -5.16e+02  3.75e+03      386    2.96e+01    1.10e+02
   4  8.842366e+08   -8.46e+08    1.08e+15   1.18e+04  -5.87e+01  4.69e+02      312    2.47e+01    1.35e+02
   5  2.935800e+07    8.61e+06    1.24e+13   3.93e+03   8.19e-01  6.32e+02      129    1.96e+01    1.54e+02
   6  2.529342e+07    4.06e+06    3.22e+12   3.39e+03   9.93e-01  1.90e+03      148    2.16e+01    1.76e+02
   7  2.343028e+07    1.86e+06    1.27e+13   6.00e+03   9.37e-01  5.68e+03      387    3.79e+01    2.14e+02
   8  2.332405e+07    1.06e+05    7.92e+12   6.47e+01   8.26e-01  7.87e+03       46    1.48e+01    2.28e+02
   9  3.591512e+14   -3.59e+14    7.92e+12   5.19e+03  -4.09e+08  3.94e+03      500    3.83e+01    2.67e+02
  10  2.956078e+07   -6.24e+06    7.92e+12   3.94e+03  -8.34e+00  9.84e+02      447    3.40e+01    3.01e+02

Solver Summary (v 2.2.0-eigen-(3.3.7)-lapack-suitesparse-(5.7.1)-metis-(5.1.0)-eigensparse-no_openmp-cuda-(11070))

                                     Original                  Reduced
Parameter blocks                      4469799                  4469799
Parameters                           13491489                 13491489
Residual blocks                      28987644                 28987644
Residuals                            57975288                 57975288

Minimizer                        TRUST_REGION
Trust region strategy     LEVENBERG_MARQUARDT
Sparse linear algebra library     CUDA_SPARSE

                                        Given                     Used
Linear solver                            CGNR                     CGNR
Preconditioner                       IDENTITY                 IDENTITY
Threads                                    24                       24
Linear solver ordering          4456117,13682            4456117,13682

Cost:
Initial                          1.126372e+09
Final                            2.332405e+07
Change                           1.103048e+09

Minimizer iterations                       11
Successful steps                            6
Unsuccessful steps                          5

Time (in seconds):
Preprocessor                        17.798455

  Residual only evaluation           8.656350 (10)
  Jacobian & residual evaluation    35.794169 (6)
  Linear solver                    208.586109 (10)
Minimizer                          283.593882

Postprocessor                        1.985112
Total                              303.377449

====================================================================
CUDA CGNR + JACOBI Preconditioner
====================================================================
iter      cost      cost_change  |gradient|   |step|    tr_ratio  tr_radius  ls_iter  iter_time  total_time
   0  1.126372e+09    0.00e+00    3.02e+15   0.00e+00   0.00e+00  1.00e+04        0    9.18e+00    2.68e+01
   1  1.491225e+14   -1.49e+14    3.02e+15   8.73e+05  -1.36e+05  5.00e+03        6    1.07e+01    3.74e+01
   2  7.461790e+12   -7.46e+12    3.02e+15   4.78e+05  -6.78e+03  1.25e+03        6    8.88e+00    4.63e+01
   3  4.357438e+07    1.08e+09    5.41e+13   1.57e+05   9.87e-01  3.75e+03        6    1.62e+01    6.25e+01
   4  2.928453e+07    1.43e+07    6.85e+13   3.81e+05   6.97e-01  3.99e+03       23    1.82e+01    8.08e+01
   5  5.977433e+14   -5.98e+14    6.85e+13   4.97e+05  -8.70e+07  2.00e+03        9    9.93e+00    9.07e+01
   6  6.423965e+10   -6.42e+10    6.85e+13   2.45e+05  -9.61e+03  4.99e+02        7    8.95e+00    9.97e+01
   7  2.337471e+07    5.91e+06    1.49e+12   8.24e+04   9.31e-01  1.39e+03        4    1.60e+01    1.16e+02
   8  2.257524e+07    7.99e+05    8.71e+12   1.62e+05   8.99e-01  2.81e+03       54    2.03e+01    1.36e+02
   9  2.285090e+07   -2.76e+05    8.71e+12   3.56e+05  -6.13e-01  1.41e+03      104    1.65e+01    1.52e+02
  10  5.909983e+12   -5.91e+12    8.71e+12   1.78e+05  -1.83e+07  3.52e+02       74    1.36e+01    1.66e+02

Solver Summary (v 2.2.0-eigen-(3.3.7)-lapack-suitesparse-(5.7.1)-metis-(5.1.0)-eigensparse-no_openmp-cuda-(11070))

                                     Original                  Reduced
Parameter blocks                      4469799                  4469799
Parameters                           13491489                 13491489
Residual blocks                      28987644                 28987644
Residuals                            57975288                 57975288

Minimizer                        TRUST_REGION
Trust region strategy     LEVENBERG_MARQUARDT
Sparse linear algebra library     CUDA_SPARSE

                                        Given                     Used
Linear solver                            CGNR                     CGNR
Preconditioner                         JACOBI                   JACOBI
Threads                                    24                       24
Linear solver ordering          4456117,13682            4456117,13682

Cost:
Initial                          1.126372e+09
Final                            2.257524e+07
Change                           1.103796e+09

Minimizer iterations                       11
Successful steps                            5
Unsuccessful steps                          6

Time (in seconds):
Preprocessor                        17.575990

  Residual only evaluation           8.461414 (10)
  Jacobian & residual evaluation    30.055383 (5)
  Linear solver                     82.550675 (10)
Minimizer                          149.137856

Postprocessor                        1.994014
Total                              168.707860

Change-Id: I458d2445bf062e54de44fc91517ed11a300c7182
2022-08-26 08:57:07 -05:00
Sameer Agarwal f802a09ff1 &foo[0] -> foo.data()
Use the more modern form of accessing the data array of a vector
rather than grabbing the pointer to the first element. The latter
can lead to errors if the vector is of zero length.

Change-Id: Ifc8fc969b06b3ba1a9385e8a3a8d5c50b25db5a8
2022-08-25 10:00:12 +05:30
Joydeep Biswas 344929647a Add CUDA GPU and Runtime Detection
* Added GPU device and CUDA compute capability identification.
* Added GpuMemoryAvailable() to aid downstream optimizations based
  on GPU memory availability.

Change-Id: I326dc1e4b7a6a7f5571b7e5479eb9aa300ad1075
2022-08-18 17:07:32 -05:00
Sameer Agarwal 6085e45be7 Minor CUDA cleanup.
1. ceres_cuda_kernels.cu -> cuda_kernels.cu.cc
2. Add missing ifdef guards.
3. Fix an errant namespace

Change-Id: I81a5bfbe3c795ff0b3ef41c3bcaa037b99d5b254
2022-08-17 16:27:13 -07:00
Sameer Agarwal e15ec89f3b Speed up bundle_adjuster
1. Use hardware_concurrency to configure number of threads.
2. Use user ordering instead of automatic ordering.

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

Change-Id: I4d7d69612e1ee40358943019a0c3a909e419c4e4
2022-08-17 12:47:02 -07:00