From f47e297d4ea63a1b0d51f54839ffbe8c79822008 Mon Sep 17 00:00:00 2001 From: George Hotz Date: Mon, 12 Feb 2024 15:46:18 +0100 Subject: [PATCH] refactor: END -> ENDLOOP --- tinygrad/codegen/linearizer.py | 4 ++-- tinygrad/codegen/uops.py | 2 +- tinygrad/graph.py | 2 +- tinygrad/renderer/cstyle.py | 2 +- tinygrad/renderer/llvmir.py | 2 +- tinygrad/runtime/ops_python.py | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tinygrad/codegen/linearizer.py b/tinygrad/codegen/linearizer.py index 0f76577ab4..6ca200574c 100644 --- a/tinygrad/codegen/linearizer.py +++ b/tinygrad/codegen/linearizer.py @@ -431,11 +431,11 @@ class Linearizer(Kernel): # (recursively) remove childless uops self.uops = remove_childless_uops(self.uops) - # add UOps.END + # add UOps.END* for u in self.uops: if u.uop is UOps.LOOP: # add END of loops after the last thing that (recursively) depends on them - self.uop(UOps.END, None, (u,), cachable=False, insert_before=self.uops.index(sorted(list(get_recursive_children(self.uops, u)), key=self.uops.index)[-1])+1) # noqa: E501 + self.uop(UOps.ENDLOOP, None, (u,), cachable=False, insert_before=self.uops.index(sorted(list(get_recursive_children(self.uops, u)), key=self.uops.index)[-1])+1) # noqa: E501 elif u.uop is UOps.IF: # END any if statements at the end of the uops self.uop(UOps.ENDIF, None, (u,), cachable=False) diff --git a/tinygrad/codegen/uops.py b/tinygrad/codegen/uops.py index ebf726197c..8bc868473c 100644 --- a/tinygrad/codegen/uops.py +++ b/tinygrad/codegen/uops.py @@ -8,7 +8,7 @@ from dataclasses import dataclass # bottom ones are asm only class UOps(Enum): - LOOP = auto(); IF = auto(); END = auto(); ENDIF = auto(); SPECIAL = auto() # loops can be global, local, or other # noqa: E702 + LOOP = auto(); IF = auto(); ENDLOOP = auto(); ENDIF = auto(); SPECIAL = auto() # loops can be global, local, or other # noqa: E702 DEFINE_GLOBAL = auto(); DEFINE_LOCAL = auto(); DEFINE_ACC = auto() # this defines buffers # noqa: E702 LOAD = auto(); STORE = auto(); CONST = auto(); BARRIER = auto(); PHI = auto() # noqa: E702 ALU = auto(); WMMA = auto(); CAST = auto(); GEP = auto() # noqa: E702 diff --git a/tinygrad/graph.py b/tinygrad/graph.py index 082cedfa33..c91569c499 100644 --- a/tinygrad/graph.py +++ b/tinygrad/graph.py @@ -89,7 +89,7 @@ def graph_uops(uops:List[UOp]): UOps.LOOP: "#c8a0e0", UOps.PHI: "#e0ffc0", UOps.BARRIER: "#ff8080", UOps.IF: "#c8b0c0"} G = nx.DiGraph() for u in uops: - if u.uop in {UOps.END, UOps.ENDIF}: continue + if u.uop in {UOps.ENDLOOP, UOps.ENDIF}: continue G.add_node(uops.index(u), label=f"{str(u.uop)[5:]}{(' '+str(u.arg)) if u.arg is not None else ''}\n{str(u.dtype)}", style="filled", fillcolor=colors.get(u.uop, "#ffffff")) # noqa: E501 for v in u.vin: G.add_edge(uops.index(v), uops.index(u)) save_graph(G, f'{GRAPHPATH}.uops', '-Grankdir=LR') diff --git a/tinygrad/renderer/cstyle.py b/tinygrad/renderer/cstyle.py index 8c51b12ac7..9fc56fbff8 100644 --- a/tinygrad/renderer/cstyle.py +++ b/tinygrad/renderer/cstyle.py @@ -112,7 +112,7 @@ def uops_to_cstyle(lang:CStyleLanguage, function_name:str, uops:List[UOp]) -> st kk(f"if ({r[vin[0]]}) {{") depth += 1 elif uop is UOps.BARRIER: kk(lang.barrier) - elif uop in {UOps.END, UOps.ENDIF}: + elif uop in {UOps.ENDLOOP, UOps.ENDIF}: depth -= 1 kk("}") elif uop is UOps.STORE: diff --git a/tinygrad/renderer/llvmir.py b/tinygrad/renderer/llvmir.py index 6ef739f8e0..05fab8122c 100644 --- a/tinygrad/renderer/llvmir.py +++ b/tinygrad/renderer/llvmir.py @@ -102,7 +102,7 @@ def uops_to_llvm_ir(function_name:str, uops:List[UOp]) -> str: if len(vin) > 3: with bb[-1].if_then(lvars[vin[3]]): store_op() else: store_op() - elif uop is UOps.END: + elif uop is UOps.ENDLOOP: block, phis = loop_blocks.pop() idx_p1 = bb[-1].add(lvars[vin[0]], ir.Constant(ir.IntType(32), 1)) lvars[vin[0]].add_incoming(idx_p1, bb[-1]._block) diff --git a/tinygrad/runtime/ops_python.py b/tinygrad/runtime/ops_python.py index fd98ed62a7..688d611025 100644 --- a/tinygrad/runtime/ops_python.py +++ b/tinygrad/runtime/ops_python.py @@ -78,7 +78,7 @@ class PythonProgram: for m,o,v in zip(*inp): _store(m, o, v) i += 1 continue - elif uop is UOps.END: + elif uop is UOps.ENDLOOP: loop_ends[idp[0]] = i i = idp[0] continue