failing test for UOp buffer ref count (#9563)

* failing test for UOp buffer ref count

* lint
This commit is contained in:
qazal
2025-03-25 00:10:48 +08:00
committed by GitHub
parent f90001e1a6
commit d7c754ce49

View File

@@ -79,5 +79,22 @@ class TestGC(unittest.TestCase):
print(inspect.getclosurevars(UOp.toposort.fget))
raise AssertionError(f"never gced {[x for x in gc.get_objects() if isinstance(x, Buffer)]}")
def test_buffer_refcount(self):
init = bufs_allocated()
a = Tensor.empty(10)
self.assertEqual(bufs_allocated()-init, 0)
a.realize()
real_buf = a.lazydata.buffer
# after the Tensor UOp is deleted there shouldn't be any references on the Buffer
with self.assertRaises(AssertionError):
self.assertEqual(real_buf.lb_refcount, 1)
self.assertEqual(bufs_allocated()-init, 1)
del a.lazydata
with self.assertRaises(AssertionError):
self.assertEqual(real_buf.lb_refcount, 0)
self.assertEqual(bufs_allocated()-init, 1) # keep the buffer alive
del real_buf
self.assertEqual(bufs_allocated()-init, 0)
if __name__ == '__main__':
unittest.main()