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
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | # gfx942 vadd: Omega is the producer; LLVM 18 tools are independent ORACLES only. |
| 4 | # Usage: sh tests/amd/run.sh /absolute/path/to/pinned/omc |
| 5 | # AMD_OUT keeps outputs (default mktemp). Missing mandatory tools => NOT_RUN exit 3, |
| 6 | # unsupported host => NOT_RUN exit 77; FAIL => 1; pin refusal => 69; usage => 64; I/O => 74. |
| 7 | # Hardware rows are always NOT_RUN; PASS is host byte/format evidence, never hardware qualification. |
| 8 | set -u |
| 9 | LC_ALL=C |
| 10 | export LC_ALL |
| 11 | for tool in uname sha256sum; do |
| 12 | command -v "$tool" >/dev/null 2>&1 || { echo "NOT_RUN missing tool $tool"; exit 3; } |
| 13 | done |
| 14 | if [ "$(uname -s)" != Linux ] || [ "$(uname -m)" != aarch64 ]; then |
| 15 | echo 'NOT_RUN gfx942 host gate requires Linux AArch64 and the pinned seeded omc'; exit 77 |
| 16 | fi |
| 17 | [ "$#" -eq 1 ] || { echo 'usage: run.sh /absolute/path/to/pinned/omc' >&2; exit 64; } |
| 18 | omc=$1 |
| 19 | case $omc in /*) ;; *) echo 'usage: omc path must be absolute' >&2; exit 64 ;; esac |
| 20 | [ -f "$omc" ] && [ -x "$omc" ] || { echo 'NOT_RUN pinned omc is missing or not executable'; exit 3; } |
| 21 | # Same source pin as tests/multitarget/run.sh and AGENTS.md (omega-mv e5b32567/369dbc96). |
| 22 | omc_pin=2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f |
| 23 | digest() { d=$(sha256sum < "$1") || return 1; printf '%s\n' "${d%% *}"; } |
| 24 | [ "$(digest "$omc")" = "$omc_pin" ] || { echo "REFUSED: compiler digest differs from pin $omc_pin" >&2; exit 69; } |
| 25 | # Pin check deliberately precedes mkdir, source reads, every compilation, and every producer run. |
| 26 | for tool in python3 llvm-mc-18 llvm-objdump-18 llvm-readelf-18 llvm-objcopy-18 timeout cmp sed grep awk dd head tail wc tr mkdir chmod mktemp cat dirname sh od; do |
| 27 | command -v "$tool" >/dev/null 2>&1 || { echo "NOT_RUN missing tool $tool"; exit 3; } |
| 28 | done |
| 29 | root=$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd) || exit 74 |
| 30 | out=${AMD_OUT:-$(mktemp -d "${TMPDIR:-/tmp}/cudapp-gfx942.XXXXXX")} || exit 74 |
| 31 | mkdir -p "$out" || exit 74 |
| 32 | # Canonicalize only after mkdir, so recursive wrong-pin control can prove it created no output dir. |
| 33 | out=$(CDPATH= cd -- "$out" && pwd) || exit 74 |
| 34 | src=$root/backend/amd/gfx942 |
| 35 | python3 -I "$root/tests/amd/receipt.py" write "$root" "$out" || exit 1 |
| 36 | python3 -I "$root/tests/amd/receipt-test.py" || exit 1 |
| 37 | printf 'PIN omc %s\nOutputs: AMD_OUT (or the fresh temporary directory)\n' "$omc_pin" |
| 38 | for tool in llvm-mc-18 llvm-objdump-18 llvm-readelf-18 llvm-objcopy-18; do |
| 39 | "$tool" --version > "$out/$tool.version" 2>&1 || { echo "FAIL cannot run $tool"; exit 1; } |
| 40 | printf 'ORACLE %s %s\n' "$tool" "$(head -n 1 "$out/$tool.version")" |
| 41 | done |
| 42 | pass=0; fail=0 |
| 43 | ok() { pass=$((pass + 1)); echo "PASS $*"; } |
| 44 | bad() { fail=$((fail + 1)); echo "FAIL $*"; } |
| 45 | expect() { |
| 46 | want=$1; name=$2; shift 2 |
| 47 | "$@" > "$out/$name.log" 2>&1; got=$? |
| 48 | if [ "$got" -eq "$want" ]; then ok "$name exit=$got $(tail -n 1 "$out/$name.log")"; |
| 49 | else bad "$name exit=$got want=$want $(tail -n 1 "$out/$name.log")"; fi |
| 50 | } |
| 51 | compare() { |
| 52 | if cmp -s "$1" "$2"; then ok "$3"; else bad "$3"; fi |
| 53 | } |
| 54 | poke() { printf "\\$3" | dd of="$1" bs=1 seek="$2" conv=notrunc status=none; } |
| 55 | build() { |
| 56 | name=$1; unit=$2 |
| 57 | timeout 120 "$omc" < "$unit" > "$out/$name" 2> "$out/$name.compile.err"; rc=$? |
| 58 | if [ "$rc" -ne 0 ] || [ -s "$out/$name.compile.err" ] || [ ! -s "$out/$name" ]; then |
| 59 | cat "$out/$name.compile.err"; echo "FAIL compile $name exit=$rc"; exit 1 |
| 60 | fi |
| 61 | chmod 700 "$out/$name" || exit 74 |
| 62 | echo "COMPILE $name src=$(digest "$unit") bin=$(digest "$out/$name")" |
| 63 | } |
| 64 | build targets "$root/backend/targets.om" |
| 65 | build hsaco "$src/hsaco.om" |
| 66 | build hsaco-again "$src/hsaco.om" |
| 67 | compare "$out/hsaco" "$out/hsaco-again" 'two producer compilations byte-identical' |
| 68 | for build in hsaco hsaco-again; do |
| 69 | timeout 30 "$out/$build" "$src/vadd.isa" > "$out/$build.hsaco" 2> "$out/$build.emit.err"; rc=$? |
| 70 | if [ "$rc" -ne 0 ] || [ -s "$out/$build.emit.err" ] || [ ! -s "$out/$build.hsaco" ]; then |
| 71 | echo "FAIL producer $build exit=$rc"; cat "$out/$build.emit.err"; exit 1 |
| 72 | fi |
| 73 | done |
| 74 | compare "$out/hsaco.hsaco" "$out/hsaco-again.hsaco" 'two code-object builds byte-identical' |
| 75 | echo "OBJECT sha256=$(digest "$out/hsaco.hsaco") bytes=$(wc -c < "$out/hsaco.hsaco" | tr -d ' ')" |
| 76 | T=$out/targets |
| 77 | expect 0 load-gfx942 "$T" load AMDGPU_HSACO "$out/hsaco.hsaco" gfx942 |
| 78 | grep -q '^LOAD ACCEPT AMDGPU_HSACO target=amdgcn-amd-amdhsa--gfx942 ' "$out/load-gfx942.log" || bad 'loader did not print LOAD ACCEPT' |
| 79 | # The oracle is ET_REL. No linker is required or invoked, and no oracle bytes are producer input. |
| 80 | if ! llvm-mc-18 -triple=amdgcn-amd-amdhsa -mcpu=gfx942 -filetype=obj "$src/vadd-gfx942.s" -o "$out/oracle.o" > "$out/assemble.log" 2>&1; then |
| 81 | echo 'FAIL oracle assembly'; cat "$out/assemble.log"; exit 1 |
| 82 | fi |
| 83 | llvm-mc-18 -triple=amdgcn-amd-amdhsa -mcpu=gfx942 -show-encoding "$src/vadd-gfx942.s" > "$out/oracle.encodings.txt" 2>&1 || { echo 'FAIL encoding oracle'; exit 1; } |
| 84 | for pair in hsaco.hsaco:omega oracle.o:oracle; do |
| 85 | file=${pair%:*}; prefix=${pair#*:} |
| 86 | # llvm-objcopy rewrites its input when no explicit output is supplied. Supply a throwaway output |
| 87 | # even for --dump-section: the original emitted/assembled objects must NEVER be modified. |
| 88 | llvm-objcopy-18 --dump-section=.text="$out/$prefix.text" --dump-section=.rodata="$out/$prefix.rodata" --dump-section=.note="$out/$prefix.note" \ |
| 89 | "$out/$file" "$out/$prefix.objcopy-rewrite" > "$out/$prefix.extract.log" 2>&1 || { echo "FAIL extract $prefix"; exit 1; } |
| 90 | llvm-readelf-18 -h -l -S -s -r -d --notes "$out/$file" > "$out/$prefix.readelf.txt" 2>&1 || { echo "FAIL readelf $prefix"; exit 1; } |
| 91 | done |
| 92 | compare "$out/omega.text" "$out/oracle.text" 'code section bytes equal llvm-mc-18 gfx942 oracle' |
| 93 | compare "$out/omega.note" "$out/oracle.note" 'AMDGPU metadata note bytes equal independent oracle' |
| 94 | # Descriptor REL64 relocation only affects byte offsets 16..23. All other bytes must agree. |
| 95 | dd if="$out/omega.rodata" of="$out/omega.descriptor-head" bs=1 count=16 status=none || exit 74 |
| 96 | dd if="$out/oracle.rodata" of="$out/oracle.descriptor-head" bs=1 count=16 status=none || exit 74 |
| 97 | dd if="$out/omega.rodata" of="$out/omega.descriptor-tail" bs=1 skip=24 status=none || exit 74 |
| 98 | dd if="$out/oracle.rodata" of="$out/oracle.descriptor-tail" bs=1 skip=24 status=none || exit 74 |
| 99 | compare "$out/omega.descriptor-head" "$out/oracle.descriptor-head" 'descriptor sizes/reserved prefix match oracle' |
| 100 | compare "$out/omega.descriptor-tail" "$out/oracle.descriptor-tail" 'descriptor resources/properties match oracle' |
| 101 | # The ET_REL oracle has a REL64 relocation here; independently check the resolved displacement. |
| 102 | entryva=$(awk '$8 == "vadd" { print "0x" $2; exit }' "$out/omega.readelf.txt") |
| 103 | descva=$(awk '$8 == "vadd.kd" { print "0x" $2; exit }' "$out/omega.readelf.txt") |
| 104 | disp=$(od -An -tu8 -j 16 -N 8 "$out/omega.rodata" | tr -d ' ') |
| 105 | if [ -n "$entryva" ] && [ -n "$descva" ] && [ "$disp" = "$((entryva - descva))" ]; then |
| 106 | ok 'descriptor entry displacement resolves to vadd (no relocation remains)' |
| 107 | else bad 'descriptor entry displacement'; fi |
| 108 | # ELF addresses differ (ET_DYN has code VA, ET_REL starts at zero); rebase ORACLE by emitted VA. |
| 109 | vma=$(awk '$3 == ".text" { print "0x" $5; exit }' "$out/omega.readelf.txt") |
| 110 | [ -n "$vma" ] || { echo 'FAIL .text VMA not found'; exit 1; } |
| 111 | (cd "$out" && llvm-objdump-18 -d hsaco.hsaco) > "$out/omega.objdump.txt" 2>&1 || exit 1 |
| 112 | (cd "$out" && llvm-objdump-18 -d --adjust-vma="$vma" oracle.o) > "$out/oracle.objdump.txt" 2>&1 || exit 1 |
| 113 | # Strip ONLY the input-filename heading, retain addresses, instruction words, operands and labels. |
| 114 | sed '1,2d' "$out/omega.objdump.txt" > "$out/omega.listing" |
| 115 | sed '1,2d' "$out/oracle.objdump.txt" > "$out/oracle.listing" |
| 116 | compare "$out/omega.listing" "$out/oracle.listing" 'objdump -d listings equal (oracle rebased to emitted .text VA)' |
| 117 | if grep -q 'NT_AMDGPU_METADATA' "$out/omega.readelf.txt" && grep -q 'amdhsa.target: *amdgcn-amd-amdhsa--gfx942' "$out/omega.readelf.txt" \ |
| 118 | && grep -q '\.name: *vadd$' "$out/omega.readelf.txt" && grep -q ' vadd.kd$' "$out/omega.readelf.txt" \ |
| 119 | && grep -q 'Flags: *0x54C, gfx942' "$out/omega.readelf.txt" && ! grep -q 'warning:\|error:' "$out/omega.readelf.txt"; then |
| 120 | ok 'llvm-readelf parses HSA v5 gfx942 flags, metadata kernel vadd and symbol vadd.kd' |
| 121 | else bad 'llvm-readelf metadata/header/symbol check'; fi |
| 122 | # Generate the probe and expected bytes from MessagePack width thresholds. |
| 123 | python3 -I "$root/tests/amd/boundaries.py" "$out" || exit 1 |
| 124 | python3 -I "$root/tests/amd/loop-sites.py" test "$root" > "$out/loop-sites.log" || exit 1 |
| 125 | cat "$out/loop-sites.log" |
| 126 | mptest() { |
| 127 | sed '/^fn main to int/,$d' "$1" > "$out/$2.om" || exit 74 |
| 128 | cat "$out/msgpack-main.om" >> "$out/$2.om" || exit 74 |
| 129 | timeout 120 "$omc" < "$out/$2.om" > "$out/$2" 2> "$out/$2.compile.err" && chmod 700 "$out/$2" \ |
| 130 | && timeout 30 "$out/$2" > "$out/$2.bytes" 2> "$out/$2.err" |
| 131 | } |
| 132 | if mptest "$src/hsaco.om" msgpack && cmp -s "$out/msgpack.bytes" "$out/msgpack.expected"; then |
| 133 | ok 'MessagePack uint and str encodings at every width boundary equal the spec bytes' |
| 134 | else bad 'MessagePack width encodings'; fi |
| 135 | # Control: the old single-byte value encoder (octet v) must be caught by the same comparison. |
| 136 | # It must compile and run, so the comparison (not a build failure) is what catches it. |
| 137 | sed 's/^if le v 127$/if le v 18446744073709551615/' "$src/hsaco.om" > "$out/mp-mutant-src.om" || exit 74 |
| 138 | if cmp -s "$src/hsaco.om" "$out/mp-mutant-src.om"; then bad 'MessagePack mutant did not apply' |
| 139 | elif ! mptest "$out/mp-mutant-src.om" mp-mutant; then bad 'MessagePack mutant did not build and run' |
| 140 | elif cmp -s "$out/mp-mutant.bytes" "$out/msgpack.expected"; then bad 'CONTROL single-byte MessagePack value escaped' |
| 141 | else ok 'CONTROL single-byte MessagePack value CAUGHT by byte comparison'; fi |
| 142 | # Control: a str16/str32 cutoff one below the spec (65534) must be caught at length 65535. |
| 143 | sed 's/^if le n 65535$/if le n 65534/' "$src/hsaco.om" > "$out/mp-mutant2-src.om" || exit 74 |
| 144 | if cmp -s "$src/hsaco.om" "$out/mp-mutant2-src.om"; then bad 'MessagePack str16 mutant did not apply' |
| 145 | elif ! mptest "$out/mp-mutant2-src.om" mp-mutant2; then bad 'MessagePack str16 mutant did not build and run' |
| 146 | elif cmp -s "$out/mp-mutant2.bytes" "$out/msgpack.expected"; then bad 'CONTROL str16 cutoff 65534 escaped' |
| 147 | else ok 'CONTROL str16 cutoff 65534 CAUGHT by byte comparison'; fi |
| 148 | # Negative 1: one bit in a TABLE operand (v_add_f32 src0 v4=260 -> v5=261). |
| 149 | sed 's/^I 5 260 8 4 0x01 /I 5 261 8 4 0x01 /' "$src/vadd.isa" > "$out/flipped.isa" |
| 150 | if cmp -s "$src/vadd.isa" "$out/flipped.isa"; then bad 'instruction-table mutation did not apply'; fi |
| 151 | timeout 30 "$out/hsaco" "$out/flipped.isa" > "$out/flipped.hsaco" 2> "$out/flipped.emit.err"; rc=$? |
| 152 | if [ "$rc" -ne 0 ] || [ -s "$out/flipped.emit.err" ]; then bad "instruction-table mutant did not produce object exit=$rc"; |
| 153 | else |
| 154 | llvm-objcopy-18 --dump-section=.text="$out/flipped.text" "$out/flipped.hsaco" "$out/flipped.objcopy-rewrite" > "$out/flipped.extract.log" 2>&1 || exit 1 |
| 155 | if cmp -s "$out/flipped.text" "$out/oracle.text"; then bad 'CONTROL instruction-table flipped bit escaped'; |
| 156 | else ok 'CONTROL instruction-table flipped bit CAUGHT code mismatch'; fi |
| 157 | fi |
| 158 | # Negative 2: gfx942 mach 0x4c -> gfx1100 mach 0x41; documented targets.om refusal 33. |
| 159 | dd if="$out/hsaco.hsaco" of="$out/wrong-mach.hsaco" status=none || exit 74 |
| 160 | poke "$out/wrong-mach.hsaco" 48 101 || exit 74 |
| 161 | expect 33 control-wrong-mach "$T" load AMDGPU_HSACO "$out/wrong-mach.hsaco" gfx942 |
| 162 | # Negative 3: retains ELF/program headers but ends before PT_NOTE: documented refusal 34. |
| 163 | head -c 600 "$out/hsaco.hsaco" > "$out/truncated.hsaco" || exit 74 |
| 164 | expect 34 control-truncated "$T" load AMDGPU_HSACO "$out/truncated.hsaco" gfx942 |
| 165 | # Negative 4: an executable with the wrong digest must not run, compile, or create output. |
| 166 | cat > "$out/wrong-omc" <<'WRONG' |
| 167 | #!/bin/sh |
| 168 | printf 'WRONG COMPILER EXECUTED\n' |
| 169 | exit 99 |
| 170 | WRONG |
| 171 | chmod 700 "$out/wrong-omc" || exit 74 |
| 172 | AMD_OUT="$out/wrong-pin-must-not-exist" sh "$root/tests/amd/run.sh" "$out/wrong-omc" > "$out/wrong-pin.log" 2>&1; rc=$? |
| 173 | if [ "$rc" -eq 69 ] && grep -q '^REFUSED: compiler digest differs from pin ' "$out/wrong-pin.log" \ |
| 174 | && ! grep -q 'WRONG COMPILER EXECUTED' "$out/wrong-pin.log" && [ ! -e "$out/wrong-pin-must-not-exist" ]; then |
| 175 | ok 'CONTROL wrong compiler digest CAUGHT exit=69 before compiler/producer/output setup' |
| 176 | else bad "CONTROL wrong compiler digest exit=$rc or effect escaped"; fi |
| 177 | # The generic table metadata must retain the existing complete vadd object, not just its .text. |
| 178 | if [ "$(digest "$out/hsaco.hsaco")" = 10eb12e019ff2117ddc0190650899d4254589375c62e5ebb970b1bbb7e67e55f ]; then |
| 179 | ok 'vadd entire object unchanged from pre-generalization' |
| 180 | else bad 'vadd object changed during metadata generalization'; fi |
| 181 | for producer in hsaco hsaco-again; do |
| 182 | timeout 30 "$out/$producer" "$src/fsum16.isa" > "$out/fsum16-$producer.hsaco" 2> "$out/fsum16-$producer.err"; rc=$? |
| 183 | if [ "$rc" -ne 0 ] || [ -s "$out/fsum16-$producer.err" ]; then |
| 184 | echo "FAIL fsum16 producer exit=$rc"; cat "$out/fsum16-$producer.err"; exit 1 |
| 185 | fi |
| 186 | done |
| 187 | compare "$out/fsum16-hsaco.hsaco" "$out/fsum16-hsaco-again.hsaco" 'fsum16 two code-object builds byte-identical' |
| 188 | if ! llvm-mc-18 -triple=amdgcn-amd-amdhsa -mcpu=gfx942 -filetype=obj "$src/fsum16-gfx942.s" -o "$out/fsum16-oracle.o" > "$out/fsum16-assemble.log" 2>&1; then |
| 189 | echo 'FAIL fsum16 oracle assembly'; cat "$out/fsum16-assemble.log"; exit 1 |
| 190 | fi |
| 191 | for pair in fsum16-hsaco.hsaco:fsum16-omega fsum16-oracle.o:fsum16-oracle; do |
| 192 | file=${pair%:*}; prefix=${pair#*:} |
| 193 | llvm-objcopy-18 --dump-section=.text="$out/$prefix.text" --dump-section=.rodata="$out/$prefix.rodata" --dump-section=.note="$out/$prefix.note" \ |
| 194 | "$out/$file" "$out/$prefix.objcopy-rewrite" > "$out/$prefix.extract.log" 2>&1 || exit 1 |
| 195 | llvm-readelf-18 -h -l -S -s -r -d --notes "$out/$file" > "$out/$prefix.readelf.txt" 2>&1 || exit 1 |
| 196 | dd if="$out/$prefix.rodata" of="$out/$prefix.descriptor-head" bs=1 count=16 status=none || exit 74 |
| 197 | dd if="$out/$prefix.rodata" of="$out/$prefix.descriptor-tail" bs=1 skip=24 status=none || exit 74 |
| 198 | done |
| 199 | compare "$out/fsum16-omega.text" "$out/fsum16-oracle.text" 'fsum16 .text bytes equal independent llvm-mc-18 oracle' |
| 200 | compare "$out/fsum16-omega.note" "$out/fsum16-oracle.note" 'fsum16 metadata note bytes equal independent oracle' |
| 201 | compare "$out/fsum16-omega.descriptor-head" "$out/fsum16-oracle.descriptor-head" 'fsum16 descriptor sizes match oracle' |
| 202 | compare "$out/fsum16-omega.descriptor-tail" "$out/fsum16-oracle.descriptor-tail" 'fsum16 descriptor resources/properties match oracle' |
| 203 | entryva=$(awk '$8 == "fsum16" { print "0x" $2; exit }' "$out/fsum16-omega.readelf.txt") |
| 204 | descva=$(awk '$8 == "fsum16.kd" { print "0x" $2; exit }' "$out/fsum16-omega.readelf.txt") |
| 205 | disp=$(od -An -tu8 -j 16 -N 8 "$out/fsum16-omega.rodata" | tr -d ' ') |
| 206 | if [ -n "$entryva" ] && [ -n "$descva" ] && [ "$disp" = "$((entryva - descva))" ]; then |
| 207 | ok 'fsum16 descriptor entry displacement resolves to kernel symbol' |
| 208 | else bad 'fsum16 descriptor entry displacement'; fi |
| 209 | if grep -q '\.name: *fsum16$' "$out/fsum16-omega.readelf.txt" \ |
| 210 | && grep -q ' fsum16.kd$' "$out/fsum16-omega.readelf.txt" \ |
| 211 | && grep -q '\.kernarg_segment_size: *20$' "$out/fsum16-omega.readelf.txt" \ |
| 212 | && grep -q '\.sgpr_count: *18$' "$out/fsum16-omega.readelf.txt" \ |
| 213 | && ! grep -q 'warning:\|error:' "$out/fsum16-omega.readelf.txt"; then |
| 214 | ok 'llvm-readelf parses fsum16 symbol, 20-byte kernarg and table register counts' |
| 215 | else bad 'fsum16 llvm-readelf metadata/header/symbol check'; fi |
| 216 | # Reject broken metadata before emitting any object; do not infer a kernel from its filename. |
| 217 | for control in missing-kernel duplicate-kernel argument-gap; do |
| 218 | case $control in |
| 219 | missing-kernel) sed '/^K /d' "$src/fsum16.isa" ;; |
| 220 | duplicate-kernel) sed '/^K /p' "$src/fsum16.isa" ;; |
| 221 | argument-gap) sed 's/^A n 16 4 1$/A n 20 4 1/' "$src/fsum16.isa" ;; |
| 222 | esac > "$out/$control.isa" |
| 223 | timeout 30 "$out/hsaco" "$out/$control.isa" > "$out/$control.hsaco" 2> "$out/$control.err"; rc=$? |
| 224 | if [ "$rc" -eq 4 ] && [ ! -s "$out/$control.hsaco" ]; then |
| 225 | ok "CONTROL $control CAUGHT exit=4 before object emission" |
| 226 | else bad "CONTROL $control exit=$rc or partial object escaped"; fi |
| 227 | done |
| 228 | echo "FSUM16 OBJECT sha256=$(digest "$out/fsum16-hsaco.hsaco") bytes=$(wc -c < "$out/fsum16-hsaco.hsaco" | tr -d ' ')" |
| 229 | if [ "$(digest "$out/fsum16-hsaco.hsaco")" = 15cf499fa114e801d931fb73cbee13fcb6e8764c08a470368306625a8df37478 ]; then |
| 230 | ok 'fsum16 entire object unchanged from pre-SGEMM' |
| 231 | else bad 'fsum16 object changed'; fi |
| 232 | for producer in hsaco hsaco-again; do |
| 233 | timeout 30 "$out/$producer" "$src/sgemm.isa" > "$out/sgemm-$producer.hsaco" 2> "$out/sgemm-$producer.emit.err"; rc=$? |
| 234 | if [ "$rc" -ne 0 ] || [ -s "$out/sgemm-$producer.emit.err" ]; then |
| 235 | echo "FAIL sgemm emit exit=$rc"; cat "$out/sgemm-$producer.emit.err"; exit 1 |
| 236 | fi |
| 237 | done |
| 238 | compare "$out/sgemm-hsaco.hsaco" "$out/sgemm-hsaco-again.hsaco" 'sgemm two code-object builds byte-identical' |
| 239 | if ! llvm-mc-18 -triple=amdgcn-amd-amdhsa -mcpu=gfx942 -filetype=obj "$src/sgemm-gfx942.s" -o "$out/sgemm-oracle.o" > "$out/sgemm-assemble.log" 2>&1; then |
| 240 | echo 'FAIL sgemm oracle assembly'; cat "$out/sgemm-assemble.log"; exit 1 |
| 241 | fi |
| 242 | llvm-mc-18 -triple=amdgcn-amd-amdhsa -mcpu=gfx942 -show-encoding "$src/sgemm-gfx942.s" > "$out/sgemm-encodings.txt" 2>&1 || exit 1 |
| 243 | for pair in sgemm-hsaco.hsaco:sgemm-omega sgemm-oracle.o:sgemm-oracle; do |
| 244 | file=${pair%:*}; name=${pair#*:} |
| 245 | llvm-objcopy-18 --dump-section .text="$out/$name.text" --dump-section .note="$out/$name.note" --dump-section .rodata="$out/$name.rodata" "$out/$file" "$out/$name.objcopy-rewrite" || exit 1 |
| 246 | llvm-readelf-18 -h -S -s -n "$out/$file" > "$out/$name.readelf.txt" || exit 1 |
| 247 | dd if="$out/$name.rodata" of="$out/$name.descriptor-head" bs=1 count=16 status=none || exit 74 |
| 248 | dd if="$out/$name.rodata" of="$out/$name.descriptor-tail" bs=1 skip=24 status=none || exit 74 |
| 249 | done |
| 250 | compare "$out/sgemm-omega.text" "$out/sgemm-oracle.text" 'sgemm .text including v_fmac_f32 and backward branch equals LLVM18 gfx942' |
| 251 | compare "$out/sgemm-omega.note" "$out/sgemm-oracle.note" 'sgemm metadata note equals independent oracle' |
| 252 | compare "$out/sgemm-omega.descriptor-head" "$out/sgemm-oracle.descriptor-head" 'sgemm descriptor sizes equal oracle' |
| 253 | compare "$out/sgemm-omega.descriptor-tail" "$out/sgemm-oracle.descriptor-tail" 'sgemm descriptor resources including workgroup Y equal oracle' |
| 254 | rsrc2=$(od -An -tu4 -j 52 -N 4 "$out/sgemm-omega.rodata" | tr -d ' ') |
| 255 | if [ "$((rsrc2 & 256))" -eq 256 ] && grep -q 'v_fmac_f32' "$out/sgemm-encodings.txt"; then |
| 256 | ok 'sgemm workgroup-id-Y enabled in rsrc2 and v_fmac_f32 accepted by gfx942 oracle' |
| 257 | else bad 'sgemm Y descriptor bit or fmac encoding'; fi |
| 258 | entryva=$(awk '$8 == "sgemm" { print "0x" $2; exit }' "$out/sgemm-omega.readelf.txt") |
| 259 | descva=$(awk '$8 == "sgemm.kd" { print "0x" $2; exit }' "$out/sgemm-omega.readelf.txt") |
| 260 | disp=$(od -An -tu8 -j 16 -N 8 "$out/sgemm-omega.rodata" | tr -d ' ') |
| 261 | if [ -n "$entryva" ] && [ -n "$descva" ] && [ "$disp" = "$((entryva - descva))" ]; then |
| 262 | ok 'sgemm descriptor entry displacement resolves to kernel symbol' |
| 263 | else bad 'sgemm descriptor entry displacement'; fi |
| 264 | if grep -q '\.name: *sgemm$' "$out/sgemm-omega.readelf.txt" \ |
| 265 | && grep -q '\.kernarg_segment_size: *36$' "$out/sgemm-omega.readelf.txt" \ |
| 266 | && grep -q '\.sgpr_count: *28$' "$out/sgemm-omega.readelf.txt" \ |
| 267 | && grep -q '\.vgpr_count: *15$' "$out/sgemm-omega.readelf.txt" \ |
| 268 | && grep -q '\.name: *K$' "$out/sgemm-omega.readelf.txt"; then |
| 269 | ok 'sgemm llvm-readelf metadata reports six arguments and descriptor resources' |
| 270 | else bad 'sgemm llvm-readelf metadata'; fi |
| 271 | if python3 -I "$root/tests/amd/branches.py" "$out/hsaco" "$src/sgemm.isa" "$out"; then |
| 272 | ok 'signed SOPP offset boundaries, undefined and duplicate labels' |
| 273 | else bad 'signed SOPP offset controls'; fi |
| 274 | compare "$out/sgemm-hsaco.hsaco" "$out/sgemm-hsaco-again.hsaco" 'sgemm original object preserved by all oracle tools' |
| 275 | echo "SGEMM OBJECT sha256=$(digest "$out/sgemm-hsaco.hsaco") bytes=$(wc -c < "$out/sgemm-hsaco.hsaco" | tr -d ' ')" |
| 276 | if [ "$(digest "$out/sgemm-hsaco.hsaco")" = 466d2a9e8ed61768ca1d09c283933dbae12f768a5bae22f5cf50f13c527d7e70 ]; then |
| 277 | ok 'corrected sgemm entire object unchanged from pre-FP8' |
| 278 | else bad 'corrected sgemm object changed'; fi |
| 279 | for producer in hsaco hsaco-again; do |
| 280 | timeout 30 "$out/$producer" "$src/fp8gemv.isa" > "$out/fp8gemv-$producer.hsaco" 2> "$out/fp8gemv-$producer.emit.err"; rc=$? |
| 281 | if [ "$rc" -ne 0 ] || [ -s "$out/fp8gemv-$producer.emit.err" ]; then |
| 282 | echo "FAIL fp8gemv emit exit=$rc"; cat "$out/fp8gemv-$producer.emit.err"; exit 1 |
| 283 | fi |
| 284 | done |
| 285 | compare "$out/fp8gemv-hsaco.hsaco" "$out/fp8gemv-hsaco-again.hsaco" 'fp8gemv two code-object builds byte-identical' |
| 286 | if ! llvm-mc-18 -triple=amdgcn-amd-amdhsa -mcpu=gfx942 -filetype=obj "$src/fp8gemv-gfx942.s" -o "$out/fp8gemv-oracle.o" > "$out/fp8gemv-assemble.log" 2>&1; then |
| 287 | echo 'FAIL fp8gemv oracle assembly'; cat "$out/fp8gemv-assemble.log"; exit 1 |
| 288 | fi |
| 289 | llvm-mc-18 -triple=amdgcn-amd-amdhsa -mcpu=gfx942 -show-encoding "$src/fp8gemv-gfx942.s" > "$out/fp8gemv-encodings.txt" 2>&1 || exit 1 |
| 290 | for pair in fp8gemv-hsaco.hsaco:fp8gemv-omega fp8gemv-oracle.o:fp8gemv-oracle; do |
| 291 | file=${pair%:*}; name=${pair#*:} |
| 292 | llvm-objcopy-18 --dump-section .text="$out/$name.text" --dump-section .note="$out/$name.note" --dump-section .rodata="$out/$name.rodata" "$out/$file" "$out/$name.objcopy-rewrite" || exit 1 |
| 293 | llvm-readelf-18 -h -S -s -n "$out/$file" > "$out/$name.readelf.txt" || exit 1 |
| 294 | dd if="$out/$name.rodata" of="$out/$name.descriptor-head" bs=1 count=16 status=none || exit 74 |
| 295 | dd if="$out/$name.rodata" of="$out/$name.descriptor-tail" bs=1 skip=24 status=none || exit 74 |
| 296 | done |
| 297 | compare "$out/fp8gemv-omega.text" "$out/fp8gemv-oracle.text" 'fp8gemv .text including SDWA conversion and VOP3 mul equals LLVM18 gfx942' |
| 298 | compare "$out/fp8gemv-omega.note" "$out/fp8gemv-oracle.note" 'fp8gemv metadata note equals independent oracle' |
| 299 | compare "$out/fp8gemv-omega.descriptor-head" "$out/fp8gemv-oracle.descriptor-head" 'fp8gemv descriptor sizes equal oracle' |
| 300 | compare "$out/fp8gemv-omega.descriptor-tail" "$out/fp8gemv-oracle.descriptor-tail" 'fp8gemv descriptor resources equal oracle' |
| 301 | entryva=$(awk '$8 == "fp8gemv" { print "0x" $2; exit }' "$out/fp8gemv-omega.readelf.txt") |
| 302 | descva=$(awk '$8 == "fp8gemv.kd" { print "0x" $2; exit }' "$out/fp8gemv-omega.readelf.txt") |
| 303 | disp=$(od -An -tu8 -j 16 -N 8 "$out/fp8gemv-omega.rodata" | tr -d ' ') |
| 304 | if [ -n "$entryva" ] && [ -n "$descva" ] && [ "$disp" = "$((entryva - descva))" ]; then |
| 305 | ok 'fp8gemv descriptor entry displacement resolves to kernel symbol' |
| 306 | else bad 'fp8gemv descriptor entry displacement'; fi |
| 307 | if grep -q 'v_cvt_f32_fp8' "$out/fp8gemv-encodings.txt" \ |
| 308 | && grep -q 'src0_sel:BYTE_0' "$out/fp8gemv-encodings.txt" \ |
| 309 | && grep -q '\.kernarg_segment_size: *40$' "$out/fp8gemv-omega.readelf.txt"; then |
| 310 | ok 'fp8gemv BYTE0 SDWA accepted by gfx942 oracle and kernarg is40 bytes' |
| 311 | else bad 'fp8gemv SDWA encoding or metadata'; fi |
| 312 | if python3 -I "$root/tests/amd/formats.py" "$out/hsaco" "$src/fp8gemv.isa" "$out/fp8gemv-hsaco.hsaco" "$out"; then |
| 313 | ok 'growable format IDs/count and undefined-format control' |
| 314 | else bad 'format registry controls'; fi |
| 315 | echo "FP8GEMV OBJECT sha256=$(digest "$out/fp8gemv-hsaco.hsaco") bytes=$(wc -c < "$out/fp8gemv-hsaco.hsaco" | tr -d ' ')" |
| 316 | if [ "$(digest "$out/fp8gemv-hsaco.hsaco")" = b2260043751f6483deae05d3c3b5cb1d2a5e97031d299998d9d4b04691fcaf5b ]; then |
| 317 | ok 'fp8gemv entire object unchanged from pre-BF16' |
| 318 | else bad 'fp8gemv object changed'; fi |
| 319 | for producer in hsaco hsaco-again; do |
| 320 | timeout 30 "$out/$producer" "$src/bf16gemv.isa" > "$out/bf16gemv-$producer.hsaco" 2> "$out/bf16gemv-$producer.emit.err"; rc=$? |
| 321 | if [ "$rc" -ne 0 ] || [ -s "$out/bf16gemv-$producer.emit.err" ]; then |
| 322 | echo "FAIL bf16gemv emit exit=$rc"; cat "$out/bf16gemv-$producer.emit.err"; exit 1 |
| 323 | fi |
| 324 | done |
| 325 | compare "$out/bf16gemv-hsaco.hsaco" "$out/bf16gemv-hsaco-again.hsaco" 'bf16gemv two code-object builds byte-identical' |
| 326 | if ! llvm-mc-18 -triple=amdgcn-amd-amdhsa -mcpu=gfx942 -filetype=obj "$src/bf16gemv-gfx942.s" -o "$out/bf16gemv-oracle.o" > "$out/bf16gemv-assemble.log" 2>&1; then |
| 327 | echo 'FAIL bf16gemv oracle assembly'; cat "$out/bf16gemv-assemble.log"; exit 1 |
| 328 | fi |
| 329 | llvm-mc-18 -triple=amdgcn-amd-amdhsa -mcpu=gfx942 -show-encoding "$src/bf16gemv-gfx942.s" > "$out/bf16gemv-encodings.txt" 2>&1 || exit 1 |
| 330 | for pair in bf16gemv-hsaco.hsaco:bf16gemv-omega bf16gemv-oracle.o:bf16gemv-oracle; do |
| 331 | file=${pair%:*}; name=${pair#*:} |
| 332 | llvm-objcopy-18 --dump-section .text="$out/$name.text" --dump-section .note="$out/$name.note" --dump-section .rodata="$out/$name.rodata" "$out/$file" "$out/$name.objcopy-rewrite" || exit 1 |
| 333 | llvm-readelf-18 -h -S -s -n "$out/$file" > "$out/$name.readelf.txt" || exit 1 |
| 334 | dd if="$out/$name.rodata" of="$out/$name.descriptor-head" bs=1 count=16 status=none || exit 74 |
| 335 | dd if="$out/$name.rodata" of="$out/$name.descriptor-tail" bs=1 skip=24 status=none || exit 74 |
| 336 | done |
| 337 | compare "$out/bf16gemv-omega.text" "$out/bf16gemv-oracle.text" 'bf16gemv .text including GLOBAL_LOAD_SHORT_D16_HI equals LLVM18 gfx942' |
| 338 | compare "$out/bf16gemv-omega.note" "$out/bf16gemv-oracle.note" 'bf16gemv metadata note equals independent oracle' |
| 339 | compare "$out/bf16gemv-omega.descriptor-head" "$out/bf16gemv-oracle.descriptor-head" 'bf16gemv descriptor sizes equal oracle' |
| 340 | compare "$out/bf16gemv-omega.descriptor-tail" "$out/bf16gemv-oracle.descriptor-tail" 'bf16gemv descriptor resources equal oracle' |
| 341 | entryva=$(awk '$8 == "bf16gemv" { print "0x" $2; exit }' "$out/bf16gemv-omega.readelf.txt") |
| 342 | descva=$(awk '$8 == "bf16gemv.kd" { print "0x" $2; exit }' "$out/bf16gemv-omega.readelf.txt") |
| 343 | disp=$(od -An -tu8 -j 16 -N 8 "$out/bf16gemv-omega.rodata" | tr -d ' ') |
| 344 | if [ -n "$entryva" ] && [ -n "$descva" ] && [ "$disp" = "$((entryva - descva))" ]; then |
| 345 | ok 'bf16gemv descriptor entry displacement resolves to kernel symbol' |
| 346 | else bad 'bf16gemv descriptor entry displacement'; fi |
| 347 | if grep -q 'global_load_short_d16_hi' "$out/bf16gemv-encodings.txt" \ |
| 348 | && grep -q '\.kernarg_segment_size: *32$' "$out/bf16gemv-omega.readelf.txt"; then |
| 349 | ok 'bf16gemv D16_HI accepted by gfx942 oracle and kernarg is32 bytes' |
| 350 | else bad 'bf16gemv D16_HI encoding or metadata'; fi |
| 351 | echo "BF16GEMV OBJECT sha256=$(digest "$out/bf16gemv-hsaco.hsaco") bytes=$(wc -c < "$out/bf16gemv-hsaco.hsaco" | tr -d ' ')" |
| 352 | if [ "$(digest "$out/bf16gemv-hsaco.hsaco")" = 59f955f07f5702235927835b98e9934e574fe266744ea53b3ab2db35d30179fa ]; then |
| 353 | ok 'bf16gemv entire object unchanged from pre-GEMV2' |
| 354 | else bad 'bf16gemv object changed'; fi |
| 355 | for table in "$src/"*.isa; do |
| 356 | kernel=${table##*/} |
| 357 | kernel=${kernel%.isa} |
| 358 | case "$kernel" in vadd|fsum16|sgemm|fp8gemv|bf16gemv) continue ;; esac |
| 359 | for producer in hsaco hsaco-again; do |
| 360 | timeout 30 "$out/$producer" "$src/$kernel.isa" > "$out/$kernel-$producer.hsaco" 2> "$out/$kernel-$producer.emit.err"; rc=$? |
| 361 | if [ "$rc" -ne 0 ] || [ -s "$out/$kernel-$producer.emit.err" ]; then |
| 362 | echo "FAIL $kernel emit exit=$rc"; cat "$out/$kernel-$producer.emit.err"; exit 1 |
| 363 | fi |
| 364 | done |
| 365 | compare "$out/$kernel-hsaco.hsaco" "$out/$kernel-hsaco-again.hsaco" "$kernel two code-object builds byte-identical" |
| 366 | if ! llvm-mc-18 -triple=amdgcn-amd-amdhsa -mcpu=gfx942 -filetype=obj "$src/$kernel-gfx942.s" -o "$out/$kernel-oracle.o" > "$out/$kernel-assemble.log" 2>&1; then |
| 367 | echo "FAIL $kernel oracle assembly"; cat "$out/$kernel-assemble.log"; exit 1 |
| 368 | fi |
| 369 | llvm-mc-18 -triple=amdgcn-amd-amdhsa -mcpu=gfx942 -show-encoding "$src/$kernel-gfx942.s" > "$out/$kernel-encodings.txt" 2>&1 || exit 1 |
| 370 | for pair in "$kernel-hsaco.hsaco:$kernel-omega" "$kernel-oracle.o:$kernel-oracle"; do |
| 371 | file=${pair%:*}; name=${pair#*:} |
| 372 | llvm-objcopy-18 --dump-section .text="$out/$name.text" --dump-section .note="$out/$name.note" --dump-section .rodata="$out/$name.rodata" "$out/$file" "$out/$name.objcopy-rewrite" || exit 1 |
| 373 | llvm-readelf-18 -h -S -s -n "$out/$file" > "$out/$name.readelf.txt" || exit 1 |
| 374 | dd if="$out/$name.rodata" of="$out/$name.descriptor-head" bs=1 count=16 status=none || exit 74 |
| 375 | dd if="$out/$name.rodata" of="$out/$name.descriptor-tail" bs=1 skip=24 status=none || exit 74 |
| 376 | done |
| 377 | compare "$out/$kernel-omega.text" "$out/$kernel-oracle.text" "$kernel complete instruction bytes equal LLVM18 gfx942" |
| 378 | compare "$out/$kernel-omega.note" "$out/$kernel-oracle.note" "$kernel metadata note equals independent oracle" |
| 379 | compare "$out/$kernel-omega.descriptor-head" "$out/$kernel-oracle.descriptor-head" "$kernel descriptor sizes equal oracle" |
| 380 | compare "$out/$kernel-omega.descriptor-tail" "$out/$kernel-oracle.descriptor-tail" "$kernel descriptor resources equal oracle" |
| 381 | case "$kernel" in attn256_*) |
| 382 | rsrc2=$(od -An -tu4 -j 52 -N 4 "$out/$kernel-omega.rodata" | tr -d ' ') |
| 383 | if [ "$((rsrc2 & 256))" -eq 256 ]; then ok "$kernel workgroup-id-Y enabled"; else bad "$kernel workgroup-id-Y disabled"; fi |
| 384 | ;; |
| 385 | esac |
| 386 | entryva=$(awk -v k="$kernel" '$8 == k { print "0x" $2; exit }' "$out/$kernel-omega.readelf.txt") |
| 387 | descva=$(awk -v k="$kernel.kd" '$8 == k { print "0x" $2; exit }' "$out/$kernel-omega.readelf.txt") |
| 388 | disp=$(od -An -tu8 -j 16 -N 8 "$out/$kernel-omega.rodata" | tr -d ' ') |
| 389 | if [ -n "$entryva" ] && [ -n "$descva" ] && [ "$disp" = "$((entryva - descva))" ]; then |
| 390 | ok "$kernel descriptor entry displacement resolves to kernel symbol" |
| 391 | else bad "$kernel descriptor entry displacement"; fi |
| 392 | echo "$kernel OBJECT sha256=$(digest "$out/$kernel-hsaco.hsaco") bytes=$(wc -c < "$out/$kernel-hsaco.hsaco" | tr -d ' ')" |
| 393 | done |
| 394 | if python3 -I "$root/tests/amd/scheduling.py" "$src" "$out"; then |
| 395 | ok 'all emitted objects satisfy CDNA3 transcendental consumer wait' |
| 396 | else bad 'CDNA3 transcendental consumer wait'; fi |
| 397 | if sh "$root/tests/amd/loop-fuel.sh" "$src"/*.isa "$out"/*.hsaco > "$out/loop-fuel.log"; then |
| 398 | ok "loop-fuel alarm quiet: largest gate input or object $(sort -t= -k2 -n "$out/loop-fuel.log" | awk -F'bytes=' '{split($2,a," "); if (a[1]>m) m=a[1]} END {print m}') bytes, threshold 500000" |
| 399 | else cat "$out/loop-fuel.log"; bad 'loop-fuel alarm fired'; fi |
| 400 | head -c 600001 /dev/zero > "$out/loop-fuel-control.bin" |
| 401 | if sh "$root/tests/amd/loop-fuel.sh" "$out/loop-fuel-control.bin" > "$out/loop-fuel-control.log"; then |
| 402 | bad 'loop-fuel alarm control escaped' |
| 403 | else ok 'loop-fuel alarm control CAUGHT a 600001-byte file'; fi |
| 404 | # The loader's ACCEPT is NOT a kernel execution check or proof of runtime-loader interoperability. |
| 405 | echo 'hardware NOT_RUN: gfx942 MI300X dispatch, FP32 outputs, n=0/tail/boundary vectors, ROCr loading and all other GPU rows' |
| 406 | echo 'hardware NOT_RUN: MI300 ISA PDF p60: The register SH_MEM_CONFIG, bit[8] must be set to 1 to produce the correct results for BF8 and FP8 operations. fp8gemv assumes E4M3FNUZ weights (bias8, NaN0x80) when set.' |
| 407 | echo 'NOT_RUN linked-oracle whole-object parity: gate uses ET_REL section parity; Spark has no ld.lld' |
| 408 | if [ "$fail" -ne 0 ]; then echo "AMD-GFX942-HOST FAIL pass=$pass fail=$fail hardware=NOT_RUN"; exit 1; fi |
| 409 | python3 -I "$root/tests/amd/receipt.py" check "$root" "$out" || exit 1 |
| 410 | kernels= |
| 411 | for table in "$src/"*.isa; do |
| 412 | name=${table##*/} |
| 413 | kernels="${kernels}${kernels:+,}${name%.isa}" |
| 414 | done |
| 415 | echo "AMD-GFX942-HOST PASS pass=$pass fail=0 kernels=$kernels hardware=NOT_RUN" |
| 416 | exit 0 |