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 / compat / cuda / test.sh

105 lines · 5274 bytes Raw Blame History
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)
6set -eu
7here=$(cd "$(dirname "$0")" && pwd)
8repo=$(cd "$here/../.." && pwd)
9w=${1:-$(mktemp -d)}
10mkdir -p "$w"
11w=$(cd "$w" && pwd)
12OMC=${OMEGA_OMC:-$repo/../omega-mv/seed/out/omc}
13pin=2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f
14got=$(sha256sum "$OMC" | cut -d' ' -f1)
15[ "$got" = "$pin" ] || { echo "omc pin mismatch: $got"; exit 2; }
16cat "$repo/om/cache/digest.om" "$here/c0_check.om" > "$w/c0src.om"
17"$OMC" < "$w/c0src.om" > "$w/c0_check"
18chmod +x "$w/c0_check"
19C="$w/c0_check"
20"$here/build.sh" "$w/a" > "$w/build-a.log"
21"$here/build.sh" "$w/b" > "$w/build-b.log"
22cmp "$w/build-a.log" "$w/build-b.log" || { echo "FAIL rebuild not deterministic"; exit 1; }
23cat "$w/build-a.log"
24PA="$here/profile-c0-aarch64-v3.tsv"
25PX="$here/profile-c0-x86_64-v3.tsv"
26EA="$w/a/aarch64/vadd_drv"
27EX="$w/a/x86_64/vadd_drv"
28PTX="$w/a/vadd_u32.ptx"
29# v1/v2 are immutable historical identities. Converter regeneration changes
30# executable hashes, never the CUDA entry-point surface.
31for 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"
38done
39fail=0
40pass() { # 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}
50refuse() { # 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}
63sha() { sha256sum "$1" | cut -d' ' -f1; }
64tab=$(printf '\t')
65pass aarch64 "$PA" "$EA" "$PTX" aarch64
66pass x86_64-static "$PX" "$EX" "$PTX" static
67# 1 host ISA: an ARM64 profile is never compared on x86-64 and the reverse.
68refuse isa-a-on-x86 host-isa "$PA" "$EA" "$PTX" x86_64
69refuse 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.
71refuse x86-exe-as-a artifact-hash "$PA" "$EX" "$PTX" static
72sed "s/$(sha "$EA")/$(sha "$EX")/" "$PA" > "$w/p-hash.tsv"
73refuse 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.
75grep -v "^import${tab}cuInit${tab}" "$PA" > "$w/p-drop.tsv"
76refuse 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"
78refuse added-import "missing import cuMemAllocManaged" "$w/p-add.tsv" "$EA" "$PTX" aarch64
79sed "s/^import${tab}cuInit${tab}cuda${tab}supported/import${tab}cuInit${tab}cuda${tab}unsupported/" "$PA" > "$w/p-unsup.tsv"
80refuse unsupported-status unsupported-status "$w/p-unsup.tsv" "$EA" "$PTX" aarch64
81sed "s/^schema${tab}AIEN_CUDA_COMPAT_PROFILE${tab}1\$/schema${tab}AIEN_CUDA_COMPAT_PROFILE${tab}2/" "$PA" > "$w/p-schema.tsv"
82refuse schema-2 schema-mismatch "$w/p-schema.tsv" "$EA" "$PTX" aarch64
83sed "s/^\(host${tab}.*${tab}\)GLIBC_2.34\$/\1GLIBC_2.17/" "$PA" > "$w/p-floor.tsv"
84refuse libc-floor libc-floor "$w/p-floor.tsv" "$EA" "$PTX" aarch64
85{ cat "$PA"; printf 'lookup\tabsent\tcuMod\n'; } > "$w/p-lookup.tsv"
86refuse 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.
88grep -v "^needed${tab}libc.so.6${tab}" "$PA" > "$w/p-noneed.tsv"
89refuse profile-missing-needed "unlisted needed libc.so.6" "$w/p-noneed.tsv" "$EA" "$PTX" aarch64
90mkdir -p "$w/nolib"
91gcc -o "$w/nolib/vadd_drv" "$w/a/aarch64/vadd_drv.o" "$w/a/aarch64/standalone_oracles.o" -Wl,--unresolved-symbols=ignore-all
92sed "s/$(sha "$EA")/$(sha "$w/nolib/vadd_drv")/" "$PA" > "$w/p-nolib.tsv"
93refuse 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.
95sed 's/^\(\tret;\)$/\tbar.sync 0;\n\1/' "$PTX" > "$w/bar.ptx"
96sed "s/$(sha "$PTX")/$(sha "$w/bar.ptx")/" "$PA" > "$w/p-bar.tsv"
97refuse ptx-barrier "unsupported-op ptxop bar.sync" "$w/p-bar.tsv" "$EA" "$w/bar.ptx" aarch64
98sed 's/^\(\tret;\)$/\tret; ret;/' "$PTX" > "$w/multi.ptx"
99sed "s/$(sha "$PTX")/$(sha "$w/multi.ptx")/" "$PA" > "$w/p-multi.tsv"
100refuse ptx-multi multi-statement "$w/p-multi.tsv" "$EA" "$w/multi.ptx" aarch64
101if [ "$fail" -ne 0 ]; then
102 echo "CUDA-C0-PROFILE-TEST FAIL"
103 exit 1
104fi
105echo "CUDA-C0-PROFILE-TEST PASS"