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
CUDApp / tests / speculation / model-map-test.om
| 1 | note Read-only weight-file attachment test. No tensor math, GPU or inference is performed. |
| 2 | note argv[1] is one local safetensors shard. Compare real mapped bytes with independent file reads. |
| 3 | global path uchar 4096 |
| 4 | global meta uchar 128 |
| 5 | global after uchar 128 |
| 6 | global mapped uchar 4096 |
| 7 | global direct uchar 4096 |
| 8 | text pass "MODEL_MAP_SAMPLES_PASS 37\n" |
| 9 | fn check yes bool to void |
| 10 | if not yes |
| 11 | exit int 80 |
| 12 | end |
| 13 | end |
| 14 | fn sizeword to ulong |
| 15 | v = ulong 0 |
| 16 | for i ulong 8 |
| 17 | v = or v shl ulong get meta add i 48 mul i 8 |
| 18 | end |
| 19 | ret v |
| 20 | end |
| 21 | fn compare fd int handle long off ulong n ulong to void |
| 22 | check eq mapread handle off mapped 0 n long n |
| 23 | check eq fseek fd long off 0 long off |
| 24 | used = ulong 0 |
| 25 | while lt used n |
| 26 | got = read fd direct used sub n used |
| 27 | check gt got 0 |
| 28 | used = add used ulong got |
| 29 | end |
| 30 | for i ulong n |
| 31 | check eq get mapped i get direct i |
| 32 | end |
| 33 | end |
| 34 | fn main to int |
| 35 | check eq argcnt 2 |
| 36 | pn = argread 1 path 0 len path |
| 37 | check and gt pn 0 lt pn long len path |
| 38 | fd = fopen path 0 ulong pn 524288 0 |
| 39 | check ge fd 0 |
| 40 | check eq fstat int fd meta 0 128 0 |
| 41 | size = sizeword |
| 42 | check and ge size 16 le size 68719476736 |
| 43 | handle = mapnew int fd 0 size 1 2 |
| 44 | check gt handle 0 |
| 45 | compare int fd handle 0 8 |
| 46 | header = ulong 0 |
| 47 | for i ulong 8 |
| 48 | header = or header shl ulong get mapped i mul i 8 |
| 49 | end |
| 50 | check and ge header 2 le header sub size 8 |
| 51 | check le header 67108864 |
| 52 | compare int fd handle 8 1 |
| 53 | check eq get mapped 0 123 |
| 54 | compare int fd handle add 7 header 1 |
| 55 | check or eq get mapped 0 125 eq get mapped 0 32 |
| 56 | take = ulong 4096 |
| 57 | if lt size take |
| 58 | take = size |
| 59 | end |
| 60 | compare int fd handle 0 take |
| 61 | compare int fd handle sub size take take |
| 62 | for i ulong 32 |
| 63 | off = div mul sub size take i 31 |
| 64 | compare int fd handle off take |
| 65 | end |
| 66 | note Recheck file identity, length and modification metadata. atime is allowed to change. |
| 67 | check eq fstat int fd after 0 128 0 |
| 68 | for i ulong 128 |
| 69 | if or or lt i 16 and ge i 48 lt i 56 and ge i 88 lt i 120 |
| 70 | check eq get after i get meta i |
| 71 | end |
| 72 | end |
| 73 | check eq mapdrop handle 0 |
| 74 | check eq fclose int fd 0 |
| 75 | check eq write 1 pass 0 len pass long len pass |
| 76 | ret 0 |
| 77 | end |