From 374f7659a75214e7f5a918a75f4a010ed1d7dd92 Mon Sep 17 00:00:00 2001 From: George Hotz <72895+geohot@users.noreply.github.com> Date: Tue, 9 Jan 2024 08:59:04 -0800 Subject: [PATCH] remove unused reciprocal (#3053) * remove unused reciprocal * comment --- test/test_uops.py | 2 -- tinygrad/lazy.py | 2 +- tinygrad/ops.py | 4 ++-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/test/test_uops.py b/test/test_uops.py index 69a24d486a..144233ae7e 100644 --- a/test/test_uops.py +++ b/test/test_uops.py @@ -74,8 +74,6 @@ class TestFloatUOps(TestUOps): def test_log2(self): self._test_uop_fxn(UnaryOps.LOG2, lambda a: math.log2(a) if a > 0 else float('-inf' if a==0 else 'nan')) def test_sin(self): self._test_uop_fxn(UnaryOps.SIN, lambda a: math.sin(a)) def test_sqrt(self): self._test_uop_fxn(UnaryOps.SQRT, lambda a: math.sqrt(a) if a >= 0 else float('nan')) - # this is not on most backends - #def test_recip(self): self._test_uop_fxn(UnaryOps.RECIP, lambda a: 1.0/a if a != 0 else float('inf')) def test_add(self): self._test_bop_fxn(BinaryOps.ADD, lambda a,b: a+b) def test_sub(self): self._test_bop_fxn(BinaryOps.SUB, lambda a,b: a-b) diff --git a/tinygrad/lazy.py b/tinygrad/lazy.py index c72d3694c4..54f69583ce 100644 --- a/tinygrad/lazy.py +++ b/tinygrad/lazy.py @@ -239,7 +239,7 @@ def _recurse_lb(buf:LazyBuffer, realizes:Set[LazyBuffer], allbufs:Dict[LazyBuffe children[x.base][buf] = None _recurse_lb(x, realizes, allbufs, simple_pads, children) -UNSAFE_PAD_OPS = {BinaryOps.DIV, BinaryOps.CMPLT, BinaryOps.CMPEQ, UnaryOps.LOG2, UnaryOps.EXP2, UnaryOps.RECIP} +UNSAFE_PAD_OPS = {BinaryOps.DIV, BinaryOps.CMPLT, BinaryOps.CMPEQ, UnaryOps.LOG2, UnaryOps.EXP2} def _is_padding_okay(buf:LazyBuffer, realizes:Set[LazyBuffer]) -> bool: if buf in realizes or buf.realized: return True # NOTE: this broke to_image_idx and coder with JIT diff --git a/tinygrad/ops.py b/tinygrad/ops.py index aeb54a2af3..c7b407f4eb 100644 --- a/tinygrad/ops.py +++ b/tinygrad/ops.py @@ -10,8 +10,8 @@ from dataclasses import dataclass # these are the llops your accelerator must implement, along with toCpu # the Enum class doesn't work with mypy, this is static. sorry it's ugly # NOTE: MOD, CMPLT don't have to be implemented on vectors, just scalars -# NOTE: rdna3 only has RECIP and not DIV. DIV is on the chopping block -class UnaryOps(Enum): EXP2 = auto(); LOG2 = auto(); CAST = auto(); SIN = auto(); SQRT = auto(); RECIP = auto(); NEG = auto() # noqa: E702 +# NOTE: many GPUs don't have DIV, but UnaryOps.RECIP doesn't work for integer division +class UnaryOps(Enum): EXP2 = auto(); LOG2 = auto(); CAST = auto(); SIN = auto(); SQRT = auto(); NEG = auto() # noqa: E702 class BinaryOps(Enum): ADD = auto(); SUB = auto(); MUL = auto(); DIV = auto(); MAX = auto(); MOD = auto(); CMPLT = auto(); CMPEQ = auto(); XOR = auto() # noqa: E702 class TernaryOps(Enum): MULACC = auto(); WHERE = auto() # noqa: E702