diff --git a/Cargo.lock b/Cargo.lock index f43e2d3..a84b46d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -113,6 +113,7 @@ version = "0.1.0" name = "xenora-semantic-review" version = "0.1.0" dependencies = [ + "xenora-metal", "xenora-ref", "xenora-shader", ] diff --git a/benchmarks/results/apple-m5/run-1795352394/metadata.json b/benchmarks/results/apple-m5/run-1795352394/metadata.json new file mode 100644 index 0000000..5fde29e --- /dev/null +++ b/benchmarks/results/apple-m5/run-1795352394/metadata.json @@ -0,0 +1,18 @@ +{ + "run_id": "run-1795352394", + "timestamp": "unix:1795352394", + "device": "Apple M5", + "host_arch": "aarch64", + "os_version": "27.3", + "os_build": "26C5047e", + "rustc": "rustc 1.100.0 (0ef1bc386 2026-11-09) (Homebrew)", + "xcode": "Xcode 27.2", + "commit": "cc0daa79e63c468e748f0333bd1314224752893a", + "profile": "release", + "api_validation": "0", + "shader_validation": "0", + "power": "AC Power", + "thermal": "no warnings recorded", + "reps": 21, + "warmup": 2 +} diff --git a/benchmarks/results/apple-m5/run-1795352394/report.md b/benchmarks/results/apple-m5/run-1795352394/report.md new file mode 100644 index 0000000..8ef253b --- /dev/null +++ b/benchmarks/results/apple-m5/run-1795352394/report.md @@ -0,0 +1,51 @@ +# Xenora benchmark report + +Generated by `xenora-bench`. Every timed fixture passed its correctness test in this run. Timings are single command-buffer samples; see `docs/testing/benchmarks.md` for the protocol. + +## Environment + +| Field | Value | +| --- | --- | +| Device | Apple M5 | +| Host arch | aarch64 | +| macOS | 27.3 | +| Build | 26C5047e | +| Rust | rustc 1.100.0 (0ef1bc386 2026-11-09) (Homebrew) | +| Xcode | Xcode 27.2 | +| Commit | cc0daa79e63c468e748f0333bd1314224752893a | +| Profile | release | +| API validation | 0 | +| Shader validation | 0 | +| Power source | AC Power | +| Thermal | no warnings recorded | +| Repetitions | 21 measured, 2 warm-up | + +## Coverage + +| Fixture | Stage | Source | Status | +| --- | --- | --- | --- | +| add | compute | translated-rdna | benchmarked | +| bitwise-branch | compute | translated-rdna | benchmarked | +| float-exact | compute | translated-rdna | benchmarked | + +## Timings + +Durations in microseconds. `compile` is the Rust decode/IR/MSL pipeline, `library` and `pipeline` are Metal compilation stages, `gpu` is the command-buffer GPU time, and `host` is the wall time of one dispatch. Values are medians with interquartile range; minimum and maximum are in `results.json`. + +| Fixture | Words | compile | library | pipeline | gpu | host | IQR(gpu) | zero-gpu | +| --- | --- | --- | --- | --- | --- | --- | --- | --- | +| add | 4 | 5.08 | 13.42 | 32.50 | 87.62 | 375.33 | 103.62 | 0% | +| add | 64 | 4.42 | 11.79 | 28.25 | 3.63 | 407.79 | 36.54 | 0% | +| add | 256 | 4.17 | 10.96 | 26.79 | 1.38 | 231.25 | 2.25 | 0% | +| add | 1024 | 4.25 | 11.17 | 26.54 | 1.46 | 218.25 | 0.08 | 0% | +| add | 4096 | 4.46 | 11.67 | 27.62 | 3.38 | 237.71 | 17.63 | 0% | +| bitwise-branch | 4 | 7.71 | 11.04 | 26.29 | 1.33 | 214.29 | 0.08 | 0% | +| bitwise-branch | 64 | 8.71 | 11.92 | 27.83 | 2.08 | 213.12 | 4.25 | 0% | +| bitwise-branch | 256 | 7.58 | 10.71 | 26.00 | 1.37 | 216.38 | 0.04 | 0% | +| bitwise-branch | 1024 | 7.62 | 10.67 | 26.08 | 1.42 | 212.58 | 0.08 | 0% | +| bitwise-branch | 4096 | 7.62 | 11.12 | 26.58 | 1.58 | 236.17 | 25.75 | 0% | +| float-exact | 4 | 8.54 | 10.88 | 25.62 | 1.33 | 212.00 | 0.08 | 0% | +| float-exact | 64 | 8.71 | 11.00 | 26.21 | 1.38 | 215.33 | 1.25 | 0% | +| float-exact | 256 | 8.62 | 10.83 | 25.83 | 1.37 | 213.88 | 0.08 | 0% | +| float-exact | 1024 | 8.54 | 11.00 | 25.92 | 1.50 | 213.67 | 0.04 | 0% | +| float-exact | 4096 | 8.54 | 10.88 | 26.04 | 1.50 | 228.00 | 30.25 | 0% | diff --git a/benchmarks/results/apple-m5/run-1795352394/results.json b/benchmarks/results/apple-m5/run-1795352394/results.json new file mode 100644 index 0000000..ccf6638 --- /dev/null +++ b/benchmarks/results/apple-m5/run-1795352394/results.json @@ -0,0 +1,46 @@ +{ + "fixtures": [ + { + "name": "add", + "stage": "compute", + "source": "translated-rdna", + "status": "benchmarked", + "reason": "", + "sizes": [ + { "words": 4, "compile": { "median": 5.083000000e-6, "min": 4.167000000e-6, "max": 4.425000000e-5, "q1": 4.375000000e-6, "q3": 7.458000000e-6, "reps": 21 }, "library": { "median": 1.341700000e-5, "min": 1.087500000e-5, "max": 3.879200000e-5, "q1": 1.150000000e-5, "q3": 1.762500000e-5, "reps": 21 }, "pipeline": { "median": 3.250000000e-5, "min": 2.666700000e-5, "max": 5.920800000e-5, "q1": 2.979200000e-5, "q3": 4.262500000e-5, "reps": 21 }, "gpu": { "median": 8.762499965e-5, "min": 5.625000085e-6, "max": 2.230416667e-4, "q1": 1.562500074e-5, "q3": 1.192500004e-4, "reps": 21 }, "host": { "median": 3.753330000e-4, "min": 2.814590000e-4, "max": 5.746250000e-4, "q1": 3.609170000e-4, "q3": 4.326250000e-4, "reps": 21 }, "gpu_zero_fraction": 0.0000 }, + { "words": 64, "compile": { "median": 4.416000000e-6, "min": 4.083000000e-6, "max": 5.792000000e-6, "q1": 4.292000000e-6, "q3": 4.542000000e-6, "reps": 21 }, "library": { "median": 1.179100000e-5, "min": 1.075000000e-5, "max": 1.741600000e-5, "q1": 1.116700000e-5, "q3": 1.312500000e-5, "reps": 21 }, "pipeline": { "median": 2.825000000e-5, "min": 2.591700000e-5, "max": 3.758400000e-5, "q1": 2.770800000e-5, "q3": 3.100000000e-5, "reps": 21 }, "gpu": { "median": 3.625000318e-6, "min": 3.125000148e-6, "max": 3.708750000e-4, "q1": 3.208333510e-6, "q3": 3.974999981e-5, "reps": 21 }, "host": { "median": 4.077910000e-4, "min": 2.125000000e-4, "max": 8.305420000e-4, "q1": 3.319170000e-4, "q3": 4.473340000e-4, "reps": 21 }, "gpu_zero_fraction": 0.0000 }, + { "words": 256, "compile": { "median": 4.167000000e-6, "min": 4.083000000e-6, "max": 4.333000000e-6, "q1": 4.166000000e-6, "q3": 4.208000000e-6, "reps": 21 }, "library": { "median": 1.095800000e-5, "min": 1.054200000e-5, "max": 1.154200000e-5, "q1": 1.062500000e-5, "q3": 1.116600000e-5, "reps": 21 }, "pipeline": { "median": 2.679200000e-5, "min": 2.583400000e-5, "max": 3.391600000e-5, "q1": 2.612500000e-5, "q3": 2.716600000e-5, "reps": 21 }, "gpu": { "median": 1.375000465e-6, "min": 1.291666194e-6, "max": 5.875000170e-6, "q1": 1.374999556e-6, "q3": 3.625000318e-6, "reps": 21 }, "host": { "median": 2.312500000e-4, "min": 2.123750000e-4, "max": 7.405830000e-4, "q1": 2.190830000e-4, "q3": 6.997080000e-4, "reps": 21 }, "gpu_zero_fraction": 0.0000 }, + { "words": 1024, "compile": { "median": 4.250000000e-6, "min": 4.083000000e-6, "max": 6.292000000e-6, "q1": 4.167000000e-6, "q3": 4.333000000e-6, "reps": 21 }, "library": { "median": 1.116700000e-5, "min": 1.054200000e-5, "max": 1.583400000e-5, "q1": 1.075000000e-5, "q3": 1.133300000e-5, "reps": 21 }, "pipeline": { "median": 2.654200000e-5, "min": 2.566700000e-5, "max": 3.695800000e-5, "q1": 2.583300000e-5, "q3": 2.758300000e-5, "reps": 21 }, "gpu": { "median": 1.458333827e-6, "min": 1.375000465e-6, "max": 5.999999303e-6, "q1": 1.416667146e-6, "q3": 1.500000508e-6, "reps": 21 }, "host": { "median": 2.182500000e-4, "min": 2.122920000e-4, "max": 5.624590000e-4, "q1": 2.162090000e-4, "q3": 2.354590000e-4, "reps": 21 }, "gpu_zero_fraction": 0.0000 }, + { "words": 4096, "compile": { "median": 4.458000000e-6, "min": 4.125000000e-6, "max": 1.104100000e-5, "q1": 4.250000000e-6, "q3": 4.833000000e-6, "reps": 21 }, "library": { "median": 1.166700000e-5, "min": 1.083300000e-5, "max": 7.970800000e-5, "q1": 1.120900000e-5, "q3": 1.337500000e-5, "reps": 21 }, "pipeline": { "median": 2.762500000e-5, "min": 2.645800000e-5, "max": 7.595800000e-5, "q1": 2.683300000e-5, "q3": 3.045800000e-5, "reps": 21 }, "gpu": { "median": 3.375000233e-6, "min": 1.375000465e-6, "max": 3.787499918e-5, "q1": 1.499999598e-6, "q3": 1.912500011e-5, "reps": 21 }, "host": { "median": 2.377080000e-4, "min": 2.014170000e-4, "max": 5.690830000e-4, "q1": 2.298750000e-4, "q3": 3.332910000e-4, "reps": 21 }, "gpu_zero_fraction": 0.0000 } + ] + }, + { + "name": "bitwise-branch", + "stage": "compute", + "source": "translated-rdna", + "status": "benchmarked", + "reason": "", + "sizes": [ + { "words": 4, "compile": { "median": 7.709000000e-6, "min": 7.416000000e-6, "max": 1.133300000e-5, "q1": 7.542000000e-6, "q3": 8.083000000e-6, "reps": 21 }, "library": { "median": 1.104100000e-5, "min": 1.054100000e-5, "max": 1.454200000e-5, "q1": 1.079200000e-5, "q3": 1.112500000e-5, "reps": 21 }, "pipeline": { "median": 2.629200000e-5, "min": 2.554100000e-5, "max": 3.658400000e-5, "q1": 2.612500000e-5, "q3": 2.637500000e-5, "reps": 21 }, "gpu": { "median": 1.333332875e-6, "min": 1.291666194e-6, "max": 1.926666664e-4, "q1": 1.291667104e-6, "q3": 1.374999556e-6, "reps": 21 }, "host": { "median": 2.142920000e-4, "min": 2.040840000e-4, "max": 4.722500000e-4, "q1": 2.110840000e-4, "q3": 2.197500000e-4, "reps": 21 }, "gpu_zero_fraction": 0.0000 }, + { "words": 64, "compile": { "median": 8.708000000e-6, "min": 7.584000000e-6, "max": 4.979100000e-5, "q1": 7.834000000e-6, "q3": 1.245800000e-5, "reps": 21 }, "library": { "median": 1.191700000e-5, "min": 1.075000000e-5, "max": 7.475000000e-5, "q1": 1.141700000e-5, "q3": 1.362500000e-5, "reps": 21 }, "pipeline": { "median": 2.783400000e-5, "min": 2.591700000e-5, "max": 5.308300000e-5, "q1": 2.716700000e-5, "q3": 2.954100000e-5, "reps": 21 }, "gpu": { "median": 2.083333129e-6, "min": 1.249999514e-6, "max": 4.854166673e-5, "q1": 1.333333785e-6, "q3": 5.583333405e-6, "reps": 21 }, "host": { "median": 2.131250000e-4, "min": 1.608750000e-4, "max": 4.971250000e-4, "q1": 1.936660000e-4, "q3": 2.450420000e-4, "reps": 21 }, "gpu_zero_fraction": 0.0000 }, + { "words": 256, "compile": { "median": 7.583000000e-6, "min": 7.416000000e-6, "max": 7.750000000e-6, "q1": 7.500000000e-6, "q3": 7.625000000e-6, "reps": 21 }, "library": { "median": 1.070900000e-5, "min": 1.050000000e-5, "max": 1.104100000e-5, "q1": 1.062500000e-5, "q3": 1.079200000e-5, "reps": 21 }, "pipeline": { "median": 2.600000000e-5, "min": 2.541700000e-5, "max": 2.670800000e-5, "q1": 2.583300000e-5, "q3": 2.625000000e-5, "reps": 21 }, "gpu": { "median": 1.374999556e-6, "min": 1.291666194e-6, "max": 1.458333827e-6, "q1": 1.333332875e-6, "q3": 1.375000465e-6, "reps": 21 }, "host": { "median": 2.163750000e-4, "min": 2.042920000e-4, "max": 2.393750000e-4, "q1": 2.125830000e-4, "q3": 2.197080000e-4, "reps": 21 }, "gpu_zero_fraction": 0.0000 }, + { "words": 1024, "compile": { "median": 7.625000000e-6, "min": 7.500000000e-6, "max": 7.875000000e-6, "q1": 7.500000000e-6, "q3": 7.625000000e-6, "reps": 21 }, "library": { "median": 1.066700000e-5, "min": 1.050000000e-5, "max": 1.091700000e-5, "q1": 1.058400000e-5, "q3": 1.083400000e-5, "reps": 21 }, "pipeline": { "median": 2.608300000e-5, "min": 2.533300000e-5, "max": 3.291700000e-5, "q1": 2.558300000e-5, "q3": 2.620800000e-5, "reps": 21 }, "gpu": { "median": 1.416667146e-6, "min": 1.374999556e-6, "max": 9.749999663e-6, "q1": 1.375000465e-6, "q3": 1.458332918e-6, "reps": 21 }, "host": { "median": 2.125830000e-4, "min": 1.951250000e-4, "max": 4.068340000e-4, "q1": 2.102090000e-4, "q3": 2.148750000e-4, "reps": 21 }, "gpu_zero_fraction": 0.0000 }, + { "words": 4096, "compile": { "median": 7.625000000e-6, "min": 7.417000000e-6, "max": 3.583300000e-5, "q1": 7.584000000e-6, "q3": 8.375000000e-6, "reps": 21 }, "library": { "median": 1.112500000e-5, "min": 1.062500000e-5, "max": 4.820800000e-5, "q1": 1.079200000e-5, "q3": 1.212500000e-5, "reps": 21 }, "pipeline": { "median": 2.658400000e-5, "min": 2.570900000e-5, "max": 1.125830000e-4, "q1": 2.595800000e-5, "q3": 2.954200000e-5, "reps": 21 }, "gpu": { "median": 1.583332960e-6, "min": 1.374999556e-6, "max": 6.262500028e-5, "q1": 1.416667146e-6, "q3": 2.716666677e-5, "reps": 21 }, "host": { "median": 2.361670000e-4, "min": 1.970840000e-4, "max": 5.112080000e-4, "q1": 2.251670000e-4, "q3": 2.410000000e-4, "reps": 21 }, "gpu_zero_fraction": 0.0000 } + ] + }, + { + "name": "float-exact", + "stage": "compute", + "source": "translated-rdna", + "status": "benchmarked", + "reason": "", + "sizes": [ + { "words": 4, "compile": { "median": 8.542000000e-6, "min": 8.292000000e-6, "max": 1.233400000e-5, "q1": 8.417000000e-6, "q3": 8.875000000e-6, "reps": 21 }, "library": { "median": 1.087500000e-5, "min": 1.050000000e-5, "max": 1.500000000e-5, "q1": 1.079100000e-5, "q3": 1.120800000e-5, "reps": 21 }, "pipeline": { "median": 2.562500000e-5, "min": 2.520900000e-5, "max": 3.454100000e-5, "q1": 2.554200000e-5, "q3": 2.575000000e-5, "reps": 21 }, "gpu": { "median": 1.333333785e-6, "min": 1.291666194e-6, "max": 1.797083332e-4, "q1": 1.291667104e-6, "q3": 1.374999556e-6, "reps": 21 }, "host": { "median": 2.120000000e-4, "min": 2.052920000e-4, "max": 4.474160000e-4, "q1": 2.097500000e-4, "q3": 2.153330000e-4, "reps": 21 }, "gpu_zero_fraction": 0.0000 }, + { "words": 64, "compile": { "median": 8.708000000e-6, "min": 8.416000000e-6, "max": 3.125000000e-5, "q1": 8.500000000e-6, "q3": 9.625000000e-6, "reps": 21 }, "library": { "median": 1.100000000e-5, "min": 1.058400000e-5, "max": 5.441600000e-5, "q1": 1.075000000e-5, "q3": 1.225000000e-5, "reps": 21 }, "pipeline": { "median": 2.620800000e-5, "min": 2.516700000e-5, "max": 7.550000000e-5, "q1": 2.533300000e-5, "q3": 2.858300000e-5, "reps": 21 }, "gpu": { "median": 1.375000465e-6, "min": 1.291666194e-6, "max": 4.275000083e-5, "q1": 1.375000465e-6, "q3": 2.625000889e-6, "reps": 21 }, "host": { "median": 2.153330000e-4, "min": 1.642920000e-4, "max": 4.004580000e-4, "q1": 2.005830000e-4, "q3": 2.202080000e-4, "reps": 21 }, "gpu_zero_fraction": 0.0000 }, + { "words": 256, "compile": { "median": 8.625000000e-6, "min": 8.208000000e-6, "max": 8.750000000e-6, "q1": 8.459000000e-6, "q3": 8.667000000e-6, "reps": 21 }, "library": { "median": 1.083400000e-5, "min": 1.066700000e-5, "max": 1.120900000e-5, "q1": 1.075000000e-5, "q3": 1.104200000e-5, "reps": 21 }, "pipeline": { "median": 2.583300000e-5, "min": 2.504200000e-5, "max": 3.329200000e-5, "q1": 2.529100000e-5, "q3": 2.595900000e-5, "reps": 21 }, "gpu": { "median": 1.374999556e-6, "min": 1.291666194e-6, "max": 7.387500045e-5, "q1": 1.291666194e-6, "q3": 1.375000465e-6, "reps": 21 }, "host": { "median": 2.138750000e-4, "min": 1.780830000e-4, "max": 2.769590000e-4, "q1": 1.977920000e-4, "q3": 2.193750000e-4, "reps": 21 }, "gpu_zero_fraction": 0.0000 }, + { "words": 1024, "compile": { "median": 8.542000000e-6, "min": 8.292000000e-6, "max": 1.145900000e-5, "q1": 8.458000000e-6, "q3": 8.666000000e-6, "reps": 21 }, "library": { "median": 1.100000000e-5, "min": 1.062500000e-5, "max": 1.925000000e-5, "q1": 1.083400000e-5, "q3": 1.108300000e-5, "reps": 21 }, "pipeline": { "median": 2.591600000e-5, "min": 2.516700000e-5, "max": 3.541700000e-5, "q1": 2.579200000e-5, "q3": 2.612500000e-5, "reps": 21 }, "gpu": { "median": 1.499999598e-6, "min": 1.374999556e-6, "max": 1.624999641e-6, "q1": 1.458332918e-6, "q3": 1.500000508e-6, "reps": 21 }, "host": { "median": 2.136670000e-4, "min": 1.936670000e-4, "max": 4.228330000e-4, "q1": 2.092920000e-4, "q3": 2.170420000e-4, "reps": 21 }, "gpu_zero_fraction": 0.0000 }, + { "words": 4096, "compile": { "median": 8.542000000e-6, "min": 8.292000000e-6, "max": 1.158300000e-5, "q1": 8.459000000e-6, "q3": 8.750000000e-6, "reps": 21 }, "library": { "median": 1.087500000e-5, "min": 1.066700000e-5, "max": 3.562500000e-5, "q1": 1.083400000e-5, "q3": 1.145800000e-5, "reps": 21 }, "pipeline": { "median": 2.604200000e-5, "min": 2.508300000e-5, "max": 1.914590000e-4, "q1": 2.550000000e-5, "q3": 2.625000000e-5, "reps": 21 }, "gpu": { "median": 1.500000508e-6, "min": 1.416666237e-6, "max": 6.304166618e-5, "q1": 1.458332918e-6, "q3": 3.170833315e-5, "reps": 21 }, "host": { "median": 2.280000000e-4, "min": 1.988340000e-4, "max": 8.358750000e-4, "q1": 2.237090000e-4, "q3": 2.523330000e-4, "reps": 21 }, "gpu_zero_fraction": 0.0000 } + ] + } + ] +} diff --git a/docs/progress.md b/docs/progress.md index f70c6c2..e4520c3 100644 --- a/docs/progress.md +++ b/docs/progress.md @@ -25,8 +25,8 @@ The independent CPU validation tests are part of the workspace. The native suite ## Remaining work -1. G7 is the immediate priority. The historical source campaign at `a34dadc` reported 387 mutants. The targeted rerun and accounting rules are in [mutation testing](testing/mutation.md). Run the complete source campaign after survivor triage, then complete the semantic and oracle campaigns with R2. +1. G7 is the immediate priority. The historical source campaign at `a34dadc` reported 387 mutants. The targeted rerun and accounting rules are in [mutation testing](testing/mutation.md). Run the complete source campaign against the clean candidate, then run the separate semantic and oracle campaigns with R2. 2. G5–G6 require independent R2 validation against the candidate. The automated three-way comparison covers all 15 decoded forms. Reproduce with the LLVM command above. 3. G9 has three successful historical 601-second transcripts in `artifacts/g9/`. Record candidate scope, nightly version and individual process exit codes on the confirmation run. Run `scripts/fuzz.sh instruction_stream`, `scripts/fuzz.sh fixture` and `scripts/fuzz.sh reference` serially. -4. G10 has a tracked [battery run](../benchmarks/results/apple-m5/run-1795338391/report.md). AC measurements and full corpus and protocol coverage remain open. +4. G10 has a tracked [battery run](../benchmarks/results/apple-m5/run-1795338391/report.md). A second exploratory run used AC power. [Benchmark protocol and outstanding coverage](testing/benchmarks.md#exploratory-ac-run). 5. G11 remains open for objc2 SDK-derived binding redistribution and the pinned license inventory audit. See the [runtime redistribution review](licenses.md#runtime-redistribution-review). R1 also owns the claims, history and status audits. Both reviewers must review the final candidate. diff --git a/docs/testing/benchmarks.md b/docs/testing/benchmarks.md index 6c304b6..d355d04 100644 --- a/docs/testing/benchmarks.md +++ b/docs/testing/benchmarks.md @@ -79,3 +79,15 @@ The corpus currently covers three synthetic gfx1030 compute fixtures under the graphics stages, guest containers, Wave64 or divergence. Translation-versus-native baseline ratios are not reported because no hand-written native MSL baseline exists yet for these fixtures. + +## Exploratory AC run + +Run `1795352394` used the release harness built at `cc0daa7` on Apple M5, +with AC power confirmed before and after, 30 seconds between the build and +timing, two warmups, 21 measured repetitions per size and Metal validation +off. Neither thermal nor performance warnings were recorded by +`pmset -g therm`. All three declared translated fixtures passed their +correctness checks. G10 remains open for the full correctness corpus, +individual compiler stages and cold/warm timing, tool and capability metadata, +and noise-based variability reporting. See the +[generated report](../../benchmarks/results/apple-m5/run-1795352394/report.md). diff --git a/tests/mutation/README.md b/tests/mutation/README.md new file mode 100644 index 0000000..9081086 --- /dev/null +++ b/tests/mutation/README.md @@ -0,0 +1,42 @@ +# Native semantic mutation + +Run serially on the native Apple Silicon gate machine. + +```sh +CARGO_BUILD_JOBS=2 cargo run --locked -p xenora-semantic-review \ + --example semantic-mutation --features native-mutation +``` + +The runner checks the compiler's actual MSL against a reviewed straight-line +kernel before dispatching it. Each case compares the original reference and +Metal output with known answers derived from the synthetic ABI, integer +arithmetic and exact binary32 representation. The mutant is killed only if +Metal compiles it, runs it and reads back the correct number of words with at +least one changed value. Compilation, API, validation and deadline failures +end the campaign separately. The process exits 2 when a mutant survives. + +| Cases | Change | +|---|---| +| Load and store | Substitute a loaded zero or the wrong store value, keeping both addresses lane-indexed. | +| Vector moves and unsigned add | Change a literal by one, zero-extend inline `-1`, emit subtraction or select the wrong operand. | +| Bitwise AND and XOR | Substitute a different bitwise operator. | +| Scalar comparison and forward branches | Substitute the lowerer's actual output for the wrong SCC path or retarget the unconditional branch to the following instruction. | +| FP32 add and multiply | Substitute multiplication for addition or addition for multiplication on reviewed finite values. | + +The unsigned-add witness includes `u32::MAX`, so ordinary wraparound is +observable. Swapping operands in any supported binary operation is equivalent +in the verified domain. The register-only integer operators are commutative, +and the float subset has exact positive normal inputs and outputs with neither +NaNs nor signed zero. The semantic mutation uses the wrong source instead of +swapping operands. The compiler has no shift, carry-output or EXEC update +lowering in this subset. Load and store waits and termination are discharged by +verification. Their mutation coverage belongs in the source campaign. The +wrong-SCC case observes the combined scalar move, compare and conditional +branch. It does not distinguish which scalar lowering rule was faulty. + +The runner accepts only embedded inputs and an enumerated set of edits. +Every dispatch uses six input words and six output words. Each thread can +access only its own lane and each output has one writer. Cases run serially +in separate child processes with a 30-second wall deadline and Metal API and +shader validation enabled. A timeout or fault stops the campaign. Keep raw +evidence under ignored `artifacts/` with the commit and toolchain environment. diff --git a/tests/mutation/semantic.rs b/tests/mutation/semantic.rs new file mode 100644 index 0000000..2f79a45 --- /dev/null +++ b/tests/mutation/semantic.rs @@ -0,0 +1,325 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +use std::error::Error; +use std::process::{Command, ExitCode}; +use std::time::{Duration, Instant}; +use std::{env, thread}; + +use xenora_metal::NativeCompute; +use xenora_shader::{Architecture, ENTRY_POINT, compile}; + +const INPUT: [u32; 6] = [0, 1, 0x0040_0000, 0x00ff_00ff, 0x8000_0000, u32::MAX]; +const ADD: &[u8] = include_bytes!("../../fixtures/rdna2/add.bin"); +const BRANCH: &[u8] = include_bytes!("../../fixtures/rdna2/bitwise-branch.bin"); +const FLOAT: &[u8] = include_bytes!("../../fixtures/rdna2/float-exact.bin"); +const ADD_MSL: &str = include_str!("../../fixtures/golden/add.metal"); +const BRANCH_MSL: &str = include_str!("../../fixtures/golden/bitwise-branch.metal"); +const FLOAT_MSL: &str = include_str!("../../fixtures/golden/float-exact.metal"); +const DEADLINE: Duration = Duration::from_secs(30); +const SURVIVED: u8 = 2; +const VALIDATION: [(&str, &str); 4] = [ + ("MTL_DEBUG_LAYER", "1"), + ("MTL_SHADER_VALIDATION", "1"), + ("MTL_SHADER_VALIDATION_REPORT_TO_STDERR", "1"), + ("MTL_SHADER_VALIDATION_ABORT_ON_FAULT", "1"), +]; + +#[derive(Clone, Copy)] +enum Fixture { + Add, + AddNegative, + BranchTaken, + BranchFallthrough, + BranchRetargeted, + Float, +} + +impl Fixture { + fn code(self) -> Vec { + match self { + Self::Add => ADD.to_vec(), + Self::AddNegative => { + let mut code = ADD.to_vec(); + // Replace the eight-byte move of the literal with v_mov_b32 v2, -1. + assert_eq!(&code[12..20], &[0xff, 2, 4, 0x7e, 0x78, 0x56, 0x34, 0x12]); + code.splice(12..20, 0x7e04_02c1_u32.to_le_bytes()); + code + } + Self::BranchTaken | Self::BranchFallthrough | Self::BranchRetargeted => { + let mut code = BRANCH.to_vec(); + if matches!(self, Self::BranchFallthrough | Self::BranchRetargeted) { + // Compare s8=7 with 7 so SCC=1 and s_cbranch_scc0 is not taken. + assert_eq!(code[17], 0x86); + code[17] = 0x87; + } + if matches!(self, Self::BranchRetargeted) { + // Change the unconditional target from .Ldone to the next instruction. + assert_eq!(&code[28..32], &0xbf82_0007_u32.to_le_bytes()); + code[28] = 0; + } + code + } + Self::Float => FLOAT.to_vec(), + } + } + + fn expected(self) -> [u32; INPUT.len()] { + match self { + Self::Add => INPUT.map(|word| (u64::from(word) + 0x1234_5678) as u32), + Self::AddNegative => INPUT.map(|word| (u64::from(word) + 0xffff_ffff) as u32), + Self::BranchTaken | Self::BranchRetargeted => { + INPUT.map(|word| (word & 0x00ff_00ff) ^ 0x1234_5678) + } + Self::BranchFallthrough => [0; INPUT.len()], + Self::Float => INPUT.map(|word| { + // Bit 22 selects 1 or 3/2. Adding and then multiplying by 5/2 + // produces 35/4 (0x410c0000) or 10 (0x41200000). + if word & 0x0040_0000 == 0 { + 0x410c_0000 + } else { + 0x4120_0000 + } + }), + } + } + + fn reviewed_msl(self) -> String { + match self { + Self::Add => ADD_MSL.into(), + Self::AddNegative => ADD_MSL.replace("0x12345678u", "0xffffffffu"), + Self::BranchTaken => BRANCH_MSL.into(), + Self::BranchFallthrough | Self::BranchRetargeted => { + let (header, _) = BRANCH_MSL + .split_once(" uint t0 = input[index];") + .unwrap(); + let mut msl = + format!("{header} uint t0 = input[index];\n uint t2 = 0x00000000u;\n"); + if matches!(self, Self::BranchFallthrough) { + msl.push_str(" output[index] = t2;\n"); + } else { + msl.push_str(concat!( + " uint t4 = 0x00ff00ffu;\n", + " uint t5 = t0 & t4;\n", + " uint t6 = 0x12345678u;\n", + " uint t7 = t5 ^ t6;\n", + " output[index] = t7;\n", + )); + } + msl.push_str("}\n"); + msl + } + Self::Float => FLOAT_MSL.into(), + } + } + + fn checked_msl(self, code: &[u8]) -> Result> { + let msl = compile(Architecture::Gfx1030, code)?.msl; + // Never dispatch a changed kernel shape until this test's allow-list is reviewed. + if msl != self.reviewed_msl() { + return Err(format!("generated MSL differs from the reviewed kernel\n{msl}").into()); + } + Ok(msl) + } +} + +enum Mutation { + Replace(&'static str, &'static str), + SelectPath(Fixture), +} + +struct Case { + name: &'static str, + baseline: Fixture, + mutation: Mutation, +} + +use Fixture::{Add, AddNegative, BranchFallthrough, BranchRetargeted, BranchTaken, Float}; +use Mutation::{Replace, SelectPath}; + +const CASES: &[Case] = &[ + Case { + name: "load-zero-instead-of-lane-word", + baseline: Add, + mutation: Replace("uint t0 = input[index];", "uint t0 = 0u;"), + }, + Case { + name: "literal-immediate-off-by-one", + baseline: Add, + mutation: Replace("0x12345678u", "0x12345679u"), + }, + Case { + name: "inline-negative-immediate-zero-extended", + baseline: AddNegative, + mutation: Replace("0xffffffffu", "0x000000ffu"), + }, + Case { + name: "unsigned-add-emitted-as-subtract", + baseline: Add, + mutation: Replace("t0 + t1", "t0 - t1"), + }, + Case { + name: "unsigned-add-selects-wrong-source", + baseline: Add, + mutation: Replace("t0 + t1", "t0 + t0"), + }, + Case { + name: "store-selects-wrong-value", + baseline: Add, + mutation: Replace("output[index] = t2;", "output[index] = t1;"), + }, + Case { + name: "bitwise-and-emitted-as-or", + baseline: BranchTaken, + mutation: Replace("t0 & t2", "t0 | t2"), + }, + Case { + name: "bitwise-xor-emitted-as-and", + baseline: BranchTaken, + mutation: Replace("t3 ^ t4", "t3 & t4"), + }, + Case { + name: "incorrect-scc-path", + baseline: BranchTaken, + mutation: SelectPath(BranchFallthrough), + }, + Case { + name: "incorrect-unconditional-branch-target", + baseline: BranchFallthrough, + mutation: SelectPath(BranchRetargeted), + }, + Case { + name: "float-add-emitted-as-multiply", + baseline: Float, + mutation: Replace( + "as_type(t4) + as_type(t5)", + "as_type(t4) * as_type(t5)", + ), + }, + Case { + name: "float-multiply-emitted-as-add", + baseline: Float, + mutation: Replace( + "as_type(t6) * as_type(t5)", + "as_type(t6) + as_type(t5)", + ), + }, +]; + +fn exercise(case: &Case) -> Result> { + if VALIDATION + .iter() + .any(|&(name, value)| env::var(name).as_deref() != Ok(value)) + { + return Err("the child process requires Metal API and shader validation".into()); + } + let code = case.baseline.code(); + let expected = case.baseline.expected(); + let baseline = case.baseline.checked_msl(&code)?; + let reference = xenora_ref::execute(&code, &INPUT)?; + if reference != expected { + return Err(format!("reference {reference:08x?} did not match {expected:08x?}").into()); + } + let mutated = match case.mutation { + Replace(before, after) => { + if baseline.matches(before).count() != 1 { + return Err(format!("expected exactly one mutation site {before:?}").into()); + } + baseline.replacen(before, after, 1) + } + SelectPath(fixture) => fixture.checked_msl(&fixture.code())?, + }; + if baseline == mutated { + return Err("mutation did not change the MSL".into()); + } + + // All checked kernels are straight-line. The mutations only replace values, + // operators or the selected straight-line path. Addresses never change. + let device = NativeCompute::new()?; + println!( + "device={} api_validation=1 shader_validation=1", + device.device_name() + ); + let actual = device.run_words(&baseline, ENTRY_POINT, &INPUT)?; + if actual != expected { + return Err(format!("baseline GPU {actual:08x?} did not match {expected:08x?}").into()); + } + let mutant = device.run_words(&mutated, ENTRY_POINT, &INPUT)?; + if mutant.len() != expected.len() { + return Err("mutant readback had the wrong word count".into()); + } + println!("baseline={expected:08x?} mutant={mutant:08x?}"); + Ok(if mutant == expected { + ExitCode::from(SURVIVED) + } else { + ExitCode::SUCCESS + }) +} + +fn campaign() -> Result> { + let executable = env::current_exe()?; + let mut killed = 0; + let mut survived = 0; + for case in CASES { + println!("case={}", case.name); + let mut child = Command::new(&executable) + .args(["--child", case.name]) + .envs(VALIDATION) + .spawn()?; + let deadline = Instant::now() + DEADLINE; + loop { + if let Some(status) = child.try_wait()? { + match status.code() { + Some(0) => { + killed += 1; + println!("result=killed"); + } + Some(code) if code == i32::from(SURVIVED) => { + survived += 1; + println!("result=survived"); + } + _ => { + return Err(format!( + "result=error case={} status={status} killed={killed} survived={survived}", + case.name + ).into()); + } + } + break; + } + if Instant::now() >= deadline { + let killed_child = child.kill(); + child.wait()?; + killed_child?; + return Err(format!( + "result=timeout case={} deadline={DEADLINE:?} killed={killed} survived={survived}", + case.name + ).into()); + } + thread::sleep(Duration::from_millis(10)); + } + } + println!( + "generated={} killed={killed} survived={survived}", + CASES.len() + ); + Ok(if survived == 0 { + ExitCode::SUCCESS + } else { + ExitCode::from(SURVIVED) + }) +} + +fn main() -> Result> { + let args: Vec<_> = env::args().skip(1).collect(); + match args.as_slice() { + [] => campaign(), + [child, name] if child == "--child" => { + let case = CASES + .iter() + .find(|case| case.name == name) + .ok_or("unknown case")?; + exercise(case) + } + _ => Err("unexpected arguments".into()), + } +} diff --git a/tests/validation/Cargo.toml b/tests/validation/Cargo.toml index 5dbbb93..56cf680 100644 --- a/tests/validation/Cargo.toml +++ b/tests/validation/Cargo.toml @@ -7,8 +7,16 @@ publish = false [lib] path = "known_answers.rs" +[features] +native-mutation = [] + +[[example]] +name = "semantic-mutation" +path = "../mutation/semantic.rs" +required-features = ["native-mutation"] [dev-dependencies] +xenora-metal = { path = "../../crates/metal" } xenora-ref = { path = "../../crates/ref" } xenora-shader = { path = "../../crates/shader" } diff --git a/tests/validation/README.md b/tests/validation/README.md index a3d824a..bb51d39 100644 --- a/tests/validation/README.md +++ b/tests/validation/README.md @@ -5,7 +5,7 @@ AMD's RDNA2 ISA reference §8.1 defines indexed buffer addressing and the four-S LLVM 23.1.6 and the production decoder agreed on all seven fixture instructions, including their bytes, lengths, offsets and printed operands. AMD defines hardware semantics. LLVM is class E evidence for the tool's encoding and decoding behavior. ```sh -LLVM_BIN=/opt/homebrew/opt/llvm/bin cargo test -p xenora-decoder --test gfx1030 -- --ignored --nocapture +LLVM_BIN="$(brew --prefix llvm)/bin" cargo test -p xenora-decoder --test gfx1030 -- --ignored --nocapture CARGO_TARGET_DIR=target/semantic-review cargo test --manifest-path tests/validation/Cargo.toml ```