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 Source

gfx942 cache-policy encodings

The bytes below were produced on this tree by:

llvm-mc-18 -triple=amdgcn -mcpu=gfx942 -show-encoding

Ubuntu LLVM 18.1.3. check.sh requires those bytes, the .text of llvm-mc-18 -filetype=obj, the .text gpu/amd/gfx942/hsaco.om packs from the .isa, and the committed .golden file to be identical. Bit positions are the positions that reproduce these bytes. They are not taken from a chat claim.

CDNA3 ISA §10.1 Table 53 names the FLAT/GLOBAL fields and their widths (OP 7, ADDR 8, DATA 8, VDST 8, SC 2, NT 1, ACC 1, SEG 2, SVE 1, OFFSET 13, SADDR 7 with 0x7F meaning off). §9.1.2 Table 40 does the same for MUBUF (OP 7, OFFSET 12, OFFEN 1, IDXEN 1, SC0 1, NT 1, ACC 1, SC1 1, LDS 1, VADDR 8, VDATA 8, SRSRC 5, SOFFSET 8). Neither table, in the text of the "AMD Instinct MI300" ISA, prints a bit number. The order of names in Table 40 is not the order of the bits.

GLOBAL word, from the bytes

global_load_dwordx4 v[0:3], v[0:1], off is 00 80 5c dc 00 00 7f 00. XOR against the sc0, nt and sc1 variants puts the flags here:

fieldbitsevidence
OFFSET12:0offset:16 changes byte 0 from 00 to 10
SC016sc0 sets byte 2 from 5c to 5d
NT17nt sets byte 2 from 5c to 5e
OP24:18dwordx4 is 23 (5c with the flags clear)
SC125sc1 sets byte 3 from dc to de
encoding31:260x37, the FLAT encoding

Word 1 is VADDR, VDATA, SADDR (7 bits, 0x7f is off), then VDST. s[0:1] as the scalar base is SADDR 0, so the plain saddr form is 00 80 5c dc 00 00 00 00.

instructionbytes
global_load_dwordx4 v[0:3], v[0:1], off00 80 5c dc 00 00 7f 00
same sc000 80 5d dc 00 00 7f 00
same sc100 80 5c de 00 00 7f 00
same nt00 80 5e dc 00 00 7f 00
same sc0 sc100 80 5d de 00 00 7f 00
same sc0 nt00 80 5f dc 00 00 7f 00
same nt sc100 80 5e de 00 00 7f 00
same sc0 nt sc100 80 5f de 00 00 7f 00
global_load_dwordx4 v[0:3], v0, s[0:1]00 80 5c dc 00 00 00 00
same nt00 80 5e dc 00 00 00 00
global_load_dwordx4 v[4:7], v1, s[2:3] offset:1610 80 5c dc 01 00 02 04
same nt10 80 5e dc 01 00 02 04

SC1 is bit 25. It is not bit 55. Bit 55 is outside this 64-bit instruction. ACC is the bit Table 53 gives a width of 1; in these encodings it stays 0.

The kernel's weight load is the saddr form with nt and no sc bit. llvm-objdump of the assembled kernel prints it as DC5E8000 08160002, which is the bytes 00 80 5e dc 02 00 16 08. Activation loads are the same opcode with nt clear. The tail, the scale load and the stores are in the kernel golden, not in the probe. From that object:

instruction in the kernelbytes
global_load_dwordx4 v[8:11], v2, s[22:23] nt00 80 5e dc 02 00 16 08
global_load_ubyte v10, v[8:9], off nt00 80 42 dc 08 00 7f 0a
global_load_dword v11, v[8:9], off00 80 50 dc 08 00 7f 0b
global_store_short v[8:9], v5, off00 80 68 dc 08 05 7f 00
global_store_dword v[8:9], v4, off00 80 70 dc 08 04 7f 00

MUBUF word, from the bytes

buffer_load_dwordx4 v[0:3], v0, s[0:3], 0 offen is 00 10 5c e0 00 00 00 80.

fieldbitsevidence
OFFSET11:0these rows use 0
OFFEN12the 10 in byte 1
SC014sc0 sets byte 1 from 10 to 50
SC115sc1 sets byte 1 from 10 to 90
NT17nt sets byte 2 from 5c to 5e
OP24:18load dwordx4 is 23; WBL2 is 40; INV is 41
encoding31:260x38

Word 1 is VADDR, VDATA, SRSRC (SGPR/4), SOFFSET. The inline constant 0 in the soffset operand is 0x80 in byte 7. buffer_wbl2 and buffer_inv use soffset 0 in the encoding (00 in byte 7), which is what llvm-mc emits for the forms with no soffset operand.

instructionbytes
buffer_load_dwordx4 offen00 10 5c e0 00 00 00 80
sc000 50 5c e0 00 00 00 80
sc100 90 5c e0 00 00 00 80
nt00 10 5e e0 00 00 00 80
sc0 sc100 d0 5c e0 00 00 00 80
sc0 nt00 50 5e e0 00 00 00 80
nt sc100 90 5e e0 00 00 00 80
sc0 nt sc100 d0 5e e0 00 00 00 80
buffer_wbl200 00 a0 e0 00 00 00 00
buffer_wbl2 sc000 40 a0 e0 00 00 00 00
buffer_wbl2 sc100 80 a0 e0 00 00 00 00
buffer_wbl2 sc0 sc100 c0 a0 e0 00 00 00 00
buffer_inv00 00 a4 e0 00 00 00 00
buffer_inv sc000 40 a4 e0 00 00 00 00
buffer_inv sc100 80 a4 e0 00 00 00 00
buffer_inv sc0 sc100 c0 a4 e0 00 00 00 00

Atomics

ISA §9.1.10.2: for vector atomics, SC0 is "return the pre-op value" (0 no, 1 yes), SC1 is 0 device / 1 system, and NT is 0 last-level allocate / 1 no allocate. That is a different meaning of SC0 from the load/store scope tables.

llvm-mc rejects global_atomic_add on the v[addr] form unless sc0 is set, and rejects sc0 on the s[addr] form. The probe records only the forms it accepts.

instructionbytes
global_atomic_add v0, v[0:1], v2, off sc000 80 09 dd 00 02 7f 00
sc0 sc100 80 09 df 00 02 7f 00
sc0 nt00 80 0b dd 00 02 7f 00
sc0 nt sc100 80 0b df 00 02 7f 00
global_atomic_add v4, v2, s[6:7]00 80 08 dd 04 02 06 00
sc100 80 08 df 04 02 06 00
nt00 80 0a dd 04 02 06 00
nt sc100 80 0a df 04 02 06 00

On the saddr form the first vector operand is the address (v4 → VADDR 4) and the second is the data (v2 → VDATA 2). SC1 is again bit 25 (dc vs df in the high byte of word 0: dd vs df).

What the bits do to L2 and the last-level cache

ISA §9.1.10.2, Table 48 (loads). SC[1:0] is 0 wave, 1 group, 2 device, 3 system. NT 0 is temporal, 1 is non-temporal. The table's third cache column is headed "Last-level Cache", not MALL.

scopeSC1SC0NTCUL2last-level
wave000Hit LRUHit LRUHit LRU
wave001Miss EvictHit StreamHit Evict
group010Hit LRUHit LRUHit Evict
group011Miss EvictHit StreamHit Evict
device100Miss EvictHit LRU if 1 L2, else coherent bypassHit LRU
device101Miss EvictHit Stream if 1 L2, else coherent bypassHit Evict
system110Miss Evictcoherent bypassHit LRU
system111Miss Evictcoherent bypassHit Evict

The table's note: if TG_SPLIT is active, the group + NT=0 row becomes Miss LRU, Hit LRU, Hit LRU. Table 49 is the store table; wave + NT=0 is CU Miss LRU rather than Hit LRU. "No Allocate" is stated for atomic NT, not for a Table 48 load. Hit Stream and Hit Evict are the table's names; the text does not define them further.

Table 50, BUFFER_WBL2: SC1=0 is a NOP for either SC0. SC1=1 and SC0=0 writebacks dirty L2 only when there is more than one L2, otherwise NOP. SC1=1 and SC0=1 writebacks dirty data.

Table 51, BUFFER_INV: SC=00 is NOP. SC0=1 and SC1=0 invalidates the CU cache only if TG split. SC1=1 and SC0=0 invalidates the CU cache, and invalidates non-coherent L2 lines only when there is more than one L2. Both bits invalidate the CU cache and the non-coherent L2 lines.

What LLVM emits on GFX942

LLVM's user guide, "AMDHSA Memory Model Code Sequences GFX942" (https://llvm.org/docs/AMDGPUUsage.html), as fetched for this change:

The system release atomic sets sc0. On an atomic, ISA §9.1.10.2 defines that bit as "return the pre-op value", not as a scope bit. The scope bit on an atomic is SC1. The probe keeps both facts: the bytes LLVM's assembler emits, and the ISA's definition of the bit.

Policy used for the weight loads

Weight loads are read once per token and must not be the lines that push activations out of cache. The kernel sets nt=1, sc0=0, sc1=0 on those loads only. That is the GFX942 nontemporal load LLVM emits, and it is Table 48's wave

A device-scope load (sc1=1, sc0=0) is a different policy. With more than one L2 it coherent-bypasses L2. That is not what the GFX942 nontemporal row emits, and it is not what the weight loads use. Activation, scale, residual, gamma and output traffic leave every sc/nt bit clear: Table 48 wave + temporal, Hit LRU at each level named in the table.

The kernel does not emit buffer_wbl2 or buffer_inv. Those encodings are in encprobe so the writer cannot drift, and so the acquire/release sequences above have a byte to point at. They are not part of the GEMV.