test_kernel_cache.py 697 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env python
  2. import unittest
  3. from tinygrad.tensor import Tensor
  4. from tinygrad import Device
  5. class TestKernelCache(unittest.TestCase):
  6. def test_kernel_cache_in_action(self):
  7. if Device.DEFAULT not in ["CLANG"]:
  8. self.skipTest("No custom kernel cache is implemented")
  9. a = Tensor.rand(4,4)
  10. b = Tensor.rand(4,4)
  11. x = a + b
  12. x.realize()
  13. orig_compile_func = Device['CLANG'].compiler
  14. Device['CLANG'].compiler = None # making it not callable
  15. a1 = Tensor.rand(4,4)
  16. b1 = Tensor.rand(4,4)
  17. x1 = a1 + b1
  18. x1.realize() # Same kernel should be from cache.
  19. Device['CLANG'].compiler = orig_compile_func
  20. if __name__ == "__main__":
  21. unittest.main()