omega-gpu-bench
First-party Omega GPU kernel benchmark harness and receipts
Brought by drakestapleton
omega-gpu-bench / tests / run.sh
| 1 | #!/bin/sh |
| 2 | # tests/run.sh -- kit and validator tests, no GPU needed. Run from a clean git checkout: sh tests/run.sh |
| 3 | # The fixture tests/fakecuda.py stands in for libcuda; its receipts say driver "fake" and the validator |
| 4 | # rejects them unless --allow-fake is given. Every check below is paired with a case that must fail. |
| 5 | # The shipped kit has no kernel (README.md, "Kernels withdrawn"), so the kit and validator rules are |
| 6 | # exercised on a fixture kit: a clone of HEAD whose kernels/ holds six placeholder files (an ELF magic |
| 7 | # and the kernel name, not cubins) under the kit's file names. Commit before running: the fixture is |
| 8 | # cloned from HEAD, not from the working tree. |
| 9 | # INTERIM host glue (sh); successor: an Omega test driver once omc-built tools replace kit/*.py. |
| 10 | set -u |
| 11 | cd "$(dirname "$0")/.." || exit 1 |
| 12 | ROOT=$(pwd) |
| 13 | T=$(mktemp -d) |
| 14 | pass=0 fail=0 |
| 15 | ok() { pass=$((pass + 1)); echo "ok $1"; } |
| 16 | bad() { fail=$((fail + 1)); echo "FAIL $1"; } |
| 17 | expect() { # expect NAME WANT_EXIT GOT_EXIT |
| 18 | if [ "$3" -eq "$2" ]; then ok "$1 (exit $3)"; else bad "$1: exit $3, want $2"; fi |
| 19 | } |
| 20 | SIGN="CI Test <ci@example.invalid>" |
| 21 | FAKE="$ROOT/tests/fakecuda.py" |
| 22 | V="python3 tools/validate.py" |
| 23 | REASON="removed pending clean-room rewrite (CudaLicenseRisk Q6)" |
| 24 | GITID="-c user.name=fixture -c user.email=fixture@example.invalid" |
| 25 | |
| 26 | [ -z "$(git status --porcelain)" ] || echo "note: the checkout has local changes; the fixture kit is cloned from HEAD without them" |
| 27 | |
| 28 | # 1. the receipts in the repository are valid |
| 29 | if ls receipts/*.json > /dev/null 2>&1; then |
| 30 | $V receipts/*.json > "$T/repo.txt"; expect "repository receipts validate" 0 $? |
| 31 | fi |
| 32 | |
| 33 | # 2. the shipped kit has no kernel: NOT_RUN on every GPU, with the reason, and no receipt |
| 34 | for cc in 8.9 9.0; do |
| 35 | OGB_FAKE_DRIVER=$FAKE OGB_FAKE_CC=$cc ./run --sign-off "$SIGN" --out "$T/shipped$cc" > "$T/shipped$cc.txt" 2>&1 |
| 36 | expect "shipped kit on cc $cc" 2 $? |
| 37 | grep -qF "NOT_RUN on every GPU" "$T/shipped$cc.txt" && grep -qF "$REASON" "$T/shipped$cc.txt" \ |
| 38 | && ok "cc $cc: says NOT_RUN and why" || bad "cc $cc: NOT_RUN reason missing" |
| 39 | [ -z "$(ls "$T/shipped$cc" 2>/dev/null)" ] && ok "cc $cc: no receipt" || bad "cc $cc: a receipt was written" |
| 40 | done |
| 41 | |
| 42 | # the fixture kit (its run, validator and tamper cases below all use it) |
| 43 | FX="$T/fx" |
| 44 | git clone -q "$ROOT" "$FX" |
| 45 | : > "$FX/kernels/SHA256SUMS" |
| 46 | for sm in 80 86 89; do |
| 47 | for k in vecadd neg; do |
| 48 | printf '\177ELF test fixture, not a cubin\000%s\000' "$k" > "$FX/kernels/${k}_sm${sm}_v7.cubin" |
| 49 | (cd "$FX/kernels" && sha256sum "${k}_sm${sm}_v7.cubin") >> "$FX/kernels/SHA256SUMS" |
| 50 | done |
| 51 | done |
| 52 | git -C "$FX" add kernels && git -C "$FX" $GITID commit -qm "test fixture kit" \ |
| 53 | && ok "fixture kit committed" || bad "fixture kit commit" |
| 54 | VF="python3 $FX/tools/validate.py" |
| 55 | |
| 56 | # 3. a full kit run against the fixture driver (cc 8.9 loads sm_80, sm_86 and sm_89 builds: 6 kernels) |
| 57 | OGB_FAKE_DRIVER=$FAKE "$FX/run" --sign-off "$SIGN" --out "$T/ok" > "$T/ok.txt" 2>&1 |
| 58 | expect "fake run, all kernels correct" 0 $? |
| 59 | K=$(ls "$T"/ok/*.json 2>/dev/null | head -n 1) |
| 60 | if [ -n "$K" ]; then |
| 61 | $VF --allow-fake "$K" > /dev/null; expect "fake receipt valid with --allow-fake" 0 $? |
| 62 | $VF "$K" > "$T/nofake.txt"; expect "fake receipt rejected without --allow-fake" 1 $? |
| 63 | grep -q "test fixture driver" "$T/nofake.txt" && ok "reason: fixture driver" || bad "reason: fixture driver" |
| 64 | n=$(python3 -c "import json,sys;print(len(json.load(open(sys.argv[1]))['results']))" "$K") |
| 65 | [ "$n" = 6 ] && ok "cc 8.9 ran 6 kernels" || bad "cc 8.9 ran $n kernels, want 6" |
| 66 | else |
| 67 | bad "fake run wrote no receipt"; cat "$T/ok.txt" |
| 68 | fi |
| 69 | |
| 70 | # 4. a GPU that computes wrong answers: exit 1, an honest WRONG receipt that still validates |
| 71 | OGB_FAKE_DRIVER=$FAKE OGB_FAKE_MODE=wrong "$FX/run" --sign-off "$SIGN" --out "$T/wrong" > "$T/wrong.txt" 2>&1 |
| 72 | expect "fake wrong-answer GPU" 1 $? |
| 73 | W=$(ls "$T"/wrong/*.json 2>/dev/null | head -n 1) |
| 74 | if [ -n "$W" ] && grep -q '"WRONG"' "$W"; then ok "receipt says WRONG"; else bad "receipt says WRONG"; fi |
| 75 | [ -n "$W" ] && { $VF --allow-fake "$W" > /dev/null; expect "WRONG receipt validates" 0 $?; } |
| 76 | |
| 77 | # 5. a card with no kernel in the kit (cc 9.0): exit 1, receipt with not_run |
| 78 | OGB_FAKE_DRIVER=$FAKE OGB_FAKE_CC=9.0 "$FX/run" --sign-off "$SIGN" --out "$T/cc90" > "$T/cc90.txt" 2>&1 |
| 79 | expect "cc 9.0 has no kernel" 1 $? |
| 80 | C=$(ls "$T"/cc90/*.json 2>/dev/null | head -n 1) |
| 81 | [ -n "$C" ] && { $VF --allow-fake "$C" > /dev/null; expect "not_run receipt validates" 0 $?; } |
| 82 | |
| 83 | # 6. no GPU: exit 2 and no receipt |
| 84 | OGB_FAKE_DRIVER=$FAKE OGB_FAKE_MODE=nogpu "$FX/run" --sign-off "$SIGN" --out "$T/nogpu" > "$T/nogpu.txt" 2>&1 |
| 85 | expect "no GPU" 2 $? |
| 86 | [ -z "$(ls "$T"/nogpu 2>/dev/null)" ] && ok "no receipt without a GPU" || bad "a receipt was written without a GPU" |
| 87 | grep -q "NOT_RUN" "$T/nogpu.txt" && ok "says NOT_RUN" || bad "says NOT_RUN" |
| 88 | |
| 89 | # 7. the real driver path on a machine without libcuda (GitHub runners): exit 2, no receipt |
| 90 | if python3 -c "import ctypes;ctypes.CDLL('libcuda.so.1')" 2>/dev/null; then |
| 91 | echo "skip real no-driver case: this machine has libcuda (NOT_RUN here, runs in CI)" |
| 92 | else |
| 93 | "$FX/run" --sign-off "$SIGN" --out "$T/real" > "$T/real.txt" 2>&1; expect "real libcuda absent" 2 $? |
| 94 | [ -z "$(ls "$T"/real 2>/dev/null)" ] && ok "no receipt without libcuda" || bad "receipt without libcuda" |
| 95 | fi |
| 96 | |
| 97 | # 8. no sign-off and no git identity: exit 4 |
| 98 | mkdir -p "$T/home" |
| 99 | HOME="$T/home" GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1 OGB_FAKE_DRIVER=$FAKE \ |
| 100 | "$FX/run" --out "$T/nosign" > "$T/nosign.txt" 2>&1 |
| 101 | expect "no sign-off" 4 $? |
| 102 | |
| 103 | # 9. a changed kernel file: the kit refuses to run (exit 3) |
| 104 | git clone -q "$FX" "$T/clone" |
| 105 | printf '\001' | dd of="$T/clone/kernels/vecadd_sm80_v7.cubin" bs=1 seek=8 conv=notrunc 2>/dev/null |
| 106 | OGB_FAKE_DRIVER=$FAKE "$T/clone/run" --sign-off "$SIGN" --out "$T/flip" > "$T/flip.txt" 2>&1 |
| 107 | expect "byte-flipped kernel file refused" 3 $? |
| 108 | |
| 109 | # 10. tampered receipts: every one must be rejected for the stated reason |
| 110 | I=$(grep -l '"origin": "cloudkernels-import"' receipts/*.json 2>/dev/null | head -n 1) |
| 111 | if [ -n "$K" ]; then |
| 112 | python3 tests/tamper.py "$K" "${I:--}" "$T/tampered" > "$T/cases.tsv" |
| 113 | while IFS="$(printf '\t')" read -r case reason; do |
| 114 | $VF --allow-fake "$T/tampered/$case.json" > "$T/v.txt" |
| 115 | if [ $? -eq 1 ] && grep -qF -- "$reason" "$T/v.txt"; then ok "tampered $case rejected: $reason" |
| 116 | else bad "tampered $case not rejected for: $reason"; cat "$T/v.txt"; fi |
| 117 | done < "$T/cases.tsv" |
| 118 | fi |
| 119 | |
| 120 | # 11. a run of the withdrawn kernels, made with the last kit that shipped them, is rejected |
| 121 | GONE=$(git log -1 --format=%H --diff-filter=D -- kernels/vecadd_sm80_v7.cubin 2>/dev/null) |
| 122 | if [ -n "$GONE" ]; then |
| 123 | git clone -q "$ROOT" "$T/old" && git -C "$T/old" checkout -q "$GONE^" |
| 124 | OGB_FAKE_DRIVER=$FAKE "$T/old/run" --sign-off "$SIGN" --out "$T/oldrun" > "$T/oldrun.txt" 2>&1 |
| 125 | O=$(ls "$T"/oldrun/*.json 2>/dev/null | head -n 1) |
| 126 | if [ -n "$O" ]; then |
| 127 | $V --allow-fake "$O" > "$T/old.txt"; expect "withdrawn-kernel run rejected" 1 $? |
| 128 | grep -qF "kernel withdrawn from this kit: $REASON" "$T/old.txt" && ok "reason: kernel withdrawn" \ |
| 129 | || bad "reason: kernel withdrawn" |
| 130 | else |
| 131 | bad "the last kit with kernels wrote no receipt"; cat "$T/oldrun.txt" |
| 132 | fi |
| 133 | else |
| 134 | echo "skip withdrawn-kernel run: no commit removing the kernels in this history (NOT_RUN here)" |
| 135 | fi |
| 136 | |
| 137 | # 12. the committed example of a tampered receipt is rejected |
| 138 | $V tests/tampered/*.json > "$T/ex.txt"; expect "tests/tampered examples rejected" 1 $? |
| 139 | grep -q "receipt_sha256 does not match" "$T/ex.txt" && ok "reason: edited after it was written" || bad "tampered example reason" |
| 140 | |
| 141 | # 13. the board builds from valid receipts only |
| 142 | python3 tools/board.py "$T/site" > "$T/board.txt"; expect "board builds" 0 $? |
| 143 | grep -q "0 rejected" "$T/board.txt" && ok "board: no rejected receipts in the repo" || bad "board rejected some receipts" |
| 144 | |
| 145 | echo "$pass passed, $fail failed" |
| 146 | rm -rf "$T" |
| 147 | [ "$fail" -eq 0 ] |