MCPcopy
hub / github.com/tinygrad/tinygrad / test_diamond

Method test_diamond

test/null/test_viz.py:762–794  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

760 self.assertEqual(len(cfg["blocks"]), 2)
761
762 def test_diamond(self):
763 k = Kernel()
764 k.label("entry")
765 k.emit(s_mov_b32(s[0], 0))
766 k.emit(s_mov_b32(s[1], 0))
767 k.emit(s_cmp_eq_u64(s[0:1], 0))
768 k.emit(s_cbranch_scc1(), target="if")
769 k.emit(s_branch(), target="else")
770 k.label("if")
771 k.emit(s_nop(1))
772 k.emit(s_branch(), target="end")
773 k.label("else")
774 k.emit(s_nop(0))
775 k.label("end")
776 k.emit(s_endpgm())
777 k.emit(s_code_end())
778 ret = self.get_cfg("diamond", k)
779 cfg = ret["data"]
780 self.assertEqual(len(cfg["blocks"]), 5)
781 edge_count = sum(len(v) for v in cfg["paths"].values())
782 self.assertEqual(edge_count, 5)
783 references:dict[str, list[str]] = {}
784 for pc, tokens in cfg["pc_tokens"].items():
785 for t in tokens:
786 for key in t["keys"]: references.setdefault(key, []).append(pc)
787 self.assertEqual(len(references["r0"]), 2)
788 insts = [cfg["pc_tokens"][pc][0]["st"] for pc in references["r0"]]
789 self.assertEqual(insts, ['s_mov_b32', 's_cmp_eq_u64'])
790 end_block = [" ".join(t["st"] for t in cfg["pc_tokens"][pc]) for pc in list(cfg["blocks"].values())[-1]]
791 code_line = ret["src"].splitlines()[-1]
792 self.assertEqual(len(end_block), 2)
793 for st in [end_block[-1], code_line]:
794 assert st.startswith("s_code_end") and st.endswith("x)"), st
795
796 def test_loop(self):
797 k = Kernel()

Callers

nothing calls this directly

Calls 5

labelMethod · 0.95
emitMethod · 0.95
get_cfgMethod · 0.95
KernelClass · 0.90
appendMethod · 0.80

Tested by

no test coverage detected