|
2 | 2 |
|
3 | 3 | Brush up on C++ personally to be a real-time engineer in AI era. For fundamental jargon you must know, please visit [jargon.md](./docs/jargon.md). |
4 | 4 |
|
5 | | -## Battlefield |
| 5 | +Contents |
6 | 6 |
|
7 | | -```shell |
8 | | - ┌──────────────────────────────┐ |
9 | | - │ CPU │ |
10 | | - │ │ |
11 | | - │ ┌──────── Core 0 ────────┐ │ Core: Executes instructions |
12 | | - │ │ Registers (R0..Rn) │ │ Register: Fastest storage |
13 | | - │ │ L1 Cache (32KB) │ │ Instructions operate |
14 | | - │ └────────────────────────┘ │ L1 Cache: Hot variables should live here |
15 | | - │ │ |
16 | | - │ ┌──────── Core 1 ────────┐ │ |
17 | | - │ │ Registers (R0..Rn) │ │ |
18 | | - │ │ L1 Cache (32KB) │ │ |
19 | | - │ └────────────────────────┘ │ |
20 | | - │ │ |
21 | | - │ Shared L2 Cache │ L2 Cache: Bigger and slower than L1 |
22 | | - │ (per-core / small) │ |
23 | | - │ │ |
24 | | - │ ┌────────────────────────┐ │ |
25 | | - │ │ L3 Cache │ │ L3 Cache: Shared across cores |
26 | | - │ │ (Shared, MBs) │ │ Bigger and slower than L2 |
27 | | - │ └────────────────────────┘ │ |
28 | | - └──────────────┬───────────────┘ |
29 | | - │ |
30 | | - Local Memory Controller |
31 | | - │ |
32 | | - ┌──────────────────┴──────────────────┐ |
33 | | - │ │ |
34 | | - RAM (NUMA Node 0) RAM (NUMA Node 1) |
35 | | - ~80ns latency ~150ns latency |
36 | | -``` |
| 7 | +[Battlefield](#battlefield) |
| 8 | +[Topics](#topics) |
| 9 | +[Allocators & Cache Behavior (Day 05)](#allocators--cache-behavior-day-05) |
| 10 | +[Practical Application](#practical-application) |
37 | 11 |
|
38 | | -How latency can grow... |
| 12 | +## Battlefield |
39 | 13 |
|
40 | | -```shell |
41 | | -Instruction → |
42 | | - uses Registers → |
43 | | - if miss → L1 → |
44 | | - miss → L2 → |
45 | | - miss → L3 → |
46 | | - miss → RAM (NUMA local?) → |
47 | | - miss → RAM (NUMA remote) |
48 | | -``` |
| 14 | + <details> |
| 15 | + <summary> Click to expand/collapse </summary> |
| 16 | + |
| 17 | + ```shell |
| 18 | + ┌──────────────────────────────┐ |
| 19 | + │ CPU │ |
| 20 | + │ │ |
| 21 | + │ ┌──────── Core 0 ────────┐ │ Core: Executes instructions |
| 22 | + │ │ Registers (R0..Rn) │ │ Register: Fastest storage |
| 23 | + │ │ L1 Cache (32KB) │ │ Instructions operate |
| 24 | + │ └────────────────────────┘ │ L1 Cache: Hot variables should live here |
| 25 | + │ │ |
| 26 | + │ ┌──────── Core 1 ────────┐ │ |
| 27 | + │ │ Registers (R0..Rn) │ │ |
| 28 | + │ │ L1 Cache (32KB) │ │ |
| 29 | + │ └────────────────────────┘ │ |
| 30 | + │ │ |
| 31 | + │ Shared L2 Cache │ L2 Cache: Bigger and slower than L1 |
| 32 | + │ (per-core / small) │ |
| 33 | + │ │ |
| 34 | + │ ┌────────────────────────┐ │ |
| 35 | + │ │ L3 Cache │ │ L3 Cache: Shared across cores |
| 36 | + │ │ (Shared, MBs) │ │ Bigger and slower than L2 |
| 37 | + │ └────────────────────────┘ │ |
| 38 | + └──────────────┬───────────────┘ |
| 39 | + │ |
| 40 | + Local Memory Controller |
| 41 | + │ |
| 42 | + ┌──────────────────┴──────────────────┐ |
| 43 | + │ │ |
| 44 | + RAM (NUMA Node 0) RAM (NUMA Node 1) |
| 45 | + ~80ns latency ~150ns latency |
| 46 | + ``` |
| 47 | + |
| 48 | + How latency can grow... |
| 49 | + |
| 50 | + ```shell |
| 51 | + Instruction → |
| 52 | + uses Registers → |
| 53 | + if miss → L1 → |
| 54 | + miss → L2 → |
| 55 | + miss → L3 → |
| 56 | + miss → RAM (NUMA local?) → |
| 57 | + miss → RAM (NUMA remote) |
| 58 | + ``` |
| 59 | + |
| 60 | + </details> |
49 | 61 |
|
50 | 62 | ## Topics |
51 | 63 |
|
@@ -96,20 +108,22 @@ If your struct is poorly laid out: |
96 | 108 | - You evict useful data |
97 | 109 | - Latency explodes |
98 | 110 |
|
99 | | -```cpp |
100 | | -struct Bad { |
101 | | - bool flag; |
102 | | - double price; |
103 | | - bool active; |
104 | | -} |
105 | | -``` |
106 | | -
|
107 | | -```cpp |
108 | | -struct Good { |
109 | | - double price; |
110 | | - bool flag; |
111 | | - bool active; |
112 | | -} |
113 | | -``` |
| 111 | + ```cpp |
| 112 | + struct Bad { |
| 113 | + bool flag; |
| 114 | + double price; |
| 115 | + bool active; |
| 116 | + } |
| 117 | + ``` |
| 118 | + |
| 119 | + ```cpp |
| 120 | + struct Good { |
| 121 | + double price; |
| 122 | + bool flag; |
| 123 | + bool active; |
| 124 | + } |
| 125 | + ``` |
114 | 126 |
|
115 | 127 | Group hot data together. |
| 128 | + |
| 129 | +## Practical Application |
0 commit comments