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 / bridge / shlib / ampqmd.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note bridge/shlib/ampqmd.om: CUDApp's src/omega_ampere_qmd.c (84b524ca, default build) in Omega: the two C entry |
| 3 | note points omega_ampere_policy and omega_ampere_build_qmd over the Ampere QMD unit. Composed after |
| 4 | note gpu/nvidia/om/encoder/amp_runtime.om and amp_qmd.om into one object and built by bridge/shlib/shlib.om from |
| 5 | note ampqmd.tsv: both are frame exports under the lock row's pthread mutex, because the C pointers are copied |
| 6 | note through the states (memcpy) and the states are one per process. |
| 7 | note States (ampqmd.tsv, frame words 8..10): AqM the 16-word request, AqQ the 256 QMD bytes, AqLock the mutex; |
| 8 | note frame word 11 is the address of the caller's stack arguments (omega_ampere_build_qmd's registers and |
| 9 | note shared_bytes, AAPCS64 arguments 9 and 10). |
| 10 | note Results as the C: 0 when amp_qmd accepts, -1 when it refuses or a pointer the C checks is NULL; the QMD is |
| 11 | note written to q only on acceptance. A trap answers -1 (the TRAP value), as the C does when its bridge call |
| 12 | note fails. |
| 13 | extern fn memcpy d ulong s ulong n ulong to ulong |
| 14 | note amp_qmd op over the request in m; on acceptance the 256 bytes are copied to the C pointer q when it is not |
| 15 | note NULL; 0 or -1 |
| 16 | fn aq_run fr view ulong 12 op ulong m edit ulong 16 q edit uchar 256 to int |
| 17 | if ne amp_qmd op m q 1 |
| 18 | ret -1 |
| 19 | end |
| 20 | d = get fr 1 |
| 21 | if eq op 1 |
| 22 | d = get fr 0 |
| 23 | end |
| 24 | if ne d 0 |
| 25 | z = memcpy d get fr 9 256 |
| 26 | end |
| 27 | ret 0 |
| 28 | end |
| 29 | note int omega_ampere_policy(const uint64_t m[16], uint32_t q[64]): x0 m, x1 q (NULL: the C's scratch) |
| 30 | export fn omega_ampere_policy fr view ulong 12 m edit ulong 16 q edit uchar 256 to int |
| 31 | if eq get fr 0 0 |
| 32 | ret -1 |
| 33 | end |
| 34 | z = memcpy get fr 8 get fr 0 128 |
| 35 | ret aq_run fr 0 m q |
| 36 | end |
| 37 | note int omega_ampere_build_qmd(uint32_t q[64], uint64_t code, uint64_t cbank, uint64_t semaphore, uint32_t tx, |
| 38 | note uint32_t ty, uint32_t gx, uint32_t gy, uint32_t registers, uint32_t shared_bytes): x0 q, x1..x3 the 64-bit |
| 39 | note words, x4..x7 tx ty gx gy (their low 32 bits), the caller's stack words 0 and 1 registers and shared_bytes |
| 40 | note (their low 32 bits); a[9..15] zero, as the C's initializer |
| 41 | export fn omega_ampere_build_qmd fr view ulong 12 m edit ulong 16 q edit uchar 256 to int |
| 42 | if eq get fr 0 0 |
| 43 | ret -1 |
| 44 | end |
| 45 | for i ulong 16 |
| 46 | put m i 0 |
| 47 | end |
| 48 | z = memcpy add get fr 8 56 get fr 11 16 |
| 49 | put m 7 and get m 7 4294967295 |
| 50 | put m 8 and get m 8 4294967295 |
| 51 | for i ulong 3 |
| 52 | put m i get fr add i 1 |
| 53 | end |
| 54 | for i ulong 4 |
| 55 | put m add i 3 and get fr add i 4 4294967295 |
| 56 | end |
| 57 | ret aq_run fr 1 m q |
| 58 | end |