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 / tests / device-trace / run-runner-controls.sh

99 lines · 3782 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# Shell orchestration only: fake compiler programs and deliberately synthetic decode rows.
4# This does not compile Omega, decode GPU bytes, open a GPU or establish native execution.
5set -eu
6root=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
7work=$(mktemp -d "${TMPDIR:-/tmp}/cudapp-runner-controls.XXXXXX")
8trap 'rm -rf -- "$work"' EXIT HUP INT TERM
9mkdir "$work/bin"
10export RUNNER_CONTROL_LOG="$work/calls"
11
12cat > "$work/bin/omc" <<'EOF'
13#!/bin/sh
14set -eu
15src=$(cat)
16case "$src" in
17 *'global Aregs ulong'*) unit=address ;;
18 *'fn gprepare to void'*) unit=guard ;;
19 *'fn ballflags to bool'*)
20 unit=body
21 case "$src" in *'fn gbvec to void'*) : ;; *) exit 32 ;; esac ;;
22 *'global Fails ulong'*) unit=emitter ;;
23 *) unit=dump ;;
24esac
25printf 'compile %s\n' "$unit" >> "$RUNNER_CONTROL_LOG"
26if [ "${CONTROL_STDERR:-}" = "$unit" ]; then echo 'synthetic compiler diagnostic' >&2; fi
27# Emit executable bytes even when the compiler later fails. They must not run.
28printf '#!/bin/sh\nprintf "run %s\\n" >> "$RUNNER_CONTROL_LOG"\n' "$unit"
29printf '[ "${CONTROL_FAIL:-}" != "%s" ] || exit 23\n' "$unit"
30if [ "$unit" = dump ]; then
31 printf 'dd if=/dev/zero bs=640 count=1 2>/dev/null\n'
32elif [ "$unit" = emitter ]; then
33 printf 'printf "1 0\\n"\n'
34fi
35if [ "${CONTROL_COMPILE_FAIL:-}" = "$unit" ]; then exit 24; fi
36EOF
37cat > "$work/bin/nvdisasm" <<'EOF'
38#!/bin/sh
39set -eu
40echo decode >> "$RUNNER_CONTROL_LOG"
41[ "${CONTROL_DECODE_FAIL:-0}" = 0 ] || exit 25
42# Only the runner's handwritten addressed expectations are meaningful here.
43# Repeated ffff rows below are intentionally not a real instruction stream.
44printf '%s\n' '/*0010*/ @P0 BRA 0x140 ;' '/*0070*/ MOV R6, 0x40 ;' \
45 '/*0080*/ IMAD.WIDE.U32 R8, R6, 0x1, R4 ;' '/*01b0*/ MOV R6, 0x80 ;' \
46 '/*01c0*/ IMAD.WIDE.U32 R8, R6, 0x1, R4 ;'
47for pair in 'BRA 1' 'ISETP.GE.AND 2' 'LDC.64 6' 'LDCU.64 2' 'MOV 6' 'S2R 2' 'STG.E 16'; do
48 set -- $pair
49 n=$2
50 while [ "$n" -gt 0 ]; do printf '/*ffff*/ %s ;\n' "$1"; n=$((n - 1)); done
51done
52EOF
53chmod +x "$work/bin/omc" "$work/bin/nvdisasm"
54
55run_case() {
56 : > "$RUNNER_CONTROL_LOG"
57 rc=0
58 OMEGA_COMPILER="$work/bin/omc" PATH="$work/bin:$PATH" \
59 sh "$root/tests/device-trace/run-emitter-checks.sh" > "$work/out" 2> "$work/err" || rc=$?
60}
61fail() { echo "runner control FAIL: $*" >&2; cat "$work/out" "$work/err" >&2; exit 1; }
62
63run_case
64[ "$rc" = 0 ] || fail 'positive shell orchestration'
65for unit in emitter address guard body dump; do
66 grep -qx "compile $unit" "$RUNNER_CONTROL_LOG" || fail "missing compile $unit"
67 grep -qx "run $unit" "$RUNNER_CONTROL_LOG" || fail "missing run $unit"
68done
69grep -qx decode "$RUNNER_CONTROL_LOG" || fail 'missing decode'
70
71for unit in emitter address guard body; do
72 export CONTROL_FAIL="$unit"
73 run_case
74 [ "$rc" = 23 ] || fail "$unit failure was not propagated"
75 if grep -qx decode "$RUNNER_CONTROL_LOG"; then fail "decode ran after $unit failed"; fi
76done
77unset CONTROL_FAIL
78
79for unit in emitter address guard body dump; do
80 export CONTROL_COMPILE_FAIL="$unit"
81 run_case
82 [ "$rc" != 0 ] || fail "$unit compiler failure was accepted"
83 if grep -qx "run $unit" "$RUNNER_CONTROL_LOG"; then fail "$unit ran rejected compiler output"; fi
84done
85unset CONTROL_COMPILE_FAIL
86
87for unit in emitter address guard body dump; do
88 export CONTROL_STDERR="$unit"
89 run_case
90 [ "$rc" != 0 ] || fail "$unit compiler diagnostic was accepted"
91 if grep -qx "run $unit" "$RUNNER_CONTROL_LOG"; then fail "$unit ran with compiler diagnostics"; fi
92done
93unset CONTROL_STDERR
94
95export CONTROL_DECODE_FAIL=1
96run_case
97[ "$rc" = 25 ] || fail 'decoder failure was not propagated'
98unset CONTROL_DECODE_FAIL
99echo 'RUNNER ORCHESTRATION CONTROLS PASS (synthetic tools; no native or GPU execution)'