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

62 lines · 4111 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# Run this entire script inside the lane's device-hidden bwrap CPU envelope.
4set -eu
5ROOT=$(cd "$(dirname "$0")/.." && pwd)
6TMP=$(mktemp -d)
7trap 'rm -rf "$TMP"' EXIT
8CC=${CC:-cc}
9LOG=${NUMERIC_REST_LOG_DIR:-$TMP/log}
10mkdir -p "$LOG"
11FILES='numeric.om tile.om rest.om patch.om check.om trace.om reduce.om'
12MUTANTS='source_lane|rest.om|ret xor b 63|ret xor b 62
13ftz_dropped|rest.om|ret nrclass 7 nrelem a nrclass 7 b nrclass 7 c nrclass 7 d 0|ret nrelem a b c d 0
14parity_compare|trace.om|if eq cmpeq get tr 9 ex got 0|if eq cmpeq get tr 9 ex got 1
15minmax_padding|rest.om|if or eq op 1 eq op 2|if eq op 99
16patch_exit|patch.om|ret word4 k 31053 0 58720256 1042944|ret word4 k 31052 0 58720256 1042944
17seed_bound|rest.om|1048576.0f64|1.0f64'
18copy_units() {
19 mkdir -p "$1"
20 for f in $FILES; do cp "$ROOT/om/numeric/$f" "$1/$f"; done
21}
22run() {
23 label=$1; dir=$2; out="$TMP/out-$label"
24 mkdir -p "$out"
25 OMEGA_UNITS="numeric=$dir/numeric.om numeric_tile=$dir/numeric.om,$dir/tile.om numeric_rest=$dir/numeric.om,$dir/rest.om numeric_patch=$dir/numeric.om,$dir/rest.om,$dir/patch.om numeric_check=$dir/numeric.om,$dir/rest.om,$dir/patch.om,$dir/check.om numeric_trace=$dir/numeric.om,$dir/rest.om,$dir/trace.om numeric_reduce=$dir/numeric.om,$dir/tile.om,$dir/rest.om,$dir/reduce.om" OMEGA_UNITS_DEST="$out" sh "$ROOT/om/units.sh" > "$LOG/$label-units.log" 2>&1 || { cat "$LOG/$label-units.log"; exit 1; }
26 $CC -std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -O2 -ffp-contract=off -DCUDAPP_MIGRATION_PENDING_C_NUMERIC_REST_DIFF -ffunction-sections -fdata-sections -Wl,--gc-sections -I"$out" -I"$ROOT/src" -o "$out/diff" "$ROOT/tests/numeric_rest_om_diff_test.c" "$ROOT/src/omega_numeric.c" "$ROOT/src/omega_numeric_reduce.c" "$ROOT/src/omega_blackwell_qmd.c" "$ROOT/src/cudapp_om_bw_qmd.c" "$out"/cudapp_om_*.c -lm > "$LOG/$label-cc.log" 2>&1 || { cat "$LOG/$label-cc.log"; exit 1; }
27 set +e
28 "$out/diff" > "$LOG/$label-run.log" 2>&1
29 rc=$?
30 set -e
31}
32copy_units "$TMP/control"
33run control "$TMP/control"
34[ "$rc" = 0 ] || { cat "$LOG/control-run.log"; exit 1; }
35echo "control rc=$rc $(grep 'NUMERIC REST OM DIFF PASS' "$LOG/control-run.log")"
36# Every exported unit is a strong link dependency. Omission must fail to link.
37for omit in rest patch check trace reduce; do
38 srcs=''
39 for unit in numeric numeric_tile numeric_rest numeric_patch numeric_check numeric_trace numeric_reduce; do
40 [ "$unit" = "numeric_$omit" ] || srcs="$srcs $out/cudapp_om_$unit.c"
41 done
42 if $CC -std=gnu11 -D_GNU_SOURCE -O0 -ffp-contract=off -DCUDAPP_MIGRATION_PENDING_C_NUMERIC_REST_DIFF -ffunction-sections -fdata-sections -Wl,--gc-sections -I"$out" -I"$ROOT/src" -o "$TMP/link-$omit" "$ROOT/tests/numeric_rest_om_diff_test.c" "$ROOT/src/omega_numeric.c" "$ROOT/src/omega_numeric_reduce.c" "$ROOT/src/omega_blackwell_qmd.c" "$ROOT/src/cudapp_om_bw_qmd.c" $srcs -lm > "$LOG/link-$omit.log" 2>&1; then
43 echo "FAIL missing strong unit $omit linked"; exit 1
44 fi
45 grep -q "undefined reference.*omega_numeric_$omit" "$LOG/link-$omit.log" || { cat "$LOG/link-$omit.log"; exit 1; }
46 echo "strong-link $omit refused as expected"
47done
48printf '%s\n' "$MUTANTS" > "$TMP/list"
49caught=0; total=0
50while IFS='|' read -r name file search repl; do
51 total=$((total+1)); dir="$TMP/$name"; copy_units "$dir"
52 count=$(grep -cF "$search" "$dir/$file" || true)
53 [ "$count" = 1 ] || { echo "FAIL $name site count=$count"; exit 1; }
54 SEARCH="$search" REPL="$repl" awk '{i=index($0,ENVIRON["SEARCH"]);if(i)$0=substr($0,1,i-1) ENVIRON["REPL"] substr($0,i+length(ENVIRON["SEARCH"]));print}' "$dir/$file" > "$dir/$file.new"
55 mv "$dir/$file.new" "$dir/$file"
56 run "$name" "$dir"
57 if [ "$rc" != 0 ] && grep -q '^FAIL ' "$LOG/$name-run.log"; then
58 caught=$((caught+1)); echo "mutant $name killed rc=$rc $(grep -m1 '^FAIL ' "$LOG/$name-run.log")"
59 else echo "FAIL mutant $name survived rc=$rc"; exit 1; fi
60done < "$TMP/list"
61[ "$caught" = "$total" ]
62echo "NUMERIC REST OM MUTANTS PASS $caught/$total; chip NOT_RUN"