-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark
- Loading branch information
Showing
5 changed files
with
104 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from tqdm import tqdm | ||
from dataclasses import dataclass | ||
import pickle, subprocess, os | ||
from typing import Dict, List, Tuple | ||
from tinygrad.codegen.linearizer import Linearizer | ||
from tinygrad.codegen.uops import UOp | ||
from tinygrad.engine.graph import print_tree | ||
from tinygrad.helpers import colored | ||
from tinygrad.ops import LazyOp | ||
|
||
@dataclass(frozen=True) | ||
class ReplayItem: | ||
ast: Tuple[LazyOp, ...] | ||
lin: Linearizer | ||
src: str | ||
|
||
TRACE_DIR = os.path.join(os.environ["HOME"], "traces") | ||
ret = subprocess.run(['ls', '-l', TRACE_DIR], capture_output=True, text=True) | ||
subprocess.run(["git", "fetch", "origin", "master"], check=True, text=True) | ||
def get_replays(h:str): | ||
sha = subprocess.run(["git", "rev-parse", h], stdout=subprocess.PIPE, check=True, text=True).stdout.strip() | ||
replay_items: List[ReplayItem] = [] | ||
with open(os.path.join(TRACE_DIR, sha), "rb") as f: | ||
while True: | ||
try: trace: Dict[Tuple[LazyOp, ...], Tuple[List[Linearizer], List[str]]] = pickle.load(f) | ||
except EOFError: break | ||
for ast, (lins, srcs) in trace.items(): | ||
for lin, src in zip(lins, srcs): replay_items.append(ReplayItem(ast, lin, src)) | ||
return replay_items | ||
|
||
feat = get_replays("origin/master") | ||
master = get_replays("HEAD") | ||
errored = 0 | ||
for f,m in tqdm(zip(feat, master)): | ||
try: | ||
assert f.ast == m.ast | ||
except AssertionError: | ||
print("excepted:") | ||
for op in m.ast: print_tree(op) | ||
print("got:") | ||
for op in f.ast: print_tree(op) | ||
errored += 1 | ||
assert f.lin.uops._uops is not None and m.lin.uops._uops is not None | ||
def _recursive_assert_uops_equal(u0:UOp, u1:UOp): | ||
# compare non-vin | ||
assert u0.cmp_tuple[:-1] == u1.cmp_tuple[:-1] | ||
# compare vin | ||
assert len(u0.vin) == len(u1.vin) | ||
for v0, v1 in zip(u0.vin, u1.vin): _recursive_assert_uops_equal(v0, v1) | ||
for u0, u1 in zip(f.lin.uops._uops, m.lin.uops._uops): | ||
try: _recursive_assert_uops_equal(u0, u1) | ||
except AssertionError: | ||
print("expected:") | ||
print(u1) | ||
print("got:") | ||
print(u0) | ||
errored += 1 | ||
try: assert f.src == m.src | ||
except AssertionError: | ||
print("expected:") | ||
print(f.src) | ||
print("got:") | ||
print(m.src) | ||
errored += 1 | ||
|
||
if errored == 0: print(colored("process replay tests passed", "green")) | ||
else: print(colored(f"{errored} processes failed", "red")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters