interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / backend / amd / kfd / records.om

164 lines · 3766 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note Serialize KFD request records from requests.tsv, without issuing any ioctl or opening a device.
3note usage: records TABLE RECORD_INDEX [FIELD_VALUE ...]; index is zero-based table order.
4note No values means the whole record is zero-filled (output fields and reserved bytes start zero).
5note Otherwise provide one unsigned value for every field, in table order; repeated fields expand.
6note requests.tsv is the wire-data authority: REQUEST SIZE FIELD_COUNT followed by OFFSET WIDTH COUNT.
7note # comments name requests and fields. No native struct is used in the producer. Little endian.
8note The 88-byte scratch extent is exactly sizeof(kfd_ioctl_create_queue_args), the largest record
9note in this fixed ABI table, not a queue/workload capacity. It is a constant because the pinned omc
10note (omega-mv e5b32567) takes only a constant length in `new` (a table size there is error 16).
11note A larger record in a later KFD revision refuses with exit 3, never truncates; the gate compares
12note every field and size with the installed header.
13note Includes GET_PROCESS_APERTURES_NEW, not deprecated GET_PROCESS_APERTURES (fixed seven GPU cap).
14note Auxiliary records (request 0) are an aperture entry, a signal-event wait entry and one GPU ID.
15note Addresses are serialized values supplied by the caller, not Omega pointers or validated mappings.
16note Pointer binding, KFD calls, event-page signal lifecycle, MMIO and hardware coherency NOT_RUN.
17note Exit: 0 emitted; 2 numeric input; 3 table/record/field shape; 64 usage; 74 I/O.
18note Exhausting the pinned compiler's loop fuel bound 999999 traps with exit 104 before output.
19note tests/amd/loop-fuel.sh alarms when a gate table passes 500000 bytes; route A (newer omc pin) removes the bound.
20om2
21global rb uchar 1
22global rfd int 1
23global ri ulong 1
24fn rbyte to ulong
25r = read get rfd 0 rb 0 1
26if eq r 0
27ret 256
28end
29if ne r 1
30exit 74
31end
32ret ulong get rb 0
33end
34fn tnum to ulong
35c = rbyte
36while true bound 999999
37if eq c 256
38exit 3
39end
40if eq c 35
41while ne c 10 bound 999999
42c = rbyte
43if eq c 256
44exit 3
45end
46end
47end
48if gt c 32
49break
50end
51c = rbyte
52end
53v = ulong 0
54while and ge c 48 le c 57 bound 999999
55d = sub c 48
56if gt v 1844674407370955161
57exit 3
58end
59if and eq v 1844674407370955161 gt d 5
60exit 3
61end
62v = add mul v 10 d
63c = rbyte
64end
65if gt c 32
66if ne c 256
67exit 3
68end
69end
70ret v
71end
72fn store b edit uchar 88 off ulong wid ulong val ulong to void
73if and ne wid 4 ne wid 8
74exit 3
75end
76if or gt off len b gt wid sub len b off
77exit 3
78end
79if and eq wid 4 gt val 4294967295
80exit 3
81end
82for i ulong wid
83put b add off i uchar and shr val mul i 8 255
84end
85end
86fn fld b edit uchar 88 idx ulong sz ulong to void
87off = tnum
88wid = tnum
89cnt = tnum
90if eq cnt 0
91exit 3
92end
93for j ulong cnt
94pos = add off mul j wid
95if gt pos sz
96exit 3
97end
98if gt wid sub sz pos
99exit 3
100end
101if eq idx 0
102v = ulong 0
103if gt argcnt 3
104if ge get ri 0 ulong argcnt
105exit 3
106end
107v = argnum get ri 0
108end
109store b pos wid v
110put ri 0 add get ri 0 1
111end
112end
113end
114fn record b edit uchar 88 idx ulong sz ulong nf ulong to void
115put ri 0 3
116for f ulong nf
117fld b idx sz
118end
119if eq idx 0
120if gt argcnt 3
121if ne get ri 0 ulong argcnt
122exit 3
123end
124end
125end
126end
127fn main to int
128if lt argcnt 3
129ret 64
130end
131path = new uchar 4095 0
132n = argread 1 path 0 len path
133if lt n 1
134ret 74
135end
136fd = fopen path 0 ulong n 0 0
137if lt fd 0
138ret 74
139end
140put rfd 0 int fd
141idx = argnum 2
142note idx + 1 bounds the row loop below; at the 64-bit maximum it would wrap to 0, so refuse it.
143if eq idx 18446744073709551615
144ret 3
145end
146buf = new uchar 88 0
147for i ulong add idx 1
148req = tnum
149sz = tnum
150nf = tnum
151if or eq sz 0 gt sz len buf
152ret 3
153end
154record buf sub idx i sz nf
155if eq i idx
156emit part buf 0 sz
157end
158end
159r = fclose int fd
160if ne r 0
161ret 74
162end
163ret 0
164end