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 / compat / cuda / test.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | # CUDApp#184 C0 admission test: rebuild the fixture, admit it against both frozen profiles, and require |
| 4 | # every negative control to be refused for its own reason. Host only: no GPU, no libcuda, no execution |
| 5 | # of the artifact. Usage: compat/cuda/test.sh [WORKDIR] (OMEGA_OMC overrides the pinned compiler path) |
| 6 | set -eu |
| 7 | here=$(cd "$(dirname "$0")" && pwd) |
| 8 | repo=$(cd "$here/../.." && pwd) |
| 9 | w=${1:-$(mktemp -d)} |
| 10 | mkdir -p "$w" |
| 11 | w=$(cd "$w" && pwd) |
| 12 | OMC=${OMEGA_OMC:-$repo/../omega-mv/seed/out/omc} |
| 13 | pin=2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f |
| 14 | got=$(sha256sum "$OMC" | cut -d' ' -f1) |
| 15 | [ "$got" = "$pin" ] || { echo "omc pin mismatch: $got"; exit 2; } |
| 16 | cat "$repo/om/cache/digest.om" "$here/c0_check.om" > "$w/c0src.om" |
| 17 | "$OMC" < "$w/c0src.om" > "$w/c0_check" |
| 18 | chmod +x "$w/c0_check" |
| 19 | C="$w/c0_check" |
| 20 | "$here/build.sh" "$w/a" > "$w/build-a.log" |
| 21 | "$here/build.sh" "$w/b" > "$w/build-b.log" |
| 22 | cmp "$w/build-a.log" "$w/build-b.log" || { echo "FAIL rebuild not deterministic"; exit 1; } |
| 23 | cat "$w/build-a.log" |
| 24 | PA="$here/profile-c0-aarch64-v3.tsv" |
| 25 | PX="$here/profile-c0-x86_64-v3.tsv" |
| 26 | EA="$w/a/aarch64/vadd_drv" |
| 27 | EX="$w/a/x86_64/vadd_drv" |
| 28 | PTX="$w/a/vadd_u32.ptx" |
| 29 | # v1/v2 are immutable historical identities. Converter regeneration changes |
| 30 | # executable hashes, never the CUDA entry-point surface. |
| 31 | for isa in aarch64 x86_64; do |
| 32 | for version in v1 v2 v3; do |
| 33 | awk -F '\t' '$1=="import" && $3=="cuda" {print $2}' "$here/profile-c0-$isa-$version.tsv" | sort > "$w/import-$isa-$version" |
| 34 | done |
| 35 | diff -u "$w/import-$isa-v1" "$w/import-$isa-v2" |
| 36 | diff -u "$w/import-$isa-v2" "$w/import-$isa-v3" |
| 37 | echo "PASS $isa v1/v2/v3 CUDA imports: empty diff" |
| 38 | done |
| 39 | fail=0 |
| 40 | pass() { # name profile exe ptx runisa |
| 41 | n=$1 |
| 42 | shift |
| 43 | if "$C" check "$@" > "$w/$n.out"; then |
| 44 | echo "PASS admit $n: $(cat "$w/$n.out")" |
| 45 | else |
| 46 | echo "FAIL admit $n rc=$?: $(cat "$w/$n.out")" |
| 47 | fail=1 |
| 48 | fi |
| 49 | } |
| 50 | refuse() { # name reason profile exe ptx runisa |
| 51 | n=$1 |
| 52 | why=$2 |
| 53 | shift 2 |
| 54 | rc=0 |
| 55 | "$C" check "$@" > "$w/$n.out" || rc=$? |
| 56 | if [ "$rc" -eq 1 ] && grep -q "REFUSED $why" "$w/$n.out"; then |
| 57 | echo "PASS refuse $n rc=1: $(tr '\n' ';' < "$w/$n.out")" |
| 58 | else |
| 59 | echo "FAIL refuse $n rc=$rc want $why: $(tr '\n' ';' < "$w/$n.out")" |
| 60 | fail=1 |
| 61 | fi |
| 62 | } |
| 63 | sha() { sha256sum "$1" | cut -d' ' -f1; } |
| 64 | tab=$(printf '\t') |
| 65 | pass aarch64 "$PA" "$EA" "$PTX" aarch64 |
| 66 | pass x86_64-static "$PX" "$EX" "$PTX" static |
| 67 | # 1 host ISA: an ARM64 profile is never compared on x86-64 and the reverse. |
| 68 | refuse isa-a-on-x86 host-isa "$PA" "$EA" "$PTX" x86_64 |
| 69 | refuse isa-x86-on-a host-isa "$PX" "$EX" "$PTX" aarch64 |
| 70 | # 2 wrong artifact: the x86-64 executable presented under the aarch64 profile, and an edited hash. |
| 71 | refuse x86-exe-as-a artifact-hash "$PA" "$EX" "$PTX" static |
| 72 | sed "s/$(sha "$EA")/$(sha "$EX")/" "$PA" > "$w/p-hash.tsv" |
| 73 | refuse edited-hash artifact-hash "$w/p-hash.tsv" "$EA" "$PTX" aarch64 |
| 74 | # 3 profile drift: dropped import, added import, unsupported status, unknown schema, wrong libc floor. |
| 75 | grep -v "^import${tab}cuInit${tab}" "$PA" > "$w/p-drop.tsv" |
| 76 | refuse dropped-import "unlisted import cuInit" "$w/p-drop.tsv" "$EA" "$PTX" aarch64 |
| 77 | { cat "$PA"; printf 'import\tcuMemAllocManaged\tcuda\tsupported\tcuMemAllocManaged\n'; } > "$w/p-add.tsv" |
| 78 | refuse added-import "missing import cuMemAllocManaged" "$w/p-add.tsv" "$EA" "$PTX" aarch64 |
| 79 | sed "s/^import${tab}cuInit${tab}cuda${tab}supported/import${tab}cuInit${tab}cuda${tab}unsupported/" "$PA" > "$w/p-unsup.tsv" |
| 80 | refuse unsupported-status unsupported-status "$w/p-unsup.tsv" "$EA" "$PTX" aarch64 |
| 81 | sed "s/^schema${tab}AIEN_CUDA_COMPAT_PROFILE${tab}1\$/schema${tab}AIEN_CUDA_COMPAT_PROFILE${tab}2/" "$PA" > "$w/p-schema.tsv" |
| 82 | refuse schema-2 schema-mismatch "$w/p-schema.tsv" "$EA" "$PTX" aarch64 |
| 83 | sed "s/^\(host${tab}.*${tab}\)GLIBC_2.34\$/\1GLIBC_2.17/" "$PA" > "$w/p-floor.tsv" |
| 84 | refuse libc-floor libc-floor "$w/p-floor.tsv" "$EA" "$PTX" aarch64 |
| 85 | { cat "$PA"; printf 'lookup\tabsent\tcuMod\n'; } > "$w/p-lookup.tsv" |
| 86 | refuse lookup-prefix dynamic-lookup "$w/p-lookup.tsv" "$EA" "$PTX" aarch64 |
| 87 | # 4 missing dependency: the profile loses libc.so.6, and an executable linked without libcuda.so.1. |
| 88 | grep -v "^needed${tab}libc.so.6${tab}" "$PA" > "$w/p-noneed.tsv" |
| 89 | refuse profile-missing-needed "unlisted needed libc.so.6" "$w/p-noneed.tsv" "$EA" "$PTX" aarch64 |
| 90 | mkdir -p "$w/nolib" |
| 91 | gcc -o "$w/nolib/vadd_drv" "$w/a/aarch64/vadd_drv.o" "$w/a/aarch64/standalone_oracles.o" -Wl,--unresolved-symbols=ignore-all |
| 92 | sed "s/$(sha "$EA")/$(sha "$w/nolib/vadd_drv")/" "$PA" > "$w/p-nolib.tsv" |
| 93 | refuse exe-missing-libcuda "missing needed libcuda.so.1" "$w/p-nolib.tsv" "$w/nolib/vadd_drv" "$PTX" aarch64 |
| 94 | # 5 unsupported PTX: a barrier and a two-statement line, each with the PTX hash re-pinned so only the op refuses. |
| 95 | sed 's/^\(\tret;\)$/\tbar.sync 0;\n\1/' "$PTX" > "$w/bar.ptx" |
| 96 | sed "s/$(sha "$PTX")/$(sha "$w/bar.ptx")/" "$PA" > "$w/p-bar.tsv" |
| 97 | refuse ptx-barrier "unsupported-op ptxop bar.sync" "$w/p-bar.tsv" "$EA" "$w/bar.ptx" aarch64 |
| 98 | sed 's/^\(\tret;\)$/\tret; ret;/' "$PTX" > "$w/multi.ptx" |
| 99 | sed "s/$(sha "$PTX")/$(sha "$w/multi.ptx")/" "$PA" > "$w/p-multi.tsv" |
| 100 | refuse ptx-multi multi-statement "$w/p-multi.tsv" "$EA" "$w/multi.ptx" aarch64 |
| 101 | if [ "$fail" -ne 0 ]; then |
| 102 | echo "CUDA-C0-PROFILE-TEST FAIL" |
| 103 | exit 1 |
| 104 | fi |
| 105 | echo "CUDA-C0-PROFILE-TEST PASS" |