diff options
| author | TreXito <81475944+TreXito@users.noreply.github.com> | 2026-11-23 08:35:41 +0000 |
|---|---|---|
| committer | TreXito <81475944+TreXito@users.noreply.github.com> | 2026-11-23 12:12:19 +0000 |
| commit | ee2d373b54aca98eb15b2b9cd8402b62f4977438 (patch) | |
| tree | 5811fe5ae81d7900acd6d0fb6d59ed2087e8cb16 /tests/test_f16misc_diff.py | |
| parent | 5ec5431c88cd1353c3298d6bcd8db712fcdb9804 (diff) | |
f16misc_diff.py: check each program as it is generated, not after building the whole list
run_sweep, run_grid, run_exhaustive and run_suite built every program before _run checked
the first, so peak memory grew with --programs and --exhaustive-f16 held all 49,152
programs. sweep_items, grid_items, suite_items and exhaustive_programs now yield one at a
time. Same programs (SHA-256 of every program in all four stages matches), same output for
--programs 300 --seed 2. Generation-only peak: --exhaustive-f16 64,279,176 -> 305,573
bytes, 3,000 random programs 5,092,014 -> 310,551. Same pattern shdann found in #5086.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/test_f16misc_diff.py')
| -rw-r--r-- | tests/test_f16misc_diff.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/tests/test_f16misc_diff.py b/tests/test_f16misc_diff.py index 3b76ae445..9d17d9cd4 100644 --- a/tests/test_f16misc_diff.py +++ b/tests/test_f16misc_diff.py | |||
| @@ -14,6 +14,7 @@ than half an f32 ulp: | |||
| 14 | M 0x2817 * 0x23d3 = 2^-11 (1 - 11 / 2^21); + (1 + 2^-10) (0x3c01): once -> below the tie -> 0x3c01; f32 lands on | 14 | M 0x2817 * 0x23d3 = 2^-11 (1 - 11 / 2^21); + (1 + 2^-10) (0x3c01): once -> below the tie -> 0x3c01; f32 lands on |
| 15 | the tie 1 + 3 * 2^-11, even is 0x3c02 | 15 | the tie 1 + 3 * 2^-11, even is 0x3c02 |
| 16 | """ | 16 | """ |
| 17 | import inspect | ||
| 17 | import io | 18 | import io |
| 18 | import os | 19 | import os |
| 19 | import random | 20 | import random |
| @@ -265,7 +266,7 @@ class Generator(unittest.TestCase): | |||
| 265 | self.assertFalse(any(all(v in nans for v in w) for w in triples)) | 266 | self.assertFalse(any(all(v in nans for v in w) for w in triples)) |
| 266 | 267 | ||
| 267 | def test_exhaustive_programs_cover_every_half(self): | 268 | def test_exhaustive_programs_cover_every_half(self): |
| 268 | progs = f.exhaustive_programs(["v_frexp_exp_i16_f16"]) | 269 | progs = list(f.exhaustive_programs(["v_frexp_exp_i16_f16"])) |
| 269 | self.assertEqual(len(progs), (1 << 16) // f.GRID_PER_PROGRAM) | 270 | self.assertEqual(len(progs), (1 << 16) // f.GRID_PER_PROGRAM) |
| 270 | seen = {int(line.split("0x")[1], 16) & M16 for _, lines in progs for line in lines | 271 | seen = {int(line.split("0x")[1], 16) & M16 for _, lines in progs for line in lines |
| 271 | if re.match(r"v_mov_b32 v1[2-5], ", line)} | 272 | if re.match(r"v_mov_b32 v1[2-5], ", line)} |
| @@ -294,6 +295,25 @@ class Translated(unittest.TestCase): | |||
| 294 | self.assertGreater(counts["events"]["v_fmamk_f16"]["tie"], 10) | 295 | self.assertGreater(counts["events"]["v_fmamk_f16"]["tie"], 10) |
| 295 | self.assertGreater(counts["events"]["v_min3_f16"]["NaN"], 100) | 296 | self.assertGreater(counts["events"]["v_min3_f16"]["NaN"], 100) |
| 296 | 297 | ||
| 298 | def test_each_program_is_checked_before_the_next_is_made(self): | ||
| 299 | # a run holds one program's text at a time, not the whole --programs list | ||
| 300 | made, seen = [], [] | ||
| 301 | real = f.program, f.sweep_program, f.grid_program, f.run_one | ||
| 302 | |||
| 303 | def count(fn): | ||
| 304 | return lambda *a: made.append(1) or fn(*a) | ||
| 305 | try: | ||
| 306 | f.program, f.sweep_program, f.grid_program = (count(fn) for fn in real[:3]) | ||
| 307 | f.run_one = lambda lines, name, tmp, events=None: seen.append(len(made)) or ("match", None) | ||
| 308 | f.run_suite(5, 1) | ||
| 309 | f.run_sweep(1, ["v_ldexp_f16"]) | ||
| 310 | f.run_grid(["v_min3_f16"]) | ||
| 311 | finally: | ||
| 312 | f.program, f.sweep_program, f.grid_program, f.run_one = real | ||
| 313 | self.assertGreater(len(seen), 10) | ||
| 314 | self.assertEqual(seen, list(range(1, len(seen) + 1))) | ||
| 315 | self.assertTrue(inspect.isgenerator(f.exhaustive_programs())) | ||
| 316 | |||
| 297 | def test_fma_rounds_once_through_the_translator(self): | 317 | def test_fma_rounds_once_through_the_translator(self): |
| 298 | for x, y, z, single, _ in BY_HAND: | 318 | for x, y, z, single, _ in BY_HAND: |
| 299 | for line in (f"v_fmamk_f16 v8, v12, 0x{y:04x}, v8", f"v_fmaak_f16 v8, v12, v13, 0x{z:04x}", | 319 | for line in (f"v_fmamk_f16 v8, v12, 0x{y:04x}, v8", f"v_fmaak_f16 v8, v12, v13, 0x{z:04x}", |