From e16755856cc4bfccd17ef758d0cbbcd8a8971671 Mon Sep 17 00:00:00 2001 From: George Hotz Date: Wed, 22 Oct 2025 17:29:58 +0800 Subject: [PATCH] panic --- tinygrad/codegen/late/control_flow.py | 4 ++-- tinygrad/helpers.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tinygrad/codegen/late/control_flow.py b/tinygrad/codegen/late/control_flow.py index 27139458d7..29564372aa 100644 --- a/tinygrad/codegen/late/control_flow.py +++ b/tinygrad/codegen/late/control_flow.py @@ -3,12 +3,12 @@ from typing import cast from collections import defaultdict from tinygrad.dtype import dtypes from tinygrad.uop.ops import PatternMatcher, UOp, Ops, UPat -from tinygrad.helpers import lambda_raise +from tinygrad.helpers import panic # only needed if device doesn't support gated stores pm_linearize_cleanups = PatternMatcher([ # if statements are not allowed in the graph - (UPat((Ops.IF, Ops.ENDIF)), lambda: lambda_raise(RuntimeError("if not allowed in graph"))), + (UPat((Ops.IF, Ops.ENDIF)), lambda: panic(RuntimeError("if not allowed in graph"))), # gated INDEX becomes IF-STORE-ENDIF. this is the only use of IF-ENDIF (UPat(Ops.STORE, name="u", src=(UPat(Ops.INDEX, src=(UPat(), UPat(), UPat(name="gate", dtype=dtypes.bool))).or_casted(), UPat()), allow_any_len=True), lambda u, gate: (u, [mif:=UOp(Ops.IF, src=(gate, u)), u, UOp(Ops.ENDIF, src=(mif,))])) diff --git a/tinygrad/helpers.py b/tinygrad/helpers.py index a1c0a2dd5c..d38a4bf36e 100644 --- a/tinygrad/helpers.py +++ b/tinygrad/helpers.py @@ -85,7 +85,7 @@ def word_wrap(x, wrap=80): while len(ansistrip(x[:i])) < wrap and i < len(x): i += 1 return x[:i] + "\n" + word_wrap(x[i:], wrap) def pad_bytes(b:bytes, align:int) -> bytes: return b + b'\x00' * ((align - (len(b) % align)) % align) -def lambda_raise(e:Exception): raise e +def panic(e:Exception=RuntimeError): raise e @functools.cache def canonicalize_strides(shape:tuple[T, ...], strides:tuple[T, ...]) -> tuple[T, ...]: