test_kernel_cache_in_action: fix test (#7792)

This commit is contained in:
Gaétan Lepage
2024-11-19 19:34:56 +01:00
committed by GitHub
parent 913a27ee27
commit 159c0bf25e

View File

@@ -8,20 +8,22 @@ class TestKernelCache(unittest.TestCase):
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
unique_const = 0.6765677269
a = Tensor.rand(4,4).realize()
b = Tensor.rand(4,4).realize()
x = a + b + unique_const
x.realize()
a1 = Tensor.rand(4,4).realize()
b1 = Tensor.rand(4,4).realize()
orig_compile_func = Device['CLANG'].compiler
Device['CLANG'].compiler = None # making it not callable
a1 = Tensor.rand(4,4)
b1 = Tensor.rand(4,4)
x1 = a1 + b1
x1.realize() # Same kernel should be from cache.
Device['CLANG'].compiler = orig_compile_func
try:
x1 = a1 + b1 + unique_const
x1.realize() # Same kernel should be from cache.
finally:
Device['CLANG'].compiler = orig_compile_func
if __name__ == "__main__":
unittest.main()