Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ceres-solver: add support for SuiteSparse, CUDA, LAPACK and METIS #23815

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a70e4b5
ceres-solver: various recipe improvements
valgur Apr 29, 2024
9593448
ceres-solver: backport a fix for a minor SuiteSparse compatibility issue
valgur Apr 29, 2024
76b3a7f
ceres-solver: bump OpenBLAS
valgur May 6, 2024
93b87ea
ceres-solver: improve CUDA support
valgur May 6, 2024
2f5d88a
ceres-solver: make SuiteSparse support more robust
valgur May 6, 2024
ac2a9d4
ceres-solver: fix v1.14 suitesparse support
valgur Jun 7, 2024
a6726e5
ceres-solver: add CXSparse to older versions
valgur Jun 17, 2024
6c90006
ceres-solver: don't force linking with gomp for OpenMP in v1.14.0
valgur Jun 22, 2024
9545199
ceres-solver: disable suitesparse
valgur Jul 8, 2024
60c20cf
ceres-solver: revert glog version bump
valgur Aug 5, 2024
47f1d3a
ceres-solver: various recipe improvements
valgur Apr 29, 2024
da34a43
ceres-solver: backport a fix for a minor SuiteSparse compatibility issue
valgur Apr 29, 2024
eaab941
ceres: bump OpenBLAS
valgur May 6, 2024
0f85938
ceres: improve CUDA support
valgur May 6, 2024
0bfc23b
ceres: make SuiteSparse support more robust
valgur May 6, 2024
c98ce4a
ceres-solver: fix v1.14 suitesparse support, WIP
valgur Jun 7, 2024
0da47c6
ceres-solver: fix SuiteSparse on Ceres v1
valgur Jun 9, 2024
5da4270
ceres-solver: add CXSparse to older versions
valgur Jun 17, 2024
5374838
ceres-solver: upgrade llvm-openmp to v18.1.8
valgur Jun 20, 2024
33393d8
ceres-solver: don't force linking with gomp for OpenMP in v1.14.0
valgur Jun 22, 2024
642b483
ceres-solver: downgrade glog for compatibility with colmap
valgur Aug 5, 2024
d38720b
ceres-solver: remove unused import
valgur Aug 28, 2024
c8094e3
Update all SuiteSparse packages
valgur Aug 28, 2024
a8e897a
Use openblas/0.3.28 for cross-compilation support
valgur Nov 11, 2024
3397ab7
ceres-solver: drop Conan v1 support
valgur Feb 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions recipes/ceres-solver/all/FindSuiteSparse.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Simplified replacement for https://github.com/ceres-solver/ceres-solver/blob/2.2.0/cmake/FindSuiteSparse.cmake

find_package(CHOLMOD REQUIRED CONFIG)
find_package(SPQR REQUIRED CONFIG)
find_package(METIS CONFIG)

add_library(SuiteSparse::Partition ALIAS SuiteSparse::CHOLMOD)

set(SuiteSparse_FOUND TRUE)

# For Ceres v1
set(SUITESPARSE_FOUND TRUE)
set(SUITESPARSE_LIBRARIES SuiteSparse::CHOLMOD SuiteSparse::SPQR)
7 changes: 7 additions & 0 deletions recipes/ceres-solver/all/ceres-conan-cuda-support.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
find_dependency(CUDAToolkit REQUIRED)

set(_Ceres_CUDA_dependencies CUDA::cublas CUDA::cudart CUDA::cusolver CUDA::cusparse)
target_link_libraries(Ceres::ceres INTERFACE ${_Ceres_CUDA_dependencies})
if(TARGET Ceres::ceres_cuda_kernels)
target_link_libraries(Ceres::ceres_cuda_kernels INTERFACE ${_Ceres_CUDA_dependencies})
endif()
18 changes: 15 additions & 3 deletions recipes/ceres-solver/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,21 @@ patches:
- patch_file: "patches/2.1.0-0002-fix-mingw-build.patch"
patch_description: "Fix MinGW build"
patch_type: "portability"
- patch_file: "patches/2.1.0-0004-suitesparse-compatibility.patch"
patch_description: "Enable compatibility with SuiteSparse 7.2.0"
patch_type: "backport"
patch_source: "https://github.com/ceres-solver/ceres-solver/commit/9cca671273c2f205ca7350422f48b7b119c5dd78"
"2.0.0":
- patch_file: "patches/2.0.0-0001-find-libraries-conan.patch"
patch_description: "Robust dependencies handling"
patch_type: "conan"
- patch_file: "patches/2.0.0-0002-fix-mingw-build.patch"
patch_description: "Fix MinGW build"
patch_type: "portability"
- patch_file: "patches/2.0.0-0001-find-libraries-conan.patch"
patch_description: "Robust dependencies handling"
patch_type: "conan"
- patch_file: "patches/2.0.0-0004-suitesparse-compatibility.patch"
patch_description: "Enable compatibility with SuiteSparse 7.2.0"
patch_type: "backport"
patch_source: "https://github.com/ceres-solver/ceres-solver/commit/9cca671273c2f205ca7350422f48b7b119c5dd78"
"1.14.0":
- patch_file: "patches/1.14.0-0001-find-libraries-conan.patch"
patch_description: "Robust dependencies handling"
Expand All @@ -41,3 +49,7 @@ patches:
patch_description: "Fix compilation with C++17 standard and above"
patch_type: "portability"
patch_source: "https://github.com/ceres-solver/ceres-solver/commit/1e8e9452d0a7dfaf5697b544810798a58e35443e"
- patch_file: "patches/1.14.0-0004-suitesparse-compatibility.patch"
patch_description: "Enable compatibility with SuiteSparse 7.2.0"
patch_type: "backport"
patch_source: "https://github.com/ceres-solver/ceres-solver/commit/9cca671273c2f205ca7350422f48b7b119c5dd78"
248 changes: 152 additions & 96 deletions recipes/ceres-solver/all/conanfile.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -209,40 +209,40 @@ endif (IOS)
@@ -209,43 +209,43 @@
unset(CERES_COMPILE_OPTIONS)

# Eigen.
Expand Down Expand Up @@ -52,8 +52,43 @@
+endif ()

if (LAPACK)
find_package(LAPACK QUIET)
@@ -376,13 +376,14 @@ else (MINIGLOG)
- find_package(LAPACK QUIET)
+ find_package(LAPACK REQUIRED)
if (LAPACK_FOUND)
message("-- Found LAPACK library: ${LAPACK_LIBRARIES}")
else (LAPACK_FOUND)
@@ -263,8 +263,8 @@
# built with SuiteSparse support.

# Check for SuiteSparse and dependencies.
- find_package(SuiteSparse)
- if (SUITESPARSE_FOUND)
+ find_package(SuiteSparse REQUIRED)
+ if (1)
# On Ubuntu the system install of SuiteSparse (v3.4.0) up to at least
# Ubuntu 13.10 cannot be used to link shared libraries.
if (BUILD_SHARED_LIBS AND
@@ -300,7 +300,7 @@
# CXSparse.
if (CXSPARSE)
# Don't search with REQUIRED as we can continue without CXSparse.
- find_package(CXSparse)
+ find_package(CXSparse REQUIRED)
if (CXSPARSE_FOUND)
# By default, if CXSparse and all dependencies are found, Ceres is
# built with CXSparse support.
@@ -336,8 +336,8 @@
# GFlags.
if (GFLAGS)
# Don't search with REQUIRED as we can continue without gflags.
- find_package(Gflags)
- if (GFLAGS_FOUND)
+ find_package(Gflags REQUIRED)
+ if (1)
message("-- Found Google Flags header in: ${GFLAGS_INCLUDE_DIRS}, "
"in namespace: ${GFLAGS_NAMESPACE}")
add_definitions(-DCERES_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE})
@@ -376,13 +376,14 @@
unset(MINIGLOG_MAX_LOG_LEVEL CACHE)
# Don't search with REQUIRED so that configuration continues if not found and
# we can output an error messages explaining MINIGLOG option.
Expand All @@ -71,7 +106,7 @@
# By default, assume gflags was found, updating the message if it was not.
set(GLOG_GFLAGS_DEPENDENCY_MESSAGE
" Assuming glog was built with gflags support as gflags was found. "
@@ -395,7 +396,8 @@ else (MINIGLOG)
@@ -395,7 +396,8 @@
"Otherwise, Ceres may fail to link due to missing gflags symbols.")
endif(NOT GFLAGS_FOUND)
message("-- Found Google Log (glog)." ${GLOG_GFLAGS_DEPENDENCY_MESSAGE})
Expand All @@ -81,7 +116,29 @@

if (NOT SCHUR_SPECIALIZATIONS)
list(APPEND CERES_COMPILE_OPTIONS CERES_RESTRICT_SCHUR_SPECIALIZATION)
@@ -526,7 +528,7 @@ if (CXX11 AND (TBB OR CXX11_THREADS))
@@ -409,18 +411,9 @@

if (OPENMP)
# Find quietly, as we can continue without OpenMP if it is not found.
- find_package(OpenMP QUIET)
- if (OPENMP_FOUND)
- message("-- Building with OpenMP.")
- list(APPEND CERES_COMPILE_OPTIONS CERES_USE_OPENMP)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
- else (OPENMP_FOUND)
- message("-- Failed to find OpenMP, disabling. This is expected on "
- "Clang < 3.8, and at least Xcode <= 8. See Ceres documentation for "
- "instructions to build with LLVM from Homebrew to enable OpenMP on OS X.")
- update_cache_variable(OPENMP OFF)
- endif (OPENMP_FOUND)
+ find_package(OpenMP REQUIRED)
+ list(APPEND CERES_COMPILE_OPTIONS CERES_USE_OPENMP)
+ link_libraries(OpenMP::OpenMP_CXX)
else (OPENMP)
message("-- Building without OpenMP, disabling.")
endif (OPENMP)
@@ -526,7 +519,7 @@
endif()

if (CXX11 AND TBB)
Expand All @@ -92,7 +149,7 @@
list(APPEND CERES_COMPILE_OPTIONS CERES_USE_TBB)
--- a/internal/ceres/CMakeLists.txt
+++ b/internal/ceres/CMakeLists.txt
@@ -152,9 +152,10 @@ else (SCHUR_SPECIALIZATIONS)
@@ -152,9 +152,10 @@
endif (SCHUR_SPECIALIZATIONS)

# Build the list of dependencies for Ceres based on the current configuration.
Expand All @@ -106,7 +163,7 @@
# If glog & gflags are both found, we assume that glog was built with
# gflags, as it is awkward to perform a try_compile() to verify this
# when gflags is an imported target (as it is in newer versions).
@@ -162,7 +163,7 @@ if (NOT MINIGLOG AND GLOG_FOUND)
@@ -162,7 +163,7 @@
# gflags, it is thus a public dependency for Ceres in this case.
list(APPEND CERES_LIBRARY_PUBLIC_DEPENDENCIES ${GFLAGS_LIBRARIES})
endif()
Expand All @@ -115,16 +172,27 @@

if (SUITESPARSE AND SUITESPARSE_FOUND)
# Define version information for use in Solver::FullReport.
@@ -191,7 +192,7 @@ if (OPENMP_FOUND)
endif (OPENMP_FOUND)
@@ -180,18 +181,8 @@
list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${LAPACK_LIBRARIES})
endif ()

-if (OPENMP_FOUND)
- # OpenMP support in Clang requires a non-GNU OpenMP library.
- if (CMAKE_COMPILER_IS_GNUCXX)
- list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES gomp)
- endif()
- if (NOT MSVC)
- list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${CMAKE_THREAD_LIBS_INIT})
- endif()
-endif (OPENMP_FOUND)
-
if (TBB_FOUND)
- list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${TBB_LIBRARIES})
+ list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES TBB::tbb)
if (NOT MSVC)
list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${CMAKE_THREAD_LIBS_INIT})
endif (NOT MSVC)
@@ -241,8 +242,8 @@ if (BUILD_SHARED_LIBS)
@@ -241,8 +232,8 @@
# When building a shared library, mark all external libraries as
# PRIVATE so they don't show up as a dependency.
target_link_libraries(ceres
Expand All @@ -135,7 +203,7 @@
else (BUILD_SHARED_LIBS)
# When building a static library, all external libraries are
# PUBLIC(default) since the user needs to link to them.
@@ -250,7 +251,9 @@ else (BUILD_SHARED_LIBS)
@@ -250,7 +241,9 @@
set(CERES_LIBRARY_DEPENDENCIES
${CERES_LIBRARY_PUBLIC_DEPENDENCIES}
${CERES_LIBRARY_PRIVATE_DEPENDENCIES})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
From 9cca671273c2f205ca7350422f48b7b119c5dd78 Mon Sep 17 00:00:00 2001
From: Mark Shachkov <markshachkov@gmail.com>
Date: Sun, 17 Sep 2023 20:57:43 +0200
Subject: [PATCH] Enable compatibility with SuiteSparse 7.2.0

Change-Id: I072dc3f7c245fc2ebbdffed715ac4def20f7dccd
---
internal/ceres/covariance_impl.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/internal/ceres/covariance_impl.cc b/internal/ceres/covariance_impl.cc
index d7a7c0790..1679f234b 100644
--- a/internal/ceres/covariance_impl.cc
+++ b/internal/ceres/covariance_impl.cc
@@ -671,7 +671,7 @@
const SuiteSparse_long rank =
SuiteSparseQR<double>(SPQR_ORDERING_BESTAMD,
SPQR_DEFAULT_TOL,
- cholmod_jacobian.ncol,
+ static_cast<int64_t>(cholmod_jacobian.ncol),
&cholmod_jacobian,
&R,
&permutation,
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -261,7 +261,7 @@
endif (EIGEN3_FOUND)

if (LAPACK)
- find_package(LAPACK QUIET)
+ find_package(LAPACK REQUIRED)
if (LAPACK_FOUND)
message("-- Found LAPACK library: ${LAPACK_LIBRARIES}")
else (LAPACK_FOUND)
@@ -279,7 +279,7 @@
# built with SuiteSparse support.

# Check for SuiteSparse and dependencies.
- find_package(SuiteSparse)
- if (SUITESPARSE_FOUND)
+ find_package(SuiteSparse REQUIRED)
+ if (1)
# On Ubuntu the system install of SuiteSparse (v3.4.0) up to at least
# Ubuntu 13.10 cannot be used to link shared libraries.
@@ -316,7 +316,7 @@
# CXSparse.
if (CXSPARSE)
# Don't search with REQUIRED as we can continue without CXSparse.
- find_package(CXSparse)
- if (CXSPARSE_FOUND)
+ find_package(CXSparse REQUIRED)
+ if (1)
# By default, if CXSparse and all dependencies are found, Ceres is
# built with CXSparse support.
@@ -340,7 +340,7 @@
endif (CXSPARSE)

if (ACCELERATESPARSE)
- find_package(AccelerateSparse)
+ find_package(AccelerateSparse REQUIRED)
if (AccelerateSparse_FOUND)
message("-- Found Apple's Accelerate framework with sparse solvers, "
"building with Accelerate sparse support.")
@@ -389,7 +389,7 @@
# GFlags.
if (GFLAGS)
# Don't search with REQUIRED as we can continue without gflags.
- find_package(gflags 2.2.0)
+ find_package(gflags 2.2.0 REQUIRED)
if (gflags_FOUND)
if (TARGET gflags)
message("-- Found Google Flags (gflags) version ${gflags_VERSION}: ${gflags_DIR}")
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -239,14 +239,14 @@ message("-- Building with C++${CMAKE_CXX_STANDARD}")
# Eigen.
# Eigen delivers Eigen3Config.cmake since v3.3.3
Expand All @@ -19,15 +68,14 @@
endif()

if (EIGENSPARSE)
@@ -258,7 +258,7 @@ if (EIGEN3_FOUND)
@@ -258,6 +258,6 @@ if (EIGEN3_FOUND)
message(" which can still use the EIGEN_SPARSE_QR algorithm.")
add_definitions(-DEIGEN_MPL2_ONLY)
endif (EIGENSPARSE)
-endif (EIGEN3_FOUND)
+endif ()

if (LAPACK)
find_package(LAPACK QUIET)
@@ -427,13 +427,14 @@ else (MINIGLOG)
unset(MINIGLOG_MAX_LOG_LEVEL CACHE)
# Don't search with REQUIRED so that configuration continues if not found and
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
Add the equivalent of /bigobj for MSVC for MinGW to fix 'too many sections'
compile errors due to extensive use of templates.

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -514,6 +514,9 @@ if (MINGW)
@@ -512,8 +512,8 @@
"to a MinGW bug: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=556")
string(REPLACE "-O3" "-O2" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
update_cache_variable(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
+ # Add the equivalent of /bigobj for MSVC for MinGW to fix 'too many sections'
+ # compile errors due to extensive use of templates.
+ add_compile_options(-Wa,-mbig-obj)
endif (MINGW)
-
# After the tweaks for the compile settings, disable some warnings on MSVC.
if (MSVC)
# On MSVC, math constants are not included in <cmath> or <math.h> unless
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
From 9cca671273c2f205ca7350422f48b7b119c5dd78 Mon Sep 17 00:00:00 2001
From: Mark Shachkov <markshachkov@gmail.com>
Date: Sun, 17 Sep 2023 20:57:43 +0200
Subject: [PATCH] Enable compatibility with SuiteSparse 7.2.0

Change-Id: I072dc3f7c245fc2ebbdffed715ac4def20f7dccd
---
internal/ceres/covariance_impl.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/internal/ceres/covariance_impl.cc b/internal/ceres/covariance_impl.cc
index d7a7c0790..1679f234b 100644
--- a/internal/ceres/covariance_impl.cc
+++ b/internal/ceres/covariance_impl.cc
@@ -634,7 +634,7 @@
// separately.
const SuiteSparse_long rank = SuiteSparseQR<double>(SPQR_ORDERING_BESTAMD,
SPQR_DEFAULT_TOL,
- cholmod_jacobian.ncol,
+ static_cast<int64_t>(cholmod_jacobian.ncol),
&cholmod_jacobian,
&R,
&permutation,
Original file line number Diff line number Diff line change
@@ -1,5 +1,50 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -227,7 +227,7 @@
endif (Eigen3_FOUND)

if (CUDA)
- find_package(CUDA QUIET)
+ find_package(CUDA REQUIRED)
if (CUDA_FOUND)
message("-- Found CUDA version ${CUDA_VERSION}: "
"${CUDA_LIBRARIES};"
@@ -244,7 +244,7 @@
endif (CUDA)

if (LAPACK)
- find_package(LAPACK QUIET)
+ find_package(LAPACK REQUIRED)
if (LAPACK_FOUND)
message("-- Found LAPACK library: ${LAPACK_LIBRARIES}")
else (LAPACK_FOUND)
@@ -266,7 +266,7 @@
# built with SuiteSparse support.

# Check for SuiteSparse and dependencies.
- find_package(SuiteSparse 4.0 COMPONENTS CHOLMOD SPQR)
+ find_package(SuiteSparse 4.0 REQUIRED COMPONENTS CHOLMOD SPQR)
if (SuiteSparse_FOUND)
set(SuiteSparse_DEPENDENCY "find_dependency(SuiteSparse ${SuiteSparse_VERSION})")
# By default, if all of SuiteSparse's dependencies are found, Ceres is
@@ -294,7 +294,7 @@
# CXSparse.
if (CXSPARSE)
# Don't search with REQUIRED as we can continue without CXSparse.
- find_package(CXSparse)
+ find_package(CXSparse REQUIRED)
if (CXSparse_FOUND)
set(CXSparse_DEPENDENCY "find_dependency(CXSparse ${CXSparse_VERSION})")
# By default, if CXSparse and all dependencies are found, Ceres is
@@ -318,7 +318,7 @@
endif (CXSPARSE)

if (ACCELERATESPARSE)
- find_package(AccelerateSparse)
+ find_package(AccelerateSparse REQUIRED)
if (AccelerateSparse_FOUND)
message("-- Found Apple's Accelerate framework with sparse solvers, "
"building with Accelerate sparse support.")
@@ -405,13 +405,14 @@ else (MINIGLOG)
unset(MINIGLOG_MAX_LOG_LEVEL CACHE)
# Don't search with REQUIRED so that configuration continues if not found and
Expand Down
Loading