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 / cubin_elf_admission.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note Compose with om/components/artifact_elf.om. Input is the image emitted by ampere_cubin_test FILE. |
| 3 | note Exercise the existing production ELF admission unit, not a new parser or relaxed loader. |
| 4 | text cefn "ampere_exit" |
| 5 | text cepass "PASS cubin ELF admission: original accepted; wrong text section size and truncated ELF refused\n" |
| 6 | fn ce_rd b view uchar 65536 p ulong n ulong to ulong |
| 7 | v = ulong 0 |
| 8 | for i ulong n |
| 9 | v = or v shl ulong get b add p i mul i 8 |
| 10 | end |
| 11 | ret v |
| 12 | end |
| 13 | fn ce_check elf view uchar 65536 n ulong to ulong |
| 14 | buf = new uchar 512 0 |
| 15 | st = new ulong 32 0 |
| 16 | put st 1 n |
| 17 | put st 2 16 |
| 18 | put st 3 len cefn |
| 19 | for i ulong len cefn |
| 20 | put buf add 256 i get cefn i |
| 21 | end |
| 22 | note Independent EXIT word from the existing fixture in tests/ampere_cubin_test.c. |
| 23 | put buf 128 uchar 77 |
| 24 | put buf 129 uchar 121 |
| 25 | note WolframLanguageEvaluator: FromDigits[#,16]& /@ {"4d","79","80","ea","0f"} -> {77,121,128,234,15}. |
| 26 | put buf 138 uchar 128 |
| 27 | put buf 139 uchar 3 |
| 28 | put buf 141 uchar 234 |
| 29 | put buf 142 uchar 15 |
| 30 | note Request buffer begins with the first 64 header bytes. |
| 31 | if lt n 64 |
| 32 | ret 0 |
| 33 | end |
| 34 | for i ulong 64 |
| 35 | put buf i get elf i |
| 36 | end |
| 37 | for step ulong 1024 |
| 38 | status = artifact_elf buf st |
| 39 | if ne status 2 |
| 40 | ret status |
| 41 | end |
| 42 | off = get st 4 |
| 43 | cnt = get st 5 |
| 44 | if gt off n |
| 45 | ret 0 |
| 46 | end |
| 47 | if gt cnt sub n off |
| 48 | ret 0 |
| 49 | end |
| 50 | for i ulong cnt |
| 51 | put buf i get elf add off i |
| 52 | end |
| 53 | end |
| 54 | ret 0 |
| 55 | end |
| 56 | fn main to int |
| 57 | path = new uchar 4096 0 |
| 58 | elf = new uchar 65536 0 |
| 59 | if ne argcnt 2 |
| 60 | ret 2 |
| 61 | end |
| 62 | pn = argread 1 path 0 4096 |
| 63 | if le pn 0 |
| 64 | ret 3 |
| 65 | end |
| 66 | fd = fopen path 0 ulong pn 0 0 |
| 67 | if lt fd 0 |
| 68 | ret 4 |
| 69 | end |
| 70 | n = ulong 0 |
| 71 | while lt n 65536 bound 65536 |
| 72 | k = read int fd elf n sub ulong 65536 n |
| 73 | if lt k 0 |
| 74 | ret 5 |
| 75 | end |
| 76 | if eq k 0 |
| 77 | break |
| 78 | end |
| 79 | n = add n ulong k |
| 80 | end |
| 81 | closed = fclose int fd |
| 82 | if or ne closed 0 eq n 65536 |
| 83 | ret 6 |
| 84 | end |
| 85 | if ne ce_check elf n 1 |
| 86 | ret 7 |
| 87 | end |
| 88 | if ne ce_check elf 63 0 |
| 89 | ret 8 |
| 90 | end |
| 91 | shoff = ce_rd elf 40 8 |
| 92 | if ne ce_check elf sub shoff 1 0 |
| 93 | ret 9 |
| 94 | end |
| 95 | count = ce_rd elf 60 2 |
| 96 | found = false |
| 97 | for i ulong count |
| 98 | base = add shoff mul i 64 |
| 99 | if eq ce_rd elf add base 4 4 1 |
| 100 | if eq ce_rd elf add base 8 8 6 |
| 101 | put elf add base 32 uchar 17 |
| 102 | found = true |
| 103 | end |
| 104 | end |
| 105 | end |
| 106 | if not found |
| 107 | ret 10 |
| 108 | end |
| 109 | if ne ce_check elf n 0 |
| 110 | ret 11 |
| 111 | end |
| 112 | k = write 1 cepass 0 len cepass |
| 113 | if ne k long len cepass |
| 114 | ret 12 |
| 115 | end |
| 116 | ret 0 |
| 117 | end |