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 / kfd / ring.om

111 lines · 2792 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note A sequential, single-producer/single-consumer model, not an MMIO implementation or memory-model
3note proof. Each command is one externally visible publication step. No AMD hardware is accessed.
4note HSA hsa.h rocm-6.2.0: packet type INVALID=1, KERNEL_DISPATCH=2; doorbell carries ready packet ID.
5note Host policy checked here: body bytes 4..63 -> header+setup (one 32-bit word) -> write index
6note -> doorbell packet ID (new write index minus one). Consumer observes after each step; once
7note the type is valid it must see every body byte. Completion consumes the published packet and
8note invalidates its header before the producer reuses the slot. KFD 1.14 minimum ring 1024 bytes;
9note 16 64-byte slots. The gate runs 40 launches, crossing the ring boundary twice.
10note A real implementation needs release publication/acquire observation and device-coherent memory,
11note as well as architecture-specific fences. This model does NOT establish those properties.
12note usage: ring STEP... (1=body 2=header 3=write-index 4=doorbell 5=consume).
13note Exit 0 complete sequences; 64 fewer than five steps; 3 bad order/data/index or incomplete sequence
14note after the minimum argument check; 2 numeric input.
15om2
16global ringbuf uchar 1024
17global rs ulong 4
18text raccept "RING ACCEPT body<header<write-index<doorbell<consume\n"
19note rs: phase, write index, read index, doorbell packet ID.
20fn bodyval id ulong k ulong to uchar
21ret uchar and add id k 255
22end
23fn inspect id ulong to void
24slot = mul rem id 16 64
25if eq get ringbuf slot 2
26for k ulong 60
27p = add k 4
28if ne get ringbuf add slot p bodyval id p
29exit 3
30end
31end
32end
33end
34fn step action ulong to void
35id = get rs 2
36slot = mul rem id 16 64
37phase = get rs 0
38if eq action 1
39if ne phase 0
40exit 3
41end
42if ne get ringbuf slot 1
43exit 3
44end
45for k ulong 60
46p = add k 4
47put ringbuf add slot p bodyval id p
48end
49put rs 0 1
50end
51if eq action 2
52if ne phase 1
53exit 3
54end
55note Model the atomic 32-bit header+setup publication, not four observable byte stores.
56put ringbuf slot 2
57put ringbuf add slot 1 21
58put ringbuf add slot 2 1
59put ringbuf add slot 3 0
60put rs 0 2
61end
62if eq action 3
63if ne phase 2
64exit 3
65end
66put rs 1 add id 1
67put rs 0 3
68end
69if eq action 4
70if ne phase 3
71exit 3
72end
73put rs 3 sub get rs 1 1
74put rs 0 4
75end
76if eq action 5
77if ne phase 4
78exit 3
79end
80if or ne get rs 1 add id 1 ne get rs 3 id
81exit 3
82end
83if or ne get ringbuf slot 2 ne get ringbuf add slot 1 21
84exit 3
85end
86inspect id
87put ringbuf slot 1
88put rs 2 add id 1
89put rs 0 0
90end
91if or lt action 1 gt action 5
92exit 3
93end
94inspect get rs 2
95end
96fn main to int
97if lt argcnt 6
98ret 64
99end
100for i ulong 16
101put ringbuf mul i 64 1
102end
103for i ulong sub ulong argcnt 1
104step argnum add i 1
105end
106if ne get rs 0 0
107ret 3
108end
109emit raccept
110ret 0
111end