fix deallocate for subbuffers (#8701)

* fix deallocate for subbuffers

* forgot this

* rm name

* hmm
This commit is contained in:
nimlgen
2025-01-21 16:34:19 +03:00
committed by GitHub
parent 6733a3a96b
commit 3628f89929
3 changed files with 22 additions and 4 deletions

View File

@@ -2,6 +2,7 @@ import unittest
from tinygrad import Device, dtypes, Tensor
from tinygrad.device import Buffer
from tinygrad.ops import view_supported_devices
from tinygrad.helpers import Context
@unittest.skipIf(Device.DEFAULT not in view_supported_devices, "subbuffer not supported")
class TestSubBuffer(unittest.TestCase):
@@ -47,5 +48,22 @@ class TestSubBuffer(unittest.TestCase):
out = vt.to(f"{Device.DEFAULT}:1").realize().tolist()
assert out == [2, 3, 4]
def test_subbuffer_deallocate(self):
with Context(LRU=0):
vbuf = self.buf.view(2, dtypes.uint8, offset=3).ensure_allocated()
self.buf.deallocate()
vbuf.deallocate()
# Allocate a fake one on the same place
_ = Buffer(Device.DEFAULT, 10, dtypes.uint8).ensure_allocated()
self.buf.ensure_allocated()
self.buf.copyin(memoryview(bytearray(range(10, 20))))
vbuf.ensure_allocated()
tst = vbuf.as_buffer().tolist()
assert tst == [13, 14]
if __name__ == '__main__':
unittest.main()