diff options
| author | iurysf <98192149+iurysf@users.noreply.github.com> | 2026-11-23 01:18:15 -0300 |
|---|---|---|
| committer | iurysf <98192149+iurysf@users.noreply.github.com> | 2026-11-23 01:18:15 -0300 |
| commit | e1e81f8a24e22c71be10db1cfeaf0cdfd59cdb94 (patch) | |
| tree | 22f9b72b80f8969c05c8117cbd3044a905610d12 | |
| parent | 7bd5f01dd166dfcf80f4f96bb678cccc5918a7bc (diff) | |
FUZZ-55: Drop div-fixup-nan-s0 from KNOWN_DIVERGENCES now that #2477 is on main
#2477 (48a1a98b) makes the translator return signed infinity for v_div_fixup_f64
with NaN(S0), as measured on RDNA2 gfx1036, which is what the reference already
modelled. The case is no longer a known divergence (as TreXito's review of #4536
observed: two tests fail on main because they expect the old divergence).
- Remove the div-fixup-nan-s0 entry, its reference skip and its dedicated --known
program; NaN(S0) programs are compared like any other.
- Add a positive test that the reference and the translator give +-inf for qNaN,
-qNaN and sNaN with both output signs.
- Rework the two --known tests so they no longer depend on div_fixup: the three
remaining forms are excluded with a reason by default, run with --known, and a
planted clamp-only translator error exits 1 and prints the shrunk program.
- docs/shader_validation.md no longer lists the div_fixup case.
Same change as 41525870 (prepared for #4586, which #2477 made redundant).
AI-assisted (OpenBot team).
Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
| -rw-r--r-- | docs/shader_validation.md | 9 | ||||
| -rw-r--r-- | tests/test_f64_diff.py | 56 | ||||
| -rw-r--r-- | tools/f64_diff.py | 21 |
3 files changed, 53 insertions, 33 deletions
diff --git a/docs/shader_validation.md b/docs/shader_validation.md index 5eb987cb5..f941064be 100644 --- a/docs/shader_validation.md +++ b/docs/shader_validation.md | |||
| @@ -1231,10 +1231,11 @@ implementation-defined for binary64; the GPU oracle therefore counts `v_rsq_f64` | |||
| 1231 | 1231 | ||
| 1232 | Known divergence probes are excluded and counted by default, then reinserted with `--known`: binary64 output modifiers | 1232 | Known divergence probes are excluded and counted by default, then reinserted with `--known`: binary64 output modifiers |
| 1233 | (SHADER-721), binary64 `OpFNegate`/`FAbs` that the CPU interpreter rounds through binary32 (TEST-912, #4172), | 1233 | (SHADER-721), binary64 `OpFNegate`/`FAbs` that the CPU interpreter rounds through binary32 (TEST-912, #4172), |
| 1234 | driver-dependent NaN or signed-zero clamp results, and `v_div_fixup_f64` with a NaN `S0` and an ordinary finite | 1234 | and driver-dependent NaN or signed-zero clamp results. The CPU translator reproduces none of these today, so |
| 1235 | division. The latter follows the RDNA2 ISA reference (`NaN(S0) -> signed infinity`), while the current translator | 1235 | `--known` is clean there; it can still return 1 where one reproduces (the RTX 4070 `--oracle gpu` run does for the |
| 1236 | preserves the NaN payload. Therefore `--known` can intentionally return 1 when this known mismatch is reproduced; | 1236 | clamp form), and the minimized case is printed. `v_div_fixup_f64` with a NaN `S0` is not a known divergence: it gives |
| 1237 | the minimized case is printed. `--oracle gpu` translates the same | 1237 | signed infinity, measured on RDNA2 `gfx1036` (TEST-983; the translator has it since #2477), and is compared like any other case. |
| 1238 | `--oracle gpu` translates the same | ||
| 1238 | fragment shader and runs it through `runtime/build/vk_harness`, comparing the raw RGBA32F output words. It assembles | 1239 | fragment shader and runs it through `runtime/build/vk_harness`, comparing the raw RGBA32F output words. It assembles |
| 1239 | the fragment module with `spirv-as` and the full-screen vertex shader with the Vulkan SDK's `glslc`; use `--exe PATH` | 1240 | the fragment module with `spirv-as` and the full-screen vertex shader with the Vulkan SDK's `glslc`; use `--exe PATH` |
| 1240 | to select another `vk_harness`. It exits 77 if the executable, SDK tools, Vulkan device or required `shaderFloat64` | 1241 | to select another `vk_harness`. It exits 77 if the executable, SDK tools, Vulkan device or required `shaderFloat64` |
diff --git a/tests/test_f64_diff.py b/tests/test_f64_diff.py index 4a02c17d7..41607eae1 100644 --- a/tests/test_f64_diff.py +++ b/tests/test_f64_diff.py | |||
| @@ -86,16 +86,35 @@ class F64DiffTests(unittest.TestCase): | |||
| 86 | self.assertIn("implementation-defined", reason) | 86 | self.assertIn("implementation-defined", reason) |
| 87 | self.assertIsNone(actual) | 87 | self.assertIsNone(actual) |
| 88 | 88 | ||
| 89 | def test_div_fixup_nan_s0_is_skipped_by_default_and_runs_with_known(self): | 89 | def test_div_fixup_nan_s0_gives_signed_infinity_in_reference_and_translator(self): |
| 90 | setup, body, _, _ = fd.make_case(random.Random(1), "v_div_fixup_f64", known_case="div-fixup-nan-s0") | 90 | # Measured on RDNA2 gfx1036 (TEST-983); the translator has it since #2477 (48a1a98b). Not a known divergence any more. |
| 91 | lines = setup + body | 91 | self.assertNotIn("div-fixup-nan-s0", fd.KNOWN_DIVERGENCES) |
| 92 | cases = (("v_mov_b32 v13, 0x7ff80000", "1.0", "2.0", fd.EXP), # qNaN, +/+ | ||
| 93 | ("v_mov_b32 v13, 0xfff80000", "-1.0", "2.0", fd.EXP | 0x8000000000000000), # -qNaN, sign_out negative | ||
| 94 | ("v_mov_b32 v13, 0x7ff00000", "1.0", "-2.0", fd.EXP | 0x8000000000000000)) # low word set below: sNaN | ||
| 95 | for index, (hi, s1, s2, want) in enumerate(cases): | ||
| 96 | lines = ["v_mov_b32 v12, 0x00000001" if index == 2 else "v_mov_b32 v12, 0x00000000", hi, | ||
| 97 | f"v_div_fixup_f64 v[8:9], v[12:13], {s1}, {s2}"] | ||
| 98 | self.assertEqual(fd.words_to_bits(*fd.ref_program(lines)[:2]), want) | ||
| 99 | with tempfile.TemporaryDirectory() as tmp: | ||
| 100 | status, reason, expected, actual = fd.run_one(lines, f"ps_f64_fixup_nan_s0_{index}", tmp) | ||
| 101 | self.assertEqual(status, "match", (reason, expected, actual)) | ||
| 102 | self.assertEqual(fd.words_to_bits(*actual[:2]), want) | ||
| 103 | |||
| 104 | def test_known_divergence_forms_are_excluded_by_default_and_run_with_known(self): | ||
| 105 | forms = {"f64-omod": "v_add_f64 v[8:9], v[10:11], 1.0 mul:2", | ||
| 106 | "fclamp-nan-zero": "v_add_f64 v[8:9], 0x7ff80001, 1.0 clamp", | ||
| 107 | "double-neg-abs": "v_add_f64 v[8:9], -|v[8:9]|, 1.0"} | ||
| 108 | self.assertEqual(set(forms), set(fd.KNOWN_DIVERGENCES)) | ||
| 92 | with tempfile.TemporaryDirectory() as tmp: | 109 | with tempfile.TemporaryDirectory() as tmp: |
| 93 | skipped = fd.run_one(lines, "ps_f64_fixup_default", tmp) | 110 | for label, line in forms.items(): |
| 94 | self.assertEqual(skipped[0], "skip") | 111 | with self.subTest(label=label): |
| 95 | self.assertIn("div-fixup-nan-s0", skipped[1]) | 112 | skipped = fd.run_one([line], "ps_f64_known_default", tmp) |
| 96 | known = fd.run_one(lines, "ps_f64_fixup_known", tmp, include_known=True) | 113 | self.assertEqual(skipped[0], "skip") |
| 97 | self.assertEqual(known[0], "mismatch") | 114 | self.assertIn(f"KNOWN_DIVERGENCE {label}", skipped[1]) |
| 98 | self.assertEqual(fd.words_to_bits(*known[2][:2]), fd.EXP) | 115 | self.assertIsNone(skipped[2]) |
| 116 | executed = fd.run_one([line], "ps_f64_known_run", tmp, include_known=True) | ||
| 117 | self.assertIn(executed[0], ("match", "mismatch")) # really executed, not skipped | ||
| 99 | 118 | ||
| 100 | def test_compare_reference_does_not_write_v8_without_cndmask(self): | 119 | def test_compare_reference_does_not_write_v8_without_cndmask(self): |
| 101 | for op in ("v_cmp_eq_f64_e64 s20, v[12:13], 0.0", | 120 | for op in ("v_cmp_eq_f64_e64 s20, v[12:13], 0.0", |
| @@ -122,9 +141,22 @@ class F64DiffTests(unittest.TestCase): | |||
| 122 | normal = self.command("--ops", "v_add_f64", "--programs", "0") | 141 | normal = self.command("--ops", "v_add_f64", "--programs", "0") |
| 123 | known = self.command("--ops", "v_add_f64", "--programs", "0", "--no-sweep", "--known", "--all-failures") | 142 | known = self.command("--ops", "v_add_f64", "--programs", "0", "--no-sweep", "--known", "--all-failures") |
| 124 | self.assertNotIn("KNOWN_DIVERGENCE", normal.stdout) | 143 | self.assertNotIn("KNOWN_DIVERGENCE", normal.stdout) |
| 125 | self.assertEqual(known.returncode, 1) | 144 | self.assertIn(f"{len(fd.KNOWN_DIVERGENCES)} total", known.stdout) # one program per known divergence |
| 126 | self.assertIn("MISMATCH:", known.stdout) | 145 | self.assertNotIn("KNOWN_DIVERGENCE", known.stdout) # none of them is skipped |
| 127 | self.assertIn("v_div_fixup_f64", known.stdout) # the known NaN(S0) case is actually executed | 146 | # The CPU translator reproduces none of them any more, so the run is clean; a reproduced one exits 1. |
| 147 | self.assertEqual(known.returncode, 0, known.stdout + known.stderr) | ||
| 148 | stdout = io.StringIO() | ||
| 149 | original = fd.translate | ||
| 150 | |||
| 151 | def planted(listing, name, temp): # a translator that gets only the clamp form wrong | ||
| 152 | out = original(listing, name, temp) | ||
| 153 | if any(" clamp" in line for line in listing): out[2] ^= 1 # an exactly compared word (a NaN result is not) | ||
| 154 | return out | ||
| 155 | with mock.patch.object(fd, "translate", planted), contextlib.redirect_stdout(stdout): | ||
| 156 | code = fd.main(["--ops", "v_add_f64", "--programs", "0", "--no-sweep", "--known", "--all-failures"]) | ||
| 157 | self.assertEqual(code, 1) | ||
| 158 | self.assertIn("MISMATCH:", stdout.getvalue()) | ||
| 159 | self.assertIn(" clamp", stdout.getvalue()) # the shrunk program of a known form is printed | ||
| 128 | 160 | ||
| 129 | def test_sabotaged_translator_mismatch_and_shrinking(self): | 161 | def test_sabotaged_translator_mismatch_and_shrinking(self): |
| 130 | lines = ["v_mov_b32 v12, 0x00000000", "v_mov_b32 v13, 0x3ff80000", | 162 | lines = ["v_mov_b32 v12, 0x00000000", "v_mov_b32 v13, 0x3ff80000", |
diff --git a/tools/f64_diff.py b/tools/f64_diff.py index 340f3d106..4e42ca6f3 100644 --- a/tools/f64_diff.py +++ b/tools/f64_diff.py | |||
| @@ -57,7 +57,6 @@ KNOWN_DIVERGENCES = { | |||
| 57 | "f64-omod": "SHADER-721: f64 output modifiers; owned by @fiestorra.", | 57 | "f64-omod": "SHADER-721: f64 output modifiers; owned by @fiestorra.", |
| 58 | "double-neg-abs": "TEST-912 (#4172): spirv_mini_interp rounds binary64 OpFNegate/FAbs through binary32, changing values as well as NaN payloads.", | 58 | "double-neg-abs": "TEST-912 (#4172): spirv_mini_interp rounds binary64 OpFNegate/FAbs through binary32, changing values as well as NaN payloads.", |
| 59 | "fclamp-nan-zero": "FClamp NaN and signed-zero results are driver-dependent after f64 clamp/omod.", | 59 | "fclamp-nan-zero": "FClamp NaN and signed-zero results are driver-dependent after f64 clamp/omod.", |
| 60 | "div-fixup-nan-s0": "RDNA2 ISA maps NaN(S0) to signed infinity; current translator preserves the NaN payload.", | ||
| 61 | } | 60 | } |
| 62 | 61 | ||
| 63 | 62 | ||
| @@ -342,15 +341,8 @@ def ref_program(lines, include_known=False): | |||
| 342 | else: | 341 | else: |
| 343 | d = int(dst[2:-1].split(":")[0]); vgpr[d], vgpr[d + 1] = bits_to_words(out) | 342 | d = int(dst[2:-1].split(":")[0]); vgpr[d], vgpr[d + 1] = bits_to_words(out) |
| 344 | elif op == "v_div_fixup_f64": | 343 | elif op == "v_div_fixup_f64": |
| 345 | args = [read_source(t, vgpr, sgpr) for t in a[:3]] | 344 | # NaN(S0) gives signed infinity, measured on RDNA2 gfx1036 (TEST-983; the translator has it since #2477, 48a1a98b). |
| 346 | s0, s1, s2 = args | 345 | d = int(dst[2:-1].split(":")[0]); vgpr[d], vgpr[d + 1] = bits_to_words(fixup(*[read_source(t, vgpr, sgpr) for t in a[:3]])) |
| 347 | ediff = ((s2 >> 52) & 0x7FF) - ((s1 >> 52) & 0x7FF) | ||
| 348 | normal_division = (not is_nan(s1) and not is_inf(s1) and not is_zero(s1) | ||
| 349 | and not is_nan(s2) and not is_inf(s2) and not is_zero(s2) | ||
| 350 | and -1074 <= ediff < 1024) | ||
| 351 | if not include_known and is_nan(s0) and normal_division: | ||
| 352 | raise SkipCase(f"KNOWN_DIVERGENCE div-fixup-nan-s0: {KNOWN_DIVERGENCES['div-fixup-nan-s0']}") | ||
| 353 | d = int(dst[2:-1].split(":")[0]); vgpr[d], vgpr[d + 1] = bits_to_words(fixup(*args)) | ||
| 354 | elif op == "v_frexp_mant_f64": | 346 | elif op == "v_frexp_mant_f64": |
| 355 | d = int(dst[2:-1].split(":")[0]); vgpr[d], vgpr[d + 1] = bits_to_words(frexp(read_source(a[0], vgpr, sgpr))[0]) | 347 | d = int(dst[2:-1].split(":")[0]); vgpr[d], vgpr[d + 1] = bits_to_words(frexp(read_source(a[0], vgpr, sgpr))[0]) |
| 356 | elif op == "v_frexp_exp_i32_f64": | 348 | elif op == "v_frexp_exp_i32_f64": |
| @@ -545,11 +537,7 @@ def make_case(rng, op, allow_literal=True, known_case=None): | |||
| 545 | if known_case == "fclamp-nan-zero": left, right = "0x7ff80001", "1.0" | 537 | if known_case == "fclamp-nan-zero": left, right = "0x7ff80001", "1.0" |
| 546 | body_lines.append(f"{op} v[8:9], {left}, {right}{suffix}") | 538 | body_lines.append(f"{op} v[8:9], {left}, {right}{suffix}") |
| 547 | elif op == "v_div_fixup_f64": | 539 | elif op == "v_div_fixup_f64": |
| 548 | if known_case == "div-fixup-nan-s0": | 540 | body_lines.append(f"{op} v[8:9], {gen_source(rng, 0, allow_literal, bus)}, {gen_source(rng, 1, allow_literal, bus)}, {gen_source(rng, 2, allow_literal, bus)}") |
| 549 | setup_lines += ["v_mov_b32 v12, 0x00000000", "v_mov_b32 v13, 0x7ff80000"] | ||
| 550 | body_lines.append(f"{op} v[8:9], v[12:13], 1.0, 2.0") | ||
| 551 | else: | ||
| 552 | body_lines.append(f"{op} v[8:9], {gen_source(rng, 0, allow_literal, bus)}, {gen_source(rng, 1, allow_literal, bus)}, {gen_source(rng, 2, allow_literal, bus)}") | ||
| 553 | elif op == "v_div_fmas_f64": | 541 | elif op == "v_div_fmas_f64": |
| 554 | # VCC is initialized true so the f64 scaled FMA path is exercised deterministically. | 542 | # VCC is initialized true so the f64 scaled FMA path is exercised deterministically. |
| 555 | body_lines += ["v_cmp_eq_i32_e32 vcc_lo, 0, 0", f"{op} v[8:9], {gen_source(rng, 0, allow_literal, bus)}, {gen_source(rng, 1, allow_literal, bus)}, {gen_source(rng, 2, allow_literal, bus)}"] | 543 | body_lines += ["v_cmp_eq_i32_e32 vcc_lo, 0, 0", f"{op} v[8:9], {gen_source(rng, 0, allow_literal, bus)}, {gen_source(rng, 1, allow_literal, bus)}, {gen_source(rng, 2, allow_literal, bus)}"] |
| @@ -681,8 +669,7 @@ def run_batch(ops, programs, seed, max_ops=1, sweep=True, allow_literal=True, kn | |||
| 681 | sequence = [(op, True, None) for op in ops] if sweep else [] | 669 | sequence = [(op, True, None) for op in ops] if sweep else [] |
| 682 | sequence += [(rng.choice(ops), False, None) for _ in range(programs)] | 670 | sequence += [(rng.choice(ops), False, None) for _ in range(programs)] |
| 683 | if known: | 671 | if known: |
| 684 | sequence += [("v_div_fixup_f64" if label == "div-fixup-nan-s0" else "v_add_f64", True, label) | 672 | sequence += [("v_add_f64", True, label) for label in KNOWN_DIVERGENCES] |
| 685 | for label in KNOWN_DIVERGENCES] | ||
| 686 | cases = [] | 673 | cases = [] |
| 687 | for idx, (op, is_sweep, known_case) in enumerate(sequence): | 674 | for idx, (op, is_sweep, known_case) in enumerate(sequence): |
| 688 | setup_lines, body_lines, _, _ = make_case(rng, op, allow_literal, known_case) | 675 | setup_lines, body_lines, _, _ = make_case(rng, op, allow_literal, known_case) |