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_om_mutants.sh

69 lines · 3489 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4#
5# Mutants of the numeric Omega units (om/numeric/numeric.om, om/numeric/tile.om).
6# Each mutant edits one site of a copy, regenerates the units with om/units.sh into a
7# scratch directory, builds tests/numeric_om_diff_test.c against them and must be
8# caught: the C-vs-Omega differential has to abort with "FAIL numeric diff".
9# The unmutated copy (control) must pass. Needs OMEGA_OMC and OMEGA_BRIDGE (om/units.sh).
10# Prints NUMERIC OM MUTANTS PASS <caught>/<total> on success.
11set -eu
12ROOT=$(cd "$(dirname "$0")/.." && pwd)
13CC=${CC:-cc}
14TMP=$(mktemp -d)
15trap 'rm -rf "$TMP"' EXIT
16CFLAGS="-std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -O2 -ffp-contract=off -DCUDAPP_MIGRATION_PENDING_C_NUMERIC_DIFF -DCUDAPP_MIGRATION_PENDING_C_NUMERIC_REST -DNUMERIC_DIFF_RANDOM=4096"
17
18# name|file|search|replacement (the search text must occur exactly once)
19MUTANTS='tie_to_odd|numeric.om|if and eq g 1 or ne r 0 eq and mant 1 1|if and eq g 1 or ne r 0 eq and mant 1 0
20f16_nan_quiet_bit|numeric.om|ret or or sign INF or QBIT shl f 13|ret or or sign INF shl f 13
21narrow_nan_quiet_bit|numeric.om|shl ulong 1 sub man 1 shr f sub 23 man|shl ulong 1 sub man 2 shr f sub 23 man
22exp_ln2_hi|numeric.om|mul fk f32of 1060205056|mul fk f32of 1060205057
23tile_stride|tile.om|get v add i d|get v add i 1
24canon_dropped|numeric.om|ret CANON|ret u'
25
26run() { # $1 = label, $2 = directory with numeric.om and tile.om
27 out="$TMP/out-$1"
28 mkdir -p "$out"
29 OMEGA_UNITS="numeric=$2/numeric.om numeric_tile=$2/numeric.om,$2/tile.om" OMEGA_UNITS_DEST="$out" \
30 sh "$ROOT/om/units.sh" > "$out/units.log" 2>&1 || { echo "FAIL $1: om/units.sh"; cat "$out/units.log"; exit 1; }
31 $CC $CFLAGS -I"$out" -I"$ROOT/src" -o "$out/diff" "$ROOT/tests/numeric_om_diff_test.c" \
32 "$ROOT/src/omega_numeric.c" "$ROOT/src/omega_numeric_reduce.c" "$out/cudapp_om_numeric.c" \
33 "$out/cudapp_om_numeric_tile.c" -lm -ffunction-sections -fdata-sections -Wl,--gc-sections \
34 > "$out/cc.log" 2>&1 || { echo "FAIL $1: build"; cat "$out/cc.log"; exit 1; }
35 set +e
36 "$out/diff" > "$out/run.log" 2>&1
37 rc=$?
38 set -e
39}
40
41mkdir -p "$TMP/control"
42cp "$ROOT/om/numeric/numeric.om" "$ROOT/om/numeric/tile.om" "$TMP/control/"
43run control "$TMP/control"
44[ "$rc" = 0 ] && grep -q 'NUMERIC OM DIFF PASS' "$out/run.log" || { echo "FAIL control rc=$rc"; cat "$out/run.log"; exit 1; }
45echo "control: rc=0 $(tail -n 1 "$out/run.log")"
46
47total=0
48caught=0
49printf '%s\n' "$MUTANTS" > "$TMP/list"
50while IFS='|' read -r name file search repl; do
51 total=$((total + 1))
52 dir="$TMP/m-$name"
53 mkdir -p "$dir"
54 cp "$ROOT/om/numeric/numeric.om" "$ROOT/om/numeric/tile.om" "$dir/"
55 n=$(grep -cF -- "$search" "$dir/$file" || true)
56 [ "$n" = 1 ] || { echo "FAIL mutant $name: site found $n times"; exit 1; }
57 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 }' \
58 "$dir/$file" > "$dir/$file.new"
59 mv "$dir/$file.new" "$dir/$file"
60 run "$name" "$dir"
61 if [ "$rc" != 0 ] && grep -q 'FAIL numeric diff' "$out/run.log"; then
62 caught=$((caught + 1))
63 echo "mutant $name: caught rc=$rc $(grep -m1 'FAIL numeric diff' "$out/run.log")"
64 else
65 echo "FAIL mutant $name survived rc=$rc"
66 fi
67done < "$TMP/list"
68[ "$caught" = "$total" ] || { echo "FAIL numeric mutants $caught/$total caught"; exit 1; }
69echo "NUMERIC OM MUTANTS PASS $caught/$total"