File tree 1 file changed +17
-0
lines changed
1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -79,5 +79,22 @@ def test_toposort_blocks_gc(self):
79
79
print (inspect .getclosurevars (UOp .toposort .fget ))
80
80
raise AssertionError (f"never gced { [x for x in gc .get_objects () if isinstance (x , Buffer )]} " )
81
81
82
+ def test_buffer_refcount (self ):
83
+ init = bufs_allocated ()
84
+ a = Tensor .empty (10 )
85
+ self .assertEqual (bufs_allocated ()- init , 0 )
86
+ a .realize ()
87
+ real_buf = a .lazydata .buffer
88
+ # after the Tensor UOp is deleted there shouldn't be any references on the Buffer
89
+ with self .assertRaises (AssertionError ):
90
+ self .assertEqual (real_buf .lb_refcount , 1 )
91
+ self .assertEqual (bufs_allocated ()- init , 1 )
92
+ del a .lazydata
93
+ with self .assertRaises (AssertionError ):
94
+ self .assertEqual (real_buf .lb_refcount , 0 )
95
+ self .assertEqual (bufs_allocated ()- init , 1 ) # keep the buffer alive
96
+ del real_buf
97
+ self .assertEqual (bufs_allocated ()- init , 0 )
98
+
82
99
if __name__ == '__main__' :
83
100
unittest .main ()
You can’t perform that action at this time.
0 commit comments