Fix cl map buffer (#2190)

* fix gpu enqueue_map_buffer out of space

* add test
This commit is contained in:
nimlgen
2023-10-31 22:02:46 +03:00
committed by GitHub
parent c59ea32f90
commit 8c07c73a9b
3 changed files with 38 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ from tinygrad.ops import GlobalCounters
from tinygrad.runtime.lib import RawBuffer, LRUAllocator
from tinygrad.helpers import dtypes, prod
from tinygrad.ops import Device
from tinygrad.tensor import Tensor
def check_gc():
if Device.DEFAULT == "GPU":
@@ -107,5 +108,29 @@ class TestAllocators(unittest.TestCase):
test()
check_gc()
@unittest.skipUnless(Device.DEFAULT == "GPU", "GPU=1 specific")
def test_gpu_copyout(self):
def test():
from tinygrad.runtime.ops_gpu import CL
# Allocation to init the allocator.
tx = Tensor.rand(1)
tx.realize()
free_space = CL.cl_allocator.free_space[tx.lazydata.realized._device]
# Spawning 128mb objects to fill half of free_space
will_allocate = free_space // 3
trash_allocation_size = free_space // 2
def sp():
trash_buffer = Tensor.rand(trash_allocation_size // 4)
trash_buffer.realize()
sp()
xx = Tensor.rand(will_allocate // 4)
_ = xx.numpy()
test()
check_gc()
if __name__ == "__main__":
unittest.main()