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 /tools/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 'tools/f16misc_diff.py')
| -rw-r--r-- | tools/f16misc_diff.py | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/tools/f16misc_diff.py b/tools/f16misc_diff.py index 0adddc046..9400b823a 100644 --- a/tools/f16misc_diff.py +++ b/tools/f16misc_diff.py | |||
| @@ -963,9 +963,9 @@ def grid_program(chunk, rng): | |||
| 963 | 963 | ||
| 964 | 964 | ||
| 965 | def exhaustive_programs(ops=None): | 965 | def exhaustive_programs(ops=None): |
| 966 | """(op, lines) programs: every f16 input through the frexp ops and ldexp, four inputs per program.""" | 966 | """(op, lines) programs: every f16 input through the frexp ops and ldexp, four inputs per program, yielded one at |
| 967 | a time.""" | ||
| 967 | exps = (-64, -25, -15, -1, 1, 15, 30, 64) | 968 | exps = (-64, -25, -15, -1, 1, 15, 30, 64) |
| 968 | out = [] | ||
| 969 | for op in ("v_frexp_mant_f16", "v_frexp_exp_i16_f16", "v_ldexp_f16"): | 969 | for op in ("v_frexp_mant_f16", "v_frexp_exp_i16_f16", "v_ldexp_f16"): |
| 970 | if ops and op not in ops: | 970 | if ops and op not in ops: |
| 971 | continue | 971 | continue |
| @@ -981,8 +981,7 @@ def exhaustive_programs(ops=None): | |||
| 981 | else: | 981 | else: |
| 982 | lines.append(f"v_mov_b32 v{12 + i}, 0x{h | 0xabcd0000:08x}") | 982 | lines.append(f"v_mov_b32 v{12 + i}, 0x{h | 0xabcd0000:08x}") |
| 983 | body.append(f"{op}_e32 {d}, v{12 + i}") | 983 | body.append(f"{op}_e32 {d}, v{12 + i}") |
| 984 | out.append((op, [f"v_mov_b32 v{r}, 0x5a5a5a5a" for r in DSTS] + lines + body)) | 984 | yield op, [f"v_mov_b32 v{r}, 0x5a5a5a5a" for r in DSTS] + lines + body |
| 985 | return out | ||
| 986 | 985 | ||
| 987 | 986 | ||
| 988 | # ---- the oracles ---- | 987 | # ---- the oracles ---- |
| @@ -1068,44 +1067,51 @@ def _run(counts, items, tag): | |||
| 1068 | return failure | 1067 | return failure |
| 1069 | 1068 | ||
| 1070 | 1069 | ||
| 1071 | def run_sweep(seed, ops=None): | 1070 | # Each stage yields its (label, lines, ops) items one at a time, so a run holds one program's text, not the whole list. |
| 1072 | counts = _new_counts() | 1071 | def sweep_items(seed, ops=None): |
| 1073 | items = [] | ||
| 1074 | for case in sweep_cases(ops): | 1072 | for case in sweep_cases(ops): |
| 1075 | op, form, kinds = case | 1073 | op, form, kinds = case |
| 1076 | for rep in range(SWEEP_REPEAT): | 1074 | for rep in range(SWEEP_REPEAT): |
| 1077 | tag = f"{op}:{form}:{'/'.join(kinds)}:{rep}" | 1075 | tag = f"{op}:{form}:{'/'.join(kinds)}:{rep}" |
| 1078 | rng = random.Random(f"{seed}:{tag}") | 1076 | rng = random.Random(f"{seed}:{tag}") |
| 1079 | items.append((f"sweep {tag} (seed {seed})", sweep_program(case, rng), [op])) | 1077 | yield f"sweep {tag} (seed {seed})", sweep_program(case, rng), [op] |
| 1080 | return counts, _run(counts, items, "sw") | ||
| 1081 | 1078 | ||
| 1082 | 1079 | ||
| 1083 | def run_grid(ops=None): | 1080 | def grid_items(ops=None): |
| 1084 | counts = _new_counts() | ||
| 1085 | cases = grid_cases(ops) | 1081 | cases = grid_cases(ops) |
| 1086 | rng = random.Random("f16misc_diff:grid-programs") | 1082 | rng = random.Random("f16misc_diff:grid-programs") |
| 1087 | items = [] | ||
| 1088 | for i in range(0, len(cases), GRID_PER_PROGRAM): | 1083 | for i in range(0, len(cases), GRID_PER_PROGRAM): |
| 1089 | chunk = cases[i:i + GRID_PER_PROGRAM] | 1084 | chunk = cases[i:i + GRID_PER_PROGRAM] |
| 1090 | items.append((f"edge grid program {i // GRID_PER_PROGRAM}", grid_program(chunk, rng), [c[0] for c in chunk])) | 1085 | yield f"edge grid program {i // GRID_PER_PROGRAM}", grid_program(chunk, rng), [c[0] for c in chunk] |
| 1091 | return counts, _run(counts, items, "gr") | 1086 | |
| 1087 | |||
| 1088 | def suite_items(programs, seed, max_ops=6, ops=None): | ||
| 1089 | rng = random.Random(f"suite:{seed}") | ||
| 1090 | for i in range(programs): | ||
| 1091 | lines, used = program(rng, rng.randint(1, max_ops), ops) | ||
| 1092 | yield f"program {i} (seed {seed})", lines, used | ||
| 1093 | |||
| 1094 | |||
| 1095 | def run_sweep(seed, ops=None): | ||
| 1096 | counts = _new_counts() | ||
| 1097 | return counts, _run(counts, sweep_items(seed, ops), "sw") | ||
| 1098 | |||
| 1099 | |||
| 1100 | def run_grid(ops=None): | ||
| 1101 | counts = _new_counts() | ||
| 1102 | return counts, _run(counts, grid_items(ops), "gr") | ||
| 1092 | 1103 | ||
| 1093 | 1104 | ||
| 1094 | def run_exhaustive(ops=None): | 1105 | def run_exhaustive(ops=None): |
| 1095 | counts = _new_counts() | 1106 | counts = _new_counts() |
| 1096 | items = [(f"exhaustive f16 program {i} ({op})", lines, [op] * GRID_PER_PROGRAM) | 1107 | items = ((f"exhaustive f16 program {i} ({op})", lines, [op] * GRID_PER_PROGRAM) |
| 1097 | for i, (op, lines) in enumerate(exhaustive_programs(ops))] | 1108 | for i, (op, lines) in enumerate(exhaustive_programs(ops))) |
| 1098 | return counts, _run(counts, items, "ex") | 1109 | return counts, _run(counts, items, "ex") |
| 1099 | 1110 | ||
| 1100 | 1111 | ||
| 1101 | def run_suite(programs, seed, max_ops=6, ops=None): | 1112 | def run_suite(programs, seed, max_ops=6, ops=None): |
| 1102 | counts = _new_counts() | 1113 | counts = _new_counts() |
| 1103 | rng = random.Random(f"suite:{seed}") | 1114 | return counts, _run(counts, suite_items(programs, seed, max_ops, ops), "rn") |
| 1104 | items = [] | ||
| 1105 | for i in range(programs): | ||
| 1106 | lines, used = program(rng, rng.randint(1, max_ops), ops) | ||
| 1107 | items.append((f"program {i} (seed {seed})", lines, used)) | ||
| 1108 | return counts, _run(counts, items, "rn") | ||
| 1109 | 1115 | ||
| 1110 | 1116 | ||
| 1111 | REJECTED = ( | 1117 | REJECTED = ( |