Merge branch 'linus/optimization_file_structure_update' into 'main'

updated structure of how we document the optimizations

See merge request course-asl-fastcode26/team70!18
This commit is contained in:
[Quy Anh] «Elliot» Nguyen
2026-05-20 09:26:22 +02:00
4 changed files with 257 additions and 166 deletions
+21 -166
View File
@@ -1,18 +1,16 @@
# Optimizations of the Social Force Model # Optimizations of the Social Force Model
## Table of Contents Summary of optimization attempts. Each optimization has its own details file
under `docs/optimization_<name>.md`. Use `docs/optimization_template.md` as
the starting point for a new entry.
1. [Performance Results](#performance-results) To document a new optimization:
2. [Baseline](#2-baseline)
3. [Optimization 1](#3-optimization-1) ```
4. [Optimization 2](#4-optimization-2) cp docs/optimization_template.md docs/optimization_<your_name>.md
5. [Optimization 3](#5-optimization-3) ```
6. [Optimization 4](#6-optimization-4)
7. [Optimization 5](#7-optimization-5) Fill it in, then add a row to the tables below pointing at your file.
8. [Optimization 6](#8-optimization-6)
9. [Optimization 7](#9-optimization-7)
10. [Optimization 8](#10-optimization-8)
11. [Optimization 9](#11-optimization-9)
--- ---
@@ -23,7 +21,7 @@
**Machine**: **Machine**:
``` ```
Processors: 16 × AMD Ryzen AI 7 350 w/ Radeon 860M Processors: 16 x AMD Ryzen AI 7 350 w/ Radeon 860M
Memory: 32 GiB of RAM (30.6 GiB usable) Memory: 32 GiB of RAM (30.6 GiB usable)
Graphics Processor: AMD Radeon 860M Graphics Graphics Processor: AMD Radeon 860M Graphics
Manufacturer: LENOVO Manufacturer: LENOVO
@@ -33,164 +31,21 @@ System Version: IdeaPad Slim 5 14AKP10
**Frequency**: 2 GHz **Frequency**: 2 GHz
| # | Optimization | W(n) [Flops] | T(n) [Cycles] | Performance [Flops/Cycle] | Author | | # | Optimization | W(n) [Flops] | T(n) [Cycles] | Performance [Flops/Cycle] | Author |
| --- | ------------ | ---------------- | -------------- | ------------------------- | ------ | | --- | --------------------------------------- | ---------------- | -------------- | ------------------------- | ------ |
| 0 | Baseline | 1'058'400'000.00 | 850'352'900.00 | 1.24 | | | 0 | [Baseline](optimization_baseline.md) | 1'058'400'000.00 | 850'352'900.00 | 1.24 | |
| 1 | Inlining | 1'058'400'000.00 | 756'088'260.00 | 1.40 | Elliot | | 1 | [Inlining](optimization_inlining.md) | 1'058'400'000.00 | 756'088'260.00 | 1.40 | Elliot |
| 2 | | | | | |
| 3 | | | | | |
| 4 | | | | | |
| 5 | | | | | |
| 6 | | | | | |
| 7 | | | | | |
| 8 | | | | | |
| 9 | | | | | |
### ARM ### ARM (Apple)
**Machine**: **Machine**:
``` ```
TBD
``` ```
**Frequency**: ... **Frequency**: TBD
| # | Optimization | W(n) [Flops] | T(n) [Cycles] | Performance [Flops/Cycle] | Author | | # | Optimization | W(n) [Flops] | T(n) [Cycles] | Performance [Flops/Cycle] | Author |
| --- | ------------ | ------------ | ------------- | ------------------------- | ------ | | --- | --------------------------------------- | ------------ | ------------- | ------------------------- | ------ |
| 0 | Baseline | | | | | | 0 | [Baseline](optimization_baseline.md) | | | | |
| 1 | | | | | |
| 2 | | | | | |
| 3 | | | | | |
| 4 | | | | | |
| 5 | | | | | |
| 6 | | | | | |
| 7 | | | | | |
| 8 | | | | | |
| 9 | | | | | |
## 2. Baseline
**Author**: [Name]
**Description**:
Standard implementation without optimizations.
```cpp
// Paste your code here only the relevant part
```
---
## 3. Optimization 1
**Author**: [Quy Anh] «Elliot» Nguyen
**Description**:
Manually inlined functions, namely `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 checks after verifying they do not affect results. Removed all references to `Vector2d` and rewrote `Pedestrian` into a struct of doubles. Reduced `sqrt()` calls using mathematical properties.
**Relevant Files**: `variant_inlining_1.cpp`, `variant_inlining_2.cpp`, `variant_inlining_3.cpp`, `variant_inlining_4.cpp`, `variant_inlining_5.cpp`, `variant_inlining_6.cpp`, `variant_inlining_7.cpp`, `pedestrian_reduced.hpp`
## 4. Optimization 2
**Author**: [Name]
**Description**:
[Briefly describe the optimization technique]
```cpp
// Paste your code here only the relevant part
```
---
## 5. Optimization 3
**Author**: [Name]
**Description**:
[Briefly describe the optimization technique]
```cpp
// Paste your code here only the relevant part
```
---
## 6. Optimization 4
**Author**: [Name]
**Description**:
[Briefly describe the optimization technique]
```cpp
// Paste your code here only the relevant part
```
---
## 7. Optimization 5
**Author**: [Name]
**Description**:
[Briefly describe the optimization technique]
```cpp
// Paste your code here only the relevant part
```
---
## 8. Optimization 6
**Author**: [Name]
**Description**:
[Briefly describe the optimization technique]
```cpp
// Paste your code here only the relevant part
```
---
## 9. Optimization 7
**Author**: [Name]
**Description**:
[Briefly describe the optimization technique]
```cpp
// Paste your code here only the relevant part
```
---
## 10. Optimization 8
**Author**: [Name]
**Description**:
[Briefly describe the optimization technique]
```cpp
// Paste your code here only the relevant part
```
---
## 11. Optimization 9
**Author**: [Name]
**Description**:
[Briefly describe the optimization technique]
```cpp
// Paste your code here only the relevant part
```
---
+65
View File
@@ -0,0 +1,65 @@
# Optimization: Baseline
- **Author**: TBD
- **Predecessor**: N/A (initial reference)
- **File(s)**: variants/variant_baseline.cpp
- **Status**: reference
## What this changes
This is the unoptimized reference implementation of the social force model.
Every other optimization is measured relative to it. See the source file for
the full implementation; key functions are `w()`, `acceleration_term_dt()`,
`pedestrian_repulsion_dt()`, `obstacle_repulsion_dt()`, and `run_simulation()`.
## Code (relevant snippet)
TBD
## Benchmark
Conditions: TBD.
### 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
TBD
## Takeaway
TBD
+95
View File
@@ -0,0 +1,95 @@
# 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
+76
View File
@@ -0,0 +1,76 @@
<!--
TEMPLATE - copy this to docs/optimization_<your_name>.md before editing.
Workflow:
1. cp docs/optimization_template.md docs/optimization_<your_name>.md
2. Fill in the fields below.
3. Add a row to the summary tables in docs/OPTIMIZATIONS.md that links to your file.
4. Delete this HTML comment block before committing.
-->
# Optimization: <name>
- **Author**: <your name>
- **Predecessor**: variant_baseline.cpp
- **File(s)**: variants/variant_<your_name>.cpp
- **Status**: <not benchmarked / negative / partial / positive>
## What this changes
<2-3 sentences. What did you change and what is the high-level idea?
No full code paste here - just a description.>
## Code (relevant snippet)
```cpp
// the part that differs from the predecessor
```
## Benchmark
Conditions: min of <N> runs, N_ITER=1000, -O3 -march=native -flto.
### x86
**Machine**:
```
<paste machine info here, e.g. CPU model, core count, RAM, manufacturer, system version>
```
**Frequency**: <e.g., 2 GHz>
| N | W(n) [Flops] | T(n) [Cycles] | Performance [Flops/Cycle] | Diff vs Predecessor |
| ---- | ------------ | ------------- | ------------------------- | ------------------- |
| 50 | | | | |
| 100 | | | | |
| 200 | | | | |
| 500 | | | | |
| 1000 | | | | |
### ARM (Apple)
**Machine**:
```
<paste machine info here, e.g. Apple M1/M2/M3/M4, chip cores, RAM>
```
**Frequency**: <e.g., 3.2 GHz>
| N | W(n) [Flops] | T(n) [Cycles] | Performance [Flops/Cycle] | Diff vs Predecessor |
| ---- | ------------ | ------------- | ------------------------- | ------------------- |
| 50 | | | | |
| 100 | | | | |
| 200 | | | | |
| 500 | | | | |
| 1000 | | | | |
## Analysis
<Why it worked or did not. What surprised you. What bottleneck this hits
or moves. Mention generated assembly or a profile if relevant.>
## Takeaway
<One short paragraph that could be lifted straight into the report.>