summaryrefslogtreecommitdiffstats
path: root/tools/cuda-ab/p2/oracle.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tools/cuda-ab/p2/oracle.sh')
-rwxr-xr-xtools/cuda-ab/p2/oracle.sh77
1 files changed, 77 insertions, 0 deletions
diff --git a/tools/cuda-ab/p2/oracle.sh b/tools/cuda-ab/p2/oracle.sh
new file mode 100755
index 0000000..80cff94
--- /dev/null
+++ b/tools/cuda-ab/p2/oracle.sh
@@ -0,0 +1,77 @@
+#!/bin/bash
+# SPDX-License-Identifier: BSD-3-Clause
+#
+# p2/oracle.sh - build the P2 programs and record host-side reference output
+# into p2/expected/<name>.txt.
+#
+# Two modes:
+# GPU mode - nvidia-smi works: each program is run bare-metal; the stable
+# lines (RESULT/CHECK/ERR/STATUS/P2PRINT/PROBE/MAIL) are
+# filtered into expected/<name>.txt and the full output is
+# kept as expected/<name>.full.txt.
+# EMIT mode - no usable host GPU (e.g. the device is owned by a running
+# guest): each program is run with --emit-expected, a
+# deterministic CPU-only computation of the stable lines a
+# correct GPU run must produce. This fallback is what
+# distinguishes "oracle not available" from "oracle passed".
+#
+# The generation mode is recorded in expected/SOURCE.txt.
+#
+# Usage: ./oracle.sh
+set -e
+
+HERE="$(cd "$(dirname "$0")" && pwd)"
+EXP="$HERE/expected"
+FILTER='^(RESULT|CHECK|ERR|STATUS|P2PRINT|PROBE|MAIL)'
+
+"$HERE/build.sh"
+mkdir -p "$EXP"
+
+mode="emit"
+if nvidia-smi -L >/dev/null 2>&1; then
+ mode="gpu"
+fi
+
+FAIL=0
+for bin in "$HERE"/bin/p2_*; do
+ name="$(basename "$bin")"
+ out="$EXP/$name.full.txt"
+
+ if [ "$mode" = "gpu" ]; then
+ echo "[oracle] $name (bare-metal GPU)"
+ if ! timeout 300 "$bin" > "$out" 2>&1; then
+ echo "[oracle] FAIL: $name exited non-zero" >&2
+ FAIL=1
+ continue
+ fi
+ if ! grep -q '^STATUS OK$' "$out"; then
+ echo "[oracle] FAIL: $name did not print STATUS OK" >&2
+ FAIL=1
+ continue
+ fi
+ grep -E "$FILTER" "$out" > "$EXP/$name.txt"
+ else
+ echo "[oracle] $name (no host GPU: deterministic emit)"
+ "$bin" --emit-expected > "$out" 2>&1
+ grep -E "$FILTER" "$out" > "$EXP/$name.txt"
+ fi
+done
+
+if [ "$FAIL" -ne 0 ]; then
+ echo "[oracle] FAILED - expected/ is incomplete" >&2
+ exit 1
+fi
+
+{
+ echo "mode=$mode"
+ echo "date=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
+ echo "host=$(hostname)"
+ if [ "$mode" = "gpu" ]; then
+ nvidia-smi --query-gpu=name,driver_version --format=csv,noheader | head -1
+ else
+ echo "deterministic CPU computation via --emit-expected"
+ echo "(no usable host GPU; rerun ./oracle.sh when one is available)"
+ fi
+} > "$EXP/SOURCE.txt"
+
+echo "[oracle] done ($mode) -> $EXP"