From f8e2dd4dd18f5805ed69a4c7f7841f2cc0822c2d Mon Sep 17 00:00:00 2001 From: George Hotz <72895+geohot@users.noreply.github.com> Date: Fri, 5 Sep 2025 07:40:29 -0700 Subject: [PATCH] investigate opts mismatches (#12020) --- extra/test_hcopt.py | 6 ++++-- tinygrad/codegen/opt/postrange.py | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/extra/test_hcopt.py b/extra/test_hcopt.py index ef4f48fb03..94831c2614 100644 --- a/extra/test_hcopt.py +++ b/extra/test_hcopt.py @@ -21,8 +21,10 @@ if __name__ == "__main__": if opt1 != opt2: print(f"******* {i:6d}") - print("Kernel: ", lin.colored_shape(), opt1) - print("Scheduler: ", sch.colored_shape(), opt2) + print("Kernel: ", lin.colored_shape(), "->", lin.apply_opts(opt1).colored_shape()) + print("Scheduler: ", sch.colored_shape(), "->", sch.apply_opts(opt2).colored_shape()) + print(opt1) + print(opt2) else: good += 1 print(f"******* {i:6d} MATCH {good/(i+1)*100:.2f}%") diff --git a/tinygrad/codegen/opt/postrange.py b/tinygrad/codegen/opt/postrange.py index b0d3093007..df418f5aea 100644 --- a/tinygrad/codegen/opt/postrange.py +++ b/tinygrad/codegen/opt/postrange.py @@ -1,6 +1,7 @@ +from __future__ import annotations import math, itertools from collections import defaultdict -from typing import cast, Final +from typing import cast, Final, Sequence from tinygrad.uop.ops import PatternMatcher, UPat, Ops, UOp, KernelInfo, graph_rewrite, _substitute, AxisType, ssimplify from tinygrad.uop.symbolic import symbolic_flat from tinygrad.device import Buffer @@ -145,6 +146,10 @@ class Scheduler: return axis except IndexError as e: raise KernelOptError from e + def apply_opts(self, opts:Sequence[Opt]) -> Scheduler: + for opt in opts: self.apply_opt(opt) + return self + def apply_opt(self, opt:Opt, append_opt:bool=True): if opt.op is OptOps.NOLOCALS: check(all(x not in {AxisType.LOCAL, AxisType.GROUP_REDUCE} for x in self.axis_types), "no locals can't have locals")