2023-10-13 21:32:01 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import unittest
|
|
|
|
from tinygrad.tensor import Tensor
|
2023-11-28 03:34:37 +08:00
|
|
|
from tinygrad import Device
|
2023-10-13 21:32:01 +08:00
|
|
|
|
2023-11-02 14:01:32 +08:00
|
|
|
class TestKernelCache(unittest.TestCase):
|
2023-10-13 21:32:01 +08:00
|
|
|
def test_kernel_cache_in_action(self):
|
|
|
|
if Device.DEFAULT not in ["CLANG"]:
|
|
|
|
self.skipTest("No custom kernel cache is implemented")
|
|
|
|
|
|
|
|
a = Tensor.rand(4,4)
|
|
|
|
b = Tensor.rand(4,4)
|
|
|
|
x = a + b
|
|
|
|
x.realize()
|
|
|
|
|
2023-11-02 14:01:32 +08:00
|
|
|
orig_compile_func = Device['CLANG'].compiler
|
|
|
|
Device['CLANG'].compiler = None # making it not callable
|
2023-10-13 21:32:01 +08:00
|
|
|
|
|
|
|
a1 = Tensor.rand(4,4)
|
|
|
|
b1 = Tensor.rand(4,4)
|
|
|
|
x1 = a1 + b1
|
|
|
|
x1.realize() # Same kernel should be from cache.
|
|
|
|
|
2023-11-02 14:01:32 +08:00
|
|
|
Device['CLANG'].compiler = orig_compile_func
|
2023-10-13 21:32:01 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|