Commit Graph

2004 Commits

Author SHA1 Message Date
Dmitriy Korchemkin 2fd81de12d Add build configuration with CUDA on Linux
Change-Id: I3144a44692a7a129857b65ed84fb2a5637b25b5d
2022-11-29 18:51:13 +03:00
Sameer Agarwal 06bfe6ffac Remove OpenMP and No threading backends.
Since c++11, we can depend on C++ threads always being available.
With the recent work on the performance of CXX threading, the
additional complexity of maintaining multiple backends for some
minor performance delta is not worth it

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

Change-Id: Idee480b22a498daec9c4366da8589aa58eaf36a1
2022-11-27 21:06:33 -08:00
Sergiu Deitsch 352b320ab1 Fixed SuiteSparse 6.0 version parsing
The version component macro names are delimited by multiple spaces in
the new release resulting in a failure to parse the version.

An additional guard ensures that if the version cannot be correctly
parsed it is discarded and a user warning is issued.

Fixes #919

Change-Id: I630f30dba0fd23979b6fe5d854e59701c22c3469
2022-11-18 17:46:50 +00:00
Sameer Agarwal 8fd7828e3d ClangTidy fixes
Change-Id: I07141aa81203dd58fb6de5c15859fffbd1b91da1
2022-11-18 09:43:06 -08:00
Dmitriy Korchemkin 0424615dcc Fix PartitionedMatrixView usage in evaluation_benchmark
Change-Id: I50a3fee923ce15a8c37a168126cb410239566025
2022-11-18 01:02:59 +03:00
Dmitriy Korchemkin 77a54dd3d2 Parallel updates to block-diagonal EtE FtF
--------------------------------------------------------------------------------
Benchmark                                                                   Time
--------------------------------------------------------------------------------
PMVUpdateBlockDiagonalFtF<final/problem-13682-4456117-pre.txt>/1   5056275941 ns
PMVUpdateBlockDiagonalFtF<final/problem-13682-4456117-pre.txt>/2   3677677097 ns
PMVUpdateBlockDiagonalFtF<final/problem-13682-4456117-pre.txt>/4   1932236015 ns
PMVUpdateBlockDiagonalFtF<final/problem-13682-4456117-pre.txt>/8    984585015 ns
PMVUpdateBlockDiagonalFtF<final/problem-13682-4456117-pre.txt>/16   614918752 ns

PMVUpdateBlockDiagonalEtE<final/problem-13682-4456117-pre.txt>/1    449324491 ns
PMVUpdateBlockDiagonalEtE<final/problem-13682-4456117-pre.txt>/2    273147462 ns
PMVUpdateBlockDiagonalEtE<final/problem-13682-4456117-pre.txt>/4    150742698 ns
PMVUpdateBlockDiagonalEtE<final/problem-13682-4456117-pre.txt>/8     81602564 ns
PMVUpdateBlockDiagonalEtE<final/problem-13682-4456117-pre.txt>/16    47010769 ns

PMVUpdateBlockDiagonalFtF<venice/problem-1778-993923-pre.txt>/1     774598200 ns
PMVUpdateBlockDiagonalFtF<venice/problem-1778-993923-pre.txt>/2     611312877 ns
PMVUpdateBlockDiagonalFtF<venice/problem-1778-993923-pre.txt>/4     326701149 ns
PMVUpdateBlockDiagonalFtF<venice/problem-1778-993923-pre.txt>/8     165634457 ns
PMVUpdateBlockDiagonalFtF<venice/problem-1778-993923-pre.txt>/16     90631068 ns

PMVUpdateBlockDiagonalEtE<venice/problem-1778-993923-pre.txt>/1      80651817 ns
PMVUpdateBlockDiagonalEtE<venice/problem-1778-993923-pre.txt>/2      49688691 ns
PMVUpdateBlockDiagonalEtE<venice/problem-1778-993923-pre.txt>/4      27199153 ns
PMVUpdateBlockDiagonalEtE<venice/problem-1778-993923-pre.txt>/8      14301768 ns
PMVUpdateBlockDiagonalEtE<venice/problem-1778-993923-pre.txt>/16      8683479 ns

PMVUpdateBlockDiagonalFtF<ladybug/problem-1723-156502-pre.txt>/1    104422529 ns
PMVUpdateBlockDiagonalFtF<ladybug/problem-1723-156502-pre.txt>/2     81555176 ns
PMVUpdateBlockDiagonalFtF<ladybug/problem-1723-156502-pre.txt>/4     43227593 ns
PMVUpdateBlockDiagonalFtF<ladybug/problem-1723-156502-pre.txt>/8     22177895 ns
PMVUpdateBlockDiagonalFtF<ladybug/problem-1723-156502-pre.txt>/16    12505813 ns

PMVUpdateBlockDiagonalEtE<ladybug/problem-1723-156502-pre.txt>/1     14205253 ns
PMVUpdateBlockDiagonalEtE<ladybug/problem-1723-156502-pre.txt>/2      7102357 ns
PMVUpdateBlockDiagonalEtE<ladybug/problem-1723-156502-pre.txt>/4      3806598 ns
PMVUpdateBlockDiagonalEtE<ladybug/problem-1723-156502-pre.txt>/8      2112615 ns
PMVUpdateBlockDiagonalEtE<ladybug/problem-1723-156502-pre.txt>/16     1245771 ns

PMVUpdateBlockDiagonalFtF<dubrovnik/problem-356-226730-pre.txt>/1   190102870 ns
PMVUpdateBlockDiagonalFtF<dubrovnik/problem-356-226730-pre.txt>/2   157359897 ns
PMVUpdateBlockDiagonalFtF<dubrovnik/problem-356-226730-pre.txt>/4    82657662 ns
PMVUpdateBlockDiagonalFtF<dubrovnik/problem-356-226730-pre.txt>/8    42746490 ns
PMVUpdateBlockDiagonalFtF<dubrovnik/problem-356-226730-pre.txt>/16   23434967 ns

PMVUpdateBlockDiagonalEtE<dubrovnik/problem-356-226730-pre.txt>/1    18894355 ns
PMVUpdateBlockDiagonalEtE<dubrovnik/problem-356-226730-pre.txt>/2    12138228 ns
PMVUpdateBlockDiagonalEtE<dubrovnik/problem-356-226730-pre.txt>/4     6808771 ns
PMVUpdateBlockDiagonalEtE<dubrovnik/problem-356-226730-pre.txt>/8     3829718 ns
PMVUpdateBlockDiagonalEtE<dubrovnik/problem-356-226730-pre.txt>/16    2103688 ns

PMVUpdateBlockDiagonalFtF<trafalgar/problem-257-65132-pre.txt>/1     34230036 ns
PMVUpdateBlockDiagonalFtF<trafalgar/problem-257-65132-pre.txt>/2     20121184 ns
PMVUpdateBlockDiagonalFtF<trafalgar/problem-257-65132-pre.txt>/4     10899938 ns
PMVUpdateBlockDiagonalFtF<trafalgar/problem-257-65132-pre.txt>/8      6186359 ns
PMVUpdateBlockDiagonalFtF<trafalgar/problem-257-65132-pre.txt>/16     4207103 ns

PMVUpdateBlockDiagonalEtE<trafalgar/problem-257-65132-pre.txt>/1      3077110 ns
PMVUpdateBlockDiagonalEtE<trafalgar/problem-257-65132-pre.txt>/2      2224104 ns
PMVUpdateBlockDiagonalEtE<trafalgar/problem-257-65132-pre.txt>/4      1274841 ns
PMVUpdateBlockDiagonalEtE<trafalgar/problem-257-65132-pre.txt>/8       721140 ns
PMVUpdateBlockDiagonalEtE<trafalgar/problem-257-65132-pre.txt>/16      437715 ns

Change-Id: If5a342a063869bd9c0505bf96b6d957da5169c1d
2022-11-17 23:17:01 +03:00
Sameer Agarwal 946fa50de7 ClangTidy fixes
Change-Id: I4b54a0b2d3a84f632ce6f5f99af6c694f9695f93
2022-11-15 16:46:27 -08:00
Sameer Agarwal e4bef95054 Refactor PartitionedMatrixView to cache the partitions
The constructor now takes a LinearSolver::Options as input
and uses that to compute the partitioning once and uses it
for its lifetime.

Change-Id: I9ef30df0b60f8fa91c8b5601c397b2d9314a2cc7
2022-11-15 16:34:04 -08:00
Sergiu Deitsch d3201798ea Clean up sparse_cholesky_test
Change-Id: I210d1181d4696b237094af1fa040064f293baa6a
2022-11-15 19:17:47 +01:00
Sameer Agarwal addcd342fd ClangTidy fixes
Change-Id: I2e7c8dad3afce24072eb81fa4690378e1cc33417
2022-11-14 12:00:18 -08:00
Sameer Agarwal c2e7002d2c Remove an unused variable from evaluation_benchmark.cc
Change-Id: Ibc1133d0fb0ee4dd160712fb3c1c72aec54f2b08
2022-11-14 10:53:01 -08:00
Dmitriy Korchemkin fef6d5875b Parallel left products for PartitionedMatrixView
Parallel left products for PartitionedMatrixView using parallel for
loops with fair partitioning.
Updates for evaluation benchmark including replacing program with a
preprocessed one

Change-Id: Ia1cc3293f106cec6b7d933675cea4e7c5a6b71e4
2022-11-14 18:37:46 +03:00
Sergiu Deitsch 37a3cb3841 Update SuiteSparse in MSVC Github workflow
The new SuiteSparse deployment bundles METIS 5.1.0 instead of 5.1.1 to
avoid heap corruption.

Fixes #918

Change-Id: Ie779dc2015c60e928c237529675e21d4635716a2
2022-11-14 03:38:00 +01:00
Dmitriy Korchemkin 5d53d1ee38 Parallel for with iteration costs and left product
Parallel for with user-supplied [cumulative] iteration costs allows to
get performance improvements on problems with significantly different
time requirements per parallel loop iteration.

One of those problems is left multiplication with block-sparse matrix.
Using number of non-zero values per column block, we partition column
blocks into contiguous sets with approximately equal number of
operations to be performed.

Change-Id: I4a862a10a586cdfbec22e8168a3423537039abc2
2022-11-12 18:58:06 +03:00
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