71 lines
2.5 KiB
Markdown
71 lines
2.5 KiB
Markdown
# Optimization: Struct of Arrays (SoA)
|
|
|
|
- **Author**: Linus
|
|
- **Predecessor**: variant_inlining_7.cpp
|
|
- **File(s)**: variants/variant_inlining_7_SoA.cpp
|
|
- **Status**: TBD
|
|
|
|
## What this changes
|
|
|
|
Replaced the `Pedestrian` struct with parallel `vector<double>` arrays, one
|
|
per field (`pos_x`, `pos_y`, `e_x`, `e_y`, `sb_e_x`, `sb_e_y`, `sb_sq`, ...).
|
|
Board obstacles are left as AoS since there are only a handful of them.
|
|
|
|
Mostly a setup step for AVX2: with SoA the inner ped-ped loop reads
|
|
contiguous chunks of `pos_x[j..]`, which is what we'll want for aligned
|
|
vector loads.
|
|
|
|
## Code (relevant snippet)
|
|
|
|
```cpp
|
|
vector<double> pos_x, pos_y;
|
|
vector<double> sb_sq, sb_e_x, sb_e_y;
|
|
vector<double> e_x, e_y;
|
|
vector<double> curr_vel_x, curr_vel_y;
|
|
// ...
|
|
```
|
|
|
|
See `variants/variant_inlining_7_SoA.cpp`.
|
|
|
|
## Benchmark
|
|
|
|
Conditions: 2 runs, N_ITER=1000, -O3 -march=native -flto. Diff is vs
|
|
`variant_inlining_7`.
|
|
On my local machine i had an improvement of about 10-15% for low N and about 5% speed up for higher N
|
|
|
|
### x86
|
|
|
|
**Machine**: TBD
|
|
|
|
**Frequency**: TBD
|
|
|
|
| N | W(n) [Flops] | T(n) [Cycles] | Performance [Flops/Cycle] | Diff vs Predecessor |
|
|
| ---- | ------------ | ------------- | ------------------------- | ------------------- |
|
|
| 50 | | | | |
|
|
| 100 | | | | |
|
|
| 200 | | | | |
|
|
| 500 | | | | |
|
|
| 1000 | | | | |
|
|
|
|
### ARM (Apple)
|
|
|
|
**Machine**: TBD
|
|
|
|
**Frequency**: TBD
|
|
|
|
| N | W(n) [Flops] | T(n) [Cycles] | Performance [Flops/Cycle] | Diff vs Predecessor |
|
|
| ---- | ------------ | ------------- | ------------------------- | ------------------- |
|
|
| 50 | | | | |
|
|
| 100 | | | | |
|
|
| 200 | | | | |
|
|
| 500 | | | | |
|
|
| 1000 | | | | |
|
|
|
|
## Analysis
|
|
|
|
No in depth Analysis done, just thought i wanna share it so you can also use it for further optimizations
|
|
|
|
## Takeaway
|
|
|
|
Layout change, not a performance win by itself. Sets up the AVX2 variant.
|