interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / om / lab-page / record.sh

170 lines · 10870 bytes Raw Blame History
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)
12set -eu
13cd "$(dirname "$0")"
14here=$(pwd)
15P=../hive-page
16omc=$P/omc
17pin=$(tr -d ' \n' < $P/omc.sha256)
18[ "$(sha256sum "$omc" | cut -d' ' -f1)" = "$pin" ] || { echo 'Compiler pin mismatch' >&2; exit 3; }
19wpin=$(tr -d ' \n' < $P/irwasm.sha256)
20[ "$(sha256sum $P/irwasm | cut -d' ' -f1)" = "$wpin" ] || { echo 'irwasm pin mismatch' >&2; exit 3; }
21mv=${OMEGA_MV:-$HOME/workspace/omega}
22rev=${OMEGA_MV_REV:-369dbc96daa1684db2d7c2c7085bbf16b3fd77ee}
23sroot=${SPIRV_ROOT:-/tmp/spirv-tools-root}
24nvcc=${NVCC:-/usr/local/cuda/bin/nvcc}
25[ "$(uname -s) $(uname -m)" = "Linux aarch64" ] || { echo 'record.sh runs on Linux aarch64 only' >&2; exit 2; }
26work=$(mktemp -d)
27trap 'rm -rf "$work"' EXIT HUP INT TERM
28run() { nice -n 19 taskset -c 8-9 "$@"; }
29now() { date +%s%N; }
30# median of 7 wall-clock runs of "$@" in microseconds; stdin from $in, stdout discarded
31in=/dev/null
32median() {
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}
40ms() { printf '%d.%03d ms' $(( $1 / 1000 )) $(( $1 % 1000 )); }
41load() { cut -d' ' -f1 /proc/loadavg; }
42stamp=$(date -u +%Y-%m-%dT%H:%M:%SZ)
43ksha=$(sha256sum axpy.om | cut -d' ' -f1)
44
45# 1. AArch64: the kernel alone, as raw instruction words, disassembled by objdump.
46host="$(uname -sm), $(nproc) of $(nproc --all) CPU cores allowed, DGX Spark (GB10)"
47in=axpy.om; t_omc=$(median "$omc"); l_omc=$(load)
48"$omc" < axpy.om > "$work/axpy.bin"
49cat axpy.om harness.om > "$work/prog.om"
50in="$work/prog.om"; t_prog=$(median "$omc"); l_prog=$(load)
51"$omc" < "$work/prog.om" > "$work/prog"; chmod +x "$work/prog"
52echo '3 1048576' > "$work/args"
53got=$("$work/prog" < "$work/args")
54want=$(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.
57sed '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"
60bad=$("$work/mutant" < "$work/args" || true)
61[ "$bad" != "$want" ] || { echo 'mutant matched the reference' >&2; exit 6; }
62in="$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.
77in=axpy.om
78{ printf 'ir\n'; cat axpy.om; } > "$work/ir.om"
79in="$work/ir.om"; t_ir=$(median "$omc")
80"$omc" < "$work/ir.om" > "$work/axpy.ir"
81in="$work/axpy.ir"; t_w=$(median $P/irwasm)
82$P/irwasm < "$work/axpy.ir" > ../../public/lab/axpy.wasm
83wsha=$(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).
86git -C "$mv" show "$rev:seed/out/omc" > "$work/omc-mv"
87git -C "$mv" show "$rev:seed/spirv/irspirv.om" > "$work/irspirv.om"
88git -C "$mv" show "$rev:seed/spirv/opencl-host.c" > "$work/opencl-host.c"
89chmod +x "$work/omc-mv"
90mvsha=$(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"
93in="$work/axpy-mv.ir"; t_s=$(median "$work/irspirv")
94"$work/irspirv" < "$work/axpy-mv.ir" > "$work/axpy.spv"
95lib=$sroot/root/usr/lib/aarch64-linux-gnu
96pocl=$(ls "$sroot"/pocl/lib/libpocl.so.*.*.* | head -1)
97LD_LIBRARY_PATH=$lib "$sroot/root/usr/bin/spirv-val" --target-env opencl2.1 "$work/axpy.spv"
98run 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
100pocl_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; }
102dev=$(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.
115nvv=$("$nvcc" --version | sed -n 's/.*release \([^,]*\), V\(.*\)/\1 (V\2)/p')
116cp axpy.cu "$work/axpy.cu"
117cd "$work"
118in=/dev/null; t_nv=$(median "$nvcc" -arch=sm_121 -o axpy-cuda axpy.cu); l_nv=$(load)
119in=/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
121cd "$here"
122tk=$(du -sbL "$(dirname "$(dirname "$nvcc")")" | cut -f1)
123osz=$(( $(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.
145printf '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
148printf '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
150mkdir -p ../../public/lab
151cp 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.
155if [ "${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"
169fi
170echo "LAB-RECORD PASS $stamp"