Skip to content

Commit

Permalink
prereqs for new block lin so PR works (tinygrad#7919)
Browse files Browse the repository at this point in the history
  • Loading branch information
geohot authored Nov 27, 2024
1 parent a6171cb commit c53261b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
6 changes: 4 additions & 2 deletions test/test_linearizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,15 +902,17 @@ def test_range_outer_op_after_phi(self):
lin = helper_linearizer_opt(out, wanna_output=[a.numpy().sum()*a.numpy().sum()])[0]
# RANGE -> LOAD -> ASSIGN -> ALU
end = max(i for i,u in enumerate(lin.uops) if u.op is Ops.ENDRANGE)
assert lin.uops[end+1].op in GroupOp.ALU
# the INDEX can be first
assert lin.uops[end+1].op in GroupOp.ALU or lin.uops[end+2].op in GroupOp.ALU

def test_range_outer_op_after_phi_nested_range(self):
a = Tensor.randn(2, ).realize()
out = a.reshape(2, 1).expand(2, 3).sum() + a.reshape(2, 1).expand(2, 3).sum()
lin = helper_linearizer_opt(out, wanna_output=[(np.broadcast_to(a.numpy().reshape(2, 1), (2, 3))).sum()*2])[0]
# RANGE -> LOAD -> ASSIGN -> ALU
end = max(i for i,u in enumerate(lin.uops) if u.op is Ops.ENDRANGE)
assert lin.uops[end+1].op in GroupOp.ALU
# the INDEX can be first
assert lin.uops[end+1].op in GroupOp.ALU or lin.uops[end+2].op in GroupOp.ALU

def test_load_dedup(self):
# for different leaves in the AST, the same loads may occur.
Expand Down
10 changes: 6 additions & 4 deletions test/test_uops.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,9 @@ def test_bitshift_left(self):
a2 = UOp(Ops.MUL, dtypes.int, (l1, c2))
uops = to_uops_list([a1,a2], opts=Device[Device.DEFAULT].renderer)
Device[Device.DEFAULT].renderer.render("test", uops)
self.assertEqual(uops[-1].op, Ops.SHL)
self.assertEqual(uops[-2].op, Ops.MUL)
ops = [x.op for x in uops]
self.assertIn(Ops.SHL, ops)
self.assertIn(Ops.MUL, ops)

def test_bitshift_right(self):
g1 = UOp(Ops.DEFINE_GLOBAL, dtypes.int32.ptr(), (), 0)
Expand All @@ -348,8 +349,9 @@ def test_bitshift_right(self):
a2 = UOp(Ops.IDIV, dtypes.int, (l1, c2))
uops = to_uops_list([a1,a2], opts=Device[Device.DEFAULT].renderer)
Device[Device.DEFAULT].renderer.render("test", uops)
self.assertEqual(uops[-1].op, Ops.SHR)
self.assertEqual(uops[-2].op, Ops.IDIV)
ops = [x.op for x in uops]
self.assertIn(Ops.SHR, ops)
self.assertIn(Ops.IDIV, ops)

class TestUOpMethod(unittest.TestCase):
@unittest.skip("uops lt no longer ordered")
Expand Down
5 changes: 4 additions & 1 deletion tinygrad/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ class Ops(FastEnum):
EMPTY = auto()
BUFFER_VIEW = auto()

# blocks in linearizer
BLOCK = auto(); BLOCKSTART = auto(); BLOCKFORK = auto(); BLOCKEND = auto() # noqa: E702

EXPAND = auto()
CONTRACT = auto()
VIEW = auto()
Expand Down Expand Up @@ -152,8 +155,8 @@ class Ops(FastEnum):

# control flow ops
BARRIER = auto()
IF = auto()
RANGE = auto()
IF = auto()

# ops that are not graph nodes
ENDRANGE = auto()
Expand Down
3 changes: 2 additions & 1 deletion tinygrad/viz/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
uops_colors = {Ops.LOAD: "#ffc0c0", Ops.PRELOAD: "#ffc0c0", Ops.STORE: "#87CEEB", Ops.CONST: "#e0e0e0", Ops.VCONST: "#e0e0e0",
Ops.DEFINE_GLOBAL: "#ffe0b0", Ops.DEFINE_LOCAL: "#ffe0d0", Ops.DEFINE_ACC: "#f0ffe0", Ops.REDUCE_AXIS: "#FF6B6B",
Ops.RANGE: "#c8a0e0", Ops.ASSIGN: "#e0ffc0", Ops.BARRIER: "#ff8080", Ops.IF: "#c8b0c0", Ops.SPECIAL: "#c0c0ff",
Ops.INDEX: "#e8ffa0", Ops.WMMA: "#efefc0", Ops.VIEW: "#C8F9D4", **{x:"#ffffc0" for x in GroupOp.ALU}, Ops.BUFFER: "#B0BDFF",}
Ops.INDEX: "#e8ffa0", Ops.WMMA: "#efefc0", Ops.VIEW: "#C8F9D4", **{x:"#ffffc0" for x in GroupOp.ALU},
Ops.BLOCK: "#C4A484", Ops.BLOCKEND: "#C4A4A4", Ops.BUFFER: "#B0BDFF",}

# ** API spec

Expand Down

0 comments on commit c53261b

Please sign in to comment.