Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 1 | %!TEX root = ceres.tex |
| 2 | \chapter{Building Ceres} |
| 3 | \label{chapter:build} |
| 4 | Ceres source code and documentation is hosted at |
Sameer Agarwal | ba3ccfb | 2012-05-22 06:58:47 -0700 | [diff] [blame] | 5 | \url{http://code.google.com/p/ceres-solver/}. |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 6 | |
| 7 | \section{Dependencies} |
| 8 | Ceres relies on a number of open source libraries, some of which are optional. However, we recommend that you start out by building Ceres with all its dependencies. For details on customizing the build process, please see Section~\ref{sec:custom}. |
| 9 | |
| 10 | \begin{enumerate} |
| 11 | \item{\cmake~\footnote{\url{http://www.cmake.org/}}} is the cross-platform build system used by Ceres. |
| 12 | \item{\eigen~\footnote{\url{http://eigen.tuxfamily.org}}} is used for doing all the low level matrix and |
Sameer Agarwal | ba3ccfb | 2012-05-22 06:58:47 -0700 | [diff] [blame] | 13 | linear algebra operations. |
Sameer Agarwal | 0d2d341 | 2012-05-06 21:16:03 -0700 | [diff] [blame] | 14 | |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 15 | \item{\glog~\footnote{\url{http://code.google.com/p/google-glog}}} is used for error checking and logging. |
Sameer Agarwal | 0d2d341 | 2012-05-06 21:16:03 -0700 | [diff] [blame] | 16 | |
| 17 | Note: Ceres requires \texttt{glog}\ version 0.3.1 or later. Version 0.3 (which ships with Fedora 16) has a namespace bug which prevents Ceres from building. |
| 18 | |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 19 | \item{\gflags~\footnote{\url{http://code.google.com/p/gflags}}} is used by the code in |
Sameer Agarwal | 921e8ab | 2012-05-13 11:39:47 -0700 | [diff] [blame] | 20 | \texttt{examples}. It is also used by some of the tests. Strictly speaking it is not required to build the core library, we do not recommend building Ceres without it. |
Sameer Agarwal | ba3ccfb | 2012-05-22 06:58:47 -0700 | [diff] [blame] | 21 | \item{\suitesparse~\footnote{\url{http://www.cise.ufl.edu/research/sparse/SuiteSparse/}}} is used for sparse matrix analysis, |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 22 | ordering and factorization. In particular Ceres uses the |
| 23 | \amd, \colamd\ and \cholmod\ libraries. This is an optional |
| 24 | dependency. |
| 25 | \item{\blas\ and \lapack} are needed by |
| 26 | \suitesparse. We |
| 27 | recommend either |
| 28 | \texttt{GotoBlas2}~\footnote{\url{http://www.tacc.utexas.edu/tacc-projects/gotoblas2}} |
| 29 | or |
| 30 | \texttt{ATLAS}~\footnote{\url{http://math-atlas.sourceforge.net/}}, |
| 31 | both of which ship with \blas\ and \lapack\ routines. |
Sameer Agarwal | 17fbc8e | 2012-05-01 00:21:19 -0700 | [diff] [blame] | 32 | \item{\texttt{protobuf}~\footnote{\url{http://code.google.com/p/protobuf/}}} is an optional dependency that is used for serializing and deserializing linear least squares problems to disk. This is useful for debugging and testing. Without it, some of the tests will be disabled. |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 33 | \end{enumerate} |
| 34 | |
| 35 | Currently we support building on Linux and MacOS X. Support for other |
| 36 | platforms is forthcoming. |
| 37 | |
| 38 | \section{Building on Linux} |
| 39 | We will use Ubuntu as our example platform. |
| 40 | |
| 41 | \begin{enumerate} |
| 42 | \item{\cmake} |
| 43 | \begin{minted}{bash} |
| 44 | sudo apt-get install cmake |
| 45 | \end{minted} |
| 46 | |
Sameer Agarwal | ba3ccfb | 2012-05-22 06:58:47 -0700 | [diff] [blame] | 47 | \item{\gflags} can either be installed from source via the \texttt{autoconf} invocation |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 48 | \begin{minted}{bash} |
| 49 | tar -xvzf gflags-2.0.tar.gz |
| 50 | cd gflags-2.0 |
| 51 | ./configure --prefix=/usr/local |
| 52 | make |
| 53 | sudo make install. |
| 54 | \end{minted} |
| 55 | or via the \texttt{deb} or \texttt{rpm} packages available on the \gflags\ website. |
| 56 | |
| 57 | \item{\glog} must be configured to use the previously installed |
| 58 | \gflags, rather than the stripped down version that is bundled with \glog. Assuming you have it installed in \texttt{/usr/local} the following \texttt{autoconf} invocation installs it. |
| 59 | \begin{minted}{bash} |
| 60 | tar -xvzf glog-0.3.2.tar.gz |
| 61 | cd glog-0.3.2 |
| 62 | ./configure --with-gflags=/usr/local/ |
| 63 | make |
| 64 | sudo make install |
| 65 | \end{minted} |
| 66 | |
| 67 | \item{\eigen} |
| 68 | \begin{minted}{bash} |
| 69 | sudo apt-get install libeigen3-dev |
| 70 | \end{minted} |
| 71 | |
| 72 | \item{\suitesparse} |
| 73 | \begin{minted}{bash} |
| 74 | sudo apt-get install libsuitesparse-dev |
| 75 | \end{minted} |
| 76 | This should automatically bring in the necessary \blas\ and \lapack\ dependencies. |
| 77 | |
| 78 | \item{\texttt{protobuf}} |
| 79 | \begin{minted}{bash} |
| 80 | sudo apt-get install libprotobuf-dev |
| 81 | \end{minted} |
| 82 | \end{enumerate} |
| 83 | |
| 84 | |
| 85 | We are now ready to build and test Ceres. Note that \texttt{cmake} requires the exact path to the \texttt{libglog.a} and \texttt{libgflag.a} |
| 86 | |
| 87 | \begin{minted}{bash} |
| 88 | tar zxf ceres-solver-1.0.tar.gz |
| 89 | mkdir ceres-bin |
| 90 | cd ceres-bin |
Sameer Agarwal | ba3ccfb | 2012-05-22 06:58:47 -0700 | [diff] [blame] | 91 | cmake ../ceres-solver-1.0 |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 92 | make -j3 |
| 93 | make test |
| 94 | \end{minted} |
| 95 | |
| 96 | You can also try running the command line bundling application with one of the |
| 97 | included problems, which comes from the University of Washington's BAL dataset~\cite{Agarwal10bal}: |
| 98 | \begin{minted}{bash} |
| 99 | examples/simple_bundle_adjuster \ |
| 100 | ../ceres-solver-1.0/data/problem-16-22106-pre.txt \ |
| 101 | \end{minted} |
Sameer Agarwal | 17fbc8e | 2012-05-01 00:21:19 -0700 | [diff] [blame] | 102 | This runs Ceres for a maximum of 10 iterations using the \denseschur\ linear solver. The output should look something like this. |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 103 | \clearpage |
| 104 | \begin{minted}{bash} |
| 105 | 0: f: 1.598216e+06 d: 0.00e+00 g: 5.67e+18 h: 0.00e+00 rho: 0.00e+00 mu: 1.00e-04 li: 0 |
| 106 | 1: f: 1.116401e+05 d: 1.49e+06 g: 1.42e+18 h: 5.48e+02 rho: 9.50e-01 mu: 3.33e-05 li: 1 |
| 107 | 2: f: 4.923547e+04 d: 6.24e+04 g: 8.57e+17 h: 3.21e+02 rho: 6.79e-01 mu: 3.18e-05 li: 1 |
| 108 | 3: f: 1.884538e+04 d: 3.04e+04 g: 1.45e+17 h: 1.25e+02 rho: 9.81e-01 mu: 1.06e-05 li: 1 |
| 109 | 4: f: 1.807384e+04 d: 7.72e+02 g: 3.88e+16 h: 6.23e+01 rho: 9.57e-01 mu: 3.53e-06 li: 1 |
| 110 | 5: f: 1.803397e+04 d: 3.99e+01 g: 1.35e+15 h: 1.16e+01 rho: 9.99e-01 mu: 1.18e-06 li: 1 |
| 111 | 6: f: 1.803390e+04 d: 6.16e-02 g: 6.69e+12 h: 7.31e-01 rho: 1.00e+00 mu: 3.93e-07 li: 1 |
| 112 | |
| 113 | Ceres Solver Report |
| 114 | ------------------- |
| 115 | Original Reduced |
| 116 | Parameter blocks 22122 22122 |
| 117 | Parameters 66462 66462 |
| 118 | Residual blocks 83718 83718 |
| 119 | Residual 167436 167436 |
| 120 | |
| 121 | Given Used |
| 122 | Linear solver DENSE_SCHUR DENSE_SCHUR |
| 123 | Preconditioner N/A N/A |
| 124 | Ordering SCHUR SCHUR |
| 125 | num_eliminate_blocks N/A 22106 |
| 126 | Threads: 1 1 |
| 127 | Linear Solver Threads: 1 1 |
| 128 | |
| 129 | Cost: |
| 130 | Initial 1.598216e+06 |
| 131 | Final 1.803390e+04 |
| 132 | Change 1.580182e+06 |
| 133 | |
| 134 | Number of iterations: |
| 135 | Successful 6 |
| 136 | Unsuccessful 0 |
| 137 | Total 6 |
| 138 | |
| 139 | Time (in seconds): |
| 140 | Preprocessor 0.000000e+00 |
| 141 | Minimizer 2.000000e+00 |
| 142 | Total 2.000000e+00 |
| 143 | Termination: FUNCTION_TOLERANCE |
| 144 | \end{minted} |
| 145 | |
| 146 | \section{Building on OS X} |
| 147 | On OS X, we recommend using the \texttt{homebrew}~\footnote{\url{http://mxcl.github.com/homebrew/}} package manager. |
| 148 | |
| 149 | \begin{enumerate} |
| 150 | \item{\cmake} |
| 151 | \begin{minted}{bash} |
| 152 | brew install cmake |
| 153 | \end{minted} |
Sameer Agarwal | 017c953 | 2012-05-02 08:21:59 -0700 | [diff] [blame] | 154 | \item{\texttt{glog}\ and \texttt{gflags}} |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 155 | |
Sameer Agarwal | 017c953 | 2012-05-02 08:21:59 -0700 | [diff] [blame] | 156 | Installing \texttt{\glog} takes also brings in \texttt{gflags} as a dependency. |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 157 | \begin{minted}{bash} |
Sameer Agarwal | 017c953 | 2012-05-02 08:21:59 -0700 | [diff] [blame] | 158 | brew install glog |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 159 | \end{minted} |
| 160 | \item{\eigen} |
| 161 | \begin{minted}{bash} |
| 162 | brew install eigen |
| 163 | \end{minted} |
| 164 | \item{\suitesparse} |
| 165 | \begin{minted}{bash} |
| 166 | brew install suite-sparse |
| 167 | \end{minted} |
| 168 | \item{\texttt{protobuf}} |
| 169 | \begin{minted}{bash} |
| 170 | brew install protobuf |
| 171 | \end{minted} |
| 172 | \end{enumerate} |
| 173 | |
| 174 | We are now ready to build and test Ceres. |
| 175 | \begin{minted}{bash} |
| 176 | tar zxf ceres-solver-1.0.tar.gz |
| 177 | mkdir ceres-bin |
| 178 | cd ceres-bin |
Sameer Agarwal | ba3ccfb | 2012-05-22 06:58:47 -0700 | [diff] [blame] | 179 | cmake ../ceres-solver-1.0 |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 180 | make -j3 |
| 181 | make test |
| 182 | \end{minted} |
Sameer Agarwal | 17fbc8e | 2012-05-01 00:21:19 -0700 | [diff] [blame] | 183 | Like the Linux build, you should now be able to run \texttt{examples/simple\_bundle\_adjuster}. |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 184 | \section{Customizing the Build Process} |
| 185 | \label{sec:custom} |
| 186 | It is possible to reduce the libraries needed to build Ceres and |
| 187 | customize the build process by passing appropriate flags to \texttt{cmake}. But unless you really know what you are |
| 188 | doing, we recommend against disabling any of the following flags. |
| 189 | |
| 190 | \begin{enumerate} |
| 191 | \item{\texttt{protobuf}} |
Sameer Agarwal | 17fbc8e | 2012-05-01 00:21:19 -0700 | [diff] [blame] | 192 | |
| 193 | |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 194 | Protocol Buffers is a big dependency and if you do not care for the tests that depend on it and the logging support it enables, you can turn it off by using |
| 195 | \begin{minted}{bash} |
| 196 | -DPROTOBUF=OFF. |
| 197 | \end{minted} |
| 198 | |
| 199 | \item{\suitesparse} |
Sameer Agarwal | 17fbc8e | 2012-05-01 00:21:19 -0700 | [diff] [blame] | 200 | |
Sameer Agarwal | ba3ccfb | 2012-05-22 06:58:47 -0700 | [diff] [blame] | 201 | By default, Ceres will only link to SuiteSparse if all its dependencies are present. |
Sameer Agarwal | 921e8ab | 2012-05-13 11:39:47 -0700 | [diff] [blame] | 202 | To build Ceres without \suitesparse\ use |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 203 | \begin{minted}{bash} |
| 204 | -DSUITESPARSE=OFF. |
| 205 | \end{minted} |
Sameer Agarwal | 921e8ab | 2012-05-13 11:39:47 -0700 | [diff] [blame] | 206 | This will also disable dependency checking for \lapack\ and \blas. This saves on binary size, but the resulting version of Ceres is not suited |
| 207 | to large scale problems due to the lack of a sparse Cholesky solver. This will reduce Ceres' dependencies down to |
| 208 | \eigen, \gflags\ and \glog. |
Sameer Agarwal | 17fbc8e | 2012-05-01 00:21:19 -0700 | [diff] [blame] | 209 | |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 210 | \item{\gflags} |
Sameer Agarwal | 17fbc8e | 2012-05-01 00:21:19 -0700 | [diff] [blame] | 211 | |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 212 | To build Ceres without \gflags, use |
| 213 | \begin{minted}{bash} |
| 214 | -DGFLAGS=OFF. |
| 215 | \end{minted} |
| 216 | Disabling this flag will prevent some of the example code from building. |
Sameer Agarwal | 17fbc8e | 2012-05-01 00:21:19 -0700 | [diff] [blame] | 217 | |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 218 | \item{Template Specializations} |
Sameer Agarwal | 17fbc8e | 2012-05-01 00:21:19 -0700 | [diff] [blame] | 219 | |
| 220 | |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 221 | If you are concerned about binary size/compilation time over some |
| 222 | small (10-20\%) performance gains in the \sparseschur\ solver, you can disable some of the template |
| 223 | specializations by using |
| 224 | \begin{minted}{bash} |
| 225 | -DSCHUR_SPECIALIZATIONS=OFF. |
| 226 | \end{minted} |
| 227 | |
| 228 | \item{\texttt{OpenMP}} |
Sameer Agarwal | 17fbc8e | 2012-05-01 00:21:19 -0700 | [diff] [blame] | 229 | |
| 230 | |
Keir Mierle | 8ebb073 | 2012-04-30 23:09:08 -0700 | [diff] [blame] | 231 | On certain platforms like Android, multithreading with OpenMP is not supported. OpenMP support can be disabled by using |
| 232 | \begin{minted}{bash} |
| 233 | -DOPENMP=OFF. |
| 234 | \end{minted} |
Sameer Agarwal | ba3ccfb | 2012-05-22 06:58:47 -0700 | [diff] [blame] | 235 | \end{enumerate} |