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 / tools / d7_same_bits_check.sh

38 lines · 2282 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# tools/d7_same_bits_check.sh LOG... -- D7 (docs/issues/D7-same-bits-chip.md): do separate runs of one job
4# print the same output hashes?
5#
6# Each LOG is the stdout of one run. Every line ending "[<label>] output sha256 <64 hex>" is collected (no label:
7# "output", as hello_gpu prints it). For each label:
8# SAME <label> <hash> in N of N runs the label appears exactly once in every log, same hash everywhere
9# MISMATCH <label> ... a log lacks it, has it twice, or two logs disagree (the hashes are listed)
10# A log with no hash line at all is a MISMATCH too (a run that printed nothing proves nothing).
11# Last line: "d7 same-bits: PASS (<labels> labels x <N> runs)" exit 0, or "d7 same-bits: MISMATCH" exit 1.
12# Fewer than two logs: usage error, exit 2. Shell + awk, no Python.
13set -eu
14if [ "$#" -lt 2 ]; then echo "usage: $0 LOG LOG [LOG...] (at least two runs)" >&2; exit 2; fi
15for f in "$@"; do [ -r "$f" ] || { echo "cannot read $f" >&2; exit 2; }; done
16awk -v nlogs="$#" '
17FNR == 1 { file++; name[file] = FILENAME; lines[file] = 0 }
18NF >= 3 && $(NF - 2) == "output" && $(NF - 1) == "sha256" && $NF ~ /^[0-9a-f]+$/ && length($NF) == 64 {
19 lab = NF >= 4 ? $(NF - 3) : "output" # hello_gpu prints a bare "output sha256 <hex>"
20 if (!(lab in seen)) { seen[lab] = 1; order[++nl] = lab }
21 cnt[lab, file]++; h[lab, file] = $NF; lines[file]++
22}
23END {
24 bad = 0
25 for (f = 1; f <= nlogs; f++) if (!lines[f]) { printf "MISMATCH %s: no output hash line\n", name[f]; bad = 1 }
26 for (i = 1; i <= nl; i++) {
27 lab = order[i]; ok = 1; ref = ""
28 for (f = 1; f <= nlogs; f++) {
29 if (cnt[lab, f] != 1) { ok = 0; continue }
30 if (ref == "") ref = h[lab, f]; else if (h[lab, f] != ref) ok = 0
31 }
32 if (ok) { printf "SAME %s %s in %d of %d runs\n", lab, ref, nlogs, nlogs; continue }
33 bad = 1; printf "MISMATCH %s\n", lab
34 for (f = 1; f <= nlogs; f++) printf " %s: %s\n", name[f], cnt[lab, f] == 1 ? h[lab, f] : (cnt[lab, f] ? "printed " cnt[lab, f] " times" : "missing")
35 }
36 if (bad || !nl) { print "d7 same-bits: MISMATCH"; exit 1 }
37 printf "d7 same-bits: PASS (%d labels x %d runs)\n", nl, nlogs
38}' "$@"