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 / tests / tools-om / lib.sh
| 1 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | # Shared helpers for tests/tools-om/*.sh. Source after setting ROOT and tmp; the caller runs |
| 3 | # under bwrap/taskset (see tests/tools-om/README.md). Every helper fails the script on a broken |
| 4 | # expectation; nothing is skipped silently. |
| 5 | OMC=${OMEGA_OMC:-$HOME/work/cudastack/omega-mv/seed/out/omc} |
| 6 | BRIDGE=${OMEGA_BRIDGE:-$HOME/work/cudastack/omega-bridge} |
| 7 | OMC_PIN=2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f |
| 8 | CC=${CC:-cc} |
| 9 | TOM_CFLAGS="-std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -O2 -ffp-contract=off -Isrc" |
| 10 | |
| 11 | tom_pin() { |
| 12 | [ "$(sha256sum < "$OMC" | cut -c1-64)" = "$OMC_PIN" ] || { echo "NOT_RUN: omc is not the pinned e5b32567 build"; exit 3; } |
| 13 | } |
| 14 | |
| 15 | # tom_mutant NAME SRC SITE REPLACEMENT: copy SRC with the one line SITE replaced, compile it through the |
| 16 | # pinned bridge to $tmp/NAME.c. SITE must occur exactly once, as a whole line. |
| 17 | tom_mutant() { |
| 18 | name=$1 src=$2 site=$3 repl=$4 |
| 19 | n=$(grep -c -x -F -- "$site" "$src" || true) |
| 20 | [ "$n" = 1 ] || { echo "FAIL mutant $name: site found $n times"; exit 1; } |
| 21 | awk -v s="$site" -v r="$repl" '$0 == s { print r; next } { print }' "$src" > "$tmp/$name.om" |
| 22 | OMEGA_SEEDED_OMC="$OMC" sh "$BRIDGE/tools/bridge-seeded" c "$tmp/$name.om" > "$tmp/$name.c" |
| 23 | } |
| 24 | |
| 25 | # tom_flip ORACLE CANDIDATE: CANDIDATE matched ORACLE byte for byte. Write CANDIDATE.flip with the last |
| 26 | # decimal digit of the last record changed and require the same cmp to reject it against ORACLE. |
| 27 | tom_flip() { |
| 28 | cmp -s "$1" "$2" || { echo "FAIL negative control: $2 did not match $1 before the flip"; exit 1; } |
| 29 | python3 - "$2" "$2.flip" <<'PY' |
| 30 | import sys |
| 31 | b = bytearray(open(sys.argv[1], "rb").read()) |
| 32 | i = max(i for i, c in enumerate(b) if 48 <= c <= 57) |
| 33 | b[i] = 48 + (b[i] - 48 + 1) % 10 |
| 34 | open(sys.argv[2], "wb").write(b) |
| 35 | PY |
| 36 | if cmp -s "$1" "$2.flip"; then echo "FAIL negative control: flipped record not caught"; exit 1; fi |
| 37 | echo "negative control: flipped record caught ($(basename "$2"))" |
| 38 | } |