Skip to content

Commit ba19870

Browse files
authored
Merge pull request #48 from fabinsch/add-benchmark-vectorization
benchmark: document speed up by vectorization
2 parents 4b7d008 + 2df2a45 commit ba19870

File tree

3 files changed

+108
-4
lines changed

3 files changed

+108
-4
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ Through **ProxSuite**, we aim at offering to the community scalable optimizers w
1616

1717
**ProxSuite** is integrated into the [cvxpy](https://www.cvxpy.org/) modeling language for convex optimization problems.
1818

19-
## Quick install
19+
## Getting started
2020

2121
**ProxSuite** is distributed on many well-known package managers.
2222

23-
### With <img src="https://www.python.org/static/community_logos/python-logo-inkscape.svg" height="30" style="vertical-align: -1em;">:
23+
### Quick install with <img src="https://www.python.org/static/community_logos/python-logo-inkscape.svg" height="30" style="vertical-align: -1em;">:
2424

2525
```bash
2626
pip install proxsuite
2727
```
2828
This approach is only available on Linux and Mac OS X.
2929

30-
### With <img src="https://s3.amazonaws.com/conda-dev/conda_logo.svg" height="18">:
30+
### Quick install with <img src="https://s3.amazonaws.com/conda-dev/conda_logo.svg" height="18">:
3131

3232
```bash
3333
conda install proxsuite -c conda-forge
@@ -36,8 +36,13 @@ This approach is available on Linux, Windows and Mac OS X.
3636

3737
### Alternative approaches
3838

39-
Alternative installation procedures are presented in the [Installation Procedure](#installation-procedure) section.
39+
Installation from source is presented [here](https://github.com/Simple-Robotics/proxsuite/blob/main/doc/5-installation.md).
4040

41+
### Compiling a program
42+
For the fastest performance use the following command to enable vectorization
43+
```bash
44+
g++ -O3 -march=native -DNDEBUG -std=gnu++17 -DPROXSUITE_VECTORIZE examples/benchmark_dense_qp.cpp -o benchmark_dense_qp $(pkg-config --cflags proxsuite)
45+
```
4146
## ProxSuite main features
4247

4348
**Proxsuite** is fast:

doc/1-Overview.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ You can compile the C++ version by including ProxSuite and Eigen header director
4848

4949
\code g++ -std=c++17 examples/cpp/overview-simple.cpp -o overview-simple $(pkg-config --cflags proxsuite) \endcode
5050

51+
If you are looking for the fastest performance, use the following flags to use SIMDE in proxsuite and tell your
52+
compiler to use the corresponding cpu instruction set
53+
\code g++ -O3 -march=native -DNDEBUG -DPROXSUITE_VECTORIZE -std=c++17 examples/cpp/overview-simple.cpp -o overview-simple $(pkg-config --cflags proxsuite)
54+
\endcode
55+
5156
Once your code is compiled, you might then run it using
5257

5358
\code ./overview-simple \endcode
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
3+
Compile this code once with and without vectorization to see performance
4+
difference.
5+
6+
Use vectorization:
7+
g++ -O3 -march=native -DNDEBUG -std=gnu++17 -DPROXSUITE_VECTORIZE
8+
benchmark_dense_qp.cpp -o benchmark_dense_qp $(pkg-config --cflags proxsuite)
9+
10+
Do not use vectorization:
11+
g++ -DNDEBUG -std=gnu++17 benchmark_dense_qp.cpp -o benchmark_dense_qp
12+
$(pkg-config --cflags proxsuite)
13+
14+
Comparison of timings on Intel i7-11850H and ubuntu 20.04 using this file:
15+
16+
With vectorization:
17+
sparsity_factor: 0.1
18+
Setup Time consumption(dense): 0.000237295s
19+
Solve Time consumption(dense): 0.000500206s
20+
sparsity_factor: 0.2
21+
Setup Time consumption(dense): 0.000465961s
22+
Solve Time consumption(dense): 0.000903787s
23+
sparsity_factor: 0.3
24+
Setup Time consumption(dense): 0.000697931s
25+
Solve Time consumption(dense): 0.00136976s
26+
sparsity_factor: 0.4
27+
Setup Time consumption(dense): 0.000931736s
28+
Solve Time consumption(dense): 0.00185252s
29+
30+
31+
Without vectorization:
32+
sparsity_factor: 0.1
33+
Setup Time consumption(dense): 0.0147825s
34+
Solve Time consumption(dense): 0.0277815s
35+
sparsity_factor: 0.2
36+
Setup Time consumption(dense): 0.029592s
37+
Solve Time consumption(dense): 0.0490869s
38+
sparsity_factor: 0.3
39+
Setup Time consumption(dense): 0.0443664s
40+
Solve Time consumption(dense): 0.0746045s
41+
sparsity_factor: 0.4
42+
Setup Time consumption(dense): 0.0592621s
43+
Solve Time consumption(dense): 0.101507s
44+
45+
*/
46+
47+
#include <proxsuite/proxqp/dense/dense.hpp>
48+
#include <proxsuite/proxqp/utils/random_qp_problems.hpp>
49+
50+
using namespace proxsuite::proxqp;
51+
using T = double;
52+
53+
int
54+
main()
55+
{
56+
double N = 100;
57+
double solve_time = 0.0;
58+
double setup_time = 0.0;
59+
60+
dense::isize dim = 100;
61+
dense::isize n_eq(dim * 0.5);
62+
dense::isize n_in(dim * 0.5);
63+
64+
for (T sparsity_factor = 0.1; sparsity_factor < 0.5; sparsity_factor += 0.1) {
65+
T strong_convexity_factor(1.e-2);
66+
dense::Model<T> qp_random = utils::dense_strongly_convex_qp(
67+
dim, n_eq, n_in, sparsity_factor, strong_convexity_factor);
68+
69+
for (int i = 0; i < N; i++) {
70+
dense::QP<T> qp(dim, n_eq, n_in);
71+
qp.settings.max_iter = 10000;
72+
qp.settings.max_iter_in = 1000;
73+
qp.settings.eps_abs = 1e-5;
74+
qp.settings.eps_rel = 0;
75+
qp.init(qp_random.H,
76+
qp_random.g,
77+
qp_random.A,
78+
qp_random.b,
79+
qp_random.C,
80+
qp_random.l,
81+
qp_random.u);
82+
qp.solve();
83+
solve_time += qp.results.info.solve_time / N;
84+
setup_time += qp.results.info.setup_time / N;
85+
}
86+
std::cout << "sparsity_factor: " << sparsity_factor << std::endl;
87+
std::cout << "Setup Time consumption(dense): " << setup_time / 1e6 << "s"
88+
<< std::endl
89+
<< "Solve Time consumption(dense): " << solve_time / 1e6 << "s"
90+
<< std::endl;
91+
}
92+
93+
return 0;
94+
}

0 commit comments

Comments
 (0)