96 lines
3.6 KiB
Markdown
96 lines
3.6 KiB
Markdown
# Optimization: Inlining
|
|
|
|
- **Author**: Elliot
|
|
- **Predecessor**: variant_baseline.cpp
|
|
- **File(s)**: variants/variant_inlining_1.cpp ... variants/variant_inlining_7.cpp, headers/pedestrian_reduced.hpp
|
|
- **Status**: positive (~+13% perf)
|
|
|
|
## What this changes
|
|
|
|
Manually inlined `w`, `acceleration_term_dt`, `pedestrian_repulsion_dt`,
|
|
`obstacle_repulsion_dt`, `norm`, `dot`, and `find_nearest_obstacle_point` all
|
|
into `run_simulation`. Got rid of small-number EPS checks after verifying they
|
|
do not affect results. Removed all references to `Vector2d` and rewrote
|
|
`Pedestrian` as a struct of doubles. Reduced `sqrt()` calls using mathematical
|
|
properties.
|
|
|
|
Built up progressively across 7 variants (`inlining_1` through `inlining_7`),
|
|
each variant adding one more change on top of the previous one. See the file
|
|
headers in each variant for the specific incremental change.
|
|
|
|
## Code (relevant snippet)
|
|
|
|
TBD - see `variants/variant_inlining_7.cpp` for the final version, and the
|
|
individual file headers for the incremental steps.
|
|
|
|
## Benchmark
|
|
|
|
Conditions: single run (TODO: switch to min-of-N), N_ITER=1000,
|
|
-O3 -march=native -flto. Predecessor reference for the same config is the
|
|
baseline row.
|
|
|
|
### x86
|
|
|
|
**Machine**:
|
|
|
|
```
|
|
Processors: 16 x AMD Ryzen AI 7 350 w/ Radeon 860M
|
|
Memory: 32 GiB of RAM (30.6 GiB usable)
|
|
Graphics Processor: AMD Radeon 860M Graphics
|
|
Manufacturer: LENOVO
|
|
Product Name: 83HX
|
|
System Version: IdeaPad Slim 5 14AKP10
|
|
```
|
|
|
|
**Frequency**: 2 GHz
|
|
|
|
Existing single-point measurement (N unspecified, kept from the previous
|
|
OPTIMIZATIONS.md; W matches roughly N=120 at N_ITER=1000):
|
|
|
|
| Variant | W(n) [Flops] | T(n) [Cycles] | Performance [Flops/Cycle] |
|
|
| -------- | ---------------- | -------------- | ------------------------- |
|
|
| Baseline | 1'058'400'000.00 | 850'352'900.00 | 1.24 |
|
|
| Inlining | 1'058'400'000.00 | 756'088'260.00 | 1.40 |
|
|
|
|
Inlining is about 12.9% faster on this point. A full N sweep with min-of-3 is TODO.
|
|
|
|
Full sweep (TODO):
|
|
|
|
| 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
|
|
|
|
TBD - speedup likely comes from a mix of: eliminating function-call overhead at
|
|
the ~2*N^2 hot-call sites, the struct-of-doubles `Pedestrian` improving
|
|
register allocation, and the algebraic sqrt reductions cutting expensive ops.
|
|
Worth confirming by looking at the generated assembly for the inner loop in
|
|
`variant_inlining_7.cpp`.
|
|
|
|
## Takeaway
|
|
|
|
TBD
|