blob: f2786d78a163ba569def0ddfa731ccbb259f9cc9 [file] [log] [blame]
Austin Schuh7400da02018-01-28 19:54:58 -08001/*!
2
3\page performance Performance Optimization
4- \subpage compile_time
5- \subpage execution_speed
6
7The Control Toolbox is optimized for performance and, if used correctly, constitutes one of the fastest
8implementation for many state-of-the-art control approaches. This page gives an overview of how to achieve
9best performance.
10
11\page compile_time Optimize Compile Time
12@tableofcontents
13
14Especially with increasing complexity of your project, compilation time of the CT can become long. However,
15there are some tricks to reduce compilation time
16- make sure you compile in Release mode (catkin build -DCMAKE_BUILD_TYPE=RELEASE)
17- use CLANG instead of gcc. See the build flags in the \ref install "Installation Guide" on how to use clang.
18- use \ref prespec
19
20\section prespec Explicit Template Instantiation
21The Control Toolbox is a heavily templated library for best runtime performance. However, this means most
22code lives in header files and gets recompiled when any changes are made to the code. Needless to say, that
23this can become cumbersome after some time. However, there is a simple yet effective workaround:
24Explicit template instantiation. The idea is simple: You define the templates that are used before compilation
25and they get compiled into a library. In CT templates are:
26
27Template Parameter | Description
28------------------ | -----------
29STATE_DIM | The dimension of the system's system state
30CONTROL_DIM | The dimension of the system's control input
31SCALAR | The scalar type used (usually double)
32POS_DIM | (optional) Dimension of the position vector for a symplectic system
33VEL_DIM | (optional) Dimension of the velocity vector for a symplectic system
34
35In case you are multiple systems of different dimensions, you can prespecify each of their dimensions.
36
37To use explicit template instantiation follow these steps:
381. add your dimensions to ct/ct/config/explicit_templates.cfg . You can set POS_DIM and VEL_DIM to 0 if you
39are not using symplectic integrators.
402. rerun cmake: catkin build -DCMAKE_BUILD_TYPE=RELEASE --force-cmake
413. In your executable change the standard CT includes from their regular ones to the prespecified ones,
42e.g. change \code{.cpp}#include <ct/core/core.h>\endcode to \code{.cpp}#include <ct/core/core-prespec.h>\endcode Remember to do this for
43optcon and rbd as well.
44
45\page execution_speed Optimize Execution Speed
46@tableofcontents
47
48- make use of \ref vectorization "Vectorization"
49- use \ref core_tut_linearization "Auto-Differentiation" with just-in-time compilation or code generation
50- if you do not want to use Auto-Diff, consider using the ct::rbd::RbdLinearizer for linearizing Rigid Body Dynamics
51- use multi-threading for Nonlinear Optimal Control Solvers
52- use HPIPM for running MPC or solving Optimal Control problems
53
54
55\section vectorization Vectorization
56Vectorization is a processor feature where a Single Instruction is applied to Multiple Data (SIMD). This
57is especially useful for linear algebra operations. CT relies on [Eigen's Vectorization](http://eigen.tuxfamily.org/index.php?title=FAQ)
58 capabilities. This means CT supports SSE, FMA and AVX2 instructions.
59
60\warning Please study Eigen's documentation carefully. Especially the part about [memory alignment](
61https://eigen.tuxfamily.org/dox/group__DenseMatrixManipulation__Alignement.html)
62
63To enable vectorization in CT build it with vectorization flags. E.g. if you are on a fairly recent Intel CPU
64the following build command will enable vectorization
65
66 catkin build -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_FLAGS="-march=native -mtune=native -mavx2 -mfma"
67
68*/