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