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 / amd-exec / run.sh

226 lines · 14183 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# Host-only gfx942 instruction execution. Usage: sh tests/amd-exec/run.sh /absolute/pinned/omc
4# AMD_EXEC_OUT optionally preserves artifacts. Production = seeded Omega; Python is test only.
5# Pin refusal=69, usage=64, missing tool=3, unsupported host=77; hardware always NOT_RUN.
6set -eu
7LC_ALL=C
8export LC_ALL
9[ "$#" -eq 1 ] || { echo 'usage: run.sh /absolute/pinned/omc' >&2; exit 64; }
10omc=$1
11case $omc in /*) ;; *) exit 64 ;; esac
12command -v sha256sum >/dev/null 2>&1 || exit 3
13[ -f "$omc" ] && [ -x "$omc" ] || exit 3
14pin=2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f
15digest=$(sha256sum < "$omc")
16[ "${digest%% *}" = "$pin" ] || { echo 'REFUSED compiler digest' >&2; exit 69; }
17# No source read, output-directory creation, compilation, or producer run precedes this check.
18[ "$(uname -s)" = Linux ] && [ "$(uname -m)" = aarch64 ] || exit 77
19for tool in python3 cat cmp chmod mkdir mktemp dirname sed grep timeout; do
20 command -v "$tool" >/dev/null 2>&1 || { echo "NOT_RUN missing $tool"; exit 3; }
21done
22root=$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd)
23out=${AMD_EXEC_OUT:-$(mktemp -d "${TMPDIR:-/tmp}/gfx942-exec.XXXXXX")}
24mkdir -p "$out"
25out=$(CDPATH= cd -- "$out" && pwd)
26src=$root/backend/amd/gfx942
27python3 -I "$root/tests/amd/receipt.py" write "$root" "$out"
28printf 'PIN omc=%s\n' "$pin"
29python3 --version
30# Instruments run with this directory first on sys.path; a stdlib-named module here breaks oracle imports.
31python3 -I "$root/tests/amd-exec/stdlib-shadow.py" test "$root/tests/amd-exec"
32cat "$src/exec/fp.om" "$src/exec/fma.om" "$src/exec/main.om" > "$out/exec.om"
33for name in hsaco exec rope; do
34 input=$src/$name.om
35 [ "$name" != exec ] || input=$out/exec.om
36 for iteration in 1 2; do
37 timeout 120 "$omc" < "$input" > "$out/$name.$iteration" 2> "$out/$name.$iteration.compile.log"
38 [ ! -s "$out/$name.$iteration.compile.log" ] || { cat "$out/$name.$iteration.compile.log"; exit 1; }
39 chmod 700 "$out/$name.$iteration"
40 done
41 cmp "$out/$name.1" "$out/$name.2"
42 echo "PASS $name two builds byte-identical"
43done
44{
45 cat "$src/exec/fp.om" "$src/exec/fma.om"
46 sed '/^fn main to int/,$d' "$src/exec/main.om"
47 cat "$root/tests/amd-exec/semantics-probe.om"
48} > "$out/semantics.om"
49mutants=$(python3 -I "$root/tests/amd-exec/semantics.py" mutate "$out/semantics.om" "$out")
50for variant in semantics $mutants; do
51 timeout 120 "$omc" < "$out/$variant.om" > "$out/$variant" 2> "$out/$variant.compile.log"
52 [ ! -s "$out/$variant.compile.log" ] || { cat "$out/$variant.compile.log"; exit 1; }
53 chmod 700 "$out/$variant"
54 if [ "$variant" = semantics ]; then
55 python3 -I "$root/tests/amd-exec/semantics.py" suite "$out/$variant" "$out"
56 else
57 python3 -I "$root/tests/amd-exec/semantics.py" control "$out/$variant" "$out" "$variant"
58 fi
59done
60{ printf 'om2\n'; cat "$src/exec/fma.om" "$root/tests/amd-exec/fma-probe.om"; } > "$out/fma-probe.om"
61timeout 120 "$omc" < "$out/fma-probe.om" > "$out/fma-probe" 2> "$out/fma-probe.compile.log"
62[ ! -s "$out/fma-probe.compile.log" ] || { cat "$out/fma-probe.compile.log"; exit 1; }
63chmod 700 "$out/fma-probe"
64python3 -I "$root/tests/amd-exec/sgemm.py" probe "$out/fma-probe"
65python3 -I "$root/tests/amd-exec/fp8gemv.py" mutate "$out/exec.om" "$out/exec-ocp.om"
66timeout 120 "$omc" < "$out/exec-ocp.om" > "$out/exec-ocp" 2> "$out/exec-ocp.compile.log"
67[ ! -s "$out/exec-ocp.compile.log" ] || { cat "$out/exec-ocp.compile.log"; exit 1; }
68chmod 700 "$out/exec-ocp"
69python3 -I "$root/tests/amd-exec/bf16gemv.py" swap-mutant "$out/exec.om" "$out/exec-swapped.om"
70timeout 120 "$omc" < "$out/exec-swapped.om" > "$out/exec-swapped" 2> "$out/exec-swapped.compile.log"
71[ ! -s "$out/exec-swapped.compile.log" ] || { cat "$out/exec-swapped.compile.log"; exit 1; }
72chmod 700 "$out/exec-swapped"
73kernels=
74for table in "$src/"*.isa; do
75 kernel=${table##*/}
76 kernels="${kernels}${kernels:+ }${kernel%.isa}"
77done
78for kernel in $kernels; do
79 for iteration in 1 2; do
80 timeout 30 "$out/hsaco.$iteration" "$src/$kernel.isa" > "$out/$kernel.$iteration.hsaco"
81 done
82 cmp "$out/$kernel.1.hsaco" "$out/$kernel.2.hsaco"
83 echo "PASS $kernel code object two builds byte-identical"
84 python3 -I "$root/tests/amd-exec/oracle.py" extract "$out/$kernel.1.hsaco" "$out/$kernel.text"
85done
86digest=$(sha256sum < "$out/vadd.1.hsaco")
87[ "${digest%% *}" = 10eb12e019ff2117ddc0190650899d4254589375c62e5ebb970b1bbb7e67e55f ]
88echo 'PASS vadd code object unchanged from pre-generalization'
89digest=$(sha256sum < "$out/fsum16.1.hsaco")
90[ "${digest%% *}" = 15cf499fa114e801d931fb73cbee13fcb6e8764c08a470368306625a8df37478 ]
91echo 'PASS fsum16 code object unchanged from pre-SGEMM'
92digest=$(sha256sum < "$out/sgemm.1.hsaco")
93[ "${digest%% *}" = 466d2a9e8ed61768ca1d09c283933dbae12f768a5bae22f5cf50f13c527d7e70 ]
94echo 'PASS corrected sgemm code object unchanged from pre-FP8'
95digest=$(sha256sum < "$out/fp8gemv.1.hsaco")
96[ "${digest%% *}" = b2260043751f6483deae05d3c3b5cb1d2a5e97031d299998d9d4b04691fcaf5b ]
97echo 'PASS fp8gemv code object unchanged from pre-BF16'
98digest=$(sha256sum < "$out/bf16gemv.1.hsaco")
99[ "${digest%% *}" = 59f955f07f5702235927835b98e9934e574fe266744ea53b3ab2db35d30179fa ]
100echo 'PASS bf16gemv code object unchanged from pre-GEMV2'
101sed 's/^I 5 260 8 4 0x01 /I 5 261 8 4 0x01 /' "$src/vadd.isa" > "$out/flipped.isa"
102if cmp -s "$src/vadd.isa" "$out/flipped.isa"; then echo 'FAIL mutant did not apply'; exit 1; fi
103timeout 30 "$out/hsaco.1" "$out/flipped.isa" > "$out/flipped.hsaco"
104python3 -I "$root/tests/amd-exec/oracle.py" extract "$out/flipped.hsaco" "$out/flipped.text"
105python3 -I "$root/tests/amd-exec/oracle.py" suite "$out/exec.1" "$out/vadd.text" "$out/flipped.text" "$out"
106python3 -I "$root/tests/amd-exec/oracle.py" reverse-table "$src/fsum16.isa" "$out/reversed.isa"
107timeout 30 "$out/hsaco.1" "$out/reversed.isa" > "$out/reversed.hsaco"
108python3 -I "$root/tests/amd-exec/oracle.py" extract "$out/reversed.hsaco" "$out/reversed.text"
109python3 -I "$root/tests/amd-exec/oracle.py" fsum-suite "$out/exec.1" "$out/fsum16.text" "$out/reversed.text" "$out"
110python3 -I "$root/tests/amd-exec/sgemm.py" mutant "$src/sgemm.isa" "$out/unfused.isa"
111timeout 30 "$out/hsaco.1" "$out/unfused.isa" > "$out/unfused.hsaco"
112python3 -I "$root/tests/amd-exec/oracle.py" extract "$out/unfused.hsaco" "$out/unfused.text"
113python3 -I "$root/tests/amd-exec/sgemm.py" suite "$out/exec.1" "$out/sgemm.text" "$out/unfused.text" "$out"
114python3 -I "$root/tests/amd-exec/fp8gemv.py" scale-mutant "$src/fp8gemv.isa" "$out/no-scale.isa"
115timeout 30 "$out/hsaco.1" "$out/no-scale.isa" > "$out/no-scale.hsaco"
116python3 -I "$root/tests/amd-exec/oracle.py" extract "$out/no-scale.hsaco" "$out/no-scale.text"
117python3 -I "$root/tests/amd-exec/fp8gemv.py" suite "$out/exec.1" "$out/fp8gemv.text" "$out/exec-ocp" "$out/no-scale.text" "$out"
118python3 -I "$root/tests/amd-exec/bf16gemv.py" truncate-mutant "$src/bf16gemv.isa" "$out/truncated-x.isa"
119timeout 30 "$out/hsaco.1" "$out/truncated-x.isa" > "$out/truncated-x.hsaco"
120python3 -I "$root/tests/amd-exec/oracle.py" extract "$out/truncated-x.hsaco" "$out/truncated-x.text"
121python3 -I "$root/tests/amd-exec/bf16gemv.py" suite "$out/exec.1" "$out/bf16gemv.text" "$out/exec-swapped" "$out/truncated-x.text" "$out"
122{
123 cat "$src/exec/fp.om" "$src/exec/fma.om"
124 sed '/^fn main to int/,$d' "$src/exec/main.om"
125 cat "$root/tests/amd-exec/row-probe.om"
126} > "$out/row-probe.om"
127timeout 120 "$omc" < "$out/row-probe.om" > "$out/row-probe" 2> "$out/row-probe.compile.log"
128[ ! -s "$out/row-probe.compile.log" ] || { cat "$out/row-probe.compile.log"; exit 1; }
129chmod 700 "$out/row-probe"
130for kernel in fp8gemv2 bf16gemv2; do
131 python3 -I "$root/tests/amd-exec/gemv2.py" mutate "$src/$kernel.isa" "$out"
132 for control in order tail stride; do
133 timeout 30 "$out/hsaco.1" "$out/$kernel-$control.isa" > "$out/$kernel-$control.hsaco"
134 python3 -I "$root/tests/amd-exec/oracle.py" extract "$out/$kernel-$control.hsaco" "$out/$kernel-$control.text"
135 done
136done
137python3 -I "$root/tests/amd-exec/gemv2.py" suite "$out/exec.1" "$out/row-probe" "$out"
138cat "$src/exec/fp.om" "$root/tests/amd-exec/trans-probe.om" > "$out/trans-probe.om"
139timeout 120 "$omc" < "$out/trans-probe.om" > "$out/trans-probe" 2> "$out/trans-probe.compile.log"
140[ ! -s "$out/trans-probe.compile.log" ] || { cat "$out/trans-probe.compile.log"; exit 1; }
141chmod 700 "$out/trans-probe"
142python3 -I "$root/tests/amd-exec/attention.py" transprobe "$out/trans-probe"
143python3 -I "$root/tests/amd-exec/log.py" "$out/trans-probe"
144python3 -I "$root/tests/amd-exec/attention.py" mutate "$src/attn256_part.isa" "$out"
145for control in no-max wrong-gqa v-from-k; do
146 timeout 30 "$out/hsaco.1" "$out/attention-$control.isa" > "$out/attention-$control.hsaco"
147 python3 -I "$root/tests/amd-exec/oracle.py" extract "$out/attention-$control.hsaco" "$out/attention-$control.text"
148done
149python3 -I "$root/tests/amd-exec/attention.py" suite "$out/exec.1" "$out"
150python3 -I "$root/tests/amd-exec/prep.py" mutate "$src" "$out"
151for control in no-one wrong-pair wrong-position truncate-cache extra-swish wrong-gate-stride; do
152 timeout 30 "$out/hsaco.1" "$out/prep-$control.isa" > "$out/prep-$control.hsaco"
153 python3 -I "$root/tests/amd-exec/oracle.py" extract "$out/prep-$control.hsaco" "$out/prep-$control.text"
154done
155timeout 120 "$omc" < "$out/rope-wrong-dim.om" > "$out/rope-wrong-dim" 2> "$out/rope-wrong-dim.compile.log"
156[ ! -s "$out/rope-wrong-dim.compile.log" ] || { cat "$out/rope-wrong-dim.compile.log"; exit 1; }
157chmod 700 "$out/rope-wrong-dim"
158{ sed '/^fn main to int/,$d' "$src/rope.om"; cat "$root/tests/amd-exec/ropefreq-probe.om"; } > "$out/ropefreq-probe.om"
159timeout 120 "$omc" < "$out/ropefreq-probe.om" > "$out/ropefreq-probe" 2> "$out/ropefreq-probe.compile.log"
160[ ! -s "$out/ropefreq-probe.compile.log" ] || { cat "$out/ropefreq-probe.compile.log"; exit 1; }
161chmod 700 "$out/ropefreq-probe"
162python3 -I "$root/tests/amd-exec/prep.py" suite "$out/exec.1" "$out/rope.1" "$out"
163python3 -I "$root/tests/amd-exec/token_ref.py" mutate "$src" "$out"
164for control in mlpsilu-no-silu mlpsilu-wrong-up; do
165 timeout 30 "$out/hsaco.1" "$out/$control.isa" > "$out/$control.hsaco"
166 python3 -I "$root/tests/amd-exec/oracle.py" extract "$out/$control.hsaco" "$out/$control.text"
167done
168python3 -I "$root/tests/amd-exec/token_ref.py" suite "$out/exec.1" "$out"
169python3 -I "$root/tests/amd-exec/norm.py" mutate "$src" "$out"
170for control in rmsnorm5120-no-one rmsnorm5120-wrong-mean rmsnorm5120-dropped-chunk; do
171 timeout 30 "$out/hsaco.1" "$out/$control.isa" > "$out/$control.hsaco"
172 python3 -I "$root/tests/amd-exec/oracle.py" extract "$out/$control.hsaco" "$out/$control.text"
173done
174python3 -I "$root/tests/amd-exec/norm.py" suite "$out/exec.1" "$out"
175python3 -I "$root/tests/amd-exec/gdnconv.py" mutate "$src" "$out"
176for control in gdnconv4-no-input-round gdnconv4-no-conv-round gdnconv4-no-silu-round gdnconv4-wrong-cache-shift; do
177 timeout 30 "$out/hsaco.1" "$out/$control.isa" > "$out/$control.hsaco"
178 python3 -I "$root/tests/amd-exec/oracle.py" extract "$out/$control.hsaco" "$out/$control.text"
179done
180python3 -I "$root/tests/amd-exec/gdnconv.py" suite "$out/exec.1" "$out"
181python3 -I "$root/tests/amd-exec/gdn.py" mutate "$src" "$out"
182for control in $(python3 -I "$root/tests/amd-exec/gdn.py" controls); do
183 timeout 30 "$out/hsaco.1" "$out/$control.isa" > "$out/$control.hsaco"
184 python3 -I "$root/tests/amd-exec/oracle.py" extract "$out/$control.hsaco" "$out/$control.text"
185done
186python3 -I "$root/tests/amd-exec/gdn.py" suite "$out/exec.1" "$out"
187python3 -I "$root/tests/amd-exec/decode.py" mutate "$src" "$out"
188for control in $(python3 -I "$root/tests/amd-exec/decode.py" controls); do
189 timeout 30 "$out/hsaco.1" "$out/$control.isa" > "$out/$control.hsaco"
190 python3 -I "$root/tests/amd-exec/oracle.py" extract "$out/$control.hsaco" "$out/$control.text"
191done
192python3 -I "$root/tests/amd-exec/decode.py" suite "$out/exec.1" "$out"
193python3 -I "$root/tests/amd-exec/prep_section.py" "$out/exec.1" "$out"
194python3 -I "$root/tests/amd-exec/token_access.py" "$omc" "$src" "$out"
195python3 -I "$root/tests/amd-exec/fp8gemv.py" flat-mutant "$out/exec.om" "$out/exec-flat.om"
196timeout 120 "$omc" < "$out/exec-flat.om" > "$out/exec-flat" 2> "$out/exec-flat.compile.log"
197[ ! -s "$out/exec-flat.compile.log" ] || { cat "$out/exec-flat.compile.log"; exit 1; }
198chmod 700 "$out/exec-flat"
199python3 -I "$root/tests/amd-exec/fp8gemv.py" long-wave "$out/exec.1" "$out/exec-flat" "$out/fp8gemv.text" "$out"
200python3 -I "$root/tests/amd-exec/fp8gemv.py" flat-grid-mutant "$out/exec.om" "$out/exec-flatgrid.om"
201timeout 120 "$omc" < "$out/exec-flatgrid.om" > "$out/exec-flatgrid" 2> "$out/exec-flatgrid.compile.log"
202[ ! -s "$out/exec-flatgrid.compile.log" ] || { cat "$out/exec-flatgrid.compile.log"; exit 1; }
203chmod 700 "$out/exec-flatgrid"
204python3 -I "$root/tests/amd-exec/fp8gemv.py" tall-grid "$out/exec.1" "$out/exec-flatgrid" "$out/vadd.text" "$out"
205cat > "$out/wrong-omc" <<'WRONG'
206#!/bin/sh
207printf 'WRONG_COMPILER_EXECUTED\n' >&2
208exit 99
209WRONG
210chmod 700 "$out/wrong-omc"
211rc=0
212AMD_EXEC_OUT="$out/wrong-pin-must-not-exist" sh "$root/tests/amd-exec/run.sh" "$out/wrong-omc" > "$out/wrong-pin.log" 2>&1 || rc=$?
213[ "$rc" -eq 69 ] && grep -qx 'REFUSED compiler digest' "$out/wrong-pin.log"
214[ ! -e "$out/wrong-pin-must-not-exist" ]
215if grep -q WRONG_COMPILER_EXECUTED "$out/wrong-pin.log"; then exit 1; fi
216echo 'CONTROL wrong-compiler-digest CAUGHT exit=69 before compiler execution or output creation'
217# Execute Markdown shell blocks verbatim with the caller's documented python3.
218# Weights are an explicit outside oracle dependency, never silently substituted.
219if [ -z "${AMD_WEIGHTS:-}" ] || [ ! -d "$AMD_WEIGHTS" ]; then
220 echo 'NOT_RUN documented commands require AMD_WEIGHTS checkpoint directory'
221 exit 77
222fi
223OMEGA_OMC="$omc" AMD_DOC_OUT="$out/documented" python3 "$root/tests/amd-exec/documented.py"
224sha256sum "$out/hsaco.1" "$out/exec.1" "$out/"*.1.hsaco
225python3 -I "$root/tests/amd/receipt.py" check "$root" "$out"
226python3 -I "$root/tests/amd-exec/sgemm.py" summary "$kernels"