interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / gpu / amd / gfx942 / fp8gemv / ENCODING.md

207 lines · 9665 bytes Raw Blame History Rendered
1# gfx942 cache-policy encodings
2
3The bytes below were produced on this tree by:
4
5```
6llvm-mc-18 -triple=amdgcn -mcpu=gfx942 -show-encoding
7```
8
9Ubuntu LLVM 18.1.3. `check.sh` requires those bytes, the `.text` of
10`llvm-mc-18 -filetype=obj`, the `.text` `gpu/amd/gfx942/hsaco.om` packs from the
11`.isa`, and the committed `.golden` file to be identical. Bit positions are the
12positions that reproduce these bytes. They are not taken from a chat claim.
13
14CDNA3 ISA §10.1 Table 53 names the FLAT/GLOBAL fields and their widths (OP 7,
15ADDR 8, DATA 8, VDST 8, SC 2, NT 1, ACC 1, SEG 2, SVE 1, OFFSET 13, SADDR 7 with
160x7F meaning off). §9.1.2 Table 40 does the same for MUBUF (OP 7, OFFSET 12,
17OFFEN 1, IDXEN 1, SC0 1, NT 1, ACC 1, SC1 1, LDS 1, VADDR 8, VDATA 8, SRSRC 5,
18SOFFSET 8). Neither table, in the text of the "AMD Instinct MI300" ISA, prints a
19bit number. The order of names in Table 40 is not the order of the bits.
20
21## GLOBAL word, from the bytes
22
23`global_load_dwordx4 v[0:3], v[0:1], off` is `00 80 5c dc 00 00 7f 00`.
24XOR against the sc0, nt and sc1 variants puts the flags here:
25
26| field | bits | evidence |
27| --- | --- | --- |
28| OFFSET | 12:0 | `offset:16` changes byte 0 from `00` to `10` |
29| SC0 | 16 | sc0 sets byte 2 from `5c` to `5d` |
30| NT | 17 | nt sets byte 2 from `5c` to `5e` |
31| OP | 24:18 | dwordx4 is 23 (`5c` with the flags clear) |
32| SC1 | 25 | sc1 sets byte 3 from `dc` to `de` |
33| encoding | 31:26 | `0x37`, the FLAT encoding |
34
35Word 1 is VADDR, VDATA, SADDR (7 bits, `0x7f` is off), then VDST. `s[0:1]` as
36the scalar base is SADDR 0, so the plain saddr form is `00 80 5c dc 00 00 00 00`.
37
38| instruction | bytes |
39| --- | --- |
40| global_load_dwordx4 v[0:3], v[0:1], off | `00 80 5c dc 00 00 7f 00` |
41| same sc0 | `00 80 5d dc 00 00 7f 00` |
42| same sc1 | `00 80 5c de 00 00 7f 00` |
43| same nt | `00 80 5e dc 00 00 7f 00` |
44| same sc0 sc1 | `00 80 5d de 00 00 7f 00` |
45| same sc0 nt | `00 80 5f dc 00 00 7f 00` |
46| same nt sc1 | `00 80 5e de 00 00 7f 00` |
47| same sc0 nt sc1 | `00 80 5f de 00 00 7f 00` |
48| global_load_dwordx4 v[0:3], v0, s[0:1] | `00 80 5c dc 00 00 00 00` |
49| same nt | `00 80 5e dc 00 00 00 00` |
50| global_load_dwordx4 v[4:7], v1, s[2:3] offset:16 | `10 80 5c dc 01 00 02 04` |
51| same nt | `10 80 5e dc 01 00 02 04` |
52
53SC1 is bit 25. It is not bit 55. Bit 55 is outside this 64-bit instruction.
54ACC is the bit Table 53 gives a width of 1; in these encodings it stays 0.
55
56The kernel's weight load is the saddr form with nt and no sc bit. `llvm-objdump`
57of the assembled kernel prints it as `DC5E8000 08160002`, which is the bytes
58`00 80 5e dc 02 00 16 08`. Activation loads are the same opcode with nt clear.
59The tail, the scale load and the stores are in the kernel golden, not in the
60probe. From that object:
61
62| instruction in the kernel | bytes |
63| --- | --- |
64| global_load_dwordx4 v[8:11], v2, s[22:23] nt | `00 80 5e dc 02 00 16 08` |
65| global_load_ubyte v10, v[8:9], off nt | `00 80 42 dc 08 00 7f 0a` |
66| global_load_dword v11, v[8:9], off | `00 80 50 dc 08 00 7f 0b` |
67| global_store_short v[8:9], v5, off | `00 80 68 dc 08 05 7f 00` |
68| global_store_dword v[8:9], v4, off | `00 80 70 dc 08 04 7f 00` |
69
70## MUBUF word, from the bytes
71
72`buffer_load_dwordx4 v[0:3], v0, s[0:3], 0 offen` is `00 10 5c e0 00 00 00 80`.
73
74| field | bits | evidence |
75| --- | --- | --- |
76| OFFSET | 11:0 | these rows use 0 |
77| OFFEN | 12 | the `10` in byte 1 |
78| SC0 | 14 | sc0 sets byte 1 from `10` to `50` |
79| SC1 | 15 | sc1 sets byte 1 from `10` to `90` |
80| NT | 17 | nt sets byte 2 from `5c` to `5e` |
81| OP | 24:18 | load dwordx4 is 23; WBL2 is 40; INV is 41 |
82| encoding | 31:26 | `0x38` |
83
84Word 1 is VADDR, VDATA, SRSRC (SGPR/4), SOFFSET. The inline constant 0 in the
85soffset operand is `0x80` in byte 7. `buffer_wbl2` and `buffer_inv` use soffset 0
86in the encoding (`00` in byte 7), which is what `llvm-mc` emits for the forms
87with no soffset operand.
88
89| instruction | bytes |
90| --- | --- |
91| buffer_load_dwordx4 offen | `00 10 5c e0 00 00 00 80` |
92| sc0 | `00 50 5c e0 00 00 00 80` |
93| sc1 | `00 90 5c e0 00 00 00 80` |
94| nt | `00 10 5e e0 00 00 00 80` |
95| sc0 sc1 | `00 d0 5c e0 00 00 00 80` |
96| sc0 nt | `00 50 5e e0 00 00 00 80` |
97| nt sc1 | `00 90 5e e0 00 00 00 80` |
98| sc0 nt sc1 | `00 d0 5e e0 00 00 00 80` |
99| buffer_wbl2 | `00 00 a0 e0 00 00 00 00` |
100| buffer_wbl2 sc0 | `00 40 a0 e0 00 00 00 00` |
101| buffer_wbl2 sc1 | `00 80 a0 e0 00 00 00 00` |
102| buffer_wbl2 sc0 sc1 | `00 c0 a0 e0 00 00 00 00` |
103| buffer_inv | `00 00 a4 e0 00 00 00 00` |
104| buffer_inv sc0 | `00 40 a4 e0 00 00 00 00` |
105| buffer_inv sc1 | `00 80 a4 e0 00 00 00 00` |
106| buffer_inv sc0 sc1 | `00 c0 a4 e0 00 00 00 00` |
107
108## Atomics
109
110ISA §9.1.10.2: for vector atomics, SC0 is "return the pre-op value" (0 no, 1 yes),
111SC1 is 0 device / 1 system, and NT is 0 last-level allocate / 1 no allocate.
112That is a different meaning of SC0 from the load/store scope tables.
113
114`llvm-mc` rejects `global_atomic_add` on the `v[addr]` form unless sc0 is set,
115and rejects sc0 on the `s[addr]` form. The probe records only the forms it accepts.
116
117| instruction | bytes |
118| --- | --- |
119| global_atomic_add v0, v[0:1], v2, off sc0 | `00 80 09 dd 00 02 7f 00` |
120| sc0 sc1 | `00 80 09 df 00 02 7f 00` |
121| sc0 nt | `00 80 0b dd 00 02 7f 00` |
122| sc0 nt sc1 | `00 80 0b df 00 02 7f 00` |
123| global_atomic_add v4, v2, s[6:7] | `00 80 08 dd 04 02 06 00` |
124| sc1 | `00 80 08 df 04 02 06 00` |
125| nt | `00 80 0a dd 04 02 06 00` |
126| nt sc1 | `00 80 0a df 04 02 06 00` |
127
128On the saddr form the first vector operand is the address (`v4` → VADDR 4) and
129the second is the data (`v2` → VDATA 2). SC1 is again bit 25 (`dc` vs `df` in
130the high byte of word 0: `dd` vs `df`).
131
132## What the bits do to L2 and the last-level cache
133
134ISA §9.1.10.2, Table 48 (loads). SC[1:0] is 0 wave, 1 group, 2 device, 3 system.
135NT 0 is temporal, 1 is non-temporal. The table's third cache column is headed
136"Last-level Cache", not MALL.
137
138| scope | SC1 | SC0 | NT | CU | L2 | last-level |
139| --- | --- | --- | --- | --- | --- | --- |
140| wave | 0 | 0 | 0 | Hit LRU | Hit LRU | Hit LRU |
141| wave | 0 | 0 | 1 | Miss Evict | Hit Stream | Hit Evict |
142| group | 0 | 1 | 0 | Hit LRU | Hit LRU | Hit Evict |
143| group | 0 | 1 | 1 | Miss Evict | Hit Stream | Hit Evict |
144| device | 1 | 0 | 0 | Miss Evict | Hit LRU if 1 L2, else coherent bypass | Hit LRU |
145| device | 1 | 0 | 1 | Miss Evict | Hit Stream if 1 L2, else coherent bypass | Hit Evict |
146| system | 1 | 1 | 0 | Miss Evict | coherent bypass | Hit LRU |
147| system | 1 | 1 | 1 | Miss Evict | coherent bypass | Hit Evict |
148
149The table's note: if TG_SPLIT is active, the group + NT=0 row becomes Miss LRU,
150Hit LRU, Hit LRU. Table 49 is the store table; wave + NT=0 is CU Miss LRU rather
151than Hit LRU. "No Allocate" is stated for atomic NT, not for a Table 48 load.
152Hit Stream and Hit Evict are the table's names; the text does not define them
153further.
154
155Table 50, BUFFER_WBL2: SC1=0 is a NOP for either SC0. SC1=1 and SC0=0 writebacks
156dirty L2 only when there is more than one L2, otherwise NOP. SC1=1 and SC0=1
157writebacks dirty data.
158
159Table 51, BUFFER_INV: SC=00 is NOP. SC0=1 and SC1=0 invalidates the CU cache only
160if TG split. SC1=1 and SC0=0 invalidates the CU cache, and invalidates
161non-coherent L2 lines only when there is more than one L2. Both bits invalidate
162the CU cache and the non-coherent L2 lines.
163
164## What LLVM emits on GFX942
165
166LLVM's user guide, "AMDHSA Memory Model Code Sequences GFX942"
167(<https://llvm.org/docs/AMDGPUUsage.html>), as fetched for this change:
168
169- A non-volatile nontemporal load is `buffer/global/flat_load nt=1`. No sc0, no sc1.
170- A non-volatile nontemporal store on GFX942 is `buffer/global/flat_store nt=1`.
171- A volatile load or store is `sc0=1 sc1=1` plus `s_waitcnt vmcnt(0)`.
172- Monotonic load: wave none, workgroup `sc0=1`, agent `sc1=1`, system `sc0=1 sc1=1`.
173 Stores follow the same pattern.
174- Acquire load, agent, global: `buffer/global_load sc1=1`, `s_waitcnt vmcnt(0)`,
175 `buffer_inv sc1=1`.
176- Acquire load, system, global: `buffer/global/flat_load sc0=1 sc1=1`,
177 `s_waitcnt vmcnt(0)`, `buffer_inv sc0=1 sc1=1`.
178- Release store, agent: `buffer_wbl2 sc1=1`, then the waits, then
179 `buffer/global/flat_store sc1=1`.
180- Release store, system: `buffer_wbl2 sc0=1 sc1=1`, then the waits, then
181 `buffer/global/flat_store sc0=1 sc1=1`.
182- Release atomicrmw, agent: `buffer_wbl2 sc1=1`, then the waits, then
183 `buffer/global/flat_atomic sc1=1`.
184- Release atomicrmw, system: `buffer_wbl2 sc0=1 sc1=1`, then the waits, then
185 `buffer/global/flat_atomic sc0=1 sc1=1`.
186
187The system release atomic sets sc0. On an atomic, ISA §9.1.10.2 defines that bit
188as "return the pre-op value", not as a scope bit. The scope bit on an atomic is
189SC1. The probe keeps both facts: the bytes LLVM's assembler emits, and the ISA's
190definition of the bit.
191
192## Policy used for the weight loads
193
194Weight loads are read once per token and must not be the lines that push
195activations out of cache. The kernel sets **nt=1, sc0=0, sc1=0** on those loads
196only. That is the GFX942 nontemporal load LLVM emits, and it is Table 48's wave
197+ NT row: CU Miss Evict, L2 Hit Stream, last-level Hit Evict.
198
199A device-scope load (sc1=1, sc0=0) is a different policy. With more than one L2
200it coherent-bypasses L2. That is not what the GFX942 nontemporal row emits, and
201it is not what the weight loads use. Activation, scale, residual, gamma and
202output traffic leave every sc/nt bit clear: Table 48 wave + temporal, Hit LRU at
203each level named in the table.
204
205The kernel does not emit `buffer_wbl2` or `buffer_inv`. Those encodings are in
206`encprobe` so the writer cannot drift, and so the acquire/release sequences
207above have a byte to point at. They are not part of the GEMV.