forked from tinygrad/tinygrad
Remove BinaryOps.SUB. Replace SUB by ADD and NEG in all tests. Regenerate dataset (#4977)
* feat: remove BinaryOps.SUB * remove SUB in test_early_end_local * regenerate dataset. remove SUB in test_linearizer_* * reenable overflow tests * simplify tensor.sub function by returning a+(-b) * remove whitespaces --------- Co-authored-by: chenyu <[email protected]>
This commit is contained in:
@@ -49,7 +49,7 @@ class UOp:
|
||||
def __neg__(self): return UOp.alu(UnaryOps.NEG, self)
|
||||
def __add__(self, x): return UOp.alu(BinaryOps.ADD, self, ufix(self.dtype, x))
|
||||
def __radd__(self, x): return UOp.alu(BinaryOps.ADD, ufix(self.dtype, x), self)
|
||||
def __sub__(self, x): return UOp.alu(BinaryOps.SUB, self, ufix(self.dtype, x))
|
||||
def __sub__(self, x): return UOp.alu(BinaryOps.ADD, self, -ufix(self.dtype, x))
|
||||
def __mul__(self, x): return UOp.alu(BinaryOps.MUL, self, ufix(self.dtype, x))
|
||||
def __rmul__(self, x): return UOp.alu(BinaryOps.MUL, ufix(self.dtype, x), self)
|
||||
def __floordiv__(self, x): return UOp.alu(BinaryOps.IDIV, self, ufix(self.dtype, x))
|
||||
@@ -200,8 +200,6 @@ constant_folder = PatternMatcher([
|
||||
(UOp.max(UOp.var('x'), UOp.const(dtypes.int, -2147483648)), lambda x: x),
|
||||
# -(-x) -> x
|
||||
(-(-UOp.var('x')), lambda x: x),
|
||||
# x+-y -> x-y
|
||||
(UOp.var('x')+(-UOp.var('y')), lambda x, y: x-y),
|
||||
# -1*x -> -x
|
||||
(-1*UOp.var('x'), lambda x: -x),
|
||||
# bool < False is always false, True < bool is always false
|
||||
@@ -228,7 +226,7 @@ constant_folder = PatternMatcher([
|
||||
UPat(UOps.LOAD, vin=(UPat(name="buf"), UPat(name="idx"))))), lambda buf, idx: UOp(UOps.NOOP)),
|
||||
# ** two stage add/sub folding **
|
||||
((UOp.var('x') + UOp.cvar('c1')) + UOp.cvar('c2'), lambda x,c1,c2: x+UOp.const(x.dtype, exec_alu(BinaryOps.ADD, x.dtype, [c1.arg, c2.arg]))),
|
||||
((UOp.var('x') - UOp.cvar('c1')) + UOp.cvar('c2'), lambda x,c1,c2: x+UOp.const(x.dtype, exec_alu(BinaryOps.SUB, x.dtype, [c2.arg, c1.arg]))),
|
||||
((UOp.var('x') - UOp.cvar('c1')) + UOp.cvar('c2'), lambda x,c1,c2: x+UOp.const(x.dtype, exec_alu(BinaryOps.ADD, x.dtype, [c2.arg, -c1.arg]))),
|
||||
# *** rules from symbolic ***
|
||||
# two stage mul, (x*c1)*c2 = x*(c1*c2)
|
||||
((UOp.var("x") * UOp.cvar("c1")) * UOp.cvar("c2"), lambda x,c1,c2: x*UOp.const(x.dtype, exec_alu(BinaryOps.MUL, x.dtype, [c1.arg, c2.arg]))),
|
||||
@@ -242,7 +240,7 @@ constant_folder = PatternMatcher([
|
||||
((UOp.var("x") // UOp.cvar("c0")) // UOp.cvar("c1"), lambda x,c0,c1: x//UOp.const(x.dtype, exec_alu(BinaryOps.MUL, x.dtype, [c0.arg, c1.arg]))),
|
||||
# c0 + x < c1 -> x < c1 - c0
|
||||
((UOp.cvar("c0") + UOp.var("x")).lt(UOp.cvar("c1")),
|
||||
lambda x,c0,c1: UOp.lt(x, UOp.const(x.dtype, exec_alu(BinaryOps.SUB, x.dtype, [c1.arg, c0.arg])))),
|
||||
lambda x,c0,c1: UOp.lt(x, UOp.const(x.dtype, exec_alu(BinaryOps.ADD, x.dtype, [c1.arg, -c0.arg])))),
|
||||
# (x+x*c0)-> x*(c0+1)
|
||||
(UOp.var("x") + UOp.var("x") * UOp.cvar("c0"), lambda x,c0: x*UOp.const(x.dtype, c0.arg+1)),
|
||||
# TODO: can do the invert of this (flip alt/load) when we fix double ops
|
||||
|
||||
Reference in New Issue
Block a user