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
omega-mv / seed / spirv / gate-vkspirv.sh
| 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. |
| 10 | set -eu |
| 11 | cd "$(dirname "$0")/../.." |
| 12 | B=build/seed/vkspirv |
| 13 | mkdir -p "$B" |
| 14 | find "$B" -mindepth 1 -maxdepth 1 -exec rm -rf {} + |
| 15 | : > "$B/gate.log" |
| 16 | say() { printf '%s\n' "$*" | tee -a "$B/gate.log"; } |
| 17 | fail() { say "FAIL $*"; exit 1; } |
| 18 | notrun() { say "NOT_RUN $*"; exit 3; } |
| 19 | [ "$(uname -m)" = aarch64 ] || notrun 'requires AArch64 Linux' |
| 20 | OMC=${OMC:-seed/out/omc} |
| 21 | SPIRV_VAL=${SPIRV_VAL:-spirv-val} |
| 22 | LVP_ICD=${LVP_ICD:-/usr/share/vulkan/icd.d/lvp_icd.json} |
| 23 | PORTLAB_DIR=${PORTLAB_DIR:-bench/portlab} |
| 24 | CC=${CC:-cc} |
| 25 | command -v "$SPIRV_VAL" >/dev/null || notrun "requires spirv-val ($SPIRV_VAL)" |
| 26 | command -v "$CC" >/dev/null || notrun "requires a C compiler ($CC) for the interim Vulkan host" |
| 27 | case "$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" |
| 29 | pin=26540e6de62402d5784b30b24d7c6faae488137c1f8a4b3e784fd0b5d5528991 |
| 30 | [ -f "$OMC" ] || fail "compiler $OMC missing" |
| 31 | [ "$(sha256sum "$OMC" | cut -d ' ' -f 1)" = "$pin" ] || fail 'compiler pin differs' |
| 32 | hostbuild() { |
| 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 | } |
| 37 | hostbuild "-DVKSPIRV_ICD=\"$LVP_ICD\"" "$B/vk-host" || |
| 38 | { cat "$B/vk-host.build.log"; fail 'Vulkan host build failed'; } |
| 39 | H=$B/vk-host |
| 40 | say "SOURCE $(git rev-parse HEAD)" |
| 41 | say "COMPILER $OMC sha256=$pin" |
| 42 | say "VALIDATOR $(command -v "$SPIRV_VAL") $("$SPIRV_VAL" --version 2>&1 | tr '\n' ' ')" |
| 43 | say "HOST_BUILD $("$CC" --version | sed -n 1p) flags=${VULKAN_CFLAGS:-} libs=${VULKAN_LIBS:--lvulkan} sha256=$(sha256sum "$H" | cut -d ' ' -f 1)" |
| 44 | say "LVP_ICD $LVP_ICD sha256=$(sha256sum "$LVP_ICD" | cut -d ' ' -f 1)" |
| 45 | if command -v dpkg-query >/dev/null; then |
| 46 | say "PACKAGES $(dpkg-query -W -f '${Package}=${Version} ' libvulkan1 mesa-vulkan-drivers 2>/dev/null || :)" |
| 47 | fi |
| 48 | say "PLATFORM $(uname -srm)" |
| 49 | nice -n 19 "$OMC" < seed/spirv/vkspirv.om > "$B/vkspirv" 2> "$B/compile.err" |
| 50 | [ ! -s "$B/compile.err" ] || fail 'translator compiler stderr' |
| 51 | chmod +x "$B/vkspirv" |
| 52 | validate() { |
| 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 | } |
| 57 | modules=0; deterministic=0; validated=0 |
| 58 | translate() { |
| 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 | } |
| 74 | for 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" |
| 77 | done |
| 78 | portlab=0 |
| 79 | if [ -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 |
| 88 | fi |
| 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. |
| 92 | od -An -v -t u4 -w4 "$B/vk.spv" | tr -d ' ' > "$B/vk.words" |
| 93 | w=$(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' |
| 95 | cp "$B/vk.spv" "$B/neg-storage.spv" |
| 96 | printf '\002\000\000\000' | dd of="$B/neg-storage.spv" bs=4 seek=$((w-1)) conv=notrunc status=none |
| 97 | if "$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' |
| 99 | fi |
| 100 | grep -q 'Storage class must match result type storage class' "$B/neg-storage.log" || |
| 101 | fail 'wrong-storage-class module rejected for an unrelated reason' |
| 102 | say 'PASS spirv-val rejects wrong storage class (binding 0 StorageBuffer -> Uniform)' |
| 103 | d=$(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' |
| 108 | if "$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' |
| 110 | fi |
| 111 | grep -q 'missing DescriptorSet decoration' "$B/neg-descset.log" || |
| 112 | fail 'dropped-DescriptorSet module rejected for an unrelated reason' |
| 113 | say '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. |
| 117 | printf '7 10\n' > "$B/avg.rows" |
| 118 | env 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' |
| 123 | printf '8 0\n' | cmp - "$B/host-environment.out" || fail 'environment control changed result' |
| 124 | for 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" |
| 136 | done |
| 137 | say '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. |
| 142 | tab=$(printf '\t') |
| 143 | canon() { |
| 144 | case "$1" in |
| 145 | bool:true) printf 1 ;; |
| 146 | bool:false) printf 0 ;; |
| 147 | *) printf '%u' "${1#*:}" ;; |
| 148 | esac |
| 149 | } |
| 150 | native_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' |
| 164 | global dumpbuf uchar 8 |
| 165 | fn ir_dump x ulong to void |
| 166 | for j ulong 8 |
| 167 | put dumpbuf j uchar and shr x mul j 8 255 |
| 168 | end |
| 169 | p = ulong 0 |
| 170 | while lt p 8 bound 8 |
| 171 | k = write 1 dumpbuf p sub ulong 8 p |
| 172 | if le k 0 |
| 173 | exit 90 |
| 174 | end |
| 175 | p = add p ulong k |
| 176 | end |
| 177 | end |
| 178 | fn main to int |
| 179 | DUMP |
| 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. |
| 216 | vk_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" |
| 238 | native_cases seed/wasm/cases.tsv case |
| 239 | [ "$i" = 129 ] || fail "seed/wasm/cases.tsv denominator is $i, expected 129" |
| 240 | cases=$i; case_traps=$traps |
| 241 | native_cases seed/spirv/demo.tsv demo; demo_cases=$i |
| 242 | native_cases seed/spirv/regression.tsv regression; regression_cases=$i |
| 243 | native_cases seed/spirv/vk-regression.tsv vkreg |
| 244 | vk_rows=$i; vk_traps=$traps; vk_skipped=$skipped |
| 245 | say "PASS native dumps cases=$cases traps=$case_traps demo=$demo_cases regression=$regression_cases vk=$vk_rows vk_traps=$vk_traps" |
| 246 | vk_cases case |
| 247 | say "RUNTIME $(grep -h 'vk-host: VK_ICD\|vk-host: device' "$B"/case.*.err | sort -u | tr '\n' ' ')" |
| 248 | cmp "$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' |
| 250 | say "PASS cases.tsv lavapipe == native rows=$cases dispatches=$groups" |
| 251 | for 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" |
| 255 | done |
| 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' |
| 261 | cp "$B/mutant.ir" "$B/mutant-flipped.ir" |
| 262 | printf '\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 $?" |
| 264 | cmp -s "$B/mutant.spv" "$B/mutant-flipped.spv" && fail 'mutant IR byte did not change the module' |
| 265 | validate "$B/mutant-flipped.spv" |
| 266 | vk_cases case "$B/mutant-flipped.spv" |
| 267 | mism=$(paste -d '|' "$B/case.expected" "$B/case.vk" | awk -F '|' '$1 != $2' | wc -l) |
| 268 | mutrows=$(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' |
| 272 | if cmp -s "$B/case.expected" "$B/case.vk"; then fail 'gate comparison accepted the mutant'; fi |
| 273 | printf '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' |
| 275 | say "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. |
| 278 | refusals=0 |
| 279 | refusefile() { |
| 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 | } |
| 291 | bytecase() { |
| 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 | } |
| 296 | bytecase bad-magic 0 '\130' 20 MAGIC |
| 297 | bytecase version2 7 '\002' 21 VERSION |
| 298 | bytecase unsupported-op 38 '\007' 24 UNSUPPORTED_OP |
| 299 | bytecase unsupported-tag 18 '\012' 25 UNSUPPORTED_TAG |
| 300 | bytecase undefined-register 42 '\002' 26 INVALID |
| 301 | size=$(wc -c < "$B/mutant.ir") |
| 302 | dd if="$B/mutant.ir" of="$B/truncated.ir" bs=1 count=$((size-1)) status=none |
| 303 | refusefile truncated 22 TRUNCATED |
| 304 | cp "$B/mutant.ir" "$B/trailing.ir" |
| 305 | printf x >> "$B/trailing.ir" |
| 306 | refusefile 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. |
| 310 | printf 'OSC1IR\000\001\001\000\005reord\000\000\000\000\003\000' > "$B/reordered.ir" |
| 311 | printf '\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" |
| 312 | printf '\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" |
| 315 | cmp "$B/reordered.spv" "$B/reordered.again.spv" || fail 'reordered CFG nondeterministic' |
| 316 | modules=$((modules+1)); deterministic=$((deterministic+1)) |
| 317 | validate "$B/reordered.spv" |
| 318 | printf '\n' | "$H" "$B/reordered.spv" reord 0 > "$B/reordered.out" 2> "$B/reordered.err" || |
| 319 | fail 'reordered CFG lavapipe execution failed' |
| 320 | printf '0 0\n' | cmp - "$B/reordered.out" || fail 'reordered CFG result differs' |
| 321 | say '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. |
| 326 | N=4096; SEED=99 |
| 327 | vecprog() { |
| 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 | } |
| 335 | vecprog vadd <<EOF |
| 336 | for i ulong $N |
| 337 | a = mix i |
| 338 | b = mix add i $N |
| 339 | vkword a |
| 340 | vkword b |
| 341 | vkword vadd a b |
| 342 | vklast 0 |
| 343 | end |
| 344 | EOF |
| 345 | vecprog saxpy <<EOF |
| 346 | for i ulong $N |
| 347 | a = sub long and mix i 2097151 long 1048576 |
| 348 | x = sub long and mix add i $N 2097151 long 1048576 |
| 349 | y = sub long and mix add i $((2*N)) 1099511627775 long 549755813888 |
| 350 | vkword bitcast ulong a |
| 351 | vkword bitcast ulong x |
| 352 | vkword bitcast ulong y |
| 353 | vkword bitcast ulong saxpy a x y |
| 354 | vklast 0 |
| 355 | end |
| 356 | EOF |
| 357 | vecprog rsum <<EOF |
| 358 | for i ulong $N |
| 359 | vkword $SEED |
| 360 | vkword mul i 64 |
| 361 | vkword 64 |
| 362 | vkword rsum $SEED mul i 64 64 |
| 363 | vklast 0 |
| 364 | end |
| 365 | EOF |
| 366 | vecprog total <<EOF |
| 367 | vkword rsum $SEED 0 $((N*64)) |
| 368 | vklast 0 |
| 369 | EOF |
| 370 | for 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: //')" |
| 380 | done |
| 381 | cp "$B/rsum.vk" "$B/level-0.vk"; level=0; rows=$N |
| 382 | while [ "$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)) |
| 389 | done |
| 390 | for 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" |
| 392 | done |
| 393 | cmp "$B/total.native" "$B/level-$level.vk" || fail 'tree reduce total differs from native sequential sum' |
| 394 | say "PASS reduce stage1=$N partials tree_levels=$level total=$(cut -d ' ' -f 1 "$B/total.native") lavapipe == native" |
| 395 | |
| 396 | say "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" |
| 397 | sha256sum 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)" |
| 401 | say "PASS VKSPIRV lavapipe GLCompute parity modules=$validated rows=$((cases+demo_cases+regression_cases+vk_rows)) invocations_vector=$((3*N))" |