mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-02-11 07:05:04 -05:00
* test tc as ctx var * remove from opts * process replay * pop variable * B -> Variable * fix re-assign * pop temp vars * move TRANSCENDENTAL=2
28 lines
1.3 KiB
Python
Executable File
28 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# compare kernels created by HEAD against master
|
|
import difflib, pickle
|
|
from tinygrad.codegen.linearizer import Linearizer
|
|
from tinygrad.helpers import Context, ContextVar, colored, db_connection, VERSION, getenv, tqdm
|
|
|
|
page_size = 100
|
|
conn = db_connection()
|
|
cur = conn.cursor()
|
|
row_count = cur.execute(f"select count(*) from 'process_replay_{VERSION}'").fetchone()[0]
|
|
for offset in tqdm(range(0, row_count, page_size)):
|
|
cur.execute(f"SELECT val FROM 'process_replay_{VERSION}' LIMIT ? OFFSET ?", (page_size, offset))
|
|
for row in cur.fetchall():
|
|
ast, opts, applied_opts, name, compare_src, ctx = pickle.loads(row[0])
|
|
with Context(**{k:v for k,v in ctx.items() if k in ContextVar._cache}):
|
|
k = Linearizer(*ast, opts=opts)
|
|
for opt in applied_opts: k.apply_opt(opt)
|
|
good_src = k.opts.render(name, k.linearize().uops)
|
|
try: assert compare_src == good_src
|
|
except AssertionError as e:
|
|
print("PROCESS REPLAY DETECTED CHANGE")
|
|
print(ast)
|
|
print(applied_opts)
|
|
diff = list(difflib.unified_diff(good_src.splitlines(), compare_src.splitlines()))
|
|
for line in diff:
|
|
print(colored(line, "red" if line.startswith("-") else "green" if line.startswith("+") else None))
|
|
if getenv("ASSERT_PROCESS_REPLAY", 1): raise e
|