update test_uops_stats for setitem (#14710)

realize both full tensor and the slice should not add to global_mem
This commit is contained in:
chenyu
2026-02-12 12:26:13 -05:00
committed by GitHub
parent 56caf6a3a2
commit 86352988d8

View File

@@ -72,6 +72,7 @@ class TestMemoryCount(unittest.TestCase):
t = Tensor.empty(100, dtype=dtypes.int).realize()
GlobalCounters.reset()
t[20:50] = 3
t.realize()
self.assertEqual(GlobalCounters.global_mem, 30*4) # 30 elements written
def test_setitem_slice_tensor(self):
@@ -79,12 +80,14 @@ class TestMemoryCount(unittest.TestCase):
v = Tensor.empty(30, dtype=dtypes.int).realize()
GlobalCounters.reset()
t[20:50] = v
t.realize()
self.assertEqual(GlobalCounters.global_mem, 30*4*2) # 30 read + 30 written
def test_setitem_full(self):
t = Tensor.empty(100, dtype=dtypes.int).realize()
GlobalCounters.reset()
t[:] = 3
t.realize()
self.assertEqual(GlobalCounters.global_mem, 100*4) # full buffer written
@unittest.skipIf(Device.DEFAULT == "CPU", "test copy to CPU from other device")