mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-01-25 14:58:46 -05:00
the correct condition is that PADTO cannot be applied to reduce axis, not Reduce.MAX in ops. even for Reduce.SUM it's possible that the reduce axis had a div before, and the padded 0 became inf then sum over it is incorrect.
36 lines
939 B
Python
36 lines
939 B
Python
from tinygrad.tensor import Tensor
|
|
from tinygrad.ops import LoadOps
|
|
from tinygrad.codegen.linearizer import Linearizer
|
|
from test.external.fuzz_linearizer import run_linearizer
|
|
from tinygrad.codegen.kernel import Opt, OptOps
|
|
|
|
N = 17**3
|
|
|
|
a = Tensor.rand(N, N)
|
|
b = Tensor.rand(N, N)
|
|
c = a @ b
|
|
sched = [si for si in c.lazydata.schedule() if si.ast.op not in LoadOps]
|
|
assert len(sched) == 1
|
|
lin = Linearizer(sched[0].ast)
|
|
|
|
lin.apply_opt(Opt(op=OptOps.PADTO, axis=0, amt=32))
|
|
lin.apply_opt(Opt(op=OptOps.PADTO, axis=1, amt=32))
|
|
lin.hand_coded_optimizations()
|
|
lin.linearize()
|
|
print(f"{lin.applied_opts=}")
|
|
|
|
run_linearizer(lin)
|
|
|
|
###
|
|
|
|
a = Tensor.rand(61, 61).sum(axis=0)
|
|
sched = [si for si in a.lazydata.schedule() if si.ast.op not in LoadOps]
|
|
assert len(sched) == 1
|
|
lin = Linearizer(sched[0].ast)
|
|
|
|
lin.apply_opt(Opt(op=OptOps.PADTO, axis=0, amt=32))
|
|
lin.hand_coded_optimizations()
|
|
lin.linearize()
|
|
print(f"{lin.applied_opts=}")
|
|
|
|
run_linearizer(lin) |