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 / streams_submit_mutants.sh

49 lines · 2984 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# Mutation test for native/streams/submit.om: each mutant is regenerated with the
4# pinned AArch64 context toolchain (same variables as native/nvrm/units.sh), linked
5# into the fake-device fixture, and must make the C-vs-Omega image compare (or the
6# fixture's own asserts) fail. HOST_ONLY.
7set -eu
8ROOT=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
9BRIDGE=${OMEGA_NVRM_BRIDGE:?set OMEGA_NVRM_BRIDGE to the pinned hosted/context bridge}
10: "${OMEGA_NATIVE_OMC:?}" "${OMEGA_NATIVE_OMC2:?}"
11[ "$(uname -m)" = aarch64 ] || { echo "NOT_RUN: submit mutants regenerate AArch64 only" >&2; exit 3; }
12OUT=${OUT_DIR:-build}
13CC=${CC:-cc}
14CFLAGS="-std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -O2 -Isrc -Im16 -Invrm -Ithird_party/nvidia-open-580.173.02/src/common/sdk/nvidia/inc -Ithird_party/nvidia-open-580.173.02/kernel-open/common/inc -Ithird_party/nvidia-open-580.173.02/kernel-open/nvidia-uvm -Ithird_party/nvidia-open-580.173.02/src/nvidia/arch/nvalloc/unix/include -Ithird_party/aien-gpu-abi1"
15cd "$ROOT"
16[ -f "$OUT/streams-submit-c.img" ] || { echo "run make test-streams-submit first" >&2; exit 2; }
17# Same link providers as the make fixtures (mk/streams-submit.mk STREAMS_SUBMIT_LINK), so a missing provider fails the build, not a mutant.
18SRCS=${STREAMS_SUBMIT_LINK:?run through make test-streams-submit-mutants (STREAMS_SUBMIT_LINK)}
19T=$(mktemp -d)
20trap 'rm -rf "$T"' EXIT
21export OMEGA_NATIVE_OMC OMEGA_NATIVE_OMC2
22caught=0 n=0
23while IFS='|' read -r name from to; do
24 [ -n "$name" ] || continue
25 n=$((n + 1))
26 [ "$(grep -cF -- "$from" native/streams/submit.om)" = 1 ] || { echo "FAIL mutant $name: site not unique" >&2; exit 1; }
27 awk -v f="$from" -v t="$to" '{ i = index($0, f); if (i) $0 = substr($0, 1, i - 1) t substr($0, i + length(f)); print }' \
28 native/streams/submit.om > "$T/submit.om"
29 rm -rf "$T/gen"
30 "$BRIDGE/tools/native" --host --target aarch64linux "$T/gen" native/nvrm/transport.om "$T/submit.om" >/dev/null
31 cp "$T/gen/omega_native.h" "$T/cudapp_nvrm_native.h"
32 $CC -I"$T" $CFLAGS -DCUDAPP_MIGRATION_PENDING_C_NVRM=0 -DCUDAPP_MIGRATION_PENDING_C_SUBMIT=0 \
33 -o "$T/m" nvrm/submit_test.c "$T/gen/omega_native.c" $SRCS
34 if "$T/m" "$T/m.img" >/dev/null 2>&1 && cmp -s "$OUT/streams-submit-c.img" "$T/m.img"; then
35 echo "FAIL mutant $name survived"
36 else
37 echo "mutant $name caught"; caught=$((caught + 1))
38 fi
39done <<'EOF'
40valid-bit|shl ulong 1 41|shl ulong 1 40
41address-mask|sub va and va 3|va
42slot|mul slot 8 8|mul add slot 1 8 8
43gpput-wrap|rem and add pos 1 4294967295 entries|rem add pos 1 entries
44gpput-stale|rem and add pos 1 4294967295 entries|rem pos entries
45doorbell-offset|ret mapset bell off 4 token|ret mapset bell 0 4 token
46nwords-bound|gt nwords 2097151|gt nwords 4294967295
47EOF
48[ "$caught" = "$n" ] || { echo "STREAMS SUBMIT MUTANTS FAIL ($caught/$n caught)"; exit 1; }
49echo "STREAMS SUBMIT MUTANTS PASS ($caught/$n caught)"