Commit Graph

1377 Commits

Author SHA1 Message Date
Alex Stewart 8f41ca6abc Add Apple's Accelerate framework as a sparse linear algebra library.
- Currently DynamicSparseNormalCholeskySolver is unsupported for
  Accelerate.

Change-Id: I03b5a86bb22fef249c4aecd48947a613e8eff7a5
2018-06-29 09:43:03 +01:00
Alex Stewart 357288008e Add description of option controlling Android debug symbol stripping.
Change-Id: I00b37f38ed5dfca1959eafb410ae85240e1f5c91
2018-06-28 19:20:35 +01:00
Linus Mårtensson 9f3d9aebed Add android CMake support
Change-Id: I78b4794786cc1b03946b6b15aa93e46a4303a39c
2018-06-26 15:59:44 +02:00
Alex Stewart d656d34809 Refactor Ceres threading option configuration.
- Previously we had separate variables for each of the threading
  backends, each of which were made mutually exclusive via
  cmake_dependent_option().  This has unfortunate side-effects when
  trying to disable options if they are not currently enabled, in which
  case they are not defined.
- As all the threading options are mutually exclusive, this replaces
  all threading option variables with a single variable: CERES_THREADS,
  which is constrained to take the value of only the available threading
  backends.

Change-Id: I0822eefbac9a30772907b7732add365b37cc8ca0
2018-06-20 23:20:57 +00:00
Alex Stewart 9671d850e6 Replace (MSVC/GCC/CLANG)_VERSION with CMAKE_CXX_COMPILER_VERSION.
- As raised in issue #377, GCC_VERSION is not always defined, in which
  case we were not enabling compiler optimisations.
- CMAKE_CXX_COMPILER_VERSION is the more modern, uniform method to
  verify the compiler version.
- Also removes legacy Apple-GCC (i.e. Apple's fork of GCC prior to their
  switch to Clang) logic, and Xcode 4.x logic (in June 2018, Xcode 9.x
  is the current version).
- Also removes addition of -march=native on Linux (was not added for
  OS X).  If users wish to append -march=native (which will affect the
  portability of the resulting output) they can do so manually as now
  explained in the docs.
- Fixes check for Clang on OS X.  As per CMP0025 (CMake 3.0+)
  CMAKE_CXX_COMPILER_ID reports AppleClang on OS X, not Clang. Thus
  using: if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") would fail for
  AppleClang.  Instead, MATCHES should be used instead of STREQUAL to
  support both Clang & AppleClang.

Change-Id: I9647030b76f4b85a9ef2deea82d80ed79812ae33
2018-06-20 19:43:12 +01:00
Alex Stewart 799fd50192 Ensure host-built packages are not used when building for iOS.
- Add missing CMAKE_FIND_ROOT_PATH_MODE_PACKAGE = ONLY, mimicking what
  we previously set for INCLUDE/LIBRARY/PROGRAM s/t the standard
  package locations on the host system will not be searched by
  find_package() when cross-compiling for iOS.
- Remove now unnecessary forced disabling of dependency options on iOS
  as they should now never be found (unless they were explicitly built
  for iOS) irrespective of whether the option defaults to ON initially.

Change-Id: I1d2c5da4838d7becb8ebd43f90a88cfc6ded4a1f
2018-06-20 09:43:26 +01:00
Alex Stewart 51dcd40ba5 Do not update CMAKE_REQUIRED_FLAGS to match CMAKE_CXX_FLAGS.
- This was a hangover from the pre-Ceres 2.0 era when we needed to
  ensure that -std=c++11 was passed to check_cxx_source_compiles() in
  FindUnorderedMap/FindSharedPtr if the user had enabled CXX11.
- Unfortunately, the same variable (CMAKE_REQUIRED_FLAGS) is used for
  both check_cxx_source_compiles() and check_c_source_compiles(), and
  thus updating it to include -std=c++11 would thus break any checks
  for C, which are made internally in the version of FindThreads.cmake
  shipped with CMake which could cause build breakage as identified
  in issue #355.

Change-Id: I36be1a21db14e3839eaf955a80bd952ef40fa269
2018-06-17 22:44:15 +00:00
Alex Stewart d7a95968ac Guard parallel_for_nothreads with CERES_NO_THREADS.
- Raised as issue #384.

Change-Id: I72954d93ce3f27b58b719b28b766c7c0e7a6faf6
2018-06-17 20:43:00 +01:00
Alex Stewart 7582834a7e Do not bypass default CMake compiler checks on iOS.
- This should no longer be required on newer (3.5+) CMake versions and
  breaks the detection of supplementary compiler feature information
  such as the population of CMAKE_CXX_COMPILE_FEATURES which is required
  in order to compile Ceres.

Change-Id: Ibceab545925aa1e829320efa03fb74ef149cbb8b
2018-06-17 16:13:56 +01:00
Pau Gargallo fda6214f33 Handle NULL permutation from SuiteSparseQR
SuiteSparseQR sets permutation to NULL when the permutation is the
identity. Thus, instead of checking that permutation is not NULL, we
handle that case when building the inverse_permutation.

Change-Id: Ib0fcdf3462da765ac0d4b7aee47a1dff7b3a6c53
2018-06-14 09:31:11 +02:00
Norbert Wenzel 1e8e9452d0 Remove chunk shuffle in multithreaded SchurEliminator
std::random_shuffle() is deprecated since C++14 and was removed in
C++17. At least MSVC with C++17 fails to compile this code, I assume
other compilers fail as well.

In a Github discussion (#373) Sameer Agarwal states this line can
likely be dropped and asks for a PR/CL.

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

Change-Id: I78e04f36cba398769b8f90916edbdaf33884e7e1
2018-05-22 17:02:02 +02:00
Sameer Agarwal e9397ad352 Enable visibility based preconditioners for CX_SPARSE and EIGEN_SPARSE
CLUSTER_JACOBI and CLUSTER_TRIDIAGONAL preconditioners require a sparse
Cholesky factorization library. Previously this code was hard coded to
use SuiteSparse. Once SparseCholesky abstraction was introduced, it
became possible to use it with Eigen or CXSParse.

Unfortunately the old code path that was enforcing the requirement
of SuiteSparse was not removed.

This change does the following:

1. Remove the SUITE_SPARSE restriction on CLUSTER_TRIDIAGONAL and
   CLUSTER_JACOBI
2. Redo the checking code to be ifdef free and more general.
3. Add bundle adjustment tests to test these configurations.

Thanks to Bjorn Piltz for catching and reporting this bug.

Change-Id: I637791f6f8149694b6aa75f6a4b6417398cb9590
2018-05-09 13:57:12 -07:00
Alex Stewart f9272d3e1b Add /bigobj to nist on MSVC.
- Required by MSVC 2017, raised as issue #368.

Change-Id: Ie1431b4c1fad7a45342a98b1fd20ab7c51d8b899
2018-05-08 09:31:22 +01:00
Alex Stewart d856af0859 Add no-threads ParallelFor implementation.
- When Ceres was configured without any multithreading enabled (actually
  the default) it would fail to build due to undefined symbols for
  ParallelFor() as there was no implementation for that case.
- This adds a trivial single-threaded implementation for that case,
  taken from the C++11 threads implementation.

Change-Id: Ib3cfd620842b09f1acafe95b8b0ba3aee4587581
2018-05-02 13:50:37 +01:00
Sameer Agarwal c6cf24cb1b Update Android.mk
1. Add some missing files.
2. Add support for EIGEN_SPARSE.
3. Enable OpenMP threading by default.

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

Change-Id: I68c6369d0176a2f48c3d036400b5b0675f2e4abb
2018-04-28 17:17:32 +00:00
Sameer Agarwal 7c037647fa Move some jet tests under a eigen 3.3.0 version ifdef
Change-Id: I65c1749d987f9b0925daed277b1373a7e31bf54d
2018-04-27 13:00:55 -07:00
Sameer Agarwal 26a470e863 Resolve two old TODOs in jet.h
1. Use using directive to pull functions from the std:: namespace
   instead of defining a forwarding function.
2. Remove Eigen 2.0 related definitions.

Change-Id: If5f24ef740c17bc4db300fa04f4a2e8f809970d2
2018-04-27 10:57:21 -07:00
Sameer Agarwal cfdc2af28b Remove Solver::Options::num_linear_solver_threads
Also removed Solver::Summary::num_linear_solver_threads_given
and Solver::Summary::num_linear_solver_threads_used.

Change-Id: I559145ae2e7af597ea06ec03d386645a3a892e9f
2018-04-26 21:13:35 -07:00
Keir Mierle cd48f83f8d Bump Ceres version to 2.0.0
Due to the large amount of changes made as part of
the C++11 migration, it makes sense to have a
large version bump.

Change-Id: I2d81828e2d8e23f0829070726e7b3ec31d7f1724
2018-04-24 17:56:25 +00:00
Sameer Agarwal dc8ef467e3 Move max_align_t handling into jet.h
This was currently buried in port.h. Since there is exactly one use
of the max_align_t handling, it is better from a readability
and cleanliness perspective to have this in jet.h.

Change-Id: I2f3dde75df7c333bd95393b9e4fc4cd5160d6afb
2018-04-23 10:03:45 -07:00
Alex Stewart f52e041c49 Fix 'xxx.cc has no symbols' warnings.
- As OPENMP, TBB & CXX11_THREADS are mutually exclusive, and their
  implementations are wholly contained within enclosing #ifdefs if the
  requisite option is not enabled then the source file is 'empty'.
- This triggers 'xxx.cc has no symbol' warnings when compiling
  Ceres statically, as such we now only include these files if they are
  not going to be empty.

Change-Id: I5390251b44c5770bbdd4ccb1bc916dbe3b1814a9
2018-04-22 14:38:54 +01:00
Sameer Agarwal 056140e3a0 Add a typedef to expose the scalar type used in a Jet.
Change-Id: I4232d76619f4f9c48a0c716150b8c5ffc8b74462
2018-04-20 14:05:14 -07:00
Sameer Agarwal 865952821f Fix a use after free bug in the tests.
The way the SystemTest fixture works is that it takes
a "FooProblem" object as a type, which contains a ceres::Problem
and a ceres::Solver::Options object.

The Options object also contains a linear_solver_ordering which
contains double* which refer to memory that is allocated when
a problem object is created.

So it is important that the lifetime of the ceres::Problem object
and the ceres::Solver::Options object be tied together. But we were
violating this by creating a FooProblem object on the stack, grabbing
its Options struct and passing it to the SystemTest fixture, which
would then create another instance of FooProblem, grab its Problem
object and copy the modified options struct into it.

In the case where a user provided ordering was being used,
this ordering would now be referring to memory allocated by the first
FooProblem object, which would cause Ceres's internal ApplyOrdering
function to fail.

The fix is ofcourse to Problem and Options object that are born
together.

Change-Id: I07c377a9d5fcabbb6c7ca8aa3460206ce045ffa9
2018-04-20 11:02:48 -07:00
Sameer Agarwal 4556eb9810 Simplify integration tests.
1. Remove SolverConfig, this was a wrapper
   around Solver::Options. As we experiment
   with more Solver::Options, it became a hurdle.

2. Updated generate_bundle_adjustment_tests.py to use
   Solver::Options directly.
3. Update system_test to use Solver::Options.

NOTE: generate_bundle_adjustment_tests.py changes are a bit
gunky, but I tried to minimize the changes in this CL
as I am going to introduce new test cases and that
is going to significantly change this file.

Change-Id: I34a2f51824b04ef368a5bbe54fbd7b281381909e
2018-04-18 17:37:20 -07:00
Sameer Agarwal d15503219f Simplify OrderedGroups using C++11 syntax
Change-Id: I3e50bb66c43245df979a471622957fd01e73d014
2018-04-18 16:32:16 -07:00
Sameer Agarwal 31f24521cc Deprecate macros.h and fpclassify.h
1. Replace CERES_DISALLOW_* with explicitly deleted constructors.
2. Replace use of CERES_ARRAY_SIZE and stack allocated arrays
   with std::vector.
3. Move CERES_ALIGN_* macros into manual_constructor.h, which is
   the one place they are used and will be deprecated along with that
   file.
4. Introduce isnan,isnormal,isinf and isfinite for Jets.
5. Replace IsNormal,IsFinite,IsNaN and IsInfinite with corresponding
   c++11 function calls.

Change-Id: I04f33a221aae77d247602150988b6d4aa4efeeab
2018-04-18 09:54:42 -07:00
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