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 / nvidia / native / aiengpu / effects.om

130 lines · 4842 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note aien-gpu compute ABI 1 client effects (CUDApp#128): the device open/close, the five AGPU ioctls, the CPU
3note mappings and the ordered submit stores. The decisions and request bytes are context.om; the C system calls stay
4note in src/omega_gpu_platform_aien.c behind CUDAPP_MIGRATION_PENDING_C_PLATFORM_AIEN_EFFECTS as the oracle. Needs
5note the OM-2 context compiler that also carries the aien-gpu devctl allowlist (omega-mv feat/om2-devctl-aien-abi1)
6note and a bridge whose mapping fingerprint names it. Returns are Linux results: >= 0, or a negative errno.
7note AGPU_BOOT, AGPU_RM_INIT and AGPU_ARENA_READ are operator requests and are absent on purpose; any request other
8note than the five below, or of another size, is -22 (EINVAL) and never reaches the kernel.
9note Request numbers, _IOC(dir, 'A' 65, nr, size): WolframLanguageEvaluator
10note BitOr[BitShiftLeft[2,30],BitShiftLeft[112,16],BitShiftLeft[65,8],16] -> 2154840336 (AGPU_INFO),
11note BitOr[BitShiftLeft[3,30],BitShiftLeft[48,16],BitShiftLeft[65,8],33] -> 3224387873 (AGPU_MEM_ALLOC),
12note BitOr[BitShiftLeft[3,30],BitShiftLeft[24,16],BitShiftLeft[65,8],34] -> 3222815010 (AGPU_MEM_FREE),
13note BitOr[BitShiftLeft[3,30],BitShiftLeft[72,16],BitShiftLeft[65,8],35] -> 3225960739 (AGPU_CHAN_CREATE),
14note BitOr[BitShiftLeft[3,30],BitShiftLeft[24,16],BitShiftLeft[65,8],36] -> 3222815012 (AGPU_CHAN_DESTROY).
15note O_RDWR|O_CLOEXEC BitOr[2,524288] -> 524290. USERD GPPut 1024*8+0x8c -> 8332; doorbell word 0x90 -> 144
16note (WolframLanguageEvaluator). Mapping extents: maphold/mapnew take 1 byte..64 GiB (2^36 = 68719476736) below
17note 1 TiB (2^40 = 1099511627776); refusals return -22/-27 here instead of trapping.
18om2
19fn ag_le b view uchar * off ulong n ulong to ulong
20v = ulong 0
21for i ulong n
22v = or v shl ulong get b add off i mul i 8
23end
24ret v
25end
26export fn aiengpu_open path view uchar * to long
27ret fopen path 0 len path 524290 0
28end
29export fn aiengpu_close fd long to long
30ret fclose int fd
31end
32export fn aiengpu_ioctl fd long req ulong b edit uchar * to long
33note The caller passes the whole request number and its argument block; both must match one of the five.
34if and eq req 2154840336 eq len b 112
35ret devctl int fd uint 2154840336 b 0 112
36end
37if and eq req 3224387873 eq len b 48
38ret devctl int fd uint 3224387873 b 0 48
39end
40if and eq req 3222815010 eq len b 24
41ret devctl int fd uint 3222815010 b 0 24
42end
43if and eq req 3225960739 eq len b 72
44ret devctl int fd uint 3225960739 b 0 72
45end
46if and eq req 3222815012 eq len b 24
47ret devctl int fd uint 3222815012 b 0 24
48end
49ret neg long 22
50end
51export fn aiengpu_reserve address ulong size ulong to long
52note PROT_NONE MAP_FIXED_NOREPLACE at exactly address; -17 when the range is taken. Refusals never trap.
53if or eq size 0 lt address 65536
54ret neg long 22
55end
56if ne and or address size 4095 0
57ret neg long 22
58end
59if gt size 68719476736
60ret neg long 27
61end
62if ge address 1099511627776
63ret neg long 27
64end
65if gt size sub 1099511627776 address
66ret neg long 27
67end
68ret maphold address size
69end
70export fn aiengpu_bind token long fd long offset ulong to long
71ret mapbind token int fd offset 3
72end
73export fn aiengpu_map_file fd long offset ulong size ulong to long
74if or eq size 0 gt size 68719476736
75ret neg long 22
76end
77ret mapnew int fd offset size 3 1
78end
79export fn aiengpu_address token long to ulong
80ret mapaddr token
81end
82export fn aiengpu_drop token long to long
83ret mapdrop token
84end
85fn ag_plan_ok plan view uchar * to ulong
86note plan: the 128-byte block context.om op 18 wrote (prefix words at 0, GP entry 24, slot 32, GPPut 36,
87note prefix count 40, total words 44).
88if ne len plan 128
89ret 0
90end
91if or gt ag_le plan 40 4 5 ge ag_le plan 32 4 1024
92ret 0
93end
94if ge ag_le plan 36 4 1024
95ret 0
96end
97ret 1
98end
99export fn aiengpu_push pb long plan view uchar * words view uchar * to long
100note Pushbuffer = the plan's prefix words, then the caller's words. The two arrays take four of the six
101note argument slots, so the ring stores are a second export (aiengpu_ring) the caller makes right after.
102if eq ag_plan_ok plan 0
103ret neg long 22
104end
105pre = ag_le plan 40 4
106n = len words
107if or eq n 0 ne and n 3 0
108ret neg long 22
109end
110if ne mul ag_le plan 44 4 4 add mul pre 4 n
111ret neg long 22
112end
113if ne pre 0
114a = mapwrite pb 0 plan 0 mul pre 4
115end
116c = mapwrite pb mul pre 4 words 0 n
117ret 0
118end
119export fn aiengpu_ring fifo long db long plan view uchar * token ulong to long
120note One fence orders the pushbuffer before the ring entry; mapset brackets each store with DSB SY, so the
121note ring entry, GPPut and the doorbell land in that order. A refused plan stores nothing.
122if eq ag_plan_ok plan 0
123ret neg long 22
124end
125cpufence
126e = mapset fifo mul ag_le plan 32 4 8 8 ag_le plan 24 8
127g = mapset fifo 8332 4 ag_le plan 36 4
128h = mapset db 144 4 and token 4294967295
129ret 0
130end