Commit Graph

1351 Commits

Author SHA1 Message Date
Sameer Agarwal 58c5edae2f Relax an overly strict tolerance in iterative_refiner_test
Change-Id: I01afef985c0d248a50df2cadb97e4be9cd8d7889
2018-04-16 12:54:18 -07:00
Sameer Agarwal 3b2f1f7d28 Add fake FloatCXSparseCholesky and FloatSuiteSparseCholesky
Change-Id: I8d61144d0678b8da92322a18517fa6924d950653
2018-04-12 11:22:49 -07:00
Sameer Agarwal 93ba16fefc Simplify IterativeRefiner
Change the loop structure of IterativeRefiner to
unconditionally refine for max_num_iterations.

This is done for two reasons.

1. We expect to use this refinement for a small number of iterations
   where the convergence test is useless.
2. Eliminating the convergence test means we can restructure the loop
   and save on a sparse matrix-vector multiply, saving precious
   compute.

Change-Id: I6347f453a5d19d234af2a2eb1bce811048963e06
2018-04-11 21:15:02 -07:00
Mike Vitus 05fc04490f Converts std::unique_lock to std::lock_guard.
Tested by compiling for CXX threads, OpenMP, no threads, and TBB.

Change-Id: If1ba5cfce83e2ad4e1015354ce67f5b23e89101f
2018-04-10 17:22:15 -07:00
Sameer Agarwal f973e107d2 Enable mixed precision solves.
1. Add Solver::Options::use_mixed_precision_solves,
   and Solver::Options::max_num_refinement_iterations.
2. Make SparseCholesky::Create return a unique_ptr.
3. SparseCholesky::Create now takes LinearSolver::Options
   as an argument.
4. IterativeRefiner's constructor does not require num_cols
   as an argument.
5. SparseNormalCholeskySolver now uses a separate rhs vector.

This basic implementation results in a 10% reduction in solver time
and 30% reduction in linear solver memory usage.

Change-Id: I6830f32cae2febf082d2733262eb2c9f0482b0ea
2018-04-10 11:01:38 -07:00
yangfan 81f413b720 Optimization for custom small blas multiplication with dynamic
template parameters in C level.

- unroll for loops
- matrix access more cache coherent
- platform independant

Briefly, this commit brings 1~50% performance improvments for
most cases in small_blas_gem(m/v)_benchmark, but a small drop
for corner cases with small dimensions especially 1,2,3. Here
we list the results partially, which show decrease percentage
of executing time, compared to unoptimized version.

Platform: desktop PC (i7-7700 CPU MP8@3.60GHz + ubuntu 17.10)
(Lenovo Research Device+ Lab, <yangfan34@lenovo.com>)

Benchmark                                   Time        CPU
-----------------------------------------------------------
BM_MatrixMatrixMultiplyDynamic/1/1/1     -0.0850    -0.0851
BM_MatrixMatrixMultiplyDynamic/1/1/2     -0.1444    -0.1446
BM_MatrixMatrixMultiplyDynamic/1/1/3     -0.1934    -0.1935
BM_MatrixMatrixMultiplyDynamic/1/1/4     -0.2933    -0.2934
BM_MatrixMatrixMultiplyDynamic/1/1/8     -0.1579    -0.1580
BM_MatrixMatrixMultiplyDynamic/1/1/12    -0.1556    -0.1558
BM_MatrixMatrixMultiplyDynamic/1/1/15    -0.1598    -0.1599
BM_MatrixMatrixMultiplyDynamic/1/2/1     -0.0797    -0.0799
BM_MatrixMatrixMultiplyDynamic/1/2/2     -0.2950    -0.2951
BM_MatrixMatrixMultiplyDynamic/1/2/3     -0.1363    -0.1364
BM_MatrixMatrixMultiplyDynamic/1/2/4     -0.2435    -0.2437
BM_MatrixMatrixMultiplyDynamic/1/2/8     -0.2299    -0.2300
BM_MatrixMatrixMultiplyDynamic/1/2/12    -0.2441    -0.2442
BM_MatrixMatrixMultiplyDynamic/1/2/15    -0.1671    -0.1673
BM_MatrixMatrixMultiplyDynamic/1/3/1     -0.0774    -0.0775
BM_MatrixMatrixMultiplyDynamic/1/3/2     -0.2761    -0.2762
BM_MatrixMatrixMultiplyDynamic/1/3/3     -0.0840    -0.0841
BM_MatrixMatrixMultiplyDynamic/1/3/4     -0.2027    -0.2028
BM_MatrixMatrixMultiplyDynamic/1/3/8     -0.2481    -0.2482
BM_MatrixMatrixMultiplyDynamic/1/3/12    -0.2629    -0.2630
BM_MatrixMatrixMultiplyDynamic/1/3/15    -0.1958    -0.1959
BM_MatrixMatrixMultiplyDynamic/1/4/1     -0.1260    -0.1261
BM_MatrixMatrixMultiplyDynamic/1/4/2     -0.1834    -0.1835
BM_MatrixMatrixMultiplyDynamic/1/4/3     -0.1379    -0.1380
BM_MatrixMatrixMultiplyDynamic/1/4/4     -0.2636    -0.2637
BM_MatrixMatrixMultiplyDynamic/1/4/8     -0.2838    -0.2839
BM_MatrixMatrixMultiplyDynamic/1/4/12    -0.3320    -0.3321
BM_MatrixMatrixMultiplyDynamic/1/4/15    -0.2464    -0.2465
BM_MatrixMatrixMultiplyDynamic/1/8/1     -0.0766    -0.0767
BM_MatrixMatrixMultiplyDynamic/1/8/2     -0.1713    -0.1714
BM_MatrixMatrixMultiplyDynamic/1/8/3     -0.1158    -0.1159
BM_MatrixMatrixMultiplyDynamic/1/8/4     -0.3205    -0.3206
BM_MatrixMatrixMultiplyDynamic/1/8/8     -0.3514    -0.3515
BM_MatrixMatrixMultiplyDynamic/1/8/12    -0.3658    -0.3658
BM_MatrixMatrixMultiplyDynamic/1/8/15    -0.3187    -0.3188
BM_MatrixMatrixMultiplyDynamic/1/12/1    -0.0424    -0.0425
BM_MatrixMatrixMultiplyDynamic/1/12/2    -0.1800    -0.1800
BM_MatrixMatrixMultiplyDynamic/1/12/3    -0.1457    -0.1457
BM_MatrixMatrixMultiplyDynamic/1/12/4    -0.3768    -0.3769
BM_MatrixMatrixMultiplyDynamic/1/12/8    -0.4072    -0.4073
BM_MatrixMatrixMultiplyDynamic/1/12/12   -0.4391    -0.4392
BM_MatrixMatrixMultiplyDynamic/1/12/15   -0.3383    -0.3383
BM_MatrixMatrixMultiplyDynamic/1/15/1    -0.0442    -0.0443
BM_MatrixMatrixMultiplyDynamic/1/15/2    -0.2378    -0.2379
BM_MatrixMatrixMultiplyDynamic/1/15/3    -0.1553    -0.1554
BM_MatrixMatrixMultiplyDynamic/1/15/4    -0.3954    -0.3955
BM_MatrixMatrixMultiplyDynamic/1/15/8    -0.4334    -0.4335
BM_MatrixMatrixMultiplyDynamic/1/15/12   -0.4175    -0.4175
BM_MatrixMatrixMultiplyDynamic/1/15/15   -0.3242    -0.3243

BM_MatrixVectorMultiply/1/1              +0.1613    +0.1613
BM_MatrixVectorMultiply/1/2              +0.1715    +0.1715
BM_MatrixVectorMultiply/1/3              +0.1051    +0.1051
BM_MatrixVectorMultiply/1/4              +0.1369    +0.1369
BM_MatrixVectorMultiply/1/8              +0.1180    +0.1180
BM_MatrixVectorMultiply/1/12             +0.0869    +0.0869
BM_MatrixVectorMultiply/1/15             +0.1887    +0.1886
BM_MatrixVectorMultiply/2/1              +0.1152    +0.1152
BM_MatrixVectorMultiply/2/2              +0.1520    +0.1520
BM_MatrixVectorMultiply/2/3              +0.1867    +0.1867
BM_MatrixVectorMultiply/2/4              +0.0173    +0.0173
BM_MatrixVectorMultiply/2/8              -0.0528    -0.0528
BM_MatrixVectorMultiply/2/12             -0.0176    -0.0176
BM_MatrixVectorMultiply/2/15             -0.0753    -0.0753
BM_MatrixVectorMultiply/3/1              +0.0844    +0.0844
BM_MatrixVectorMultiply/3/2              +0.0750    +0.0750
BM_MatrixVectorMultiply/3/3              -0.0153    -0.0153
BM_MatrixVectorMultiply/3/4              +0.0060    +0.0060
BM_MatrixVectorMultiply/3/8              +0.0152    +0.0152
BM_MatrixVectorMultiply/3/12             +0.0101    +0.0101
BM_MatrixVectorMultiply/3/15             -0.0795    -0.0795
BM_MatrixVectorMultiply/4/1              -0.1425    -0.1425
BM_MatrixVectorMultiply/4/2              -0.0869    -0.0869
BM_MatrixVectorMultiply/4/3              -0.1371    -0.1371
BM_MatrixVectorMultiply/4/4              -0.0088    -0.0088
BM_MatrixVectorMultiply/4/8              -0.1049    -0.1049
BM_MatrixVectorMultiply/4/12             -0.2566    -0.2566
BM_MatrixVectorMultiply/4/15             -0.2940    -0.2940
BM_MatrixVectorMultiply/6/1              -0.1798    -0.1798
BM_MatrixVectorMultiply/6/2              -0.0627    -0.0627
BM_MatrixVectorMultiply/6/3              -0.0389    -0.0389
BM_MatrixVectorMultiply/6/4              -0.1088    -0.1088
BM_MatrixVectorMultiply/6/8              -0.1815    -0.1815
BM_MatrixVectorMultiply/6/12             -0.1650    -0.1650
BM_MatrixVectorMultiply/6/15             -0.1855    -0.1855
BM_MatrixVectorMultiply/8/1              -0.1630    -0.1630
BM_MatrixVectorMultiply/8/2              -0.1248    -0.1248
BM_MatrixVectorMultiply/8/3              -0.1911    -0.1911
BM_MatrixVectorMultiply/8/4              -0.1996    -0.1996
BM_MatrixVectorMultiply/8/8              -0.2590    -0.2590
BM_MatrixVectorMultiply/8/12             -0.3266    -0.3266
BM_MatrixVectorMultiply/8/15             -0.3999    -0.3999
BM_MatrixTransposeVectorMultiply/1/1     -0.0234    -0.0234
BM_MatrixTransposeVectorMultiply/1/2     -0.0243    -0.0243
BM_MatrixTransposeVectorMultiply/1/3     -0.1324    -0.1324
BM_MatrixTransposeVectorMultiply/1/4     -0.2635    -0.2635
BM_MatrixTransposeVectorMultiply/1/8     -0.2461    -0.2461
BM_MatrixTransposeVectorMultiply/1/12    -0.2702    -0.2702
BM_MatrixTransposeVectorMultiply/1/15    -0.2538    -0.2538
BM_MatrixTransposeVectorMultiply/2/1     -0.0170    -0.0170
BM_MatrixTransposeVectorMultiply/2/2     -0.1475    -0.1475
BM_MatrixTransposeVectorMultiply/2/3     -0.1082    -0.1082
BM_MatrixTransposeVectorMultiply/2/4     -0.2594    -0.2595
BM_MatrixTransposeVectorMultiply/2/8     -0.2710    -0.2710
BM_MatrixTransposeVectorMultiply/2/12    -0.3053    -0.3053
BM_MatrixTransposeVectorMultiply/2/15    -0.2706    -0.2706
BM_MatrixTransposeVectorMultiply/3/1     -0.0096    -0.0096
BM_MatrixTransposeVectorMultiply/3/2     -0.2885    -0.2886
BM_MatrixTransposeVectorMultiply/3/3     -0.0790    -0.0790
BM_MatrixTransposeVectorMultiply/3/4     -0.2329    -0.2330
BM_MatrixTransposeVectorMultiply/3/8     -0.2742    -0.2742
BM_MatrixTransposeVectorMultiply/3/12    -0.3177    -0.3177
BM_MatrixTransposeVectorMultiply/3/15    -0.2610    -0.2610
BM_MatrixTransposeVectorMultiply/4/1     -0.0024    -0.0024
BM_MatrixTransposeVectorMultiply/4/2     -0.1578    -0.1578
BM_MatrixTransposeVectorMultiply/4/3     -0.0918    -0.0918
BM_MatrixTransposeVectorMultiply/4/4     -0.2570    -0.2570
BM_MatrixTransposeVectorMultiply/4/8     -0.3064    -0.3064
BM_MatrixTransposeVectorMultiply/4/12    -0.3316    -0.3316
BM_MatrixTransposeVectorMultiply/4/15    -0.2794    -0.2794
BM_MatrixTransposeVectorMultiply/6/1     -0.0484    -0.0484
BM_MatrixTransposeVectorMultiply/6/2     -0.1102    -0.1102
BM_MatrixTransposeVectorMultiply/6/3     -0.1188    -0.1188
BM_MatrixTransposeVectorMultiply/6/4     -0.2967    -0.2967
BM_MatrixTransposeVectorMultiply/6/8     -0.3190    -0.3190
BM_MatrixTransposeVectorMultiply/6/12    -0.3441    -0.3441
BM_MatrixTransposeVectorMultiply/6/15    -0.2723    -0.2723
BM_MatrixTransposeVectorMultiply/8/1     -0.0397    -0.0397
BM_MatrixTransposeVectorMultiply/8/2     -0.1453    -0.1453
BM_MatrixTransposeVectorMultiply/8/3     -0.1337    -0.1337
BM_MatrixTransposeVectorMultiply/8/4     -0.3084    -0.3084
BM_MatrixTransposeVectorMultiply/8/8     -0.3444    -0.3444
BM_MatrixTransposeVectorMultiply/8/12    -0.3717    -0.3717
BM_MatrixTransposeVectorMultiply/8/15    -0.3440    -0.3440

Change-Id: I17de05bf94699a07eea880b92a6d08daf1f038bb
2018-04-10 14:42:23 +08:00
Sameer Agarwal bdda32bb16 Add MixedSparseCholesky.
A simple class that composes SparseCholesky with IterativeRefiner.

Change-Id: I4a67b8ca33a604aaa7b6a4bf511dad9501815f5b
2018-04-09 17:40:34 -07:00
Sameer Agarwal 7750c4c55c Add a single precision variant of EigenSparseCholesky.
Given a double precision linear system, solve it using
a single precision Cholesky factorization.

Change-Id: I8a6e8b7a451e961a8a23a62dd7b5d8159c4db8ce
2018-04-09 15:59:45 -07:00
Sameer Agarwal 83f70e5c02 Remove unnecessary memory allocations when using SuiteSparse.
1. Add SuiteSparse::CreateDenseVectorView
2. Replace calls to SuiteSparse::CreateDenseVector with
   SuiteSparse::CreateDenseVectorView.
2. Replace NULL with nullptr in suitesparse.cc and
   dynamic_sparse_normal_cholesky_solver.cc

Change-Id: I94355c1dc27789e5b987a7b2850e9db6176a0914
2018-04-09 14:39:02 -07:00
Sameer Agarwal 21ec8f462c Change the API description for SparseCholesky::Solve.
The description does not reflect reality and puts constraints
on the underlying implementation.

Change-Id: I5f64e776c952868ae82fb2144acf51c2dcdfab56
2018-04-09 14:20:58 -07:00
Sameer Agarwal d0e06760ec Bring the Bazel build in sync with the CMake build.
1. Remove defines which are not used anymore.
2. Enable CXX11 threading.
3. Enable EIGEN_SPARSE by default.

Change-Id: I841ba517367e6b204475e5255c91313f01a5bcdb
2018-04-09 11:42:43 -07:00
Mike Vitus 5d8b494557 Adds a ParallelFor wrapper for no threads and OpenMP.
With the addition of C++11 support we can simplify the parallel for code by
removing the ifdef branching.  Converts coordinate_descent_minimizer.cc to use
the thread_id ParallelFor API.

Tested by building with OpenMP, C++11 threads, TBB, and no threads.  All tests
pass.

Also compared timing via the bundle adjuster.

./bin/bundle_adjuster --input=../problem-744-543562-pre.txt

With OpenMP num_threads=8

Head:
Time (in seconds):
  Residual only evaluation           0.807753 (5)
  Jacobian & residual evaluation     4.489404 (6)
  Linear solver                     41.826481 (5)
Minimizer                           50.745857
Total                               73.294424

CL:
Time (in seconds):
  Residual only evaluation           0.970483 (5)
  Jacobian & residual evaluation     4.647438 (6)
  Linear solver                     41.781892 (5)
Minimizer                           50.848904
Total                               73.089983

With OpenMP num_threads=1

HEAD:
Time (in seconds):
  Residual only evaluation           2.990246 (5)
  Jacobian & residual evaluation    14.132090 (6)
  Linear solver                     79.631951 (5)
Minimizer                          100.281847
Total                              122.946267

CL:
Time (in seconds):
  Residual only evaluation           3.075178 (5)
  Jacobian & residual evaluation    13.966451 (6)
  Linear solver                     77.005441 (5)
Minimizer                           97.568712
Total                              120.410454

Change-Id: I1857d7943073be7465b6c6476bf46ab11c5475a3
2018-04-09 10:10:03 -07:00
Sameer Agarwal 8d7b2528bc Improve the test coverage in small_blas_test
1. Add explicit tests for MatrixMatrixMultiplyNaive and
   MatrixTransposeMatrixMultiplyNaive
2. Add tests that exercise a variety of matrix sizes for
   MatrixVectorMultiply and MatrixTransposeVectorMultiply.

Change-Id: I0b25ec346b719f19b2067848f9d4bb64c9848750
2018-04-08 15:26:52 -07:00
Sameer Agarwal df4de10ace Revert "Optimization for custom small blas multiplication with dynamic"
This reverts commit 68cc71ce5d.

Reason for revert: Breaks a number of tests.

Change-Id: I543eaf2103e9903e9026a1fcc2c0bf517d971190
2018-04-08 17:56:16 +00:00
Sameer Agarwal 865ac62d38 Change a rather strict tolerance in the iterative_refiner_test
Change-Id: I924ab56e24b18502797202167703e4e9bf555550
2018-04-08 10:42:10 -07:00
yangfan 68cc71ce5d Optimization for custom small blas multiplication with dynamic
template parameters in C level.

- unroll for loops
- matrix access more cache coherent
- platform independant

Briefly, this commit brings 1~50% performance improvments for
most cases in small_blas_gem(m/v)_benchmark, but a small drop
for corner cases with small dimensions especially 1,2,3. Here
we list the results partially, which show decrease percentage
of executing time, compared to unoptimized version.

Platform: desktop PC (i7-7700 CPU MP8@3.60GHz + ubuntu 17.10)
(Lenovo Research Device+ Lab, <yangfan34@lenovo.com>)

Benchmark                                   Time        CPU
-----------------------------------------------------------
BM_MatrixMatrixMultiplyDynamic/2/2/2     -0.1082    -0.1083
BM_MatrixMatrixMultiplyDynamic/2/2/15    -0.1270    -0.1270
BM_MatrixMatrixMultiplyDynamic/2/4/2     -0.1433    -0.1433
BM_MatrixMatrixMultiplyDynamic/2/4/15    -0.2069    -0.2068
BM_MatrixMatrixMultiplyDynamic/2/6/2     -0.1446    -0.1446
BM_MatrixMatrixMultiplyDynamic/2/6/15    -0.2156    -0.2156
BM_MatrixMatrixMultiplyDynamic/2/8/2     -0.1788    -0.1788
BM_MatrixMatrixMultiplyDynamic/2/8/15    -0.3316    -0.3316
BM_MatrixMatrixMultiplyDynamic/2/10/2    -0.2025    -0.2025
BM_MatrixMatrixMultiplyDynamic/2/10/15   -0.3444    -0.3444
BM_MatrixMatrixMultiplyDynamic/2/12/2    -0.0515    -0.0515
BM_MatrixMatrixMultiplyDynamic/2/12/15   -0.3733    -0.3733
BM_MatrixMatrixMultiplyDynamic/2/15/2    -0.2784    -0.2784
BM_MatrixMatrixMultiplyDynamic/2/15/15   -0.3704    -0.3704
BM_MatrixMatrixMultiplyDynamic/4/2/2     -0.1839    -0.1839
BM_MatrixMatrixMultiplyDynamic/4/2/15    -0.1922    -0.1922
BM_MatrixMatrixMultiplyDynamic/4/4/2     -0.2248    -0.2248
BM_MatrixMatrixMultiplyDynamic/4/4/15    -0.3132    -0.3132
BM_MatrixMatrixMultiplyDynamic/4/6/2     -0.2311    -0.2311
BM_MatrixMatrixMultiplyDynamic/4/6/15    -0.3239    -0.3239
BM_MatrixMatrixMultiplyDynamic/4/8/2     -0.0574    -0.0574
BM_MatrixMatrixMultiplyDynamic/4/8/15    -0.4173    -0.4173
BM_MatrixMatrixMultiplyDynamic/4/10/2    -0.2861    -0.2861
BM_MatrixMatrixMultiplyDynamic/4/10/15   -0.4065    -0.4064
BM_MatrixMatrixMultiplyDynamic/4/12/2    -0.2976    -0.2975
BM_MatrixMatrixMultiplyDynamic/4/12/15   -0.4218    -0.4218
BM_MatrixMatrixMultiplyDynamic/4/15/2    -0.3116    -0.3116
BM_MatrixMatrixMultiplyDynamic/4/15/15   -0.4242    -0.4241
BM_MatrixMatrixMultiplyDynamic/8/12/2    -0.3675    -0.3674
BM_MatrixMatrixMultiplyDynamic/8/12/4    -0.5055    -0.5055
BM_MatrixMatrixMultiplyDynamic/8/12/6    -0.4302    -0.4302
BM_MatrixMatrixMultiplyDynamic/8/12/8    -0.4854    -0.4854
BM_MatrixMatrixMultiplyDynamic/8/12/10   -0.4882    -0.4882
BM_MatrixMatrixMultiplyDynamic/8/12/12   -0.5209    -0.5209
BM_MatrixMatrixMultiplyDynamic/8/12/15   -0.4558    -0.4558
BM_MatrixMatrixMultiplyDynamic/8/15/2    -0.2319    -0.2319
BM_MatrixMatrixMultiplyDynamic/8/15/4    -0.5105    -0.5105
BM_MatrixMatrixMultiplyDynamic/8/15/6    -0.4477    -0.4477
BM_MatrixMatrixMultiplyDynamic/8/15/8    -0.5479    -0.5479
BM_MatrixMatrixMultiplyDynamic/8/15/10   -0.4843    -0.4843
BM_MatrixMatrixMultiplyDynamic/8/15/12   -0.5212    -0.5212
BM_MatrixMatrixMultiplyDynamic/8/15/15   -0.4459    -0.4459

BM_MatrixVectorMultiply/1/1              +0.0978    +0.0978
BM_MatrixVectorMultiply/1/2              +0.0551    +0.0551
BM_MatrixVectorMultiply/1/3              -0.0019    -0.0020
BM_MatrixVectorMultiply/1/4              +0.0563    +0.0562
BM_MatrixVectorMultiply/1/6              +0.1379    +0.1379
BM_MatrixVectorMultiply/1/7              +0.1090    +0.1090
BM_MatrixVectorMultiply/1/12             +0.0901    +0.0901
BM_MatrixVectorMultiply/1/16             +0.0493    +0.0493
BM_MatrixVectorMultiply/1/20             +0.2255    +0.2255
BM_MatrixVectorMultiply/2/1              +0.1261    +0.1261
BM_MatrixVectorMultiply/2/2              +0.2328    +0.2328
BM_MatrixVectorMultiply/2/3              +0.1404    +0.1403
BM_MatrixVectorMultiply/2/4              +0.0257    +0.0256
BM_MatrixVectorMultiply/2/6              -0.1691    -0.1691
BM_MatrixVectorMultiply/2/7              -0.2619    -0.2619
BM_MatrixVectorMultiply/2/12             -0.4261    -0.4261
BM_MatrixVectorMultiply/2/16             -0.5387    -0.5387
BM_MatrixVectorMultiply/2/20             -0.6171    -0.6171
BM_MatrixVectorMultiply/3/1              +0.1664    +0.1664
BM_MatrixVectorMultiply/3/2              +0.0848    +0.0848
BM_MatrixVectorMultiply/3/3              -0.0044    -0.0044
BM_MatrixVectorMultiply/3/4              -0.0683    -0.0684
BM_MatrixVectorMultiply/3/6              -0.1652    -0.1652
BM_MatrixVectorMultiply/3/7              -0.1633    -0.1633
BM_MatrixVectorMultiply/3/12             -0.1921    -0.1921
BM_MatrixVectorMultiply/3/16             -0.3659    -0.3659
BM_MatrixVectorMultiply/3/20             -0.4137    -0.4137
BM_MatrixVectorMultiply/4/1              -0.0577    -0.0577
BM_MatrixVectorMultiply/4/2              -0.1337    -0.1338
BM_MatrixVectorMultiply/4/3              -0.1443    -0.1443
BM_MatrixVectorMultiply/4/4              +0.0013    +0.0013
BM_MatrixVectorMultiply/4/6              -0.1071    -0.1071
BM_MatrixVectorMultiply/4/7              -0.1396    -0.1397
BM_MatrixVectorMultiply/4/12             -0.2792    -0.2792
BM_MatrixVectorMultiply/4/16             -0.4485    -0.4486
BM_MatrixVectorMultiply/4/20             -0.3588    -0.3588

Change-Id: I64a8cf11391e3d06341a2b8764cd1b4f1b8a23f1
2018-04-08 14:23:10 +00:00
Sameer Agarwal f27082a174 Handle possible overflow in TrustRegionStepEvaluator.
Thanks to Volker Grabe for reporting the problem and suggesting
a fix.

Change-Id: I8072ffb275907baac62ee2ad84a02f17eb447c63
2018-04-06 20:13:16 -07:00
Sameer Agarwal 86814ab193 Add Iterative Refinement
Add a class IterativeRefiner which implements iterative refinement
for SPD linear systems.

Change-Id: I705d4e96cb7de9226ee35e2a9c11d98ffc0ee239
2018-04-06 16:51:14 -07:00
Sameer Agarwal 9814a91fcf Use C++11's inline member initialization syntax
Migrate all Option and Summary structs to use
inline member initialization syntax.

This reduces the amount of code, and collocates the
default values with the documentation for the corresponding
member variable.

Change-Id: I8e6b9ee3b31464699d678667f6166ace5fc137c9
2018-04-06 16:50:42 -07:00
Alex Stewart 6851a63861 Fix lower-bound on result of minimising step-size polynomial.
- Previously we were requesting a step-size which minimised the
  polynomial in: [previous.x, current.x * factor].
- This is incorrect c/f Nocedal & Wright p60, the bounds for the
  minimising step-size should be: [current.x, current.x * factor].
- However, Nocedal & Wright's bounds are insufficient when the function
  can return invalid values, which we support.
- In the case that f(current) is invalid, we need to contract the
  step-size to lie within: [previous.x, current.x) given that we know
  that previous.x is valid so a valid step must exist within that range.

Change-Id: I67b5aaa09cc6d54cf5f264e2cf894ddc2af3f3ad
2018-04-06 19:57:38 +01:00
Sameer Agarwal 8202edcbb4 Add missing <algorithm> headers.
Thanks to kea@google.com for reporting this.

Change-Id: I9bde5823e9ea89451f476694c9b860080dffdf17
2018-04-05 11:53:48 -07:00
Sameer Agarwal 47863a1e56 Remove unnecessary unique_ptr initializations
Change-Id: Ibcd3676907f8cb0662b80f600101bcd7bec8e785
2018-04-03 11:29:04 -07:00
Mike Vitus e809cf0c28 Adds missing functional include in thread_pool.h
Fixes a build error when building with CXX11_THREADS=ON.

Change-Id: I5828dc408261c88a93745c2ade0b8da740a68e54
2018-04-03 11:14:41 -07:00
Sameer Agarwal e49507cbea More C++ification.
"> >" -> ">>"
"> > >" -> ">>>"

Change-Id: Id1ddd9dbf030fe21d57207741b4ca8403068e55b
2018-04-03 10:58:15 -07:00
Alex Stewart af77d3e676 Fix exported gflags include path.
- In practice, this was not causing any errors, as
  GFLAGS_INCLUDE_DIR_HINTS is set from GFLAGS_INCLUDE_DIRS so the two
  would have been equivalent, but we should nonetheless be using the
  one set after the find_package() call.
- Note that this would only have been active for older gflags versions
  that were not built with CMake.

Change-Id: Ie54145f522c974b7685052aafb1d2f6055d22337
2018-04-03 18:07:43 +01:00
Keir Mierle 7c4e8a454e Replace scoped_ptr with C++11's unique_ptr
Change-Id: Ib5a504c491e3a79af52a95accf009df473470c6b
2018-04-02 14:47:47 -07:00
Sameer Agarwal fc9336e12a Deprecate mutex.h
Use C++11's std::mutex and std::lock_guard instead.

Change-Id: If8d513d5d8f2ee2a49c1ebb249ffa93e4a80086b
2018-04-02 06:03:06 -07:00
Sameer Agarwal a1458f3348 More C++11ification.
1. Replace HashMap and HashSet with std::unordered_map and
   std::unordered_set respectively.
2. Extract the pair hasher into a struct pair_hash.
3. Delete collections_port.h
4. Convert explicit iterator based loops to auto based
   loops where sensible.

Change-Id: Ib88bcd13a7463d18435639d3b771abaa52080efb
2018-03-30 12:03:28 -07:00
Sameer Agarwal ffae101c75 Removed CERES_USE_CXX11
Remove the special handling for tr1::shared_ptr.

Change-Id: Ic405dcfe881dd6560d236956f84bfb8911d0bcbb
2018-03-29 15:16:49 -07:00
Alex Stewart 282b8b5f35 Require >= C++11 & CMake >= 3.5 when building Ceres.
- Removes CXX11 option, and all associate paraphernalia.  Ceres now
  requires a compiler with full >= C++11 support.  In MSVC terms this
  means >= 2013 Release 4.
- This deprecates the use of CERES_STD_UNORDERED_MAP and CERES_USE_CXX11
  as they will now always be defined.  They will be removed from the
  source in a future CL.
- For clients with CMake >= 3.8 we propagate via the exported/installed
  Ceres target the CXX version that was specified when Ceres was built.
  For versions < 3.8 (but >= 3.5) we specify the CXX features currently
  used in the Ceres public API.

Change-Id: I535b545b10156e4426659c270a4a0649e071df0e
2018-03-29 09:32:59 +01:00
Sameer Agarwal 9d4d0bfe29 Make CompressedRowSparseMatrix sensitive to StorageType
Even though we added support for storing the upper and
lower triangular parts of symmetric matrices in
CompressedRowSparseMatrix. RightMultiply, LeftMultiply
and SquaredColumnNorm were not modified to account for this.

This CL changes their implementation and adds thorough
tests.

Also methods that cannot work correctly with symmetric
storage now CHECK and fail, because that indicates
programmer error.

Change-Id: I76288472c8bac98db7376a79bdb6259e346ef2b7
2018-03-26 20:46:57 +00:00
Sameer Agarwal edffd386d2 Remove an unneeded virtual method from EigenSparseCholesky.
Change-Id: I4f9d1730feb98b21db8dea9cc1357a365fb8fcb8
2018-03-26 13:32:52 -07:00
Sameer Agarwal 0258b2a0b0 Update the sizes in small_blas_gem?_benchmark.cc
The sizes are reflective of the matrix sizes
that occur in production.

Change-Id: I8cd85d0640702df09afafced0d28ef416bab946f
2018-03-23 13:40:14 -07:00
Sameer Agarwal facb199f3e Add the missing (2,4,6) specialization to Android.mk
Change-Id: I02c7a9bd1ac1d4b4b4a19e9846c1347c4c1981a4
1.14.0
2018-03-21 21:00:14 -07:00
Alex Stewart b5d6ee4a88 Move C++11 checks to after external find_package() calls.
- Testing for C++11, and subsequent testing for components using C++11
  requires adding -std=c++11 to CMAKE_REQUIRED_FLAGS used by the
  check_cxx_source_compiles() (and similar) macros if required by the
  compiler.
- This variable is also used for the C equivalent macros, which are used
  by find_package(BLAS), and would cause the detection to fail if
  present.
- Thus if CXX11 was forced ON via -D (not via the GUI) then detection
  would fail (with the GUI an initial configure without CXX11 would
  initialise the variables and no errors would occur in later
  reconfigures).

Change-Id: I08d300baf3730e926fb8e853a384badcceefeaf5
1.14.0rc2
2018-03-19 14:39:07 +00:00
Alex Stewart a80b8cfeac Fix C++11 detection for VS2010.
- Use cmake_dependent_option() for all threading models and encode their
  respective mutual exclusivity in the dependent-option s/t the job of
  ensuring mutual exclusivity is performed by CMake.
- Use of cmake_dependent_option() has the downside that options are
  removed from the GUI if their requirements for availability are not
  met.  So if CXX11 is OFF, then neither TBB nor CXX11_THREADS will
  even appear as options (they will be undefined, assumed OFF).
- Perform checks for availability of C++11 if CXX11 is enabled prior to
  testing other options to handle dependence of TBB & CXX11_THREADS on
  CXX11 actually being present.
- Add check for availability of C++11-specific math functions used in
  jet.h before reporting C++11 as found.
- Add check for <atomic> before allowing TBB or CXX11_THREADS, as both
  options require it and it may not always be available even if the
  other required C++11 components are.

Change-Id: Ife8cd182aeb1978539ce2c9966910ae59ebd9177
2018-03-19 09:40:48 +00:00
Sameer Agarwal 76fc404579 Do not add CERES_NO_THREADS is OPENMP is not detected.
This logic was too strict and conflicted with CXX11 threads.

Change-Id: If9ac543be9765555c1eaa4e1f69d4398c72dc26f
1.14.0rc1
2018-03-13 10:27:07 -07:00
Sameer Agarwal c2f5cd10e7 Update docs and code in preparation for 1.14.0
Change-Id: I81b430fbff62fb5e3f4c75945f6d40361d546918
2018-03-13 10:10:13 -07:00
Keir Mierle 7bdceb46cf Evaluation callback API
This adds a callback mechanism to for users to get notified just
before jacobian and residual evaluations. This will enable
aggressive caching and sharing of compute between cost functions.

Change-Id: I67993726920218edf71ab9ae70c34c204756c71a
2018-03-07 12:41:22 -08:00
Sameer Agarwal 83098e12e8 Two changes to how we manage user's state.
1. When Solver::Options::update_state_every_iteration = true,
   the StateUpdatingCallback only updates the state on a
   successful iteration. This works fine but will not work
   if the user provides an EvaluationCallback, because
   every call to Evaluator::Evaluate will change the state
   visible to the user. This means that on unsuccessful
   iterations when the user's IterationCallback is called
   the state visible to the user would be the last evaluation
   which did not lead to an improved cost. This CL forces
   the StateUpdatingCallback to unconditionally update
   the user visible state.

2. When the minimizer terminates, we update the user visible
   state only if the solution is usable, otherwise the user's
   state will remain the same. To maintain this invariant
   we will now cache the user's state and make sure we
   use it to reset it upon return if the solver is not
   successful.

Change-Id: Ic1f8fa6cb10d2753130ea752c70ff3d6b2f1462f
2018-03-06 19:12:14 +00:00
Alex Stewart df2d882540 Remove armv7 from target architectures when building for iOS >= 11.
- iOS 11+ requires a 64-bit architecture, so only arm64 is supported.

Change-Id: Ieb2ead13ba8722c6c0777b78f59f667331ad670c
2018-03-04 12:16:27 +00:00
Sameer Agarwal 2f2e7222fa Fix c++98 mode compilation for parallel_utils_test.cc
Change-Id: I009032978bca910704c52f4de693d04fa13c6e07
2018-03-02 16:41:18 -08:00
William Rucklidge 21f519d009 Improve threading in covariance.
Covariance computation wants to do a triangular iteration but as a
single loop. Right now it iterates over a square and does nothing half
the time, which is inefficient and has bad worst-case threading
performance. This adds a utility that allows waste-free linear iteration
over a triangle.

Change-Id: I881d5683c65882f87dc2b5f8449a855d22ace755
2018-03-02 13:33:19 -08:00
Keir Mierle 0a30117489 Add parallel bundle tests to CMake build
This converts the bundle_adjustment_test to the parallel
version with multiple binaries, as is already in place for
the Bazel build. Additionally, since there is no longer a
need for it, this deletes bundle_adjustment_test.cc.

The test suite now runs on my 6 year old desktop in ~60 seconds!

Change-Id: Ib4a59f8749e823f697e6da5d303977d284303ae3
2018-03-02 19:38:32 +00:00
Sameer Agarwal 660960294c Remove an errant binary character
Change-Id: I22b6ef8975c3c8a34e7f96ca89e4ec90461f453c
2018-03-01 13:12:57 -08:00
Mike Vitus f0c3b23684 Increases the performance of the C++11 threading.
Previously, the thread ID was acquired and released on every iteration
of the for loop.  The C++11 concurrent queue implementation is much
slower than TBB's version and consequently this was a huge bottleneck.

This introduces another ParallelFor API which takes the thread ID as a
parameter in the evaluation function.  This allows us to acquire and
release the thread ID for each block of work which drastically improves
the performance.

This change brings us on par with OpenMP and TBB.  See below for a
timing comparison.  Note: in this example this CLs C++11 version is
faster to compute the residuals because TBB still must acquire the
thread ID on every iteration, which has some overhead.

Tested by building and running tests for no threading, OpenMP, TBB, and
C++11 threads.  Also ran bazel tests.

./bin/bundle_adjuster --input=problem-744-543562-pre.txt --num_threads=8

C++11 @Head
Time (in seconds):
  Residual only evaluation           7.819692 (5)
  Jacobian & residual evaluation    11.606063 (6)
  Linear solver                     47.860195 (5)
Minimizer                           70.877072

Total                               90.806338
---------------------------------------------------

C++11 (This CL)
Time (in seconds):
  Residual only evaluation           1.217500 (5)
  Jacobian & residual evaluation     5.796112 (6)
  Linear solver                     44.080873 (5)
Minimizer                           54.635524

Total                               77.640072

---------------------------------------------------
OpenMP
Time (in seconds):
  Residual only evaluation           0.797023 (5)
  Jacobian & residual evaluation     5.633916 (6)
  Linear solver                     43.280020 (5)
Minimizer                           53.199058

Total                               76.250861

---------------------------------------------------
TBB
Time (in seconds):

  Residual only evaluation           1.911095 (5)
  Jacobian & residual evaluation     5.557807 (6)
  Linear solver                     44.074680 (5)
Minimizer                           55.002688

Total                               78.052687

---------------------------------------------------
No Threads

Time (in seconds):

  Residual only evaluation           2.939212 (5)
  Jacobian & residual evaluation    18.519874 (6)
  Linear solver                     74.017837 (5)
Minimizer                           98.980080

Total                              122.216391

Change-Id: I3af959b0771bbdfe8cad8c13896191d6ac903181
2018-03-01 09:00:44 -08:00
Mike Vitus 4e391c36c1 Corrects the documentation of Problem::AddResidualBlock.
This change is provided on behalf of Steve Hsu.

Tested by compiling and inspecting the documentation.

Change-Id: Ib892bcc3ad76cba1bad133a1fd1d26468d0e6437
2018-03-01 04:09:09 +00:00
Sameer Agarwal 8c81149e4d Revert changes to MatrixTransposeMatrixMultiply.
This change while algebraically equivalent was causing non-trivial
changes in the numbers being reported by ceres and in some cases
they got worse.

Also fix a small header include in parallel_for_test.cc which
was discovered as part of testing this patch.

Change-Id: I8c8d61538819f0b25af6059fa75ad068fc22f5e4
2018-02-28 19:47:52 -08:00
Sameer Agarwal 3d933750a7 Deprecate Solver::Options::num_linear_solver_threads
1. Solver::Options::num_threads now controls parallelism in Ceres
   Solver. The user specified value of
   Solver::Options::num_linear_solver_threads is ignored.
2. If the user specifies Solver::Options::num_linear_solver_threads
   and it is different from Solver::Options::num_threads,
   a warning is printed.
3. Solver::Summary:num_linear_solver_threads_given and
   Solver::Summary::num_linear_solver_threads_used are also
   deprecated and are always set to Solver::Summary::num_threads_given
   and Solver::Summary::num_threads_used.

Change-Id: I20b9336d9336e400e6f0a15b63857c0c43eb271c
2018-02-27 20:38:05 -08:00
Sameer Agarwal d9d8de556a Convert a nested loop into a linear loop in covariance_impl.h
This improves the readability and simplifies the logic
for interfacing with ParallelFor. More importantly, it paves the
way for ParallelFor refactoring to improve its performance.

Change-Id: I13b05596228900ee00d71f2ccce1db338844b9ab
2018-02-27 15:43:41 -08:00