mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-04-29 03:00:14 -04:00
fix deallocate for subbuffers (#8701)
* fix deallocate for subbuffers * forgot this * rm name * hmm
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user