interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / spirv / gate-vkspirv.sh

401 lines · 20647 bytes Raw Blame History
1#!/bin/sh
2# Host-only CPU verification of seed/spirv/vkspirv.om (OSC IR v1 -> SPIR-V 1.3
3# Shader/GLCompute) on Mesa lavapipe. spirv-val, the Vulkan loader, lavapipe and
4# the interim vk-host.c are read-only oracles, never generators of IR or SPIR-V.
5# Native results come from omc-built programs calling the same functions.
6# Optional: OMC, SPIRV_VAL, LVP_ICD, CC, VULKAN_CFLAGS, VULKAN_LIBS, PORTLAB_DIR.
7# PORTLAB_DIR (default bench/portlab) holds gen.om and kernels/*.om, consumed
8# read-only; without it the portlab-* rows are NOT_RUN and the gate exits 3.
9# Exit 0 PASS, 1 FAIL, 3 NOT_RUN. Every artifact stays under build/seed/vkspirv.
10set -eu
11cd "$(dirname "$0")/../.."
12B=build/seed/vkspirv
13mkdir -p "$B"
14find "$B" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
15: > "$B/gate.log"
16say() { printf '%s\n' "$*" | tee -a "$B/gate.log"; }
17fail() { say "FAIL $*"; exit 1; }
18notrun() { say "NOT_RUN $*"; exit 3; }
19[ "$(uname -m)" = aarch64 ] || notrun 'requires AArch64 Linux'
20OMC=${OMC:-seed/out/omc}
21SPIRV_VAL=${SPIRV_VAL:-spirv-val}
22LVP_ICD=${LVP_ICD:-/usr/share/vulkan/icd.d/lvp_icd.json}
23PORTLAB_DIR=${PORTLAB_DIR:-bench/portlab}
24CC=${CC:-cc}
25command -v "$SPIRV_VAL" >/dev/null || notrun "requires spirv-val ($SPIRV_VAL)"
26command -v "$CC" >/dev/null || notrun "requires a C compiler ($CC) for the interim Vulkan host"
27case "$LVP_ICD" in /*lvp_icd*.json) ;; *) notrun 'LVP_ICD must name the absolute lavapipe ICD manifest' ;; esac
28[ -f "$LVP_ICD" ] || notrun "lavapipe ICD manifest $LVP_ICD missing"
29pin=26540e6de62402d5784b30b24d7c6faae488137c1f8a4b3e784fd0b5d5528991
30[ -f "$OMC" ] || fail "compiler $OMC missing"
31[ "$(sha256sum "$OMC" | cut -d ' ' -f 1)" = "$pin" ] || fail 'compiler pin differs'
32hostbuild() {
33 # shellcheck disable=SC2086 # flag lists are intentionally word-split
34 "$CC" -std=c11 -O2 -Wall -Wextra -Werror ${VULKAN_CFLAGS:-} "$1" seed/spirv/vk-host.c \
35 -o "$2" ${VULKAN_LIBS:--lvulkan} > "$2.build.log" 2>&1
36}
37hostbuild "-DVKSPIRV_ICD=\"$LVP_ICD\"" "$B/vk-host" ||
38 { cat "$B/vk-host.build.log"; fail 'Vulkan host build failed'; }
39H=$B/vk-host
40say "SOURCE $(git rev-parse HEAD)"
41say "COMPILER $OMC sha256=$pin"
42say "VALIDATOR $(command -v "$SPIRV_VAL") $("$SPIRV_VAL" --version 2>&1 | tr '\n' ' ')"
43say "HOST_BUILD $("$CC" --version | sed -n 1p) flags=${VULKAN_CFLAGS:-} libs=${VULKAN_LIBS:--lvulkan} sha256=$(sha256sum "$H" | cut -d ' ' -f 1)"
44say "LVP_ICD $LVP_ICD sha256=$(sha256sum "$LVP_ICD" | cut -d ' ' -f 1)"
45if command -v dpkg-query >/dev/null; then
46 say "PACKAGES $(dpkg-query -W -f '${Package}=${Version} ' libvulkan1 mesa-vulkan-drivers 2>/dev/null || :)"
47fi
48say "PLATFORM $(uname -srm)"
49nice -n 19 "$OMC" < seed/spirv/vkspirv.om > "$B/vkspirv" 2> "$B/compile.err"
50[ ! -s "$B/compile.err" ] || fail 'translator compiler stderr'
51chmod +x "$B/vkspirv"
52validate() {
53 "$SPIRV_VAL" --target-env vulkan1.3 "$1" > "$1.val.log" 2>&1 ||
54 { cat "$1.val.log"; fail "spirv-val rejected $1"; }
55 validated=$((validated+1))
56}
57modules=0; deterministic=0; validated=0
58translate() {
59 id=$1; source=$2
60 [ ! -e "$B/$id.source" ] || fail "duplicate unit id $id"
61 { printf 'ir\n'; cat "$source"; } > "$B/$id.input"
62 nice -n 19 "$OMC" < "$B/$id.input" > "$B/$id.ir" || fail "$id IR compile exited $?"
63 nice -n 19 "$B/vkspirv" < "$B/$id.ir" > "$B/$id.spv" 2> "$B/$id.translate.err" ||
64 fail "$id translator exited $?"
65 [ ! -s "$B/$id.translate.err" ] || fail "$id translator stderr"
66 nice -n 19 "$B/vkspirv" < "$B/$id.ir" > "$B/$id.again.spv" || fail "$id translator rerun exited $?"
67 modules=$((modules+1))
68 cmp "$B/$id.spv" "$B/$id.again.spv" || fail "$id nondeterministic"
69 deterministic=$((deterministic+1))
70 validate "$B/$id.spv"
71 printf '%s\n' "$source" > "$B/$id.source"
72 say "PASS $id deterministic spirv-val=vulkan1.3"
73}
74for source in tests/one_layer/omegese/dev/*.omegese seed/wasm/*.unit.om seed/spirv/*.unit.om; do
75 id=$(basename "$source" .omegese)
76 translate "${id%.unit.om}" "$source"
77done
78portlab=0
79if [ -f "$PORTLAB_DIR/gen.om" ] && [ -d "$PORTLAB_DIR/kernels" ]; then
80 portlab=1
81 say "PORTLAB_DIR $PORTLAB_DIR gen.om sha256=$(sha256sum "$PORTLAB_DIR/gen.om" | cut -d ' ' -f 1)"
82 for kernel in "$PORTLAB_DIR"/kernels/*.om; do
83 k=$(basename "$kernel" .om)
84 say "PORTLAB_KERNEL $k sha256=$(sha256sum "$kernel" | cut -d ' ' -f 1)"
85 cat "$PORTLAB_DIR/gen.om" "$kernel" > "$B/portlab-$k.unit.om"
86 translate "portlab-$k" "$B/portlab-$k.unit.om"
87 done
88fi
89
90# Validator negative controls on the vk fixture module. Patch positions are
91# located by word pattern, asserted, and the rejection reason is checked.
92od -An -v -t u4 -w4 "$B/vk.spv" | tr -d ' ' > "$B/vk.words"
93w=$(awk 'p3==262203 && p2==20 && p1==21 && $1==12 {print NR; exit} {p3=p2; p2=p1; p1=$1}' "$B/vk.words")
94[ -n "$w" ] || fail 'binding-0 OpVariable StorageBuffer not found'
95cp "$B/vk.spv" "$B/neg-storage.spv"
96printf '\002\000\000\000' | dd of="$B/neg-storage.spv" bs=4 seek=$((w-1)) conv=notrunc status=none
97if "$SPIRV_VAL" --target-env vulkan1.3 "$B/neg-storage.spv" > "$B/neg-storage.log" 2>&1; then
98 fail 'spirv-val accepted a StorageBuffer variable declared Uniform'
99fi
100grep -q 'Storage class must match result type storage class' "$B/neg-storage.log" ||
101 fail 'wrong-storage-class module rejected for an unrelated reason'
102say 'PASS spirv-val rejects wrong storage class (binding 0 StorageBuffer -> Uniform)'
103d=$(awk '{w[NR]=$1} END {for (i=1;i<=NR;i++) if (w[i]==262215 && w[i+1]==21 && w[i+2]==34 && w[i+3]==0) {print i; exit}}' "$B/vk.words")
104[ -n "$d" ] || fail 'OpDecorate DescriptorSet 0 on binding 0 not found'
105{ dd if="$B/vk.spv" bs=4 count=$((d-1)) status=none; dd if="$B/vk.spv" bs=4 skip=$((d+3)) status=none; } \
106 > "$B/neg-descset.spv"
107[ $(($(wc -c < "$B/vk.spv") - $(wc -c < "$B/neg-descset.spv"))) = 16 ] || fail 'descriptor-set cut size'
108if "$SPIRV_VAL" --target-env vulkan1.3 "$B/neg-descset.spv" > "$B/neg-descset.log" 2>&1; then
109 fail 'spirv-val accepted a StorageBuffer without DescriptorSet'
110fi
111grep -q 'missing DescriptorSet decoration' "$B/neg-descset.log" ||
112 fail 'dropped-DescriptorSet module rejected for an unrelated reason'
113say 'PASS spirv-val rejects dropped OpDecorate DescriptorSet (VUID-StandaloneSpirv-UniformConstant-06677)'
114
115# Host controls: inherited loader/driver/layer variables cannot select another
116# ICD; unconfigured and missing-manifest builds fail closed with empty stdout.
117printf '7 10\n' > "$B/avg.rows"
118env VK_ICD_FILENAMES=/nonexistent/vk-icd.json VK_DRIVER_FILES=/nonexistent/vk-drv.json \
119 VK_ADD_DRIVER_FILES=/nonexistent/vk-add.json VK_LAYER_PATH=/nonexistent/vk-layers \
120 VK_INSTANCE_LAYERS=VK_LAYER_untrusted VK_LOADER_DRIVERS_SELECT='*nvidia*' \
121 "$H" "$B/demo.spv" avgu32 2 < "$B/avg.rows" > "$B/host-environment.out" 2> "$B/host-environment.err" ||
122 fail 'inherited discovery changed the configured lavapipe oracle'
123printf '8 0\n' | cmp - "$B/host-environment.out" || fail 'environment control changed result'
124for control in unconfigured missing-manifest; do
125 definition='-DVKSPIRV_ICD=""'
126 [ "$control" = unconfigured ] || definition='-DVKSPIRV_ICD="/nonexistent/vkspirv/lvp_icd.json"'
127 hostbuild "$definition" "$B/host-$control" || fail "host $control control build failed"
128 set +e
129 (ulimit -c 0; "$B/host-$control" "$B/demo.spv" avgu32 2 < "$B/avg.rows") \
130 > "$B/host-$control.out" 2> "$B/host-$control.err"
131 rc=$?
132 set -e
133 [ "$rc" -ne 0 ] || fail "$control silently fell back to a working ICD"
134 [ ! -s "$B/host-$control.out" ] || fail "$control printed a result"
135 [ "$control" != unconfigured ] || [ "$rc" = 3 ] || fail "unconfigured host exited $rc rather than 3"
136done
137say 'PASS host controls: inherited discovery ignored; unconfigured and missing manifest fail closed'
138
139# Each table row gets a real native program calling the same function and inputs.
140# Expected line: the native 8-byte result as u64 decimal and its exit status;
141# a trapped row has no native result word and the Vulkan ABI writes 0.
142tab=$(printf '\t')
143canon() {
144 case "$1" in
145 bool:true) printf 1 ;;
146 bool:false) printf 0 ;;
147 *) printf '%u' "${1#*:}" ;;
148 esac
149}
150native_cases() {
151 table=$1; prefix=$2; i=0; traps=0; skipped=0
152 : > "$B/$prefix.rows"
153 while IFS="$tab" read -r unit function result typed status; do
154 case "$unit" in ''|'#'*) continue ;; esac
155 if [ "${unit#portlab-}" != "$unit" ] && [ "$portlab" = 0 ]; then
156 skipped=$((skipped+1)); continue
157 fi
158 i=$((i+1))
159 [ "$status" = 0 ] || traps=$((traps+1))
160 [ -f "$B/$unit.source" ] || fail "$table row $i names unknown unit $unit"
161 case_om=$B/$prefix-$i.om
162 cat "$(cat "$B/$unit.source")" > "$case_om"
163 cat >> "$case_om" <<'DUMP'
164global dumpbuf uchar 8
165fn ir_dump x ulong to void
166for j ulong 8
167put dumpbuf j uchar and shr x mul j 8 255
168end
169p = ulong 0
170while lt p 8 bound 8
171k = write 1 dumpbuf p sub ulong 8 p
172if le k 0
173exit 90
174end
175p = add p ulong k
176end
177end
178fn main to int
179DUMP
180 actual=; row=; np=0
181 if [ "$typed" != - ]; then
182 for arg in $(printf '%s' "$typed" | tr ',' ' '); do
183 type=${arg%%:*}; value=${arg#*:}
184 if [ "$type" = bool ]; then actual="$actual $value"
185 else actual="$actual $type $value"; fi
186 row="$row${row:+ }$(canon "$arg")"; np=$((np+1))
187 done
188 fi
189 case "$result" in
190 bool) printf 'if %s %s\nir_dump ulong 1\nelse\nir_dump ulong 0\nend\n' "$function" "$actual" ;;
191 void) printf '%s %s\nir_dump ulong 0\n' "$function" "$actual" ;;
192 byte|short|int|long) printf 'ir_dump bitcast ulong long %s %s\n' "$function" "$actual" ;;
193 uchar|ushort|uint|ulong) printf 'ir_dump ulong %s %s\n' "$function" "$actual" ;;
194 *) fail "unknown result $result" ;;
195 esac >> "$case_om"
196 printf 'ret 0\nend\n' >> "$case_om"
197 nice -n 19 "$OMC" < "$case_om" > "$B/$prefix-$i.native"
198 chmod +x "$B/$prefix-$i.native"
199 set +e
200 timeout 60 "$B/$prefix-$i.native" > "$B/$prefix-$i.out"
201 rc=$?
202 set -e
203 [ "$rc" = "$status" ] || fail "$prefix $i $unit.$function native exit $rc expected $status"
204 value=0
205 if [ "$rc" = 0 ]; then
206 [ "$(wc -c < "$B/$prefix-$i.out")" = 8 ] || fail "$prefix $i native dump is not 8 bytes"
207 value=$(od -An -t u8 "$B/$prefix-$i.out" | tr -d ' \n')
208 else
209 [ ! -s "$B/$prefix-$i.out" ] || fail "$prefix $i trapped native wrote a result"
210 fi
211 printf '%s\t%s\t%s\t%s %s\n' "$unit.$function" "$np" "$row" "$value" "$rc" >> "$B/$prefix.rows"
212 done < "$table"
213}
214# One dispatch per unit.function group (one invocation per row, in table order).
215# The concatenated Vulkan output must be byte-identical to the native lines.
216vk_cases() {
217 prefix=$1; module_override=${2:-}
218 : > "$B/$prefix.expected"; : > "$B/$prefix.vk"; groups=0
219 for key in $(cut -f1 "$B/$prefix.rows" | awk '!seen[$0]++'); do
220 unit=${key%.*}; function=${key##*.}
221 awk -F "$tab" -v k="$key" '$1 == k' "$B/$prefix.rows" > "$B/$prefix.$key.group"
222 np=$(sed -n 1p "$B/$prefix.$key.group" | cut -f2)
223 cut -f3 "$B/$prefix.$key.group" > "$B/$prefix.$key.in"
224 cut -f4 "$B/$prefix.$key.group" > "$B/$prefix.$key.expected"
225 cat "$B/$prefix.$key.expected" >> "$B/$prefix.expected"
226 module=$B/$unit.spv
227 [ -z "$module_override" ] || [ "$unit" != mutant ] || module=$module_override
228 nice -n 19 "$H" "$module" "$function" "$np" < "$B/$prefix.$key.in" \
229 >> "$B/$prefix.vk" 2> "$B/$prefix.$key.err" ||
230 { cat "$B/$prefix.$key.err"; fail "$prefix $key Vulkan run exited $?"; }
231 groups=$((groups+1))
232 [ -n "$module_override" ] ||
233 printf '%s\t%s\t%s\t%s\t%s\tmatch\n' "$unit.spv" "$function" "$np" \
234 "$prefix.$key.in" "$prefix.$key.expected" >> "$B/replay.tsv"
235 done
236}
237: > "$B/replay.tsv"
238native_cases seed/wasm/cases.tsv case
239[ "$i" = 129 ] || fail "seed/wasm/cases.tsv denominator is $i, expected 129"
240cases=$i; case_traps=$traps
241native_cases seed/spirv/demo.tsv demo; demo_cases=$i
242native_cases seed/spirv/regression.tsv regression; regression_cases=$i
243native_cases seed/spirv/vk-regression.tsv vkreg
244vk_rows=$i; vk_traps=$traps; vk_skipped=$skipped
245say "PASS native dumps cases=$cases traps=$case_traps demo=$demo_cases regression=$regression_cases vk=$vk_rows vk_traps=$vk_traps"
246vk_cases case
247say "RUNTIME $(grep -h 'vk-host: VK_ICD\|vk-host: device' "$B"/case.*.err | sort -u | tr '\n' ' ')"
248cmp "$B/case.expected" "$B/case.vk" || fail 'seed/wasm/cases.tsv Vulkan output differs from native'
249[ "$(wc -l < "$B/case.vk")" = "$cases" ] || fail 'cases.tsv row count differs'
250say "PASS cases.tsv lavapipe == native rows=$cases dispatches=$groups"
251for t in demo regression vkreg; do
252 vk_cases "$t"
253 cmp "$B/$t.expected" "$B/$t.vk" || fail "$t Vulkan output differs from native"
254 say "PASS $t lavapipe == native rows=$(wc -l < "$B/$t.vk") dispatches=$groups"
255done
256
257# Opcode mutant: BIN ADD -> SUB in the mutant fixture IR (offsets 38,39 asserted),
258# translated, validated and run in place of the baseline; exactly the mutadd
259# rows must mismatch, so the comparison provably catches a wrong opcode.
260[ "$(od -An -j 38 -N 2 -t u1 "$B/mutant.ir" | tr -s ' ' | tr -d '\n')" = ' 3 1' ] || fail 'mutant IR layout changed'
261cp "$B/mutant.ir" "$B/mutant-flipped.ir"
262printf '\002' | dd of="$B/mutant-flipped.ir" bs=1 seek=39 conv=notrunc status=none
263"$B/vkspirv" < "$B/mutant-flipped.ir" > "$B/mutant-flipped.spv" || fail "mutant translator exited $?"
264cmp -s "$B/mutant.spv" "$B/mutant-flipped.spv" && fail 'mutant IR byte did not change the module'
265validate "$B/mutant-flipped.spv"
266vk_cases case "$B/mutant-flipped.spv"
267mism=$(paste -d '|' "$B/case.expected" "$B/case.vk" | awk -F '|' '$1 != $2' | wc -l)
268mutrows=$(grep -c '^mutant\.' "$B/case.rows" || :)
269[ "$mism" -ge 1 ] || fail 'mutated opcode produced no mismatch'
270[ "$(paste "$B/case.rows" "$B/case.vk" | awk -F "$tab" '$4 != $5 {print $1}' | sort -u)" = mutant.mutadd ] ||
271 fail 'mutant mismatch outside mutant.mutadd'
272if cmp -s "$B/case.expected" "$B/case.vk"; then fail 'gate comparison accepted the mutant'; fi
273printf 'mutant-flipped.spv\tmutadd\t2\tcase.mutant.mutadd.in\tcase.mutant.mutadd.expected\tmismatch\n' >> "$B/replay.tsv"
274[ "$(sed -n 1p "$B/case.mutant.mutadd.group" | cut -f2)" = 2 ] || fail 'mutadd arity changed'
275say "PASS opcode mutant add->sub caught: mismatched_rows=$mism of mutant_rows=$mutrows (all mutant.mutadd)"
276
277# Refusals: invalid IR is rejected with a named class and empty stdout.
278refusals=0
279refusefile() {
280 name=$1; code=$2; class=$3
281 set +e
282 "$B/vkspirv" < "$B/$name.ir" > "$B/$name.refused" 2> "$B/$name.err"
283 rc=$?
284 set -e
285 [ "$rc" = "$code" ] || fail "$name exit $rc expected $code"
286 [ ! -s "$B/$name.refused" ] || fail "$name emitted partial module"
287 printf 'vkspirv: %s\n' "$class" | cmp - "$B/$name.err" || fail "$name wrong refusal name"
288 refusals=$((refusals+1))
289 say "PASS $name $class exit=$rc stdout=empty"
290}
291bytecase() {
292 cp "$B/mutant.ir" "$B/$1.ir"
293 printf '%b' "$3" | dd of="$B/$1.ir" bs=1 seek="$2" conv=notrunc status=none
294 refusefile "$1" "$4" "$5"
295}
296bytecase bad-magic 0 '\130' 20 MAGIC
297bytecase version2 7 '\002' 21 VERSION
298bytecase unsupported-op 38 '\007' 24 UNSUPPORTED_OP
299bytecase unsupported-tag 18 '\012' 25 UNSUPPORTED_TAG
300bytecase undefined-register 42 '\002' 26 INVALID
301size=$(wc -c < "$B/mutant.ir")
302dd if="$B/mutant.ir" of="$B/truncated.ir" bs=1 count=$((size-1)) status=none
303refusefile truncated 22 TRUNCATED
304cp "$B/mutant.ir" "$B/trailing.ir"
305printf x >> "$B/trailing.ir"
306refusefile trailing 27 TRAILING
307
308# A valid OSC CFG may number a dominator after its dominated block: 0 -> 2 -> 1,
309# void return in block 1. The dispatcher must not depend on block order.
310printf 'OSC1IR\000\001\001\000\005reord\000\000\000\000\003\000' > "$B/reordered.ir"
311printf '\000\000\000\000\001\000\000\000\001\000\000\000\001\000\000\000\002\000\000\000\001\000\000\000' >> "$B/reordered.ir"
312printf '\003\000\000\000\015\002\000\017\377\377\015\001\000\000\000\000\000' >> "$B/reordered.ir"
313"$B/vkspirv" < "$B/reordered.ir" > "$B/reordered.spv" || fail "reordered translator exited $?"
314"$B/vkspirv" < "$B/reordered.ir" > "$B/reordered.again.spv"
315cmp "$B/reordered.spv" "$B/reordered.again.spv" || fail 'reordered CFG nondeterministic'
316modules=$((modules+1)); deterministic=$((deterministic+1))
317validate "$B/reordered.spv"
318printf '\n' | "$H" "$B/reordered.spv" reord 0 > "$B/reordered.out" 2> "$B/reordered.err" ||
319 fail 'reordered CFG lavapipe execution failed'
320printf '0 0\n' | cmp - "$B/reordered.out" || fail 'reordered CFG result differs'
321say 'PASS reordered CFG 0->2->1 deterministic validated lavapipe result=0 status=0'
322
323# Vector phase: vecadd and saxpy over 4096 invocations (64 workgroups), and a
324# two-stage reduce: 4096 rsum partials of 64 generated u32 elements, combined
325# by a vadd tree, one dispatch per level, against the native sequential sum.
326N=4096; SEED=99
327vecprog() {
328 name=$1; shift
329 { cat seed/spirv/vk.unit.om seed/spirv/vk-native.om; printf 'fn main to int\n'; cat; printf 'vkflush\nret 0\nend\n'; } \
330 > "$B/$name-native.om"
331 nice -n 19 "$OMC" < "$B/$name-native.om" > "$B/$name-native" || fail "$name native compile"
332 chmod +x "$B/$name-native"
333 timeout 120 "$B/$name-native" > "$B/$name.native" || fail "$name native run exited $?"
334}
335vecprog vadd <<EOF
336for i ulong $N
337a = mix i
338b = mix add i $N
339vkword a
340vkword b
341vkword vadd a b
342vklast 0
343end
344EOF
345vecprog saxpy <<EOF
346for i ulong $N
347a = sub long and mix i 2097151 long 1048576
348x = sub long and mix add i $N 2097151 long 1048576
349y = sub long and mix add i $((2*N)) 1099511627775 long 549755813888
350vkword bitcast ulong a
351vkword bitcast ulong x
352vkword bitcast ulong y
353vkword bitcast ulong saxpy a x y
354vklast 0
355end
356EOF
357vecprog rsum <<EOF
358for i ulong $N
359vkword $SEED
360vkword mul i 64
361vkword 64
362vkword rsum $SEED mul i 64 64
363vklast 0
364end
365EOF
366vecprog total <<EOF
367vkword rsum $SEED 0 $((N*64))
368vklast 0
369EOF
370for k in vadd:2 saxpy:3 rsum:3; do
371 name=${k%:*}; np=${k#*:}
372 [ "$(wc -l < "$B/$name.native")" = $N ] || fail "$name native row count"
373 cut -d ' ' -f "1-$np" "$B/$name.native" > "$B/$name.in"
374 cut -d ' ' -f "$((np+1))-" "$B/$name.native" > "$B/$name.expected"
375 nice -n 19 "$H" "$B/vk.spv" "$name" "$np" < "$B/$name.in" > "$B/$name.vk" 2> "$B/$name.err" ||
376 { cat "$B/$name.err"; fail "$name Vulkan run exited $?"; }
377 cmp "$B/$name.expected" "$B/$name.vk" || fail "$name Vulkan output differs from native"
378 printf 'vk.spv\t%s\t%s\t%s.in\t%s.expected\tmatch\n' "$name" "$np" "$name" "$name" >> "$B/replay.tsv"
379 say "PASS $name lavapipe == native invocations=$N $(grep 'workgroups=' "$B/$name.err" | sed 's/^vk-host: //')"
380done
381cp "$B/rsum.vk" "$B/level-0.vk"; level=0; rows=$N
382while [ "$rows" -gt 1 ]; do
383 [ $((rows % 2)) = 0 ] || fail "tree level $level has odd row count $rows"
384 awk '$2 != 0 {exit 1}' "$B/level-$level.vk" || fail "tree level $level carried a trap status"
385 cut -d ' ' -f 1 "$B/level-$level.vk" | paste -d ' ' - - > "$B/level-$((level+1)).in"
386 nice -n 19 "$H" "$B/vk.spv" vadd 2 < "$B/level-$((level+1)).in" > "$B/level-$((level+1)).vk" \
387 2> "$B/level-$((level+1)).err" || fail "tree level $((level+1)) Vulkan run exited $?"
388 level=$((level+1)); rows=$((rows/2))
389done
390for l in $(seq 1 "$level"); do
391 printf 'vk.spv\tvadd\t2\tlevel-%s.in\tlevel-%s.vk\tmatch\n' "$l" "$l" >> "$B/replay.tsv"
392done
393cmp "$B/total.native" "$B/level-$level.vk" || fail 'tree reduce total differs from native sequential sum'
394say "PASS reduce stage1=$N partials tree_levels=$level total=$(cut -d ' ' -f 1 "$B/total.native") lavapipe == native"
395
396say "SUMMARY modules=$modules deterministic=$deterministic validated=$validated cases=$cases demo=$demo_cases regression=$regression_cases vk_rows=$vk_rows vk_traps=$vk_traps refusals=$refusals validator_negatives=2 mutant=caught"
397sha256sum seed/spirv/vkspirv.om "$B/vkspirv" seed/spirv/gate-vkspirv.sh seed/spirv/vk-host.c "$H" \
398 seed/spirv/vk-regression.tsv seed/spirv/vk.unit.om seed/spirv/vk-native.om \
399 seed/wasm/cases.tsv seed/spirv/demo.tsv seed/spirv/regression.tsv | tee -a "$B/gate.log"
400[ "$portlab" = 1 ] || notrun "portlab rows=$vk_skipped (PORTLAB_DIR $PORTLAB_DIR missing gen.om/kernels)"
401say "PASS VKSPIRV lavapipe GLCompute parity modules=$validated rows=$((cases+demo_cases+regression_cases+vk_rows)) invocations_vector=$((3*N))"