forked from tinygrad/tinygrad
* move everything to code_for_op to reason about it * loop the loopable parts * its not that unreadable * these are loopable too * nitpick * tests p1 - replace these with the actual compiler running alu ops tests * tests p2: compile test_dtype_alu in HIP! +add to CI * nobody liked test_renderer * revert test_dtypes change * isolated mockhip tests * dont need the WHERE hack after #2782 +ruff * bf16 is broken in HIP job failed in: https://github.com/tinygrad/tinygrad/actions/runs/7232101987/job/19705951290?pr=2778#step:8:73 * picking this back up * add compile tests for unary ops and binary ops * MOD is only in ints * CMPLT wont work after the dtypes pr is merged because it will always be bool * test all combinations * Update cstyle.py * don't use vload * no getenv * set seed --------- Co-authored-by: qazal <[email protected]> Co-authored-by: qazal <[email protected]>
54 lines
2.3 KiB
Python
54 lines
2.3 KiB
Python
import random
|
|
from typing import List
|
|
from tqdm import trange
|
|
from tinygrad.helpers import getenv, DEBUG, colored
|
|
from tinygrad.shape.shapetracker import ShapeTracker
|
|
from test.external.fuzz_shapetracker import shapetracker_ops
|
|
from test.external.fuzz_shapetracker import do_permute, do_reshape_split_one, do_reshape_combine_two, do_flip, do_pad
|
|
|
|
class MultiShapeTracker:
|
|
def __init__(self, sts:List[ShapeTracker]): self.sts = sts
|
|
@property
|
|
def shape(self): return self.sts[0].shape
|
|
def reshape(self, arg): self.sts = [x.reshape(arg) for x in self.sts]
|
|
def permute(self, arg): self.sts = [x.permute(arg) for x in self.sts]
|
|
def expand(self, arg): self.sts = [x.expand(arg) for x in self.sts]
|
|
def shrink(self, arg): self.sts = [x.shrink(arg) for x in self.sts]
|
|
def stride(self, arg): self.sts = [x.stride(arg) for x in self.sts]
|
|
def pad(self, arg): self.sts = [x.pad(arg) for x in self.sts]
|
|
|
|
def fuzz_plus():
|
|
m = MultiShapeTracker([ShapeTracker.from_shape((random.randint(1, 10), random.randint(1, 10), random.randint(1, 10)))])
|
|
for _ in range(4): random.choice(shapetracker_ops)(m)
|
|
backup = m.sts[0]
|
|
m.sts.append(ShapeTracker.from_shape(m.sts[0].shape))
|
|
for _ in range(4): random.choice(shapetracker_ops)(m)
|
|
st_sum = backup + m.sts[1]
|
|
return m.sts[0], st_sum
|
|
|
|
# shrink and expand aren't invertible, and stride is only invertible in the flip case
|
|
invertible_shapetracker_ops = [do_permute, do_reshape_split_one, do_reshape_combine_two, do_flip, do_pad]
|
|
|
|
def fuzz_invert():
|
|
start = ShapeTracker.from_shape((random.randint(1, 10), random.randint(1, 10), random.randint(1, 10)))
|
|
m = MultiShapeTracker([start])
|
|
for _ in range(8): random.choice(invertible_shapetracker_ops)(m)
|
|
inv = m.sts[0].invert(start.shape)
|
|
st_sum = (ShapeTracker.from_shape(m.sts[0].shape) + inv) if inv else None
|
|
return start, st_sum
|
|
|
|
if __name__ == "__main__":
|
|
random.seed(42)
|
|
total = getenv("CNT", 100)
|
|
for fuzz in [globals()[f'fuzz_{x}'] for x in getenv("FUZZ", "invert,plus").split(",")]:
|
|
good = 0
|
|
for _ in trange(total):
|
|
st1, st2 = fuzz()
|
|
if st1 == st2: good += 1
|
|
if st1 != st2 or DEBUG >= 1:
|
|
print(f"EXP: {st1}")
|
|
print(f"GOT: {st2}")
|
|
print(colored("****", "red" if st1 != st2 else "green"))
|
|
print(f"hit {good}/{total}")
|
|
assert good == total
|