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 / bench / barrier / seq.s

62 lines · 2366 bytes Raw Blame History
1// gfx942 barrier encodings for the persistent-kernel micro-benchmark.
2// Data, not a kernel. The Omega gate feeds this file to:
3// llvm-mc-18 -triple=amdgcn -mcpu=gfx942 -show-encoding
4// and requires the bytes to match seq.enc.
5//
6// Sequences are the GFX942 rows of the table "AMDHSA Memory Model Code Sequences
7// GFX940, GFX941, GFX942" in LLVM AMDGPUUsage at llvmorg-20.1.0
8// (llvm/docs/AMDGPUUsage.rst, section "Memory Model GFX942").
9// Release puts buffer_wbl2 first, then s_waitcnt, then the atomic.
10// Acquire puts the atomic, then s_waitcnt vmcnt(0), then buffer_inv.
11//
12// The agent-release step 3 in that table is "buffer/global/flat_atomic sc1=1"
13// with no sc0. CDNA3 ISA 9.1.10.2 says SC0=1 returns the previous value and
14// SC1=0 is device scope. A sense-reversing barrier needs the ticket, so the
15// ticket lines below set sc0 and are not the LLVM step-3 spelling. Both are
16// assembled here. Do not copy the branch offsets at the bottom as a spin loop.
17
18.text
19
20// atomicrmw release, agent, global. LLVM steps 1, 2, 3.
21buffer_wbl2 sc1
22s_waitcnt vmcnt(0) lgkmcnt(0)
23buffer_atomic_add v0, off, s[0:3], 0 sc1
24
25// atomicrmw release, system, global. LLVM steps 1, 2, 3.
26buffer_wbl2 sc0 sc1
27s_waitcnt vmcnt(0) lgkmcnt(0)
28buffer_atomic_add v0, off, s[0:3], 0 sc0 sc1
29
30// atomicrmw acquire, agent, global. LLVM steps 1, 2, 3.
31buffer_atomic_add v0, off, s[0:3], 0
32s_waitcnt vmcnt(0)
33buffer_inv sc1
34
35// atomicrmw acquire, system, global. LLVM steps 1, 2, 3.
36buffer_atomic_add v0, off, s[0:3], 0 sc1
37s_waitcnt vmcnt(0)
38buffer_inv sc0 sc1
39
40// Ticket atomics. ISA SC0 returns the pre-op value. SC1=0 device, SC1=1 system.
41// NT=1 is "no Allocate" in the last-level cache (MALL). NT=0 allocates.
42buffer_atomic_add v0, off, s[0:3], 0 sc0
43buffer_atomic_add v0, off, s[0:3], 0 sc0 nt
44buffer_atomic_add v0, off, s[0:3], 0 sc0 sc1
45buffer_atomic_add v0, off, s[0:3], 0 sc0 nt sc1
46
47// CDNA3 ISA 8.2.5 S_MEMREALTIME. Fixed 100 MHz, not the core clock.
48s_memrealtime s[0:1]
49s_memrealtime s[2:3]
50s_waitcnt lgkmcnt(0)
51
52// 64-bit unsigned compare pieces (now in s[2:3], deadline in s[4:5]).
53// Offsets below reach the two s_endpgm labels in THIS fragment only.
54// A device spin branches back to s_memrealtime instead of the second s_endpgm.
55s_cmp_lt_u32 s3, s5
56s_cbranch_scc1 5
57s_cmp_eq_u32 s3, s5
58s_cbranch_scc0 2
59s_cmp_lt_u32 s2, s4
60s_cbranch_scc1 1
61s_endpgm
62s_endpgm