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 / prof / selftest.sh

129 lines · 4334 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# Host and simulator gate for tools/prof. No GPU is opened. The caller chooses CPU placement
4# (taskset/nice): fixed cores 10-14 here failed on a 4-CPU hosted runner (taskset: Invalid argument).
5set -eu
6ROOT=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
7PROF="$ROOT/tools/prof"
8: "${OMEGA_OMC:=$HOME/work/cudastack/omega-mv/seed/out/omc}"
9expected=2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f
10if [ ! -x "$OMEGA_OMC" ]; then
11 echo "NOT_RUN: pinned omc is not executable at $OMEGA_OMC"
12 exit 2
13fi
14actual=$(sha256sum < "$OMEGA_OMC" | cut -c1-64)
15if [ "$actual" != "$expected" ]; then
16 echo "NOT_RUN: profiler compiler pin mismatch"
17 exit 2
18fi
19T=$(mktemp -d)
20trap 'rm -rf "$T"' EXIT HUP INT TERM
21
22"$OMEGA_OMC" < "$PROF/prof.om" > "$T/prof" 2>"$T/omc.err"
23chmod +x "$T/prof"
24
25"$T/prof" words 4294967408 0 > "$T/words.txt"
26printf '%s\n' 537206870 0 0 112 1 0 > "$T/words.exp"
27diff -u "$T/words.exp" "$T/words.txt"
28cc -std=c11 -Wall -Wextra -Werror -o "$T/oracle" "$PROF/stamp_oracle.c"
29"$T/oracle" 4294967408 0 > "$T/oracle.txt"
30diff -u "$T/words.txt" "$T/oracle.txt"
31"$T/prof" words 100 1 > "$T/w1.txt"
32"$T/oracle" 100 1 > "$T/o1.txt"
33diff -u "$T/w1.txt" "$T/o1.txt"
34
35"$T/prof" fix "$T/fix.bin"
36cc -std=c11 -Wall -Wextra -Werror -o "$T/wfix" "$PROF/write_fix.c"
37"$T/wfix" "$T/cfix.bin"
38cmp "$T/fix.bin" "$T/cfix.bin"
39
40"$T/prof" sim "$T/sim.txt"
41diff -u "$PROF/golden.txt" "$T/sim.txt"
42"$T/prof" report "$T/fix.bin" "$T/rep.txt"
43diff -u "$PROF/golden.txt" "$T/rep.txt"
44
45grep -F 'k 0 time_ns 1000000000 bytes 195100000000 flops 115140000000 ai_milli 590 bound_probe mem' "$T/sim.txt" >/dev/null
46grep -F 'ai_milli 590158892 bound_probe compute' "$T/sim.txt" >/dev/null
47grep -F 'ai_milli 590158 bound_probe ridge' "$T/sim.txt" >/dev/null
48grep -F 'probe_mem_milli 1000 probe_flop_milli 1 sec5_mem_237_milli 823 sec5_mem_207_milli 942 sec5_flop_milli 0' "$T/sim.txt" >/dev/null
49grep -F 'sec5_flop_milli 484' "$T/sim.txt" >/dev/null
50grep -F 'probe_mem_milli 500 probe_flop_milli 500 sec5_mem_237_milli 411 sec5_mem_207_milli 471 sec5_flop_milli 242' "$T/sim.txt" >/dev/null
51grep -F 'ridge_probe_milli 590158' "$T/sim.txt" >/dev/null
52
53set +e
54"$T/prof" >/dev/null 2>&1
55usage=$?
56set -e
57[ "$usage" -eq 2 ]
58
59python3 - "$T" << 'PY'
60import pathlib, sys
61t = pathlib.Path(sys.argv[1])
62b = bytearray((t / "fix.bin").read_bytes())
63swap = bytearray(b)
64swap[112:120], swap[128:136] = swap[128:136], swap[112:120]
65(t / "swap.bin").write_bytes(swap)
66zero = bytearray(b)
67zero[128:136] = zero[112:120]
68(t / "zero.bin").write_bytes(zero)
69bad = bytearray(b)
70bad[0] = 0
71(t / "bad.bin").write_bytes(bad)
72(t / "short.bin").write_bytes(bytes(b[:32]))
73PY
74
75set +e
76"$T/prof" report "$T/swap.bin" "$T/swap.txt" >/dev/null 2>&1
77swap=$?
78"$T/prof" report "$T/zero.bin" "$T/zero.txt" >/dev/null 2>&1
79zero=$?
80"$T/prof" report "$T/bad.bin" "$T/bad.txt" >/dev/null 2>&1
81bad=$?
82"$T/prof" report "$T/short.bin" "$T/short.txt" >/dev/null 2>&1
83short=$?
84set -e
85[ "$swap" -eq 3 ]
86[ "$zero" -eq 3 ]
87[ "$bad" -eq 4 ]
88[ "$short" -eq 4 ]
89
90sed 's/bad = lt t1 t0/bad = lt t1 t1/' "$PROF/prof.om" > "$T/order.om"
91grep -F 'bad = lt t1 t1' "$T/order.om" >/dev/null
92if grep -F 'bad = lt t1 t0' "$T/order.om" >/dev/null; then
93 echo "order mutant sed did not apply"
94 exit 1
95fi
96"$OMEGA_OMC" < "$T/order.om" > "$T/order" 2>"$T/order.err"
97chmod +x "$T/order"
98set +e
99"$T/order" report "$T/swap.bin" "$T/order.txt" >/dev/null 2>&1
100ord=$?
101set -e
102[ "$ord" -ne 3 ]
103
104sed 's/const flop_at ulong 16/const flop_at ulong 8/' "$PROF/prof.om" > "$T/flop.om"
105grep -F 'const flop_at ulong 8' "$T/flop.om" >/dev/null
106if grep -F 'const flop_at ulong 16' "$T/flop.om" >/dev/null; then
107 echo "flop mutant sed did not apply"
108 exit 1
109fi
110"$OMEGA_OMC" < "$T/flop.om" > "$T/flop" 2>"$T/flop.err"
111chmod +x "$T/flop"
112"$T/flop" report "$T/fix.bin" "$T/flop.txt"
113if diff -q "$PROF/golden.txt" "$T/flop.txt" >/dev/null; then
114 echo "flop mutant was not caught"
115 exit 1
116fi
117
118set +e
119sh "$PROF/chip.sh" > "$T/chip.txt"
120chip=$?
121set -e
122[ "$chip" -eq 2 ]
123grep -F 'NOT_RUN' "$T/chip.txt" >/dev/null
124if grep -F '/dev/nvidia' "$PROF/chip.sh" >/dev/null; then
125 echo "chip.sh names a GPU device node"
126 exit 1
127fi
128
129echo "PROFILER HOST SIM PASS words oracle fixture sim report mutants swap=$swap order=$ord chip=$chip"