interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / tests / cubin_elf_admission.om

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