omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / gpu / qual / gate.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | # gpu/qual/gate.sh: compile and run pure-Omega x86 Linux & non-NVIDIA GPU qualification units. |
| 4 | # Strictly separates HOST_TESTED / EMULATED from PHYSICAL hardware qualification: |
| 5 | # - On non-x86_64 hosts (e.g. AArch64 Spark), x86linux_qual MUST refuse default execution (exit 3, |
| 6 | # BLOCKED_HARDWARE) under qemu-x86_64, and only pass its selftest with --allow-emulated-selftest. |
| 7 | # - On NVIDIA-only or CPU-only hosts, non_nvidia_qual MUST exit 3 (BLOCKED_HARDWARE). |
| 8 | set -eu |
| 9 | |
| 10 | ROOT=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd) |
| 11 | OMC=${OMC:-"$ROOT/seed/out/omc"} |
| 12 | WORK=$(mktemp -d "${TMPDIR:-/tmp}/omega-gpu-qual.XXXXXX") |
| 13 | trap 'rm -rf "$WORK"' EXIT |
| 14 | |
| 15 | if [ ! -x "$OMC" ]; then |
| 16 | echo "OMEGA-GPU-QUAL NOT_RUN: compiler missing at $OMC" >&2 |
| 17 | exit 3 |
| 18 | fi |
| 19 | |
| 20 | WANT=$(awk '{print $1; exit}' "$ROOT/seed/out/omc.sha256") |
| 21 | GOT=$(sha256sum "$OMC" | awk '{print $1}') |
| 22 | if [ "$GOT" != "$WANT" ]; then |
| 23 | echo "OMEGA-GPU-QUAL REFUSED: omc sha256 $GOT != $WANT" >&2 |
| 24 | exit 69 |
| 25 | fi |
| 26 | |
| 27 | # 1. Host classification test (AArch64 or native host) |
| 28 | HOST_ARCH=$(uname -m) |
| 29 | HDR="" |
| 30 | if [ "$HOST_ARCH" = "x86_64" ]; then |
| 31 | HDR="target x86linux\n" |
| 32 | fi |
| 33 | { printf "${HDR}om2\n"; grep -v '^om2$' "$ROOT/gpu/qual/qual_test.om"; } | "$OMC" > "$WORK/qual_test" 2> "$WORK/qual_test.err" |
| 34 | [ ! -s "$WORK/qual_test.err" ] || { cat "$WORK/qual_test.err" >&2; exit 1; } |
| 35 | chmod 700 "$WORK/qual_test" |
| 36 | "$WORK/qual_test" |
| 37 | |
| 38 | # 2. Build non_nvidia_qual for BOTH AArch64 and x86linux (reproducible cross-compile) |
| 39 | { printf 'om2\n'; grep -v '^om2$' "$ROOT/gpu/qual/non_nvidia_qual.om"; } | "$OMC" > "$WORK/nnq_a64" 2> "$WORK/nnq_a64.err" |
| 40 | [ ! -s "$WORK/nnq_a64.err" ] || { cat "$WORK/nnq_a64.err" >&2; exit 1; } |
| 41 | { printf 'target x86linux\nom2\n'; grep -v '^om2$' "$ROOT/gpu/qual/non_nvidia_qual.om"; } | "$OMC" > "$WORK/nnq_x86" 2> "$WORK/nnq_x86.err" |
| 42 | [ ! -s "$WORK/nnq_x86.err" ] || { cat "$WORK/nnq_x86.err" >&2; exit 1; } |
| 43 | chmod 700 "$WORK/nnq_a64" "$WORK/nnq_x86" |
| 44 | |
| 45 | NNQ="$WORK/nnq_a64" |
| 46 | [ "$HOST_ARCH" = "x86_64" ] && NNQ="$WORK/nnq_x86" |
| 47 | |
| 48 | # Synthetic fixture positive controls: AMD MI300X and Intel Panther Lake |
| 49 | mkdir -p "$WORK/fix-amd/sys/bus/pci/devices/0000:c1:00.0" "$WORK/fix-amd/dev" |
| 50 | printf '0x1002\n' > "$WORK/fix-amd/sys/bus/pci/devices/0000:c1:00.0/vendor" |
| 51 | printf '0x74a1\n' > "$WORK/fix-amd/sys/bus/pci/devices/0000:c1:00.0/device" |
| 52 | printf '0x038000\n' > "$WORK/fix-amd/sys/bus/pci/devices/0000:c1:00.0/class" |
| 53 | : > "$WORK/fix-amd/dev/kfd" |
| 54 | "$NNQ" --root "$WORK/fix-amd" > "$WORK/amd.out" |
| 55 | grep -q 'VERDICT=NON_NVIDIA_HARDWARE_PRESENT' "$WORK/amd.out" |
| 56 | |
| 57 | mkdir -p "$WORK/fix-intel/sys/bus/pci/devices/0000:00:02.0" "$WORK/fix-intel/dev/dri" |
| 58 | printf '0x8086\n' > "$WORK/fix-intel/sys/bus/pci/devices/0000:00:02.0/vendor" |
| 59 | printf '0xb080\n' > "$WORK/fix-intel/sys/bus/pci/devices/0000:00:02.0/device" |
| 60 | printf '0x030000\n' > "$WORK/fix-intel/sys/bus/pci/devices/0000:00:02.0/class" |
| 61 | : > "$WORK/fix-intel/dev/dri/renderD128" |
| 62 | "$NNQ" --root "$WORK/fix-intel" > "$WORK/intel.out" |
| 63 | grep -q 'VERDICT=NON_NVIDIA_HARDWARE_PRESENT' "$WORK/intel.out" |
| 64 | |
| 65 | # Synthetic fixture negative control: NVIDIA-only GB10 must exit 3 (BLOCKED_HARDWARE) |
| 66 | mkdir -p "$WORK/fix-nv/sys/bus/pci/devices/000f:01:00.0" |
| 67 | printf '0x10de\n' > "$WORK/fix-nv/sys/bus/pci/devices/000f:01:00.0/vendor" |
| 68 | printf '0x2e12\n' > "$WORK/fix-nv/sys/bus/pci/devices/000f:01:00.0/device" |
| 69 | printf '0x030000\n' > "$WORK/fix-nv/sys/bus/pci/devices/000f:01:00.0/class" |
| 70 | rc=0 |
| 71 | "$NNQ" --root "$WORK/fix-nv" > "$WORK/nv.out" || rc=$? |
| 72 | [ "$rc" -eq 3 ] || { echo "FAIL: NVIDIA-only fixture returned $rc, expected 3" >&2; exit 1; } |
| 73 | grep -q 'VERDICT=BLOCKED_HARDWARE' "$WORK/nv.out" |
| 74 | |
| 75 | # Live host inventory (informational; records real hardware state) |
| 76 | LIVE_NNQ_RC=0 |
| 77 | "$NNQ" > "$WORK/live_nnq.out" || LIVE_NNQ_RC=$? |
| 78 | echo "--- live non_nvidia_qual (exit=$LIVE_NNQ_RC) ---" |
| 79 | cat "$WORK/live_nnq.out" |
| 80 | |
| 81 | # 3. Build x86linux_qual (target x86linux + sha256) |
| 82 | { printf 'target x86linux\nom2\n'; cat "$ROOT/seed/ng/sha256.om"; grep -v '^target x86linux$' "$ROOT/gpu/qual/x86linux_qual.om" | grep -v '^om2$'; } | "$OMC" > "$WORK/x86linux_qual" 2> "$WORK/x86.err" |
| 83 | [ ! -s "$WORK/x86.err" ] || { cat "$WORK/x86.err" >&2; exit 1; } |
| 84 | chmod 700 "$WORK/x86linux_qual" |
| 85 | |
| 86 | X86_STATUS="NOT_RUN" |
| 87 | if [ "$HOST_ARCH" = "x86_64" ]; then |
| 88 | "$WORK/x86linux_qual" > "$WORK/x86.out" |
| 89 | cat "$WORK/x86.out" |
| 90 | grep -q 'EXEC_CLASS=PHYSICAL_X86_64' "$WORK/x86.out" |
| 91 | X86_STATUS="PHYSICAL_X86_64_PASS" |
| 92 | elif command -v qemu-x86_64 >/dev/null 2>&1; then |
| 93 | # Default invocation under QEMU MUST refuse with exit 3 (BLOCKED_HARDWARE) |
| 94 | rc=0 |
| 95 | qemu-x86_64 "$WORK/x86linux_qual" > "$WORK/x86_def.out" || rc=$? |
| 96 | [ "$rc" -eq 3 ] || { echo "FAIL: x86linux_qual under QEMU returned $rc, expected 3 (BLOCKED_HARDWARE)" >&2; exit 1; } |
| 97 | grep -q 'EXEC_CLASS=EMULATED' "$WORK/x86_def.out" |
| 98 | grep -q 'VERDICT=BLOCKED_HARDWARE' "$WORK/x86_def.out" |
| 99 | # Explicit emulated selftest verifies x86_64 codegen, floats, sha256, and traps 1/2/3/5 |
| 100 | qemu-x86_64 "$WORK/x86linux_qual" --allow-emulated-selftest > "$WORK/x86_emu.out" |
| 101 | cat "$WORK/x86_emu.out" |
| 102 | grep -q 'VERDICT=EMULATED_SELFTEST_PASS' "$WORK/x86_emu.out" |
| 103 | X86_STATUS="EMULATED_SELFTEST_PASS_PHYSICAL_NOT_RUN" |
| 104 | fi |
| 105 | |
| 106 | echo "OMEGA-GPU-QUAL PASS host_controls=all x86linux=$X86_STATUS non_nvidia_live_exit=$LIVE_NNQ_RC" |