ceres.bzl 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. # Ceres Solver - A fast non-linear least squares minimizer
  2. # Copyright 2018 Google Inc. All rights reserved.
  3. # http://ceres-solver.org/
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions are met:
  7. #
  8. # * Redistributions of source code must retain the above copyright notice,
  9. # this list of conditions and the following disclaimer.
  10. # * Redistributions in binary form must reproduce the above copyright notice,
  11. # this list of conditions and the following disclaimer in the documentation
  12. # and/or other materials provided with the distribution.
  13. # * Neither the name of Google Inc. nor the names of its contributors may be
  14. # used to endorse or promote products derived from this software without
  15. # specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  21. # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  24. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  25. # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  27. # POSSIBILITY OF SUCH DAMAGE.
  28. #
  29. # Support for building Ceres Solver with a specific configuration.
  30. CERES_SRCS = ["internal/ceres/" + filename for filename in [
  31. "accelerate_sparse.cc",
  32. "array_utils.cc",
  33. "block_evaluate_preparer.cc",
  34. "block_jacobi_preconditioner.cc",
  35. "block_jacobian_writer.cc",
  36. "block_random_access_dense_matrix.cc",
  37. "block_random_access_diagonal_matrix.cc",
  38. "block_random_access_matrix.cc",
  39. "block_random_access_sparse_matrix.cc",
  40. "block_sparse_matrix.cc",
  41. "block_structure.cc",
  42. "c_api.cc",
  43. "callbacks.cc",
  44. "canonical_views_clustering.cc",
  45. "cgnr_solver.cc",
  46. "compressed_col_sparse_matrix_utils.cc",
  47. "compressed_row_jacobian_writer.cc",
  48. "compressed_row_sparse_matrix.cc",
  49. "conditioned_cost_function.cc",
  50. "context.cc",
  51. "context_impl.cc",
  52. "coordinate_descent_minimizer.cc",
  53. "corrector.cc",
  54. "cost_function.cc",
  55. "covariance.cc",
  56. "covariance_impl.cc",
  57. "dense_cholesky.cc",
  58. "dense_normal_cholesky_solver.cc",
  59. "dense_qr.cc",
  60. "dense_qr_solver.cc",
  61. "dense_sparse_matrix.cc",
  62. "detect_structure.cc",
  63. "dogleg_strategy.cc",
  64. "dynamic_compressed_row_jacobian_writer.cc",
  65. "dynamic_compressed_row_sparse_matrix.cc",
  66. "dynamic_sparse_normal_cholesky_solver.cc",
  67. "eigensparse.cc",
  68. "evaluation_callback.cc",
  69. "evaluator.cc",
  70. "file.cc",
  71. "first_order_function.cc",
  72. "float_suitesparse.cc",
  73. "function_sample.cc",
  74. "gradient_checker.cc",
  75. "gradient_checking_cost_function.cc",
  76. "gradient_problem.cc",
  77. "gradient_problem_solver.cc",
  78. "implicit_schur_complement.cc",
  79. "inner_product_computer.cc",
  80. "is_close.cc",
  81. "iteration_callback.cc",
  82. "iterative_refiner.cc",
  83. "iterative_schur_complement_solver.cc",
  84. "levenberg_marquardt_strategy.cc",
  85. "line_search.cc",
  86. "line_search_direction.cc",
  87. "line_search_minimizer.cc",
  88. "line_search_preprocessor.cc",
  89. "linear_least_squares_problems.cc",
  90. "linear_operator.cc",
  91. "linear_solver.cc",
  92. "loss_function.cc",
  93. "low_rank_inverse_hessian.cc",
  94. "manifold.cc",
  95. "minimizer.cc",
  96. "normal_prior.cc",
  97. "parallel_for.cc",
  98. "parallel_invoke.cc",
  99. "parallel_utils.cc",
  100. "parameter_block_ordering.cc",
  101. "partitioned_matrix_view.cc",
  102. "polynomial.cc",
  103. "power_series_expansion_preconditioner.cc",
  104. "preconditioner.cc",
  105. "preprocessor.cc",
  106. "problem.cc",
  107. "problem_impl.cc",
  108. "program.cc",
  109. "reorder_program.cc",
  110. "residual_block.cc",
  111. "residual_block_utils.cc",
  112. "schur_complement_solver.cc",
  113. "schur_eliminator.cc",
  114. "schur_jacobi_preconditioner.cc",
  115. "schur_templates.cc",
  116. "scratch_evaluate_preparer.cc",
  117. "single_linkage_clustering.cc",
  118. "solver.cc",
  119. "solver_utils.cc",
  120. "sparse_cholesky.cc",
  121. "sparse_matrix.cc",
  122. "sparse_normal_cholesky_solver.cc",
  123. "stringprintf.cc",
  124. "subset_preconditioner.cc",
  125. "suitesparse.cc",
  126. "thread_pool.cc",
  127. "thread_token_provider.cc",
  128. "triplet_sparse_matrix.cc",
  129. "trust_region_minimizer.cc",
  130. "trust_region_preprocessor.cc",
  131. "trust_region_step_evaluator.cc",
  132. "trust_region_strategy.cc",
  133. "types.cc",
  134. "visibility_based_preconditioner.cc",
  135. "visibility.cc",
  136. "wall_time.cc",
  137. ]]
  138. # TODO(rodrigoq): add support to configure Ceres into various permutations,
  139. # like SuiteSparse or not, threading or not, glog or not, and so on.
  140. # See https://github.com/ceres-solver/ceres-solver/issues/335.
  141. def ceres_library(name,
  142. restrict_schur_specializations=False):
  143. # The path to internal/ depends on whether Ceres is the main workspace or
  144. # an external repository.
  145. if native.repository_name() != '@':
  146. internal = 'external/%s/internal' % native.repository_name().lstrip('@')
  147. else:
  148. internal = 'internal'
  149. # The fixed-size Schur eliminator template instantiations incur a large
  150. # binary size penalty, and are slow to compile, so support disabling them.
  151. schur_eliminator_copts = []
  152. if restrict_schur_specializations:
  153. schur_eliminator_copts.append("-DCERES_RESTRICT_SCHUR_SPECIALIZATION")
  154. schur_sources = [
  155. "internal/ceres/generated/schur_eliminator_d_d_d.cc",
  156. "internal/ceres/generated/partitioned_matrix_view_d_d_d.cc",
  157. ]
  158. else:
  159. schur_sources = native.glob(["internal/ceres/generated/*.cc"])
  160. native.cc_library(
  161. name = name,
  162. # Internal sources, options, and dependencies.
  163. srcs = CERES_SRCS + schur_sources + native.glob([
  164. "include/ceres/internal/*.h",
  165. ]) + native.glob([
  166. "internal/ceres/*.h",
  167. ]),
  168. # These headers are made available to other targets.
  169. hdrs =
  170. native.glob(["include/ceres/*.h"]) + native.glob([
  171. "include/ceres/internal/*.h",
  172. ]) +
  173. # This is an empty config and export, since the
  174. # Bazel-based build does not generate a
  175. # config.h/export.h. This is fine, since Bazel properly
  176. # handles propagating -D defines to dependent targets.
  177. native.glob([
  178. "config/ceres/internal/config.h",
  179. "config/ceres/internal/export.h",
  180. ]),
  181. copts = [
  182. "-I" + internal,
  183. "-Wunused-parameter",
  184. "-Wno-sign-compare",
  185. ] + schur_eliminator_copts,
  186. # These include directories and defines are propagated to other targets
  187. # depending on Ceres.
  188. # TODO(keir): These defines are placeholders for now to facilitate getting
  189. # started with a Bazel build. However, these should become configurable as
  190. # part of a Skylark Ceres target macro.
  191. # https://github.com/ceres-solver/ceres-solver/issues/396
  192. defines = [
  193. "CERES_EXPORT=",
  194. "CERES_NO_ACCELERATE_SPARSE",
  195. "CERES_NO_CHOLMOD_PARTITION",
  196. "CERES_NO_CUDA",
  197. "CERES_NO_EIGEN_METIS",
  198. "CERES_NO_EXPORT=",
  199. "CERES_NO_LAPACK",
  200. "CERES_NO_SUITESPARSE",
  201. "CERES_USE_EIGEN_SPARSE",
  202. ],
  203. includes = [
  204. "config",
  205. "include",
  206. ],
  207. visibility = ["//visibility:public"],
  208. deps = [
  209. "@com_gitlab_libeigen_eigen//:eigen",
  210. "@com_github_google_glog//:glog",
  211. ],
  212. )