mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-10 06:23:43 +08:00
22a8575199
Keep official openpilot ancestry and dependency licenses. Store resources directly in Git, remove LFS setup requirements, and leave the downloadable big model outside the source tree.
46 lines
1.8 KiB
Python
46 lines
1.8 KiB
Python
import unittest
|
|
from tinygrad import Tensor, Context, Device
|
|
from tinygrad.codegen import to_program
|
|
from tinygrad.codegen.opt import Opt, OptOps
|
|
from tinygrad.uop.ops import KernelInfo, AxisType
|
|
|
|
class TestLinearizerRewrite(unittest.TestCase):
|
|
def test_reduction(self):
|
|
t = Tensor.ones((64,64), device="NULL").contiguous().realize()
|
|
out = (t*2).sum(axis=1)
|
|
with Context(SPLIT_REDUCEOP=0):
|
|
si = out.schedule_linear().src[-1]
|
|
opts_to_apply = []
|
|
opts_to_apply.append(Opt(OptOps.SPLIT, 0, (4, AxisType.UPCAST)))
|
|
opts_to_apply.append(Opt(OptOps.SPLIT, 2, (4, AxisType.UNROLL)))
|
|
ast = si.src[0].replace(arg=KernelInfo(opts_to_apply=tuple(opts_to_apply)))
|
|
prg = to_program(ast, Device["CPU"].renderer)
|
|
print(prg.src[2].arg)
|
|
|
|
def test_arange(self):
|
|
out = Tensor.arange(32).clone("NULL")
|
|
with Context(SPLIT_REDUCEOP=0):
|
|
si = out.schedule_linear().src[-1]
|
|
opts_to_apply = []
|
|
opts_to_apply.append(Opt(OptOps.SPLIT, 0, (4, AxisType.UPCAST)))
|
|
ast = si.src[0].replace(arg=KernelInfo(opts_to_apply=tuple(opts_to_apply)))
|
|
prg = to_program(ast, Device["CPU"].renderer)
|
|
print(prg.src[2].arg)
|
|
|
|
def test_kernel_info(self):
|
|
out = Tensor.arange(4).clone("NULL")
|
|
si = out.schedule_linear().src[-1]
|
|
|
|
ast = si.src[0].replace(arg=KernelInfo(opts_to_apply=()))
|
|
prg = to_program(ast, Device["CPU"].renderer)
|
|
assert prg.src[0].arg.applied_opts == (), f"expected no opts, got {prg}"
|
|
|
|
#prg = to_program(ast.replace(arg=KernelInfo()), Device["CPU"].renderer)
|
|
#assert prg.src[0].arg.applied_opts != (), f"expected opts to apply, got {prg.src[0].arg.applied_opts}"
|
|
|
|
prg = to_program(ast.replace(arg=KernelInfo(name="custom")), Device["CPU"].renderer)
|
|
self.assertEqual(prg.src[0].arg.name, "custom")
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|