aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / om / lab-page / record.sh
| 1 | #!/bin/sh |
| 2 | # Records the /lab/ captures on Drake's DGX Spark (Linux aarch64). Host orchestration only: |
| 3 | # it runs the pinned Omega compiler and the read-only oracles (objdump, spirv-val, spirv-dis, |
| 4 | # PoCL, nvcc, cuobjdump) and writes what they printed, with the command, pins and load. |
| 5 | # Nothing here runs on the GPU. Run it by hand, then `sh check.sh` with OMEGA_ACCEPT_CHANGE=1. |
| 6 | # |
| 7 | # Inputs (environment): |
| 8 | # OMEGA_MV omega-mv git directory (default ~/workspace/omega), read with git show only |
| 9 | # OMEGA_MV_REV omega-mv revision for irspirv, opencl-host and the GB10 SASS (default below) |
| 10 | # SPIRV_ROOT extracted SPIRV-Tools + OpenCL ICD root (default /tmp/spirv-tools-root) |
| 11 | # NVCC CUDA compiler (default /usr/local/cuda/bin/nvcc) |
| 12 | set -eu |
| 13 | cd "$(dirname "$0")" |
| 14 | here=$(pwd) |
| 15 | P=../hive-page |
| 16 | omc=$P/omc |
| 17 | pin=$(tr -d ' \n' < $P/omc.sha256) |
| 18 | [ "$(sha256sum "$omc" | cut -d' ' -f1)" = "$pin" ] || { echo 'Compiler pin mismatch' >&2; exit 3; } |
| 19 | wpin=$(tr -d ' \n' < $P/irwasm.sha256) |
| 20 | [ "$(sha256sum $P/irwasm | cut -d' ' -f1)" = "$wpin" ] || { echo 'irwasm pin mismatch' >&2; exit 3; } |
| 21 | mv=${OMEGA_MV:-$HOME/workspace/omega} |
| 22 | rev=${OMEGA_MV_REV:-369dbc96daa1684db2d7c2c7085bbf16b3fd77ee} |
| 23 | sroot=${SPIRV_ROOT:-/tmp/spirv-tools-root} |
| 24 | nvcc=${NVCC:-/usr/local/cuda/bin/nvcc} |
| 25 | [ "$(uname -s) $(uname -m)" = "Linux aarch64" ] || { echo 'record.sh runs on Linux aarch64 only' >&2; exit 2; } |
| 26 | work=$(mktemp -d) |
| 27 | trap 'rm -rf "$work"' EXIT HUP INT TERM |
| 28 | run() { nice -n 19 taskset -c 8-9 "$@"; } |
| 29 | now() { date +%s%N; } |
| 30 | # median of 7 wall-clock runs of "$@" in microseconds; stdin from $in, stdout discarded |
| 31 | in=/dev/null |
| 32 | median() { |
| 33 | : > "$work/t" |
| 34 | for k in 1 2 3 4 5 6 7; do |
| 35 | s=$(now); run "$@" < "$in" > /dev/null; e=$(now) |
| 36 | echo $(( (e - s) / 1000 )) >> "$work/t" |
| 37 | done |
| 38 | sort -n "$work/t" | sed -n 4p |
| 39 | } |
| 40 | ms() { printf '%d.%03d ms' $(( $1 / 1000 )) $(( $1 % 1000 )); } |
| 41 | load() { cut -d' ' -f1 /proc/loadavg; } |
| 42 | stamp=$(date -u +%Y-%m-%dT%H:%M:%SZ) |
| 43 | ksha=$(sha256sum axpy.om | cut -d' ' -f1) |
| 44 | |
| 45 | # 1. AArch64: the kernel alone, as raw instruction words, disassembled by objdump. |
| 46 | host="$(uname -sm), $(nproc) of $(nproc --all) CPU cores allowed, DGX Spark (GB10)" |
| 47 | in=axpy.om; t_omc=$(median "$omc"); l_omc=$(load) |
| 48 | "$omc" < axpy.om > "$work/axpy.bin" |
| 49 | cat axpy.om harness.om > "$work/prog.om" |
| 50 | in="$work/prog.om"; t_prog=$(median "$omc"); l_prog=$(load) |
| 51 | "$omc" < "$work/prog.om" > "$work/prog"; chmod +x "$work/prog" |
| 52 | echo '3 1048576' > "$work/args" |
| 53 | got=$("$work/prog" < "$work/args") |
| 54 | want=$(awk 'BEGIN{s=0;for(i=0;i<1048576;i++)s+=3*i+2*i+1;printf "%.0f\n",s}') |
| 55 | [ "$got" = "$want" ] || { echo "native run $got != reference $want" >&2; exit 6; } |
| 56 | # Negative control: the same program with the kernel's add turned into sub must not match. |
| 57 | sed 's/^ret add mul a x y$/ret sub mul a x y/' "$work/prog.om" > "$work/mutant.om" |
| 58 | ! cmp -s "$work/prog.om" "$work/mutant.om" || { echo 'mutant edit did not apply' >&2; exit 6; } |
| 59 | "$omc" < "$work/mutant.om" > "$work/mutant"; chmod +x "$work/mutant" |
| 60 | bad=$("$work/mutant" < "$work/args" || true) |
| 61 | [ "$bad" != "$want" ] || { echo 'mutant matched the reference' >&2; exit 6; } |
| 62 | in="$work/args"; t_run=$(median "$work/prog"); l_run=$(load) |
| 63 | { |
| 64 | printf 'compiler omc sha256 %s (the site pin)\n' "$pin" |
| 65 | printf 'command omc < axpy.om > axpy.bin\n' |
| 66 | printf 'compile %s, median of 7, %s, load1 %s, %s\n' "$(ms "$t_omc")" "$host" "$l_omc" "$stamp" |
| 67 | printf 'output %s bytes of raw AArch64 code, sha256 %s\n' "$(wc -c < "$work/axpy.bin")" "$(sha256sum "$work/axpy.bin" | cut -d' ' -f1)" |
| 68 | printf 'program axpy.om + harness.om into one Linux program: %s, median of 7, load1 %s\n' "$(ms "$t_prog")" "$l_prog" |
| 69 | printf 'run a=3, n=1048576: checksum %s, awk reference %s, MATCH\n' "$got" "$want" |
| 70 | printf 'control add changed to sub in the kernel: %s, MISMATCH as it should be\n' "${bad:-no output}" |
| 71 | printf 'run time %s per process (start, 1048576 elements, print, exit), median of 7, load1 %s\n' "$(ms "$t_run")" "$l_run" |
| 72 | printf 'disasm objdump -D -b binary -m aarch64 -M no-aliases (%s)\n\n' "$(objdump --version | head -1)" |
| 73 | objdump -D -z -b binary -m aarch64 -M no-aliases "$work/axpy.bin" | sed -n '/^ *[0-9a-f]*:/p' | sed 's/^ *//' |
| 74 | } > captures/aarch64.txt |
| 75 | |
| 76 | # 2. WebAssembly: IR mode, then the pinned irwasm. The page serves this exact file. |
| 77 | in=axpy.om |
| 78 | { printf 'ir\n'; cat axpy.om; } > "$work/ir.om" |
| 79 | in="$work/ir.om"; t_ir=$(median "$omc") |
| 80 | "$omc" < "$work/ir.om" > "$work/axpy.ir" |
| 81 | in="$work/axpy.ir"; t_w=$(median $P/irwasm) |
| 82 | $P/irwasm < "$work/axpy.ir" > ../../public/lab/axpy.wasm |
| 83 | wsha=$(sha256sum ../../public/lab/axpy.wasm | cut -d' ' -f1) |
| 84 | |
| 85 | # 3. SPIR-V: irspirv built from omega-mv with that revision's own omc, validated, run on PoCL (CPU). |
| 86 | git -C "$mv" show "$rev:seed/out/omc" > "$work/omc-mv" |
| 87 | git -C "$mv" show "$rev:seed/spirv/irspirv.om" > "$work/irspirv.om" |
| 88 | git -C "$mv" show "$rev:seed/spirv/opencl-host.c" > "$work/opencl-host.c" |
| 89 | chmod +x "$work/omc-mv" |
| 90 | mvsha=$(sha256sum "$work/omc-mv" | cut -d' ' -f1) |
| 91 | "$work/omc-mv" < "$work/irspirv.om" > "$work/irspirv"; chmod +x "$work/irspirv" |
| 92 | "$work/omc-mv" < "$work/ir.om" > "$work/axpy-mv.ir" |
| 93 | in="$work/axpy-mv.ir"; t_s=$(median "$work/irspirv") |
| 94 | "$work/irspirv" < "$work/axpy-mv.ir" > "$work/axpy.spv" |
| 95 | lib=$sroot/root/usr/lib/aarch64-linux-gnu |
| 96 | pocl=$(ls "$sroot"/pocl/lib/libpocl.so.*.*.* | head -1) |
| 97 | LD_LIBRARY_PATH=$lib "$sroot/root/usr/bin/spirv-val" --target-env opencl2.1 "$work/axpy.spv" |
| 98 | run cc -std=c11 -O2 -Wall -Wextra -Werror -DIRSPIRV_POCL_LIBRARY="\"$pocl\"" -I"$sroot/root/usr/include" \ |
| 99 | -o "$work/opencl-host" "$work/opencl-host.c" -L"$lib" -Wl,-rpath,"$lib" -lOpenCL |
| 100 | pocl_out=$(run "$work/opencl-host" "$work/axpy.spv" run 3 0 1000 2> "$work/pocl.err") |
| 101 | [ "$pocl_out" = "2498500 0" ] || { echo "PoCL run printed $pocl_out" >&2; exit 7; } |
| 102 | dev=$(sed -n 's/.*device=\([^ ]*\).*/\1/p' "$work/pocl.err" | head -1) |
| 103 | { |
| 104 | printf 'compiler omega-mv %s: omc sha256 %s builds irspirv\n' "$rev" "$mvsha" |
| 105 | printf 'command { printf '"'"'ir\\n'"'"'; cat axpy.om; } | omc > axpy.ir && irspirv < axpy.ir > axpy.spv\n' |
| 106 | printf 'translate %s for irspirv, median of 7, %s, load1 %s\n' "$(ms "$t_s")" "$host" "$(load)" |
| 107 | printf 'output %s bytes, sha256 %s\n' "$(wc -c < "$work/axpy.spv")" "$(sha256sum "$work/axpy.spv" | cut -d' ' -f1)" |
| 108 | printf 'validate spirv-val --target-env opencl2.1: valid (%s)\n' "$(LD_LIBRARY_PATH=$lib "$sroot/root/usr/bin/spirv-val" --version | head -1)" |
| 109 | printf 'run PoCL 7.2 on the CPU (%s): run 3 0 1000 = %s, trap 0; reference 2498500, MATCH\n' "$dev" "${pocl_out% *}" |
| 110 | printf 'not run no GPU has executed this SPIR-V yet\n\n' |
| 111 | LD_LIBRARY_PATH=$lib "$sroot/root/usr/bin/spirv-dis" "$work/axpy.spv" |
| 112 | } > captures/spirv.txt |
| 113 | |
| 114 | # 4. CUDA C, compiled with nvcc for comparison only. Nothing is launched. |
| 115 | nvv=$("$nvcc" --version | sed -n 's/.*release \([^,]*\), V\(.*\)/\1 (V\2)/p') |
| 116 | cp axpy.cu "$work/axpy.cu" |
| 117 | cd "$work" |
| 118 | in=/dev/null; t_nv=$(median "$nvcc" -arch=sm_121 -o axpy-cuda axpy.cu); l_nv=$(load) |
| 119 | in=/dev/null; t_nvc=$(median "$nvcc" -arch=sm_121 -cubin -o axpy.cubin axpy.cu) |
| 120 | "$nvcc" -arch=sm_121 -cubin -o axpy.cubin axpy.cu |
| 121 | cd "$here" |
| 122 | tk=$(du -sbL "$(dirname "$(dirname "$nvcc")")" | cut -f1) |
| 123 | osz=$(( $(wc -c < "$omc") + $(wc -c < $P/irwasm) )) |
| 124 | { |
| 125 | printf 'compiler nvcc %s\n' "$nvv" |
| 126 | printf 'command nvcc -arch=sm_121 -o axpy axpy.cu (host + device, a runnable program)\n' |
| 127 | printf 'compile %s, median of 7, %s, load1 %s\n' "$(ms "$t_nv")" "$host" "$l_nv" |
| 128 | printf 'device nvcc -arch=sm_121 -cubin: %s, median of 7\n' "$(ms "$t_nvc")" |
| 129 | printf 'not run this CUDA program has not been launched; that needs a GPU window\n' |
| 130 | printf 'disasm cuobjdump -sass axpy.cubin\n\n' |
| 131 | "$(dirname "$nvcc")/cuobjdump" -sass "$work/axpy.cubin" | sed -n 's/^ *\(\/\*[0-9a-f]\{4\}\*\/.*;\).*/\1/p' | sed 's/ */ /g' |
| 132 | } > captures/nvcc.txt |
| 133 | |
| 134 | # 5. The GB10 run that exists: hand-written asm2 vector add, public receipt in omega-mv. |
| 135 | { |
| 136 | printf 'source omega-mv seed/sm121/vecadd.s2, written in asm2 (not compiled from .om)\n' |
| 137 | printf 'run GB10 (sm_121), 1048576 sums, 0 wrong, launch_to_done_ns=214257, 2026-10-19\n' |
| 138 | printf 'control a mutated copy of the same kernel fails the same check\n' |
| 139 | printf 'note launched by omega-mv'"'"'s bytes tool with no CUDA library (seed/sm121/chip6.sh); the Spark still runs NVIDIA DGX OS and the GPU loads NVIDIA signed firmware; the run record says dirty=3 (the bytes tool, copied in)\n' |
| 140 | printf 'disasm nvdisasm, as committed in evidence/SEED-0/sm121/vecadd.sass.txt\n\n' |
| 141 | git -C "$mv" show "$rev:evidence/SEED-0/sm121/vecadd.sass.txt" | sed -n 's/^ *\(\/\*[0-9a-f]\{4\}\*\/.*;\).*/\1/p' | grep -v 'NOP' | sed 's/ */ /g' |
| 142 | } > captures/gb10.txt |
| 143 | |
| 144 | # 6. One sentence for the top of the page, built only from the numbers above. |
| 145 | printf 'Measured on my DGX Spark at %s, load1 %s, both compilers on the same %s of %s CPU cores. omc built the Omega kernel and its host loop into a Linux program in %s. nvcc %s built the CUDA C kernel and its host main in %s. Median of 7 each, same minute.\n' \ |
| 146 | "$stamp" "$l_nv" "$(nproc)" "$(nproc --all)" "$(ms "$t_prog")" "${nvv%% *}" "$(ms "$t_nv")" > captures/headline.txt |
| 147 | |
| 148 | printf 'stamp\t%s\nkernel_sha256\t%s\nomc_kernel_us\t%s\nomc_program_us\t%s\nnative_run_us\t%s\nir_us\t%s\nirwasm_us\t%s\nirspirv_us\t%s\nnvcc_us\t%s\nnvcc_cubin_us\t%s\nwasm_sha256\t%s\nwasm_bytes\t%s\ncuda_toolkit_bytes\t%s\nomega_tool_bytes\t%s\n' \ |
| 149 | "$stamp" "$ksha" "$t_omc" "$t_prog" "$t_run" "$t_ir" "$t_w" "$t_s" "$t_nv" "$t_nvc" "$wsha" "$(wc -c < ../../public/lab/axpy.wasm)" "$tk" "$osz" > captures/record.tsv |
| 150 | mkdir -p ../../public/lab |
| 151 | cp captures/record.tsv ../../public/lab/record.tsv |
| 152 | |
| 153 | # 7. The take-home, exactly as a visitor types it, from a clean directory and a fresh clone of the Radicle mirror. |
| 154 | # LAB_CLONE_REF names the branch to clone (default main); LAB_SKIP_HOME=1 keeps the last transcript. |
| 155 | if [ "${LAB_SKIP_HOME:-0}" != 1 ]; then |
| 156 | home=$(mktemp -d) |
| 157 | ref=${LAB_CLONE_REF:-main} |
| 158 | { |
| 159 | printf '$ git clone --depth 1 https://www.aienos.com/rad/z3iwnx2pktbGhnfBpJSsaFcTmKgHU.git aienos.com\n' |
| 160 | [ "$ref" = main ] || printf '(recorded from branch %s before merge)\n' "$ref" |
| 161 | git -C "$home" clone -q --depth 1 --branch "$ref" https://www.aienos.com/rad/z3iwnx2pktbGhnfBpJSsaFcTmKgHU.git aienos.com 2>&1 |
| 162 | printf '$ cd aienos.com\n$ sh om/lab-page/run.sh\n' |
| 163 | (cd "$home/aienos.com" && sh om/lab-page/run.sh 2>&1) |
| 164 | printf '(recorded %s in an empty directory, Linux aarch64, load1 %s)\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$(cut -d' ' -f1 /proc/loadavg)" |
| 165 | } > "$home/home.txt" |
| 166 | grep -q 'PASS' "$home/home.txt" || { cat "$home/home.txt" >&2; echo 'take-home did not PASS' >&2; exit 7; } |
| 167 | cp "$home/home.txt" captures/home.txt |
| 168 | rm -rf "$home" |
| 169 | fi |
| 170 | echo "LAB-RECORD PASS $stamp" |