Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/tests/share/run-share-host.sh # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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). 11 set -eu 12 : "${OMEGA_OMC:?set the pinned seeded compiler}" 13 MODE=${1:-} 14 OUT=${ZERO_COPY_OUT:-build/zero-copy} 15 SRC=${ZERO_COPY_SHARE_SRC:-native/share/share.om} 16 PIN=`2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f` 17 GOT=$(sha256sum < "$OMEGA_OMC" | cut -c1-64) 18 if 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 21 fi 22 mkdir -p "$OUT" 23 T=third_party/nvidia-open-580.173.02 24 25 # Host reference: layouts, request numbers and statuses from the pinned NVIDIA headers. 26 if test -n "${ZERO_COPY_ABI:-}"; then 27 cp "$ZERO_COPY_ABI" "$OUT/abi.om" 28 else 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" 34 fi 35 36 # Rename device words; drop the shared byte-array operands, which the fake reads directly. 37 fake() { 38 sed -E '/^note /!{ 39 s/fopen nvctl 0 len nvctl 524290 0/fkopen 1/ 40 s/fopen nvdev 0 len nvdev 524290 0/fkopen 2/ 41 s/fopen nvuvm 0 len nvuvm 524290 0/fkopen 3/ 42 /\b(devcall|devctl|uvmctl)\b/s/ (nvhdr|nvpar|nvcard) / /g 43 s/\bdevcall\b/fkcall/g 44 s/\bdevctl\b/fkctl/g 45 s/\buvmctl\b/fkuvm/g 46 s/\bfclose\b/fkclose/g 47 s/\bmapbind\b/fkbind/g 48 s/\bmapnew\b/fknew/g 49 }' "$@" 50 } 51 52 # Build one variant: $1 main body function, $2 output stem. 53 build() { 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. 70 build tall share 71 echo "zero-copy: compiled" 72 rc=0 73 "$OUT/share" > "$OUT/share.stdout" 2> "$OUT/share.stderr" || rc=$? 74 cat "$OUT/share.stderr" >&2 75 if 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 78 fi 79 echo "zero-copy: suite pass" 80 test "$MODE" = --suite-only && exit 0 81 82 # Negative control: a write through a read-only import must trap (exit 103), not land. 83 build trowrite rowrite 84 rc=0 85 "$OUT/rowrite" > "$OUT/rowrite.stdout" 2>/dev/null || rc=$? 86 test "$(cat "$OUT/rowrite.stdout")" = ZERO_COPY_SHARE_RO_ARMED 87 if test "$rc" != 103; then 88 echo "zero-copy: FAIL read-only import write exited $rc, want trap 103" >&2 89 exit 1 90 fi 91 echo "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" 98 chmod 0644 "$OUT/chip-share" 99 echo "zero-copy: chip gate compiled, NOT_RUN (needs an authorized GPU window)" 100 101 if test "$MODE" != --no-mutants; then 102 ZERO_COPY_OUT="$OUT" sh tests/share/mutants.sh 103 fi 104 sha256sum "$OUT/abi.om" "$OUT/share" "$OUT/chip-share" "$SRC" 105 echo "ZERO-COPY SHARE HOST PASS"