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 / tools / numeric_rest_om_mutants.sh
| 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. |
| 4 | set -eu |
| 5 | ROOT=$(cd "$(dirname "$0")/.." && pwd) |
| 6 | TMP=$(mktemp -d) |
| 7 | trap 'rm -rf "$TMP"' EXIT |
| 8 | CC=${CC:-cc} |
| 9 | LOG=${NUMERIC_REST_LOG_DIR:-$TMP/log} |
| 10 | mkdir -p "$LOG" |
| 11 | FILES='numeric.om tile.om rest.om patch.om check.om trace.om reduce.om' |
| 12 | MUTANTS='source_lane|rest.om|ret xor b 63|ret xor b 62 |
| 13 | ftz_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 |
| 14 | parity_compare|trace.om|if eq cmpeq get tr 9 ex got 0|if eq cmpeq get tr 9 ex got 1 |
| 15 | minmax_padding|rest.om|if or eq op 1 eq op 2|if eq op 99 |
| 16 | patch_exit|patch.om|ret word4 k 31053 0 58720256 1042944|ret word4 k 31052 0 58720256 1042944 |
| 17 | seed_bound|rest.om|1048576.0f64|1.0f64' |
| 18 | copy_units() { |
| 19 | mkdir -p "$1" |
| 20 | for f in $FILES; do cp "$ROOT/om/numeric/$f" "$1/$f"; done |
| 21 | } |
| 22 | run() { |
| 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 | } |
| 32 | copy_units "$TMP/control" |
| 33 | run control "$TMP/control" |
| 34 | [ "$rc" = 0 ] || { cat "$LOG/control-run.log"; exit 1; } |
| 35 | echo "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. |
| 37 | for 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" |
| 47 | done |
| 48 | printf '%s\n' "$MUTANTS" > "$TMP/list" |
| 49 | caught=0; total=0 |
| 50 | while 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 |
| 60 | done < "$TMP/list" |
| 61 | [ "$caught" = "$total" ] |
| 62 | echo "NUMERIC REST OM MUTANTS PASS $caught/$total; chip NOT_RUN" |