Skip to content

Commit 69529a5

Browse files
committed
Merge branch 'add_dispatching'
2 parents f6e2e07 + 2e54785 commit 69529a5

File tree

4 files changed

+74
-15
lines changed

4 files changed

+74
-15
lines changed

cppcon2025/cppcon_2025_slides.md

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,34 @@ JSON can be *slow*. E.g., 20 MB/s.
7575
<img src="images/simdjson.png" width="10%" />
7676

7777

78+
---
79+
80+
81+
## SIMD
82+
83+
- Stands for Single instruction, multiple data
84+
- Allows us to process 16 (or more) bytes or more with one instruction
85+
- Supported on all modern CPUs (phone, laptop)
86+
87+
---
88+
89+
# Superscalar vs. SIMD execution
90+
91+
| processor | year | arithmetic logic units | SIMD units | simdjson |
92+
|-----------------|---------|---------------------------|----------------|----------|
93+
| Apple M* | 2019 | 6+ | $4 \times 128$ | 🥉 |
94+
| Intel Lion Cove | 2024 | 6 | $4 \times 256$ | 🥈🥈 |
95+
| AMD Zen 5 | 2024 | 6 | $4 \times 512$ | 🥇🥇🥇 |
96+
97+
98+
---
99+
100+
101+
<img src="images/simdjson_benchmark.png" width="60%"/>
102+
103+
https://openbenchmarking.org/test/pts/simdjson
104+
105+
78106
---
79107

80108
# Usage
@@ -445,7 +473,8 @@ template <typename T>
445473
requires(std::is_class_v<T>) // For user-defined types
446474
error_code deserialize(auto& json_value, T& out) {
447475
simdjson::ondemand::object obj;
448-
SIMDJSON_TRY(json_value.get_object().get(obj));
476+
auto er = json_value.get_object().get(obj);
477+
if(er) { return er; }
449478
450479
// This [:expand:] happens at COMPILE TIME
451480
// It literally generates code for each member
@@ -822,14 +851,6 @@ simple_needs_escaping(std::string_view v) {
822851
}
823852
```
824853

825-
---
826-
827-
828-
## SIMD
829-
830-
- Stands for Single instruction, multiple data
831-
- Allows us to process 16 (or more) bytes or more with one instruction
832-
- Supported on all modern CPUs (phone, laptop)
833854

834855
---
835856

cppcon2025/images/barsimdjson.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import matplotlib.pyplot as plt
2+
3+
# Data from the user
4+
processors = [
5+
"AMD Ryzen 9 9950X3D",
6+
"Intel Core Ultra 9 285K",
7+
"Snapdragon X Elite X1E78100",
8+
"ARMv8 Neoverse-V2 72-Core"
9+
]
10+
gb_per_second = [13.64, 10.07, 4.27, 4.06]
11+
12+
13+
# Define colors for each processor type
14+
colors = ['#FF6F61', "#0655F1", '#2ECC71', '#2ECC71'] # AMD: coral, Intel: gray, ARM: green
15+
16+
# Create bar chart
17+
plt.figure(figsize=(10, 6))
18+
bars = plt.bar(processors, gb_per_second, color=colors, edgecolor='black')
19+
20+
# Remove top and right spines
21+
ax = plt.gca()
22+
ax.spines['top'].set_visible(False)
23+
ax.spines['right'].set_visible(False)
24+
25+
# Add data labels on top of each bar
26+
for bar in bars:
27+
yval = bar.get_height()
28+
plt.text(bar.get_x() + bar.get_width()/2, yval + 0.2, f'{yval:.2g} GB/s',
29+
ha='center', va='bottom', fontsize=14)
30+
31+
plt.ylabel('Throughput (GB/s)', fontsize=14)
32+
33+
# Add legend
34+
plt.legend(handles=[
35+
plt.Rectangle((0,0),1,1,fc=colors[0],edgecolor='black'),
36+
plt.Rectangle((0,0),1,1,fc=colors[1],edgecolor='black'),
37+
plt.Rectangle((0,0),1,1,fc=colors[2],edgecolor='black')
38+
], labels=['AMD', 'Intel', 'ARM'], loc='upper right', fontsize=16, frameon=False)
39+
plt.tight_layout()
40+
41+
# Save the plot as PNG
42+
plt.savefig('simdjson_benchmark.png', dpi=300, bbox_inches='tight')
43+
plt.close()
111 KB
Loading

cppcon2025/software/examples/dispatch.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ float sum_avx2(const float *data, size_t n) {
2626
}
2727

2828
SumFunc &get_sum_fnc();
29-
// Fonction d'initialisation pour le dispatching
29+
3030
float sum_init(const float *data, size_t n) {
31-
std::cout << "Initialisation de la fonction sum...\n";
3231
SumFunc &sum_impl = get_sum_fnc();
3332
if (has_avx2()) {
3433
sum_impl = sum_avx2;
@@ -40,21 +39,17 @@ float sum_init(const float *data, size_t n) {
4039
return sum_impl(data, n);
4140
}
4241

43-
// Gestion du pointeur de fonction statique
4442
SumFunc &get_sum_fnc() {
4543
static SumFunc sum_impl = sum_init;
4644
return sum_impl;
4745
}
4846

49-
// Fonction principale avec dispatching
5047
float sum(const float *data, size_t n) { return get_sum_fnc()(data, n); }
5148

5249
int main() {
5350
float data[] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f};
5451
size_t n = sizeof(data) / sizeof(data[0]);
5552
float result = sum(data, n);
5653
std::cout << "sum : " << result << std::endl;
57-
float result2 = sum(data, n);
58-
std::cout << "sum : " << result2 << std::endl;
5954
return 0;
6055
}

0 commit comments

Comments
 (0)