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 / tools-om / ampfam.sh

111 lines · 5615 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# ampfam acceptance: tools/ampere_families.c (seeded Omega om/tools/ampfam.om) against its C oracle
4# (-DCUDAPP_MIGRATION_PENDING_C_TOOLS_AMPFAM). tests/tools-om/ampfam_stub.c stands in for the generators and
5# encoders and traces every call; the baseline and ten outcomes at each of the 133 steps compare stdout,
6# stderr, exit and the call trace byte for byte. Then a flipped-record negative control and recompiled
7# mutants. TOOLS_OM_COVERAGE=DIR writes gcov branch data of the oracle. TOOLS_OM_AMPFAM_REAL=1 also links
8# both builds against the real library and compares their output and SM86 corpus files.
9# Run under: bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10
10set -eu
11ROOT=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
12cd "$ROOT"
13tmp=$(mktemp -d)
14trap 'rm -rf "$tmp"' EXIT
15. tests/tools-om/lib.sh
16tom_pin
17SRC=tools/ampere_families.c
18STUB=tests/tools-om/ampfam_stub.c
19OFF=-DCUDAPP_MIGRATION_PENDING_C_TOOLS_AMPFAM
20KINDS="g g7 r a0keep rc1 rc0 rcm1 rcm2 bplus bkeep"
21$CC $TOM_CFLAGS $OFF -o "$tmp/af_c" $SRC $STUB
22$CC $TOM_CFLAGS -o "$tmp/af_om" $SRC $STUB src/cudapp_om_ampfam.c
23
24one() { # BIN CASE: the report of one run
25 rm -f "$tmp/tr"
26 rc=0
27 AMPFAM_CASE=$2 AMPFAM_TRACE_FD=3 "$1" 3>> "$tmp/tr" > "$tmp/o" 2> "$tmp/e" || rc=$?
28 echo "case $2"
29 sed 's/^/ out /' "$tmp/o"
30 sed 's/^/ err /' "$tmp/e"
31 echo " exit $rc"
32 [ ! -f "$tmp/tr" ] || sed 's/^/ /' "$tmp/tr"
33}
34run() { # BIN OUT
35 {
36 one "$1" none
37 k=1
38 while [ $k -le 133 ]; do
39 for kind in $KINDS; do one "$1" "$k:$kind"; done
40 k=$((k + 1))
41 done
42 } > "$2"
43}
44run "$tmp/af_c" "$tmp/c.out"
45run "$tmp/af_om" "$tmp/om.out"
46cmp "$tmp/c.out" "$tmp/om.out" || { echo "FAIL ampfam differential"; diff "$tmp/c.out" "$tmp/om.out" | head -20; exit 1; }
47cases=$(grep -c '^case ' "$tmp/c.out")
48steps=$(sed -n '/^case none$/,/^case 1:g$/p' "$tmp/c.out" | grep -c '^ gen ')
49grep -q '^ out Ampere extended existing generator families encoded (host only)$' "$tmp/c.out" ||
50 { echo "FAIL ampfam baseline did not finish"; exit 1; }
51outs=$(grep '^ exit ' "$tmp/c.out" | sort | uniq -c | tr -s ' \n' ' ')
52echo "differential: $cases cases identical ($steps steps in the baseline; outcomes:$outs)"
53tom_flip "$tmp/c.out" "$tmp/om.out"
54
55killed=0
56mut() { # NAME SITE REPLACEMENT
57 tom_mutant "$1" om/tools/ampfam.om "$2" "$3"
58 $CC $TOM_CFLAGS -o "$tmp/$1.bin" $SRC $STUB "$tmp/$1.c"
59 run "$tmp/$1.bin" "$tmp/$1.out"
60 if cmp -s "$tmp/c.out" "$tmp/$1.out"; then echo "FAIL mutant $1 survived"; exit 1; fi
61 echo "mutant $1: killed ($(diff "$tmp/c.out" "$tmp/$1.out" | grep -m1 '^[<>]' | cut -c1-60))"
62 killed=$((killed + 1))
63}
64mut line 'x = af_set s 22 0 112' 'x = af_set s 22 0 113'
65mut ternskip 'if and gt k get f 17 eq e get f 18' 'if and ge k get f 17 eq e get f 18'
66mut refuserc 'if or ne rc sub ulong 0 2 ne get s 4 0' 'if or ne rc sub ulong 0 1 ne get s 4 0'
67mut append 'if eq m get f 2' 'if ne m get f 2'
68mut resmode 'x = af_fl s 2 get f 9' 'x = af_fl s 2 get f 7'
69mut binit 'put s 10 get s 5' 'put s 10 ulong 0'
70mut qpc 'x = af_fl s 5 4' 'x = af_fl s 5 6'
71mut lencheck 'if or ne rc 0 ne get s 3 get s 4' 'if ne rc 0'
72mut gdnbf16 'x = af_set s 24 1 122' 'x = af_set s 24 0 122'
73echo "ampfam mutants: $killed killed"
74
75if [ -n "${TOOLS_OM_COVERAGE:-}" ]; then
76 mkdir -p "$TOOLS_OM_COVERAGE" "$tmp/cov"
77 cp $SRC "$tmp/cov/ampere_families.c"
78 (cd "$tmp/cov" && $CC -std=gnu11 -D_GNU_SOURCE -O0 --coverage -I"$ROOT/src" $OFF -o af_cov ampere_families.c "$ROOT/$STUB")
79 run "$tmp/cov/af_cov" "$tmp/cov/r.out"
80 cmp -s "$tmp/c.out" "$tmp/cov/r.out" || { echo "FAIL ampfam coverage build differs from the oracle"; exit 1; }
81 (cd "$tmp/cov" && gcov -b -c af_cov-ampere_families.c > "$TOOLS_OM_COVERAGE/ampfam.gcov.txt" 2>&1)
82 cp "$tmp/cov/ampere_families.c.gcov" "$TOOLS_OM_COVERAGE/ampere_families.c.gcov"
83 echo "coverage: $TOOLS_OM_COVERAGE/ampfam.gcov.txt"
84fi
85
86# TOOLS_OM_AMPFAM_REAL=1: one library with CUDAPP_AMPERE_CORPUS=1 (real generators and encoders), the tool
87# linked against it both ways; stdout, stderr, exit and every corpus file (name with the pid replaced and
88# sha256) must match.
89real=
90if [ -n "${TOOLS_OM_AMPFAM_REAL:-}" ]; then
91 make -j3 OUT_DIR="$tmp/b" CUDAPP_AMPERE_CORPUS=1 "$tmp/b/libomega_gpu.a" > "$tmp/b.log" 2>&1 ||
92 { tail -20 "$tmp/b.log"; echo "FAIL building the library"; exit 1; }
93 for v in om c; do
94 sw=; [ $v = c ] && sw=$OFF
95 $CC $TOM_CFLAGS $sw -DCUDAPP_AMPERE_CORPUS -o "$tmp/real-$v" $SRC "$tmp/b/libomega_gpu.a" -lpthread -lm
96 d="$tmp/corpus-$v"
97 mkdir -p "$d"
98 rc=0
99 OMEGA_AMPERE_CORPUS_DIR="$d" "$tmp/real-$v" > "$tmp/real-$v.out" 2>&1 || rc=$?
100 { cat "$tmp/real-$v.out"; echo "exit $rc"
101 (cd "$d" && for f in *; do echo "$(echo "$f" | sed 's/^[0-9]*-/PID-/') $(sha256sum < "$f" | cut -c1-64)"; done) | sort -V
102 } > "$tmp/real-$v.manifest"
103 done
104 cmp "$tmp/real-c.manifest" "$tmp/real-om.manifest" || { echo "FAIL ampfam real build"; diff "$tmp/real-c.manifest" "$tmp/real-om.manifest" | head; exit 1; }
105 grep -qx 'exit 0' "$tmp/real-c.manifest" || { echo "FAIL ampfam real oracle did not pass"; exit 1; }
106 tom_flip "$tmp/real-c.manifest" "$tmp/real-om.manifest"
107 files=$(grep -c '^PID-' "$tmp/real-c.manifest")
108 real=", real library $files corpus files"
109 echo "real library: output and $files corpus files identical ($(grep '^PID-' "$tmp/real-c.manifest" | cut -d' ' -f1 | sed 's/^PID-[0-9]*\.//' | sort | uniq -c | tr -s ' \n' ' '))"
110fi
111echo "tools-om ampfam: PASS (differential $cases cases$real, negative control, $killed mutants killed)"