add test coverage for search (#2104)

* add test coverage for search

* only in compiled backends

* dont use device.default in decorator

* time_til is the other way around xd
This commit is contained in:
qazal 2023-10-19 20:06:47 -04:00 committed by GitHub
parent 7268b3c6fb
commit 36d4001b4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

16
test/test_search.py Normal file
View File

@ -0,0 +1,16 @@
import unittest
from tinygrad.codegen.linearizer import Linearizer
from tinygrad.features.search import time_linearizer
from tinygrad.ops import Compiled, Device, LoadOps
from tinygrad.tensor import Tensor
class TestTimeLinearizer(unittest.TestCase):
def setUp(self) -> None:
if not isinstance(Device[Device.DEFAULT], Compiled): raise unittest.SkipTest("only test for compiled backends")
def test_reasonable_time(self):
si = [si for si in Tensor([1,2,3,4]).add(1).lazydata.schedule() if si.ast.op not in LoadOps][0]
rawbufs = [Device[Device.DEFAULT].buffer(si.out.st.size(), si.out.dtype)] + [Device[Device.DEFAULT].buffer(x.st.size(), x.dtype) for x in si.inputs]
tm = time_linearizer(Linearizer(si.ast), rawbufs, allow_test_size=False, cnt=10, should_copy=False)
assert tm > 0 and tm != float('inf')

View File

@ -33,7 +33,7 @@ if getenv("CUDACPU", 0) == 1:
class Event:
def __init__(self): pass
def record(self): self.start = time.perf_counter()
def time_till(self, other): return self.start - other.start
def time_till(self, other): return other.start - self.start
def synchronize(self): pass
class Context:
synchronize = lambda:0 # noqa: E731