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 / share / run-share-host.sh

105 lines · 4437 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# Host verification of native/share/share.om (ROADMAP section 3, zero-copy shared memory).
4# External harness; not a runtime dependency. No device file is opened: every RM, UVM and
5# device-file word in a private copy of context.om + share.om is renamed to the fake in
6# tests/share/fake-rm.om, and a guard refuses the run if any raw device word survives.
7# Usage: run-share-host.sh [--no-mutants | --suite-only]
8# --suite-only full suite only, for mutants.sh; prints "zero-copy: compiled" once built.
9# Env: OMEGA_OMC (pinned), CC, ZERO_COPY_OUT (build/zero-copy), ZERO_COPY_SHARE_SRC
10# (native/share/share.om), ZERO_COPY_ABI (reuse a generated abi.om instead of rebuilding).
11set -eu
12: "${OMEGA_OMC:?set the pinned seeded compiler}"
13MODE=${1:-}
14OUT=${ZERO_COPY_OUT:-build/zero-copy}
15SRC=${ZERO_COPY_SHARE_SRC:-native/share/share.om}
16PIN=2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f
17GOT=$(sha256sum < "$OMEGA_OMC" | cut -c1-64)
18if test "$GOT" != "$PIN"; then
19 echo "zero-copy: FAIL OMEGA_OMC sha256 $GOT, want the pinned omc $PIN (omega-mv e5b32567)" >&2
20 exit 1
21fi
22mkdir -p "$OUT"
23T=third_party/nvidia-open-580.173.02
24
25# Host reference: layouts, request numbers and statuses from the pinned NVIDIA headers.
26if test -n "${ZERO_COPY_ABI:-}"; then
27 cp "$ZERO_COPY_ABI" "$OUT/abi.om"
28else
29 ${CC:-cc} -std=gnu11 -Wall -Wextra -Werror \
30 -I$T/src/common/sdk/nvidia/inc -I$T/kernel-open/common/inc \
31 -I$T/kernel-open/nvidia-uvm -I$T/src/nvidia/arch/nvalloc/unix/include \
32 tests/share/abi-oracle.c -o "$OUT/abi-oracle"
33 "$OUT/abi-oracle" > "$OUT/abi.om"
34fi
35
36# Rename device words; drop the shared byte-array operands, which the fake reads directly.
37fake() {
38 sed -E '/^note /!{
39s/fopen nvctl 0 len nvctl 524290 0/fkopen 1/
40s/fopen nvdev 0 len nvdev 524290 0/fkopen 2/
41s/fopen nvuvm 0 len nvuvm 524290 0/fkopen 3/
42/\b(devcall|devctl|uvmctl)\b/s/ (nvhdr|nvpar|nvcard) / /g
43s/\bdevcall\b/fkcall/g
44s/\bdevctl\b/fkctl/g
45s/\buvmctl\b/fkuvm/g
46s/\bfclose\b/fkclose/g
47s/\bmapbind\b/fkbind/g
48s/\bmapnew\b/fknew/g
49}' "$@"
50}
51
52# Build one variant: $1 main body function, $2 output stem.
53build() {
54 cat native/nvrm/context.om "$SRC" | fake > "$OUT/$2.dev.om"
55 if grep -v '^note ' "$OUT/$2.dev.om" | grep -nE '\b(devcall|devctl|uvmctl|fopen|fclose|mapbind|mapnew)\b'; then
56 echo "zero-copy: FAIL raw device word survived the rewrite" >&2
57 exit 1
58 fi
59 if grep -v '^note ' tests/share/fake-rm.om tests/share/share-test.om | grep -nE '\b(devcall|devctl|uvmctl|fopen)\b'; then
60 echo "zero-copy: FAIL fake or test names a device word" >&2
61 exit 1
62 fi
63 { cat "$OUT/$2.dev.om" "$OUT/abi.om" tests/share/fake-rm.om tests/share/share-test.om
64 printf 'fn main to int\nret %s\nend\n' "$1"; } > "$OUT/$2.om"
65 "$OMEGA_OMC" < "$OUT/$2.om" > "$OUT/$2"
66 chmod +x "$OUT/$2"
67}
68
69# Simulated tier: the full suite against the fake RM.
70build tall share
71echo "zero-copy: compiled"
72rc=0
73"$OUT/share" > "$OUT/share.stdout" 2> "$OUT/share.stderr" || rc=$?
74cat "$OUT/share.stderr" >&2
75if test "$rc" != 0 || test "$(cat "$OUT/share.stdout")" != ZERO_COPY_SHARE_HOST_PASS; then
76 echo "zero-copy: FAIL suite exited $rc (103 = write through a read-only mapping)" >&2
77 exit 1
78fi
79echo "zero-copy: suite pass"
80test "$MODE" = --suite-only && exit 0
81
82# Negative control: a write through a read-only import must trap (exit 103), not land.
83build trowrite rowrite
84rc=0
85"$OUT/rowrite" > "$OUT/rowrite.stdout" 2>/dev/null || rc=$?
86test "$(cat "$OUT/rowrite.stdout")" = ZERO_COPY_SHARE_RO_ARMED
87if test "$rc" != 103; then
88 echo "zero-copy: FAIL read-only import write exited $rc, want trap 103" >&2
89 exit 1
90fi
91echo "zero-copy: read-only write trapped 103"
92
93# Chip gate: compiled from the unrewritten sources so the window runs exactly this binary.
94# It opens /dev/nvidia*; this script never executes it (mode 0644).
95{ cat native/nvrm/context.om "$SRC" tests/share/chip-share.om
96 printf 'fn main to int\nret cmain\nend\n'; } > "$OUT/chip-share.om"
97"$OMEGA_OMC" < "$OUT/chip-share.om" > "$OUT/chip-share"
98chmod 0644 "$OUT/chip-share"
99echo "zero-copy: chip gate compiled, NOT_RUN (needs an authorized GPU window)"
100
101if test "$MODE" != --no-mutants; then
102 ZERO_COPY_OUT="$OUT" sh tests/share/mutants.sh
103fi
104sha256sum "$OUT/abi.om" "$OUT/share" "$OUT/chip-share" "$SRC"
105echo "ZERO-COPY SHARE HOST PASS"